forked from alletsz/devrel-workshops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouting.js
More file actions
96 lines (72 loc) · 2.28 KB
/
routing.js
File metadata and controls
96 lines (72 loc) · 2.28 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function getEVChargingRoute(){
let url = `https://fleet.ls.hereapi.com/2/calculateroute.json`+
`?apikey=${window.hereCreds.JS_KEY}`+
`&waypoint0=52.53086235,13.38475371`+//HERE Berlin
`&waypoint1=52.45709,13.38059`+//my Location
`&mode=fastest;car;traffic:disabled`+
`&routeAttributes=shape`;
fetch(url)
.then(response => response.json())
.then(response => {
let route = response.response.route[0];
if(route){
let routeShape = route.shape,
polyline,
routeGroup = new H.map.Group();
var lineString = new H.geo.LineString.fromLatLngArray(routeShape);
polyline = new H.map.Polyline(lineString, {
style: {
lineWidth: 4,
strokeColor: "blue"
}
});
routeGroup.addObject(polyline);
route.waypoint.forEach(waypoint => {
let startMarker = new H.map.Marker({
lat:waypoint.mappedPosition.latitude,
lng:waypoint.mappedPosition.longitude
},{icon:(new H.map.Icon('img/start.png'))});
routeGroup.addObject(startMarker);
});
map.addObject(routeGroup);
searchCorridor(routeShape);
}
}, error =>{
console.error(error);
});
}
getEVChargingRoute();
function searchCorridor(corridor){
let searchUrl = `https://fleet.ls.hereapi.com/1//search/corridor.json`+
`?apiKey=${window.hereCreds.JS_KEY}`+
`&corridor=${corridor}`+//
`&radius=500`+// in meters
`&layer_ids=EVCHARGING_POI`+
`&key_attributes=POI_ID`;
fetch(searchUrl)
.then(result => result.json())
.then(result => {
displayEV(result);
}, err =>{
console.error(err);
});
}
function displayEV(result){
if(result.geometries){
let evGroup = new H.map.Group();
result.geometries.forEach(ev =>{
let evMarker = new H.map.Marker({
lat:ev.nearestLat,
lng:ev.nearestLon
},{icon:(new H.map.Icon('img/EVCharging.png'))});
evGroup.addObject(evMarker);
evMarker.setData("Distance from route: "+ev.distance+" m");
});
map.addObject(evGroup);
map.getViewPort().setPadding(100, 0, 0, 0);
map.getViewModel().setLookAtData({
bounds: evGroup.getBoundingBox()
});
map.getViewPort().setPadding(0, 0, 0, 0);
}
}