1 function GraphHopperEngine(id, vehicleType) {
5 "-1": 5, // slight left
10 4: 14, // finish reached
17 creditline: '<a href="https://www.graphhopper.com/" target="_blank">Graphhopper</a>',
20 getRoute: function (points, callback) {
21 // GraphHopper Directions API documentation
22 // https://graphhopper.com/api/1/docs/routing/
24 url: document.location.protocol + OSM.GRAPHHOPPER_URL,
27 locale: I18n.currentLocale(),
28 key: "LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn",
29 "ch.disable": vehicleType === "car",
33 point: points.map(function (p) { return p.lat + "," + p.lng; })
37 success: function (data) {
38 if (!data.paths || data.paths.length === 0)
39 return callback(true);
41 var path = data.paths[0];
42 var line = L.PolylineUtil.decode(path.points);
45 var len = path.instructions.length;
46 for (var i = 0; i < len; i++) {
47 var instr = path.instructions[i];
48 var instrCode = (i === len - 1) ? 14 : GH_INSTR_MAP[instr.sign];
49 var instrText = "<b>" + (i + 1) + ".</b> ";
50 instrText += instr.text;
51 var latLng = line[instr.interval[0]];
52 var distInMeter = instr.distance;
54 for (var j = instr.interval[0]; j <= instr.interval[1]; j++) {
55 lineseg.push({lat: line[j][0], lng: line[j][1]});
58 {lat: latLng[0], lng: latLng[1]},
63 ]); // TODO does graphhopper map instructions onto line indices?
69 distance: path.distance,
70 time: path.time / 1000,
83 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_car", "car"), true);
84 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_bicycle", "bike"), true);
85 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_foot", "foot"), true);