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