webglearth / webglearth2

[UNMAINTAINED] WebGL Earth 2 - the source code of the project
Apache License 2.0
884 stars 212 forks source link

How to change the style of existing polygon? #132

Closed eprtha closed 3 weeks ago

eprtha commented 3 weeks ago

A polygon is added to the map as follows. polygon = WE.polygon(boundarydata, { color: '#000080', fillOpacity: 0, weight: 1 // Border weight in pixels }).addTo(map);

How to change the color and weight of the polygon later? I have tried as follows but seems like WebGL Earth doesn't support setStyle. polygon.setStyle({ color: '#00FF00', // New border color (green) weight: 3 // Border weight in pixels });

Thanks in advance.

sebastian-marinescu commented 3 weeks ago

Hi @eprtha

There is a function called setStrokeColor

So you could change the color like this: polygon.setStrokeColor('#0f0')

I don't see any native way to set the width of the stroke. But can't you draw a new polygon over the old one, with a different color/width, and then destroy the old polygon?

eprtha commented 3 weeks ago

Thanks for the response. Current routine does as you advised. polygon.setStrokeColor('#0f0') works well. I really appreciate your help.