[GIS] Different Leaflet / Folium markers for different zoom levels

foliumleaflet

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?

Best Answer

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);
        }
    }
);