在动画中动态更改多边形的颜色? [英] Dynamically change the color of a polygon in leaflet?

查看:113
本文介绍了在动画中动态更改多边形的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于熟悉Leaflet的人,你知道一种动态改变多边形颜色的方法吗?例如,采用如下定义的圆圈:

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";

代码更改window.circle.options.fillColor的值,但更改未反映更改地图上多边形的颜色。我已经四处寻找但没找到任何东西。有什么想法?

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?

谢谢。

推荐答案

L.Circle 扩展 L.Path http ://leafletjs.com/reference.html#path ),有方法 setStyle(<路径选项>对象),你可以申请新款式as window.circle.setStyle({fillColor:'#ddddd'});

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'});

这篇关于在动画中动态更改多边形的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆