2 function GraphHopperEngine(id, vehicleType) {
6 "-1": 5, // slight left
8 "1": 1, // slight right
10 "3": 3, // sharp right
11 "4": 14, // finish reached
12 "5": 14, // via reached
13 "6": 10, // roundabout
14 "-7": 19, // keep left
15 "7": 18, // keep right
16 "-98": 4, // unknown direction u-turn
17 "-8": 4, // left u-turn
18 "8": 4 // right u-turn
23 creditline: "<a href=\"https://www.graphhopper.com/\" target=\"_blank\">GraphHopper</a>",
26 getRoute: function (points, callback) {
27 // GraphHopper Directions API documentation
28 // https://graphhopper.com/api/1/docs/routing/
30 url: OSM.GRAPHHOPPER_URL,
33 locale: I18n.currentLocale(),
34 key: "LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn",
37 turn_costs: vehicleType === "car",
38 point: points.map(function (p) { return p.lat + "," + p.lng; })
42 success: function (data) {
43 if (!data.paths || data.paths.length === 0) {
44 return callback(true);
47 var path = data.paths[0];
48 var line = L.PolylineUtil.decode(path.points);
51 var len = path.instructions.length;
52 for (var i = 0; i < len; i++) {
53 var instr = path.instructions[i];
54 var instrCode = (i === len - 1) ? 14 : GH_INSTR_MAP[instr.sign];
55 var instrText = "<b>" + (i + 1) + ".</b> ";
56 instrText += instr.text;
57 var latLng = line[instr.interval[0]];
58 var distInMeter = instr.distance;
60 for (var j = instr.interval[0]; j <= instr.interval[1]; j++) {
61 lineseg.push({ lat: line[j][0], lng: line[j][1] });
64 { lat: latLng[0], lng: latLng[1] },
69 ]); // TODO does graphhopper map instructions onto line indices?
75 distance: path.distance,
76 time: path.time / 1000,
89 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_car", "car"), true);
90 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_bicycle", "bike"), true);
91 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_foot", "foot"), true);