Tuesday, 19 November 2019

Leaflet layers on different zoom levels. How?


I've added a polygon layer and a point layer to my leaflet map.


I would like the points to appear after a certain zoom level or when a "click" event occurs e.g. (polygons.on("click", function....)


I have looked at different questions here and also this example


But I am still unable to understand what to do in my code.


Here is my code:




Answer



okay. I would go like this:


map.on('zoomend', function() {
var zoomlevel = map.getZoom();
if (zoomlevel <10){
if (map.hasLayer(points)) {
map.removeLayer(points);
} else {

console.log("no point layer active");
}
}
if (zoomlevel >= 10){
if (map.hasLayer(points)){
console.log("layer already added");
} else {
map.addLayer(points);
}
}

console.log("Current Zoom Level =" + zoomlevel)
});

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...