[Note] Một số ghi chú về Leaflet

Hôm qua sửa cái WebMap dùng leaflet, sẵn note lại một số cái hay dùng

Add layer

map.addLayer(kcnlonghaujson);

Remove layer

map.removeLayer(maplayer);

Check if layer is added

map.hasLayer(khucongnghiepjson);

//return true/false

Zoom event

map.on(‘zoomend’, function() {
var zoomlevel=map.getZoom();
var is_added=map.hasLayer(khucongnghiepjson);
if((zoomlevel<=14) && (is_added==false)){
map.addLayer(khucongnghiepjson);
removeall();
}
console.log(zoomlevel);
console.log(is_added);
});

Zoom to location

map.setView([10.77894,106.48133],16)

//16 is zoom level

Zoom to extent/bounds

function zoomtoext(n1,n2,n3,n4){
var southWest = new L.LatLng(n1,n2),
northEast = new L.LatLng(n3,n4),
bounds = new L.LatLngBounds(southWest, northEast);
map.fitBounds(bounds);

//map.fitBounds([106.486448568691,10.6007400693728][106.501824300484,10.6177644165618]);
/* zoomtoext(106.486448568691,10.6007400693728,106.501824300484,10.6177644165618);
map.fitBounds([
[-4.8587000, 39.8772333]
[-6.4917667, 39.0945000]
]);
*/
}

Get WMS FeatureInfo

 

–note vậy thôi, mốt làm lại vô xem cho nhanh =))

-soiqualang_chentreu-