Table of Contents
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
ms_url='http://'+hname+':9999/geoserver/kcn_v3/wms?'; function Identify(e){ // set parameters needed for GetFeatureInfo WMS request var BBOX = map.getBounds().toBBoxString(); var WIDTH = map.getSize().x; var HEIGHT = map.getSize().y; var X = map.layerPointToContainerPoint(e.layerPoint).x; var Y = map.layerPointToContainerPoint(e.layerPoint).y; // compose the URL for the request var URL=ms_url+'SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image/png&TRANSPARENT=true&QUERY_LAYERS=kcnlongan_v3:cumcongnghiep_duchoadong,kcnlongan_v3:cumcongnghiep_duchoaha&INFO_FORMAT=application/json&FEATURE_COUNT=50&X='+X+'&Y='+Y+'&SRS=EPSG:4326&WIDTH='+WIDTH+'&HEIGHT='+HEIGHT+'&BBOX='+BBOX; //send the asynchronous HTTP request using jQuery $.ajax $.ajax({ url: URL, //dataType: "html", type: "GET", success: function(data) { var popup = new L.Popup ({ maxWidth: 300 }); popup.setContent(jsontotxt(data)); popup.setLatLng(e.latlng); map.openPopup(popup); } }); } map.on('click', Identify);--note vậy thôi, mốt làm lại vô xem cho nhanh =)) -soiqualang_chentreu-]]>