in code veritas in code veritas - 2 years ago 219
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download