1 function GraphHopperEngine(id, vehicleType) {
5 "-1": 8, // slight left
10 4: -1, // finish reached
17 creditline: '<a href="https://graphhopper.com/" target="_blank">Graphhopper</a>',
20 getRoute: function (points, callback) {
21 // GraphHopper Directions API documentation
22 // https://github.com/graphhopper/directions-api/blob/master/docs-routing.md
24 url: document.location.protocol + "//graphhopper.com/api/1/route",
27 locale: I18n.currentLocale(),
28 key: "LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn",
32 point: points.map(function (p) { return p.lat + "," + p.lng; })
36 success: function (data) {
37 if (!data.paths || data.paths.length === 0)
38 return callback(true);
40 var path = data.paths[0];
41 var line = L.PolylineUtil.decode(path.points);
44 var len = path.instructions.length;
45 for (var i = 0; i < len; i++) {
46 var instr = path.instructions[i];
47 var instrCode = (i === len - 1) ? 15 : GH_INSTR_MAP[instr.sign];
48 var instrText = "<b>" + (i + 1) + ".</b> ";
49 instrText += instr.text;
50 var latLng = line[instr.interval[0]];
51 var distInMeter = instr.distance;
53 {lat: latLng.lat, lng: latLng.lng},
58 ]); // TODO does graphhopper map instructions onto line indices?
64 distance: path.distance,
65 time: path.time / 1000
76 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_bicycle", "bike"), true);
77 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_foot", "foot"), true);