Reputation: 23811
I want to change the options assigned to a Leaflet polyline (and then render it) after building it:
// 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?
Upvotes: 14
Views: 21177
Reputation: 28638
L.Polyline
is extended from L.Path
which has a setStyle
method:
polyline.setStyle({
color: 'black'
});
Example: http://plnkr.co/edit/kfLcoG?p=preview
Reference: http://leafletjs.com/reference.html#path
Upvotes: 27