Openlayers獲取鼠標點擊時的經緯度


在Openlayers點擊事件中,常常需要獲取當前點擊點的經緯度,可以用此方法獲取:

map.events.register('click', map, function (e) {
        var pixel = new OpenLayers.Pixel(e.xy.x,e.xy.y);
        var lonlat = map.getLonLatFromPixel(pixel);
        lonlat.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326")); //由900913坐標系轉為4326
     alert(lonlat.lon+", "+lonlat.lat);
})

 

End.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM