更改折线选项传单

mik*_*ike 6 javascript leaflet

我想在构建之后更改分配给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
Run Code Online (Sandbox Code Playgroud)

这可能吗?

iH8*_*iH8 17

L.Polyline从中扩展L.Path有一个setStyle方法:

polyline.setStyle({
    color: 'black'
});
Run Code Online (Sandbox Code Playgroud)

示例:http://plnkr.co/edit/kfLcoG?p = preview

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