我想在构建之后更改分配给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
这可能吗?
答案 0 :(得分:16)
L.Polyline
从L.Path
扩展而来setStyle
方法:
polyline.setStyle({
color: 'black'
});