Leaflet獲取可視范圍內4個頂點


//地圖級別改變時發生
map.on("zoomend", function (e) {
var zoom_val = e.target.getZoom();
map_drag();;
});
//拖動地圖時發生
map.on("moveend", function (e) {
map_drag();;
});

function map_drag() {
//左下角坐標(西南方)
var leftdown = map.getBounds().getSouthWest().lng + "," + map.getBounds().getSouthWest().lat;
L.circleMarker([map.getBounds().getSouthWest().lat, map.getBounds().getSouthWest().lng], { fillColor: "#f00", radius: 10 }).bindLabel("左下角坐標" + leftdown, { direction: 'right', noHide: true }).addTo(map);
//右上角坐標(東北方向)
var rightdown = map.getBounds().getNorthEast().lng + "," + map.getBounds().getNorthEast().lat;
L.circleMarker([map.getBounds().getNorthEast().lat, map.getBounds().getNorthEast().lng], { fillColor: "#f00", radius: 10 }).bindLabel("右上角坐標" + rightdown, { direction: 'left', noHide: true }).addTo(map);
//var strText = "當前地圖級別:" + zoom_val + " 左下角坐標:" + leftdown + " 右下角坐標:" + rightdown;
//左上角:西北方
var leftdown = map.getBounds().getNorthWest().lng + "," + map.getBounds().getNorthWest().lat;
L.circleMarker([map.getBounds().getNorthWest().lat, map.getBounds().getNorthWest().lng], { fillColor: "#f00", radius: 10 }).bindLabel("左上角坐標" + leftdown, { direction: 'right', noHide: true }).addTo(map);

//右下角:東南方
var leftdown = map.getBounds().getSouthEast().lng + "," + map.getBounds().getSouthEast().lat;
L.circleMarker([map.getBounds().getSouthEast().lat, map.getBounds().getSouthEast().lng], { fillColor: "#f00", radius: 10 }).bindLabel("右下角坐標" + leftdown, { direction: 'left', noHide: true }).addTo(map);

}


免責聲明!

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



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