From: Marwin Hochfelsner <50826859+hlfan@users.noreply.github.com> Date: Sun, 6 Apr 2025 17:05:29 +0000 (+0200) Subject: Simplify step mapping function X-Git-Tag: live~67^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/ce52ba1e6ae4e5ae5fb03e64bde9c7df1dcae4ff?ds=inline;hp=--cc Simplify step mapping function --- ce52ba1e6ae4e5ae5fb03e64bde9c7df1dcae4ff diff --git a/app/assets/javascripts/index/directions/fossgis_osrm.js b/app/assets/javascripts/index/directions/fossgis_osrm.js index cacf0100c..40181e588 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 getInstructionText(step, maneuver_id) { + function getInstructionText(step) { const INSTRUCTION_TEMPLATE = { "continue": "continue", "merge right": "merge_right", @@ -38,7 +38,7 @@ } const instrPrefix = "javascripts.directions.instructions."; - let template = instrPrefix + INSTRUCTION_TEMPLATE[maneuver_id]; + let template = instrPrefix + INSTRUCTION_TEMPLATE[step.maneuverId]; const destinations = "" + step.destinations + ""; let namedRoad = true; @@ -133,17 +133,14 @@ "arrive": "destination" }; - const steps = leg.steps.map(function (step) { - const maneuver_id = getManeuverId(step.maneuver); - const step_geometry = L.PolylineUtil.decode(step.geometry, { precision: 5 }); - const instText = getInstructionText(step, maneuver_id); - return [ - ICON_MAP[maneuver_id], - instText, - step.distance, - step_geometry - ]; - }); + for (const step of leg.steps) step.maneuverId = getManeuverId(step.maneuver); + + const steps = leg.steps.map(step => [ + ICON_MAP[step.maneuverId], + getInstructionText(step), + step.distance, + L.PolylineUtil.decode(step.geometry, { precision: 5 }) + ]); return { line: steps.flatMap(step => step[3]), diff --git a/app/assets/javascripts/index/directions/fossgis_valhalla.js b/app/assets/javascripts/index/directions/fossgis_valhalla.js index 7228f488d..7e20d02d6 100644 --- a/app/assets/javascripts/index/directions/fossgis_valhalla.js +++ b/app/assets/javascripts/index/directions/fossgis_valhalla.js @@ -45,16 +45,12 @@ function _processDirections(leg) { const line = L.PolylineUtil.decode(leg.shape, { precision: 6 }); - const steps = leg.maneuvers.map(manoeuvre => { - const lineseg = line - .slice(manoeuvre.begin_shape_index, manoeuvre.end_shape_index + 1); - return [ - INSTR_MAP[manoeuvre.type], - manoeuvre.instruction, - manoeuvre.length * 1000, - lineseg - ]; - }); + const steps = leg.maneuvers.map(manoeuvre => [ + INSTR_MAP[manoeuvre.type], + manoeuvre.instruction, + manoeuvre.length * 1000, + line.slice(manoeuvre.begin_shape_index, manoeuvre.end_shape_index + 1) + ]); return { line: line, diff --git a/app/assets/javascripts/index/directions/graphhopper.js b/app/assets/javascripts/index/directions/graphhopper.js index acbd776a0..3579fd168 100644 --- a/app/assets/javascripts/index/directions/graphhopper.js +++ b/app/assets/javascripts/index/directions/graphhopper.js @@ -21,16 +21,12 @@ function _processDirections(path) { const line = L.PolylineUtil.decode(path.points); - const steps = path.instructions.map(function (instr) { - const lineseg = line - .slice(instr.interval[0], instr.interval[1] + 1); - return [ - GH_INSTR_MAP[instr.sign], - instr.text, - instr.distance, - lineseg - ]; - }); + const steps = path.instructions.map(instr => [ + GH_INSTR_MAP[instr.sign], + instr.text, + instr.distance, + line.slice(instr.interval[0], instr.interval[1] + 1) + ]); steps.at(-1)[0] = "destination"; return {