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(instr => [
 
  25         GH_INSTR_MAP[instr.sign],
 
  28         line.slice(instr.interval[0], instr.interval[1] + 1)
 
  30       steps.at(-1)[0] = "destination";
 
  35         distance: path.distance,
 
  36         time: path.time / 1000,
 
  38         descend: path.descend,
 
  39         credit: "GraphHopper",
 
  40         creditlink: "https://www.graphhopper.com/"
 
  46       provider: "graphhopper",
 
  49       getRoute: function (points, signal) {
 
  50         // GraphHopper Directions API documentation https://docs.graphhopper.com
 
  51         const query = new URLSearchParams({
 
  53           locale: OSM.i18n.locale,
 
  54           key: "7cb4eb19-e0f4-40a3-a5e0-f2c039366f32",
 
  58         points.forEach(p => query.append("point", p.lat + "," + p.lng));
 
  59         return fetch(OSM.GRAPHHOPPER_URL + "?" + query, { signal })
 
  60           .then(response => response.json())
 
  61           .then(({ paths }) => {
 
  62             if (!paths || paths.length === 0) throw new Error();
 
  63             return _processDirections(paths[0]);
 
  69   OSM.Directions.addEngine(new GraphHopperEngine("car", "car"), true);
 
  70   OSM.Directions.addEngine(new GraphHopperEngine("bicycle", "bike"), true);
 
  71   OSM.Directions.addEngine(new GraphHopperEngine("foot", "foot"), true);