我正在尝试使用 openlayers 中的方形多边形来获取边界框。我需要从框中获取 North、South、West 和 East 值。现在我正在使用:
var topleft = vectors.features[0].geometry.getVertices()[0];
得到左上角的顶点。但是它返回一个这样的值:
POINT(-13393350.718762 4024321.5982824)
我怎样才能从这个返回点获得纬度和经度值?
最佳答案
您拥有的一种选择是使用 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
关于OpenLayers 从多边形顶点获取纬度、经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8434261/