4

How to set up a maximal zoom for some layer, for example state polygons? I need that my US polygons which represent states have maxZoom 6, and when zoomed higher than 6, that US counties show up instead of states. Is that possible in Leaflet? All states are defined like Leaflet polygons.

Thanks in advance.

1 Answer 1

2

It sounds like you want to toggle the state info off and turn on counties when zoomed in to a certain zoom level. This should be simple all you need to do is listen to the zoomend event then toggle the layers based on the zoom level. Here is some pseudo code.

map.on('zoomend', function(e){
    var zoomLevel = map.getZoom();
    if(zoomLevel == 6){
       //then toggle vibility or add/remove the desired layers
    }
    else{
       //Do the opposite
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.