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
53 lines (44 loc) · 1.51 KB
/
routing.js
File metadata and controls
53 lines (44 loc) · 1.51 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
var circle10Km = new H.map.Circle({lat:52.4571601,lng:13.3806395}, 10000);
// Add the circle to the map:
map.addObject(circle10Km);
map.getViewModel().setLookAtData({
bounds: circle10Km.getBoundingBox()
});
var routingParams = {
'mode': 'fastest;car;',
'start': '52.4571601,13.3806395',
'range': '900',// 15 x 60 sec
'rangetype': 'time'
};
// Define a callback function to process the isoline response.
var onResult = function(result) {
var center = new H.geo.Point(
result.response.center.latitude,
result.response.center.longitude),
isolineCoords = result.response.isoline[0].component[0].shape,
linestring = new H.geo.LineString(),
isolinePolygon,
isolineCenter;
// Add the returned isoline coordinates to a linestring:
isolineCoords.forEach(function(coords) {
linestring.pushLatLngAlt.apply(linestring, coords.split(','));
});
// Create a polygon and a marker representing the isoline:
isolinePolygon = new H.map.Polygon(linestring);
isolineCenter = new H.map.Marker(center);
// Add the polygon and marker to the map:
map.addObjects([isolineCenter, isolinePolygon]);
// Center and zoom the map so that the whole isoline polygon is
// in the viewport:
map.getViewModel().setLookAtData({bounds: isolinePolygon.getBoundingBox()});
};
// Get an instance of the routing service:
var router = platform.getRoutingService();
// Call the Routing API to calculate an isoline:
router.calculateIsoline(
routingParams,
onResult,
function(error) {
alert(error.message);
}
);