2 function GraphHopperEngine(modeId, vehicleType) {
11 "4": "destination", // finish reached
12 "5": "destination", // via reached
16 "-98": "u-turn-left", // unknown direction u-turn
17 "-8": "u-turn-left", // left u-turn
18 "8": "u-turn-right" // right u-turn
21 function _processDirections(path) {
22 const line = L.PolylineUtil.decode(path.points);
24 const steps = path.instructions.map(function (instr) {
26 .slice(instr.interval[0], instr.interval[1] + 1);
29 GH_INSTR_MAP[instr.sign],
35 steps.at(-1)[1] = "destination";
40 distance: path.distance,
41 time: path.time / 1000,
49 provider: "graphhopper",
50 creditline: "<a href=\"https://www.graphhopper.com/\" target=\"_blank\">GraphHopper</a>",
53 getRoute: function (points, signal) {
54 // GraphHopper Directions API documentation
55 // https://graphhopper.com/api/1/docs/routing/
56 const query = new URLSearchParams({
58 locale: OSM.i18n.locale,
59 key: "LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn",
62 turn_costs: vehicleType === "car"
64 points.forEach(p => query.append("point", p.lat + "," + p.lng));
65 return fetch(OSM.GRAPHHOPPER_URL + "?" + query, { signal })
66 .then(response => response.json())
67 .then(({ paths }) => {
68 if (!paths || paths.length === 0) throw new Error();
69 return _processDirections(paths[0]);
75 OSM.Directions.addEngine(new GraphHopperEngine("car", "car"), true);
76 OSM.Directions.addEngine(new GraphHopperEngine("bicycle", "bike"), true);
77 OSM.Directions.addEngine(new GraphHopperEngine("foot", "foot"), true);