MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / toDataURL

Method toDataURL

src/common/overlay/levelRenderer/Painter.js:622–670  ·  view source on GitHub ↗

* @function LevelRenderer.Painter.prototype.toDataURL * @description 图像导出。 * @param {string} type - 图片类型。 * @param {string} backgroundColor - 背景色。默认值:'#fff'。 * @param {Object} args * @return {string} 图片的 Base64 URL。

(type, backgroundColor, args)

Source from the content-addressed store, hash-verified

620 * @return {string} 图片的 Base64 URL。
621 */
622 toDataURL(type, backgroundColor, args) {
623 //var imageDom = Painter.createDom('image', 'canvas', this);
624 var imageDom = Painter.createDom(CommonUtil.createUniqueID("SuperMap.Theme.image_"), 'canvas', this);
625 this._bgDom.appendChild(imageDom);
626 var ctx = imageDom.getContext('2d');
627 Painter.devicePixelRatio != 1
628 && ctx.scale(Painter.devicePixelRatio, Painter.devicePixelRatio);
629
630 ctx.fillStyle = backgroundColor || '#fff';
631 ctx.rect(
632 0, 0,
633 this._width * Painter.devicePixelRatio,
634 this._height * Painter.devicePixelRatio
635 );
636 ctx.fill();
637
638 var self = this;
639 // 升序遍历,shape上的zlevel指定绘画图层的z轴层叠
640
641 this.storage.iterShape(
642 function (shape) {
643 if (!shape.invisible) {
644 if (!shape.onbrush // 没有onbrush
645 // 有onbrush并且调用执行返回false或undefined则继续粉刷
646 || (shape.onbrush && !shape.onbrush(ctx, false))
647 ) {
648 if (Config.catchBrushException) {
649 try {
650 shape.brush(ctx, false, self.updatePainter);
651 } catch (error) {
652 SUtil.Util_log(
653 error,
654 'brush error of ' + shape.type,
655 shape
656 );
657 }
658 } else {
659 shape.brush(ctx, false, self.updatePainter);
660 }
661 }
662 }
663 },
664 {normal: 'up', update: true}
665 );
666 var image = imageDom.toDataURL(type, args);
667 ctx = null;
668 this._bgDom.removeChild(imageDom);
669 return image;
670 }
671
672
673 /**

Callers

nothing calls this directly

Calls 6

createDomMethod · 0.80
iterShapeMethod · 0.80
removeChildMethod · 0.80
getContextMethod · 0.45
scaleMethod · 0.45
brushMethod · 0.45

Tested by

no test coverage detected