更改折线选项传单

时间:2015-03-12 02:11:43

标签: 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

这可能吗?

1 个答案:

答案 0 :(得分:16)

L.PolylineL.Path扩展而来setStyle方法:

polyline.setStyle({
    color: 'black'
});

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

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