1 function GraphHopperEngine(id, vehicleType) {
5 "-1": 5, // slight left
7 "1": 1, // slight right
10 "4": 14, // finish reached
11 "5": 14, // via reached
12 "6": 10, // roundabout
13 "-7": 19, // keep left
19 creditline: "<a href=\"https://www.graphhopper.com/\" target=\"_blank\">GraphHopper</a>",
22 getRoute: function (points, callback) {
23 // GraphHopper Directions API documentation
24 // https://graphhopper.com/api/1/docs/routing/
26 url: OSM.GRAPHHOPPER_URL,
29 locale: I18n.currentLocale(),
30 key: "LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn",
33 turn_costs: vehicleType === "car",
34 point: points.map(function (p) { return p.lat + "," + p.lng; })
38 success: function (data) {
39 if (!data.paths || data.paths.length === 0) {
40 return callback(true);
43 var path = data.paths[0];
44 var line = L.PolylineUtil.decode(path.points);
47 var len = path.instructions.length;
48 for (var i = 0; i < len; i++) {
49 var instr = path.instructions[i];
50 var instrCode = (i === len - 1) ? 14 : GH_INSTR_MAP[instr.sign];
51 var instrText = "<b>" + (i + 1) + ".</b> ";
52 instrText += instr.text;
53 var latLng = line[instr.interval[0]];
54 var distInMeter = instr.distance;
56 for (var j = instr.interval[0]; j <= instr.interval[1]; j++) {
57 lineseg.push({ lat: line[j][0], lng: line[j][1] });
60 { lat: latLng[0], lng: latLng[1] },
65 ]); // TODO does graphhopper map instructions onto line indices?
71 distance: path.distance,
72 time: path.time / 1000,
85 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_car", "car"), true);
86 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_bicycle", "bike"), true);
87 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_foot", "foot"), true);