in code veritas in code veritas - 1 year ago 107
Javascript Question

Changing the style of each feature in a Leaflet GeoJSON layer

I have been studying the Leaflet Chloropleth example.

In my Leaflet application, I have a jQuery dropdown that, when selected, fires a function that takes the name of a state as an argument. I want to use that state name to update the Chloropleth map.

What is the pattern for changing the style of a Leaflet GeoJSON layer? Should I recreate the layer I created with

a second time? It seems as though the layers are drawing on top of each other with that approach.

I can provide a Fiddle if needed.


Here's an example of changing a choropleth to classify on different properties - the trick is to call setStyle again with different values.