Aucune description

index.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var validator_1 = require("../../utils/validator");
  4. var Synthetizer = (function () {
  5. function Synthetizer() {
  6. }
  7. Synthetizer.prototype.rasterize = function (target, markerImage, done) {
  8. if (!validator_1.isHTMLImageElement(target)) {
  9. throw new Error('Error: only support export to HTMLImageElement');
  10. }
  11. var canvas = document.createElement('canvas');
  12. canvas.width = markerImage.width.baseVal.value;
  13. canvas.height = markerImage.height.baseVal.value;
  14. var data = markerImage.outerHTML;
  15. var ctx = canvas.getContext('2d');
  16. if (!ctx) {
  17. throw new Error('Invalid ctx');
  18. }
  19. ctx.drawImage(target, 0, 0, canvas.width, canvas.height);
  20. var DOMURL = window.URL;
  21. var img = new Image(canvas.width, canvas.height);
  22. img.setAttribute('crossOrigin', 'anonymous');
  23. var blob = new Blob([data], { type: 'image/svg+xml' });
  24. var url = DOMURL.createObjectURL(blob);
  25. img.onload = function () {
  26. ctx.drawImage(img, 0, 0);
  27. DOMURL.revokeObjectURL(url);
  28. done(canvas.toDataURL('image/png'));
  29. };
  30. img.src = url;
  31. };
  32. return Synthetizer;
  33. }());
  34. exports.Synthetizer = Synthetizer;