-
Notifications
You must be signed in to change notification settings - Fork 65
/
routing.js
73 lines (56 loc) · 1.93 KB
/
routing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Get an instance of the routing service version 7:
var router = platform.getRoutingService();
var routingParameters = {
waypoint0:"52.53086235,13.38475371",
waypoint1:"52.1370754,11.6326044",
mode:"fastest;truck;traffic:enabled",
truckRestrictionPenalty:'strict',
shippedHazardousGoods:'radioActive',
alternatives:3,
representation: "display",
};
// Define a callback function to process the routing response:
var onResult = function(result) {
console.log(result);
var colors =["green","orange","yellow","red"]
result.response.route.forEach(route =>{
var lineString = new H.geo.LineString(),
routeShape = route.shape,
polyline,
startMarker,
endMarker;
// Retrieve the mapped positions of the requested waypoints:
startPoint = route.waypoint[0].mappedPosition;
endPoint = route.waypoint[1].mappedPosition;
routeShape.forEach(function(point) {
var parts = point.split(',');
lineString.pushLatLngAlt(parts[0], parts[1]);
});
polyline = new H.map.Polyline(lineString, {
style: {
lineWidth: 4,
strokeColor: colors[result.response.route.indexOf(route)]
}
});
startMarker = new H.map.Marker({
lat:route.waypoint[0].mappedPosition.latitude,
lng:route.waypoint[0].mappedPosition.longitude
},{icon:(new H.map.Icon('img/radioactive.png',{size:{w:40, h:40}}))});
endMarker = new H.map.Marker({
lat:route.waypoint[1].mappedPosition.latitude,
lng:route.waypoint[1].mappedPosition.longitude
},{icon:(new H.map.Icon('img/end.png'))});
// Add the polyline to the map
map.addObjects([polyline,startMarker,endMarker]);
// And zoom to its bounding rectangle
map.getViewPort().setPadding(100, 0, 0, 0);
map.getViewModel().setLookAtData({
bounds: polyline.getBoundingBox()
});
map.getViewPort().setPadding(0, 0, 0, 0);
});
};
var onError = function(error) {
alert(error.message);
};
router.calculateRoute(routingParameters, onResult, onError);