Reputation: 1233
Is there any way to display one polyline with two different colours(ex: based on road speed limit) in leaflet by using shiny?
Upvotes: 1
Views: 932
Reputation: 1785
You can use this plugin : http://hgoebl.github.io/Leaflet.MultiOptionsPolyline/demo/
You will have to define the speed for each point in your GeoJSON properties.
Then you simply have to add this code after :
var myPolyline = L.multiOptionsPolyline(YourGeoJSONHere, {
multiOptions: {
optionIdxFn: function (latLng) {
var i,
speedThresholds = [5, 10, 15, 30];
for (i = 0; i < speedThresholds.length; ++i) {
if (latLng.alt <= speedThresholds[i]) {
return i;
}
}
return speedThresholds.length;
},
options: [
{color: '#0000FF'}, {color: '#0040FF'},
{color: '#0080FF'}, {color: '#00FFB0'}
]
},
weight: 5,
opacity: 0.9,
smoothFactor: 1
}).addTo(layerTrace);
For the speed : https://github.com/hgoebl/Leaflet.MultiOptionsPolyline/blob/master/demo/js/demo.js#L59-L80
Upvotes: 2