Dynamically change the color of a polygon in leaflet?(动态更改传单中多边形的颜色?)
问题描述
对于熟悉 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
extends L.Path
(http://leafletjs.com/reference.html#path),有方法 setStyle( <Path options> object )
,你可以将新样式应用为 window.circle.setStyle({fillColor: '#dddddd'});
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'});
这篇关于动态更改传单中多边形的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:动态更改传单中多边形的颜色?


基础教程推荐
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01