Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
147
rated 0 times [  154] [ 7]  / answers: 1 / hits: 47339  / 11 Years ago, mon, march 25, 2013, 12:00:00

For anyone who is familiar with Leaflet, do you know a way to dynamically change a polygon's color? For example, take a circle defined like this:



window.circle = L.circle([51.508, -0.11], 500, {
color: 'red',
fillColor: '#ffffff',
fillOpacity: 0.5
}).addTo(map);


Then later, after a user clicks a button somewhere on an interface (for example), I want to change the color of the circle like this:



window.circle.options.fillColor = #dddddd;


The code changes the value for window.circle.options.fillColor, but the change is not reflected by a change to the color of the polygon on the map. I've searched around but haven't found anything. Any ideas?



Thanks.


More From » leaflet

 Answers
34

L.Circle extends L.Path (http://leafletjs.com/reference.html#path), that have method setStyle( <Path options> object ), and you can apply new style as window.circle.setStyle({fillColor: '#dddddd'});


[#79382] Saturday, March 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harrisonnelsonb

Total Points: 63
Total Questions: 112
Total Answers: 97

Location: Kazakhstan
Member since Mon, Sep 26, 2022
2 Years ago
;