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

Method brush

src/common/overlay/levelRenderer/SmicText.js:58–275  ·  view source on GitHub ↗

* @function LevelRenderer.Shape.SmicText.prototype.brush * @description 笔触。 * * @param {CanvasRenderingContext2D} ctx - Context2D 上下文。 * @param {boolean} isHighlight - 是否使用高亮属性。 *

(ctx, isHighlight)

Source from the content-addressed store, hash-verified

56 *
57 */
58 brush(ctx, isHighlight) {
59 if (!this.refOriginalPosition || this.refOriginalPosition.length !== 2) {
60 this.refOriginalPosition = [0, 0];
61 }
62 var __OP = this.refOriginalPosition;
63
64 var style = this.style;
65 if (isHighlight) {
66 // 根据style扩展默认高亮样式
67 style = this.getHighlightStyle(
68 style, this.highlightStyle || {}
69 );
70 }
71
72 if (typeof(style.text) == 'undefined' || style.text === false) {
73 return;
74 }
75
76 ctx.save();
77 this.doClip(ctx);
78
79 this.setContext(ctx, style);
80
81 // 设置transform
82 this.setTransform(ctx);
83
84 if (style.textFont) {
85 ctx.font = style.textFont;
86 }
87 ctx.textAlign = style.textAlign || 'start';
88 ctx.textBaseline = style.textBaseline || 'middle';
89
90 var text = (style.text + '').split('\n');
91 var lineHeight = SUtil.Util_area.getTextHeight('ZH', style.textFont);
92 var rect = this.getRectNoRotation(style);
93 // var x = style.x;
94 var x = style.x + __OP[0];
95 var y;
96 if (style.textBaseline == 'top') {
97 y = rect.y;
98 } else if (style.textBaseline == 'bottom') {
99 y = rect.y + lineHeight;
100 } else {
101 y = rect.y + lineHeight / 2;
102 }
103 var ox = style.x + __OP[0];
104 var oy = style.y + __OP[1];
105
106 //文本绘制
107 for (var i = 0, l = text.length; i < l; i++) {
108 //是否渲染矩形背景及颜色
109 if (style.labelRect) {
110 //+4,-2是为了让文字距边框左右边缘有点间隔
111 ctx.fillRect(rect.x - 2, rect.y, rect.width + 4, rect.height);
112 ctx.fillStyle = style.strokeColor;
113 ctx.strokeRect(rect.x - 2, rect.y, rect.width + 4, rect.height);
114 ctx.fillStyle = style.textColor;
115 }

Callers

nothing calls this directly

Calls 11

getRectNoRotationMethod · 0.95
getHighlightStyleMethod · 0.80
saveMethod · 0.80
doClipMethod · 0.80
setContextMethod · 0.80
setTransformMethod · 0.80
getTextHeightMethod · 0.80
setCtxGlobalAlphaMethod · 0.80
translateMethod · 0.80
restoreMethod · 0.80
rotateMethod · 0.45

Tested by

no test coverage detected