* @function Label.prototype.getLabelPxLocation * @description 获取标签要素的像素坐标。 * @param {FeatureVector} feature - 标签要素。 * @returns {Object} 标签位置,例如:{"x":1,"y":1}。
(feature)
| 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 | /** |
no test coverage detected