- getRoute: function (points, callback) {
- // GraphHopper Directions API documentation
- // https://graphhopper.com/api/1/docs/routing/
- return $.ajax({
- url: OSM.GRAPHHOPPER_URL,
- data: {
- "vehicle": vehicleType,
- "locale": I18n.currentLocale(),
- "key": "LijBPDQGfu7Iiq80w3HzwB4RUDJbMbhs6BU0dEnn",
- "ch.disable": vehicleType === "car",
- "elevation": false,
- "instructions": true,
- "point": points.map(function (p) { return p.lat + "," + p.lng; })
- },
- traditional: true,
- dataType: "json",
- success: function (data) {
- if (!data.paths || data.paths.length === 0) {
- return callback(true);
- }
+ const steps = path.instructions.map(function (instr, i) {
+ const num = `<b>${i + 1}.</b> `;
+ const lineseg = line
+ .slice(instr.interval[0], instr.interval[1] + 1)
+ .map(([lat, lng]) => ({ lat, lng }));
+ return [
+ lineseg[0],
+ GH_INSTR_MAP[instr.sign],
+ num + instr.text,
+ instr.distance,
+ lineseg
+ ]; // TODO does graphhopper map instructions onto line indices?
+ });
+ steps.at(-1)[1] = 14;
+
+ return {
+ line: line,
+ steps: steps,
+ distance: path.distance,
+ time: path.time / 1000,
+ ascend: path.ascend,
+ descend: path.descend
+ };
+ }