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

Method getLabelPxLocation

src/openlayers/overlay/Label.js:453–472  ·  view source on GitHub ↗

* @function Label.prototype.getLabelPxLocation * @description 获取标签要素的像素坐标。 * @param {FeatureVector} feature - 标签要素。 * @returns {Object} 标签位置,例如:{"x":1,"y":1}。

(feature)

Source from the content-addressed store, hash-verified

451 * @returns {Object} 标签位置,例如:{"x":1,"y":1}。
452 */
453 getLabelPxLocation(feature) {
454 var geoText = feature.geometry;
455 var styleTmp = feature.style;
456
457 //将标签的地理位置转为像素位置
458 var locationTmp = geoText.getCentroid();
459 var locTmp = this.map.getPixelFromCoordinate([locationTmp.x, locationTmp.y]);
460 var loc = new Point([locTmp[0], locTmp[1]]);
461
462 //偏移处理
463 if (styleTmp.labelXOffset || styleTmp.labelYOffset) {
464 var xOffset = isNaN(styleTmp.labelXOffset) ? 0 : styleTmp.labelXOffset;
465 var yOffset = isNaN(styleTmp.labelYOffset) ? 0 : styleTmp.labelYOffset;
466 loc.translate(xOffset, -yOffset);
467 }
468 return {
469 x: loc.getCoordinates()[0],
470 y: loc.getCoordinates()[1]
471 };
472 }
473
474
475 /**

Callers 5

getDrawnLabelsMethod · 0.95
LabelSpec.jsFile · 0.45
LabelThemeLayer.jsFile · 0.45

Calls 2

getCentroidMethod · 0.80
translateMethod · 0.80

Tested by

no test coverage detected