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

Method _getTextRect

src/common/overlay/levelRenderer/Shape.js:876–908  ·  view source on GitHub ↗

* @function LevelRenderer.Shape._getTextRect * @description 返回矩形区域,用于局部刷新和文字定位 * * @param {string} text - text。 * @param {number} x - x。 * @param {number} y - y。 * @param {string} textFont - textFont。 * @param {string} textAlign - textAlign。 * @param {string}

(text, x, y, textFont, textAlign, textBaseline)

Source from the content-addressed store, hash-verified

874 * @return {Object} 矩形区域。
875 */
876 static _getTextRect(text, x, y, textFont, textAlign, textBaseline) {
877 var width = SUtil.Util_area.getTextWidth(text, textFont);
878 var lineHeight = SUtil.Util_area.getTextHeight('ZH', textFont);
879
880 text = (text + '').split('\n');
881
882 switch (textAlign) {
883 case 'end':
884 case 'right':
885 x -= width;
886 break;
887 case 'center':
888 x -= (width / 2);
889 break;
890 }
891
892 switch (textBaseline) {
893 case 'top':
894 break;
895 case 'bottom':
896 y -= lineHeight * text.length;
897 break;
898 default:
899 y -= lineHeight * text.length / 2;
900 }
901
902 return {
903 x: x,
904 y: y,
905 width: width,
906 height: lineHeight * text.length
907 };
908 }
909
910}

Callers 1

_fillTextMethod · 0.80

Calls 2

getTextWidthMethod · 0.80
getTextHeightMethod · 0.80

Tested by

no test coverage detected