MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / getCanvas

Method getCanvas

src/openlayers/core/StyleUtils.js:741–779  ·  view source on GitHub ↗

* 获取文字标注对应的canvas * @param style * @returns {{canvas: *, width: number, height: number}}

(style)

Source from the content-addressed store, hash-verified

739 * @returns {{canvas: *, width: number, height: number}}
740 */
741 static getCanvas(style) {
742 let canvas;
743 if (style.canvas) {
744 if (document.querySelector("#" + style.canvas)) {
745 canvas = document.getElemntById(style.canvas);
746 } else {
747 canvas = this.createCanvas(style);
748 }
749 } else {
750 //不存在canvas,当前feature
751 canvas = this.createCanvas(style);
752 style.canvas = canvas.id;
753 }
754 canvas.style.display = "none";
755 var ctx = canvas.getContext("2d");
756 //行高
757 let lineHeight = Number(style.font.replace(/[^0-9]/ig, ""));
758 let textArray = style.text.split('\r\n');
759 let lenght = textArray.length;
760 //在改变canvas大小后再绘制。否则会被清除
761 ctx.font = style.font;
762 let size = this.drawRect(ctx, style, textArray, lineHeight, canvas);
763 this.positionY = padding;
764 if (lenght > 1) {
765 textArray.forEach(function (text, i) {
766 if (i !== 0) {
767 this.positionY = this.positionY + lineHeight;
768 }
769 this.canvasTextAutoLine(text, style, ctx, lineHeight, size.width);
770 }, this);
771 } else {
772 this.canvasTextAutoLine(textArray[0], style, ctx, lineHeight, size.width);
773 }
774 return {
775 canvas: canvas,
776 width: size.width,
777 height: size.height
778 };
779 }
780 /**
781 * 创建当前feature对应的canvas
782 * @param {Object} style

Callers 12

toOpenLayersStyleMethod · 0.95
ThreeLayerSpec.jsFile · 0.45
MapVLayerSpec.jsFile · 0.45
GraphicSpec.jsFile · 0.45
ThreeLayerSpec.jsFile · 0.45
StyleUtils2Spec.jsFile · 0.45
getContextMethod · 0.45
mapv.min.jsFile · 0.45
mapv.jsFile · 0.45
ol.jsFile · 0.45

Calls 5

createCanvasMethod · 0.95
drawRectMethod · 0.95
canvasTextAutoLineMethod · 0.95
forEachMethod · 0.80
getContextMethod · 0.45

Tested by

no test coverage detected