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

Method getTextHeight

src/common/overlay/levelRenderer/Area.js:1045–1072  ·  view source on GitHub ↗

* @function LevelRenderer.Tool.Areal.prototype.getTextHeight * @description 测算多行文本高度

(text, textFont)

Source from the content-addressed store, hash-verified

1043 * @description 测算多行文本高度
1044 */
1045 getTextHeight(text, textFont) {
1046 var key = text + ':' + textFont;
1047 if (this._textHeightCache[key]) {
1048 return this._textHeightCache[key];
1049 }
1050
1051 this._ctx = this._ctx || this.util.getContext();
1052
1053 this._ctx.save();
1054 if (textFont) {
1055 this._ctx.font = textFont;
1056 }
1057
1058 text = (text + '').split('\n');
1059 // 比较粗暴
1060 //var height = (this._ctx.measureText('国').width + 2) * text.length; //打包不支持中文,替换掉
1061 var height = (this._ctx.measureText('ZH').width + 2) * text.length;
1062
1063 this._ctx.restore();
1064
1065 this._textHeightCache[key] = height;
1066 if (++this._textHeightCacheCounter > this.TEXT_CACHE_MAX) {
1067 // 内存释放
1068 this._textHeightCacheCounter = 0;
1069 this._textHeightCache = {};
1070 }
1071 return height;
1072 }
1073}

Callers 4

brushMethod · 0.80
getRectNoRotationMethod · 0.80
_fillTextMethod · 0.80
_getTextRectMethod · 0.80

Calls 3

saveMethod · 0.80
restoreMethod · 0.80
getContextMethod · 0.45

Tested by

no test coverage detected