2
votes

Not sure if anyone is familiar with this leaflet map on the leaflet site found here: http://leafletjs.com/examples/choropleth.html
It is a really cool map, just one thing. Is there a way to get the choropleth to disappear upon a certain zoom level? I know you can use map.getZoom() to detect zoom level. Essentially, I am trying to reset the styles that are invoked on page load within the function getColor(d).
Not sure how though. Any ideas?

Thanks in advance.

1

1 Answers

3
votes

L.geoJson(statesData) returns an object with the method removeLayer. If you pass that object to a variable (let's just call it data) and call an anonymous function on zoomend you can capture the map's zoom level with map.getZoom(), you can match it to any arbitrary zoom level and then call data.removeLayer().

If you open up dev tools (aka your web inspector) in your browser and input the following line into your JavaScript console, you'll be able to see more methods and information that's fired whenever you zoom in and out of the map.

map.on('zoomend', function(e) { console.log(e); })