1 function GraphHopperEngine(id, vehicleParam) {
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
23 var url = document.location.protocol + "//graphhopper.com/api/1/route?" +
25 "&locale=" + I18n.currentLocale() +
26 "&key=LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn" +
31 for (var i = 0; i < points.length; i++) {
32 url += "&point=" + points[i].lat + ',' + points[i].lng;
38 success: function (data) {
39 if (!data.paths || data.paths.length === 0)
40 return callback(true);
42 var path = data.paths[0];
43 var line = L.PolylineUtil.decode(path.points);
46 var len = path.instructions.length;
47 for (var i = 0; i < len; i++) {
48 var instr = path.instructions[i];
49 var instrCode = (i === len - 1) ? 15 : GH_INSTR_MAP[instr.sign];
50 var instrText = "<b>" + (i + 1) + ".</b> ";
51 instrText += instr.text;
52 var latLng = line[instr.interval[0]];
53 var distInMeter = instr.distance;
55 {lat: latLng.lat, lng: latLng.lng},
60 ]); // TODO does graphhopper map instructions onto line indices?
66 distance: path.distance,
67 time: path.time / 1000
75 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_bicycle", "vehicle=bike"), true);
76 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_foot", "vehicle=foot"), true);