2011-12-08 61 views
4

我試圖讓使用的OpenLayers一個正方形多邊形的邊界框。我需要從箱子中獲得北,南,西,東價值。現在我正在使用:的OpenLayers從多邊形頂點獲得緯度,經度

var topleft = vectors.features[0].geometry.getVertices()[0]; 

得到左上角的頂點。但是它返回的值如下:

POINT(-13393350.718762 4024321.5982824) 

如何從此返回點獲取經度和緯度值?你必須使用getVertices()

+0

什麼是自己的OpenLayers的投影圖? – AlexC

+0

@AlexC它使用墨卡託投影。我不需要幫助轉換。我只是堅持如何從返回的值「POINT(-13393350.718762 4024321.5982824)」獲取緯度/經度值 – gberg927

回答

6

一種選擇[I],生成點

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

然後變換點獲得緯度和長着像

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