我要在构建后更改分配给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

这可能吗?

最佳答案

L.Polyline是从具有L.Path方法的setStyle扩展而来的:

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

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

引用:http://leafletjs.com/reference.html#path

关于javascript - 更改折线选项单张,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29000768/

10-09 20:58