Reputation: 35
I want to draw polyline on roads and based on specific road speedLimit show the polyline in different color, something like this:
Is it possible to achieve this whit HERE map API?
var lineString = new H.geo.LineString();
routeShape.forEach(function(point) {
var parts = point[0].split(',');
lineString.pushLatLngAlt(parts[0], parts[1]);
});
polyline = new H.map.Polyline(lineString, {
style: {
lineWidth: 4,
strokeColor: 'rgba(0, 128, 255, 0.7)'
}
});
map.addObject(polyline);
map.setViewBounds(polyline.getBounds(), true);
Upvotes: 1
Views: 3047
Reputation: 879
Use routeattributes: "shape" for your routing request, and you may get each segment and associated speed limit as below:
let route = res.body.response.route[0];
let legs = route.leg;
let links = [];
legs.forEach(leg => {
Object.assign(links, leg.link);
});
console.log("#links", links.length);
links.forEach(link => {
let sl = link.speedLimit; // in m/sec
let shape = link.shape; // shape to draw
let style = {
lineWidth: 4,
strokeColor: "yellow"
};
if (sl < 50 * 1000 / 3600)
style.strokeColor = "red";
else if (sl < 90 * 1000 / 3600)
style.strokeColor = "orange";
else
style.strokeColor = "green";
let line = new H.geo.LineString();
shape.forEach(latlng => {
let coord = latlng.split(",");
line.pushLatLngAlt(coord[0], coord[1]);
});
let polyline = new H.map.Polyline(line, {
style: style
});
/* group created previously as
group = new H.map.Group();
map.addObject(group);
*/
group.addObject(polyline);
});
just draw each shape independantly, according to your own style depending on speed limit.
Upvotes: 1
Reputation:
Your question poses two kind of interpretations. I shall try answering both so that you can pick your intend. Hope it helps!
How to get speed limits of each link in a route - Using routing api as given in the below example. Check the answer in How to get SpeedLimit in HERE API
Upvotes: 1