0

I'd like to use, say, a circle or map pin when zoomed out, and for this to change to a polygon / shapefile when zoomed in (specifying the zoom level at which the change occurs).

Can Leaflet do this?

2

This should get you started, might need some adaption to your usecase:

map.on('zoomend', function() {                        //triggers after zoom event
        if (map.getZoom() <x){                        //where x is the zoom level where the change occurs
                map.removeLayer(yourPolygon);
        }
        else {
                map.addLayer(yourMarker);
        }
    }
);
| improve this answer | |
  • 2
    In a (very small) nutshell, this is correct. You'll need to subscribe to Leaflet's map state change events, evaluate the new map state's current zoom level, then make modifications to the target layer. – elrobis Jul 9 at 21:26
  • Thank you. Is there also a way to do this with Folium? – zadrozny Jul 9 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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