2011-04-19 48 views
2

我是很新的打開圖層,但我從畫線和polygones的幫助已經suceeded:http://openlayers.org/dev/examples/draw-feature.html從現有生產線獲取座標中打開圖層

我不知道如何獲得的經度和緯度,從矢量? 我看到一個解釋這裏:how to get co-ordinates of vector layer line points from openlayers? 但我新,使其工作。

任何人都可以幫助我的代碼或提供一個例子嗎?

編輯: 這裏是解決方案。

function lineAdded(feature) { 
    var nodes = feature.geometry.getVertices(); 

    for (var i=0; i<nodes.length; i++) { 
    var lon = nodes[i].x; 
    var lat = nodes[i].y; 
    console.log("lon: "+lon+", lat"+lat); 
    } 
} 
lineControl = new OpenLayers.Control.DrawFeature(vectors, path, {'featureAdded': lineAdded}); 

回答

0

喜 你可以把你的觀點feauture:

map.vectorLayer.features[i] 

您可以選擇逐個您的載體功能,以供循環... 但所有的第一移動你想要做的?喲想選擇點功能或其他的東西?

+0

你好,感謝您的回覆。基本上我想要做的是存儲LonLat座標供以後使用。我通過添加一個回調來成功。 'code'function lineAdded(feature){ var nodes = feature.geometry.getVertices(); 爲(VAR I = 0; I 2011-04-19 10:47:20

+0

看起來好像你在這個循環則座標?那你在哪裏遇到麻煩? – 2011-04-19 11:29:45

+0

實際上,代碼解決了它!所以沒有更多的麻煩。我只是想我可以更好地格式化代碼,以便其他人可以使用它,因爲我之前看到過這個問題,但沒有真正簡單的解決方案。 – 2011-04-19 11:47:36