javascript 更改折线选项小册子
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29000768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change polyline options leaflet
提问by mike
I want to change the options assigned to a Leaflet polyline (and then render it) after building it:
我想在构建后更改分配给 Leaflet 折线的选项(然后渲染它):
// Add polyline
var polyline = L.polyline([], {weight:weight, opacity:1, color:'gray'}).addTo(map);
// Attempts to change color
polyline.options.color = 'blue' // doesn't render
polyline.options.color('blue') // throws error
polyline({color:'blue'}) // throws error
polyline._updateStyle(polyline) // throws error: not sure how exactly this works
polyline._updateStyle() // throws error
polyline({color:blue}) // throws error
Is this possible?
这可能吗?
回答by iH8
L.Polyline
is extended from L.Path
which has a setStyle
method:
L.Polyline
是从L.Path
其中扩展了一个setStyle
方法:
polyline.setStyle({
color: 'black'
});
Example: http://plnkr.co/edit/kfLcoG?p=preview
示例:http: //plnkr.co/edit/kfLcoG?p=preview
Reference: http://leafletjs.com/reference.html#path