dandelion
dandelion

Reputation: 1782

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?

Upvotes: 3

Views: 4376

Answers (2)

Leia Scofield
Leia Scofield

Reputation: 11

Check out Adding/Removing Leaflet GeoJSON layers. The answer there helped me pull off different GoeJSON sets at differing zoom levels.

Upvotes: 1

Mourner
Mourner

Reputation: 3301

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

Upvotes: 2

Related Questions