Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet - Switch GeoJSON based on zoom level

I'd like to make a Leaflet map based on GeoJSON (not TileLayer) data, and have it switch between different GeoJSONs based on the zoom level. For example, switching from a state to county GeoJSON, or switching from a highly-simplified GeoJSON to a high resolution GeoJSON.

I see from this question a How to set different zoom levels in layers in a map using leaflet that it can be done using the minZoom and maxZoom options when creating a TileLayer. However, these properties aren't available for a GeoJSON feature group. Is there a natural way to change maps based on zoom level when using GeoJSON?

like image 744
dandelion Avatar asked Jan 18 '26 00:01

dandelion


1 Answers

You can put a listener on map zoomend, removing one geojson (e.g. countries) and adding another one (e.g. counties) to the map.

like image 63
Mourner Avatar answered Jan 19 '26 19:01

Mourner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!