* @function FeatureTheme.prototype.getLocalXY * @description 地理坐标转为像素坐标。 * @param {GeometryPoint|GeometryGeoText|LonLat} coordinate - 地理坐标点。 * @returns {Array. } 长度为 2 的像素坐标数组,第一个元素表示 x 坐标,第二个元素表示 y 坐标。
(coordinate)
| 92 | * @returns {Array.<number>} 长度为 2 的像素坐标数组,第一个元素表示 x 坐标,第二个元素表示 y 坐标。 |
| 93 | */ |
| 94 | getLocalXY(coordinate) { |
| 95 | var resolution = this.layer.map.getResolution(); |
| 96 | var extent = this.layer.map.getExtent(); |
| 97 | |
| 98 | if (coordinate instanceof Point || coordinate instanceof GeoText) { |
| 99 | let x = (coordinate.x / resolution + (-extent.left / resolution)); |
| 100 | let y = ((extent.top / resolution) - coordinate.y / resolution); |
| 101 | return [x, y]; |
| 102 | } else if (coordinate instanceof LonLat) { |
| 103 | let x = (coordinate.lon / resolution + (-extent.left / resolution)); |
| 104 | let y = ((extent.top / resolution) - coordinate.lat / resolution); |
| 105 | return [x, y]; |
| 106 | } else { |
| 107 | return null; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | } |