我正在尝试在 openlayers 中使用方形多边形来获取边界框。我需要从框中获取 North、South、West 和 East 值。现在我正在使用:
var topleft = vectors.features[0].geometry.getVertices()[0];
得到左上角的顶点。但是它返回一个像这样的值:
POINT(-13393350.718762 4024321.5982824)
如何从该返回点获取 lat 和 lon 值?
我正在尝试在 openlayers 中使用方形多边形来获取边界框。我需要从框中获取 North、South、West 和 East 值。现在我正在使用:
var topleft = vectors.features[0].geometry.getVertices()[0];
得到左上角的顶点。但是它返回一个像这样的值:
POINT(-13393350.718762 4024321.5982824)
如何从该返回点获取 lat 和 lon 值?
您拥有的一个选项是使用 getVertices()[i] 生成一个点
var myPoint = new OpenLayers.Geometry.Point(vectors.features[0].geometry.getVertices()[0].x,
vectors.features[0].geometry.getVertices()[0].y )
然后转换该点以获得 Lat 和 Long 类似的东西
var myLatLonPoint = myPoint.transform( map.getProjectionObject(),
new OpenLayers.Projection("EPSG:4326"));
然后你应该能够从这些点中获取经纬度。
另一种可能更可取的选择是转换边界,然后拉出各个顶点。
var myLatLonSquare = vectors.features[0].geometry.transform( map.getProjectionObject(),
new OpenLayers.Projection("EPSG:4326"));
然后用以下方法拉出顶点的纬度:
myLatLonSquare.getVertices()[0].x myLatLonSquare.getVertices()[0].y