Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change polyline options leaflet

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?

like image 937
mike Avatar asked Mar 12 '15 02:03

mike


1 Answers

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

like image 102
iH8 Avatar answered Oct 24 '22 10:10

iH8