]> git.openstreetmap.org Git - rails.git/commitdiff
Simplify step mapping function
authorMarwin Hochfelsner <50826859+hlfan@users.noreply.github.com>
Sun, 6 Apr 2025 17:05:29 +0000 (19:05 +0200)
committerMarwin Hochfelsner <50826859+hlfan@users.noreply.github.com>
Sun, 6 Apr 2025 17:45:20 +0000 (19:45 +0200)
app/assets/javascripts/index/directions/fossgis_osrm.js
app/assets/javascripts/index/directions/fossgis_valhalla.js
app/assets/javascripts/index/directions/graphhopper.js

index cacf0100ca23f62c3221e811b0b815f422ef2abe..40181e588e7679382d47f72a397ff3a5c5fd2eae 100644 (file)
@@ -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 = "<b>" + step.destinations + "</b>";
       let namedRoad = true;
         "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]),
index 7228f488dbb3d02b4a81466117ebe532683bbc1e..7e20d02d687ed5a9694700511469ecddb1c38b2d 100644 (file)
     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,
index acbd776a0c86783be40a0ed553136f73a47415e9..3579fd168aa8d4fc69e8f94020238e31b8c0430e 100644 (file)
     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 {