OpenLayers从多边形顶点获取Lat,Lon

gbe*_*927 4 polygon vertices latitude-longitude openlayers

我试图在openlayers中使用方形多边形来获取边界框.我需要从框中获取北,南,西和东的价值.现在我正在使用:

var topleft = vectors.features[0].geometry.getVertices()[0];
Run Code Online (Sandbox Code Playgroud)

得到左上角的顶点.但是它返回一个这样的值:

POINT(-13393350.718762 4024321.5982824)
Run Code Online (Sandbox Code Playgroud)

如何从此返回点获取lat和lon值?

Ale*_*exC 6

您有一个选择是使用getVertices()[i]生成一个点

var myPoint = new OpenLayers.Geometry.Point(vectors.features[0].geometry.getVertices()[0].x,
                              vectors.features[0].geometry.getVertices()[0].y )
Run Code Online (Sandbox Code Playgroud)

然后将这一点转换为Lat和Long

var myLatLonPoint = myPoint.transform( map.getProjectionObject(),
                   new OpenLayers.Projection("EPSG:4326"));
Run Code Online (Sandbox Code Playgroud)

那么你应该能够从那些点抓住纬度和长度.

可能更可取的另一种选择是变换边界然后拉出各个顶点.

var myLatLonSquare = vectors.features[0].geometry.transform( map.getProjectionObject(),
                   new OpenLayers.Projection("EPSG:4326"));
Run Code Online (Sandbox Code Playgroud)

然后用以下方法拉出lat的顶点:

myLatLonSquare.getVertices()[0].x  myLatLonSquare.getVertices()[0].y
Run Code Online (Sandbox Code Playgroud)