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
 
  14     "7": 18, // keep right
 
  15     "-98": 4, // unknown direction u-turn
 
  16     "-8": 4, // left u-turn
 
  17     "8": 4 // right u-turn
 
  22     creditline: "<a href=\"https://www.graphhopper.com/\" target=\"_blank\">GraphHopper</a>",
 
  25     getRoute: function (points, callback) {
 
  26       // GraphHopper Directions API documentation
 
  27       // https://graphhopper.com/api/1/docs/routing/
 
  29         url: OSM.GRAPHHOPPER_URL,
 
  32           locale: I18n.currentLocale(),
 
  33           key: "LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn",
 
  36           turn_costs: vehicleType === "car",
 
  37           point: points.map(function (p) { return p.lat + "," + p.lng; })
 
  41         success: function (data) {
 
  42           if (!data.paths || data.paths.length === 0) {
 
  43             return callback(true);
 
  46           var path = data.paths[0];
 
  47           var line = L.PolylineUtil.decode(path.points);
 
  50           var len = path.instructions.length;
 
  51           for (var i = 0; i < len; i++) {
 
  52             var instr = path.instructions[i];
 
  53             var instrCode = (i === len - 1) ? 14 : GH_INSTR_MAP[instr.sign];
 
  54             var instrText = "<b>" + (i + 1) + ".</b> ";
 
  55             instrText += instr.text;
 
  56             var latLng = line[instr.interval[0]];
 
  57             var distInMeter = instr.distance;
 
  59             for (var j = instr.interval[0]; j <= instr.interval[1]; j++) {
 
  60               lineseg.push({ lat: line[j][0], lng: line[j][1] });
 
  63               { lat: latLng[0], lng: latLng[1] },
 
  68             ]); // TODO does graphhopper map instructions onto line indices?
 
  74             distance: path.distance,
 
  75             time: path.time / 1000,
 
  88 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_car", "car"), true);
 
  89 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_bicycle", "bike"), true);
 
  90 OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_foot", "foot"), true);