From: Marwin Hochfelsner <50826859+hlfan@users.noreply.github.com>
Date: Sun, 6 Apr 2025 15:55:42 +0000 (+0200)
Subject: Remove unused multi-leg logic
X-Git-Tag: live~67^2~6
X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/e23d8426a2b6de00292e14d3b20f63868bdc0e3d?ds=inline;hp=-c
Remove unused multi-leg logic
---
e23d8426a2b6de00292e14d3b20f63868bdc0e3d
diff --git a/app/assets/javascripts/index/directions/fossgis_osrm.js b/app/assets/javascripts/index/directions/fossgis_osrm.js
index b5faca510..c7ea197b6 100644
--- a/app/assets/javascripts/index/directions/fossgis_osrm.js
+++ b/app/assets/javascripts/index/directions/fossgis_osrm.js
@@ -5,7 +5,7 @@
function FOSSGISOSRMEngine(modeId, vehicleType) {
let cachedHints = [];
- function _processDirections(route) {
+ function _processDirections(leg) {
const INSTRUCTION_TEMPLATE = {
"continue": "continue",
"merge right": "merge_right",
@@ -88,64 +88,62 @@
}
}
- const steps = route.legs.flatMap(
- leg => leg.steps.map(function (step) {
- const maneuver_id = getManeuverId(step.maneuver);
+ const steps = leg.steps.map(function (step) {
+ const maneuver_id = getManeuverId(step.maneuver);
- const instrPrefix = "javascripts.directions.instructions.";
- let template = instrPrefix + INSTRUCTION_TEMPLATE[maneuver_id];
+ const instrPrefix = "javascripts.directions.instructions.";
+ let template = instrPrefix + INSTRUCTION_TEMPLATE[maneuver_id];
- const step_geometry = L.PolylineUtil.decode(step.geometry, { precision: 5 }).map(L.latLng);
+ const step_geometry = L.PolylineUtil.decode(step.geometry, { precision: 5 }).map(L.latLng);
- let instText;
- const destinations = "" + step.destinations + "";
- let namedRoad = true;
- let name;
+ let instText;
+ const destinations = "" + step.destinations + "";
+ let namedRoad = true;
+ let name;
- if (step.name && step.ref) {
- name = "" + step.name + " (" + step.ref + ")";
- } else if (step.name) {
- name = "" + step.name + "";
- } else if (step.ref) {
- name = "" + step.ref + "";
- } else {
- name = OSM.i18n.t(instrPrefix + "unnamed");
- namedRoad = false;
- }
+ if (step.name && step.ref) {
+ name = "" + step.name + " (" + step.ref + ")";
+ } else if (step.name) {
+ name = "" + step.name + "";
+ } else if (step.ref) {
+ name = "" + step.ref + "";
+ } else {
+ name = OSM.i18n.t(instrPrefix + "unnamed");
+ namedRoad = false;
+ }
- if (step.maneuver.type.match(/^exit (rotary|roundabout)$/)) {
- instText = OSM.i18n.t(template, { name: name });
- } else if (step.maneuver.type.match(/^(rotary|roundabout)$/)) {
- if (step.maneuver.exit) {
- if (step.maneuver.exit <= 10) {
- instText = OSM.i18n.t(template + "_with_exit_ordinal", { exit: OSM.i18n.t(instrPrefix + "exit_counts." + numToWord(step.maneuver.exit)), name: name });
- } else {
- instText = OSM.i18n.t(template + "_with_exit", { exit: step.maneuver.exit, name: name });
- }
+ if (step.maneuver.type.match(/^exit (rotary|roundabout)$/)) {
+ instText = OSM.i18n.t(template, { name: name });
+ } else if (step.maneuver.type.match(/^(rotary|roundabout)$/)) {
+ if (step.maneuver.exit) {
+ if (step.maneuver.exit <= 10) {
+ instText = OSM.i18n.t(template + "_with_exit_ordinal", { exit: OSM.i18n.t(instrPrefix + "exit_counts." + numToWord(step.maneuver.exit)), name: name });
} else {
- instText = OSM.i18n.t(template + "_without_exit", { name: name });
+ instText = OSM.i18n.t(template + "_with_exit", { exit: step.maneuver.exit, name: name });
}
- } else if (step.maneuver.type.match(/^(on ramp|off ramp)$/)) {
- const params = {};
- if (step.exits && step.maneuver.type.match(/^(off ramp)$/)) params.exit = step.exits;
- if (step.destinations) params.directions = destinations;
- if (namedRoad) params.directions = name;
- if (Object.keys(params).length > 0) {
- template = template + "_with_" + Object.keys(params).join("_");
- }
- instText = OSM.i18n.t(template, params);
} else {
instText = OSM.i18n.t(template + "_without_exit", { name: name });
}
- return [[step.maneuver.location[1], step.maneuver.location[0]], ICON_MAP[maneuver_id], instText, step.distance, step_geometry];
- })
- );
+ } else if (step.maneuver.type.match(/^(on ramp|off ramp)$/)) {
+ const params = {};
+ if (step.exits && step.maneuver.type.match(/^(off ramp)$/)) params.exit = step.exits;
+ if (step.destinations) params.directions = destinations;
+ if (namedRoad) params.directions = name;
+ if (Object.keys(params).length > 0) {
+ template = template + "_with_" + Object.keys(params).join("_");
+ }
+ instText = OSM.i18n.t(template, params);
+ } else {
+ instText = OSM.i18n.t(template + "_without_exit", { name: name });
+ }
+ return [[step.maneuver.location[1], step.maneuver.location[0]], ICON_MAP[maneuver_id], instText, step.distance, step_geometry];
+ });
return {
line: steps.flatMap(step => step[4]),
steps,
- distance: route.distance,
- time: route.duration
+ distance: leg.distance,
+ time: leg.duration
};
}
@@ -176,7 +174,7 @@
.then(response => {
if (response.code !== "Ok") throw new Error();
cachedHints = response.waypoints.map(wp => wp.hint);
- return _processDirections(response.routes[0]);
+ return _processDirections(response.routes[0].legs[0]);
});
}
};
diff --git a/app/assets/javascripts/index/directions/fossgis_valhalla.js b/app/assets/javascripts/index/directions/fossgis_valhalla.js
index 48b3ad64a..cc230f348 100644
--- a/app/assets/javascripts/index/directions/fossgis_valhalla.js
+++ b/app/assets/javascripts/index/directions/fossgis_valhalla.js
@@ -42,41 +42,27 @@
"merge-left" // kMergeLeft = 38;
];
- function _processDirections(tripLegs) {
- let line = [];
- let steps = [];
- let distance = 0;
- let time = 0;
+ function _processDirections(leg) {
+ const line = L.PolylineUtil.decode(leg.shape, { precision: 6 });
- for (const leg of tripLegs) {
- const legLine = L.PolylineUtil.decode(leg.shape, {
- precision: 6
- });
-
- const legSteps = leg.maneuvers.map(function (manoeuvre) {
- const lineseg = legLine
- .slice(manoeuvre.begin_shape_index, manoeuvre.end_shape_index + 1)
- .map(([lat, lng]) => ({ lat, lng }));
- return [
- lineseg[0],
- INSTR_MAP[manoeuvre.type],
- manoeuvre.instruction,
- manoeuvre.length * 1000,
- lineseg
- ];
- });
-
- line = line.concat(legLine);
- steps = steps.concat(legSteps);
- distance += leg.summary.length;
- time += leg.summary.time;
- }
+ const steps = leg.maneuvers.map(manoeuvre => {
+ const lineseg = line
+ .slice(manoeuvre.begin_shape_index, manoeuvre.end_shape_index + 1)
+ .map(([lat, lng]) => ({ lat, lng }));
+ return [
+ lineseg[0],
+ INSTR_MAP[manoeuvre.type],
+ manoeuvre.instruction,
+ manoeuvre.length * 1000,
+ lineseg
+ ];
+ });
return {
line: line,
steps: steps,
- distance: distance * 1000,
- time: time
+ distance: leg.summary.length * 1000,
+ time: leg.summary.time
};
}
@@ -104,7 +90,7 @@
.then(response => response.json())
.then(({ trip }) => {
if (trip.status !== 0) throw new Error();
- return _processDirections(trip.legs);
+ return _processDirections(trip.legs[0]);
});
}
};