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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 09:55:08  来源:igfitidea点击:

Change polyline options leaflet

javascriptleaflet

提问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.Polylineis extended from L.Pathwhich has a setStylemethod:

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

参考:http: //leafletjs.com/reference.html#path