]> git.openstreetmap.org Git - rails.git/commitdiff
Remove unused multi-leg logic
authorMarwin Hochfelsner <50826859+hlfan@users.noreply.github.com>
Sun, 6 Apr 2025 15:55:42 +0000 (17:55 +0200)
committerMarwin Hochfelsner <50826859+hlfan@users.noreply.github.com>
Sun, 6 Apr 2025 17:44:38 +0000 (19:44 +0200)
app/assets/javascripts/index/directions/fossgis_osrm.js
app/assets/javascripts/index/directions/fossgis_valhalla.js

index b5faca510617d6031f35beb5f3622ab1ebad43df..c7ea197b6bc09a61fdd4cfa22e8b3644a50f853f 100644 (file)
@@ -5,7 +5,7 @@
   function FOSSGISOSRMEngine(modeId, vehicleType) {
     let cachedHints = [];
 
   function FOSSGISOSRMEngine(modeId, vehicleType) {
     let cachedHints = [];
 
-    function _processDirections(route) {
+    function _processDirections(leg) {
       const INSTRUCTION_TEMPLATE = {
         "continue": "continue",
         "merge right": "merge_right",
       const INSTRUCTION_TEMPLATE = {
         "continue": "continue",
         "merge right": "merge_right",
         }
       }
 
         }
       }
 
-      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 = "<b>" + step.destinations + "</b>";
-          let namedRoad = true;
-          let name;
+        let instText;
+        const destinations = "<b>" + step.destinations + "</b>";
+        let namedRoad = true;
+        let name;
 
 
-          if (step.name && step.ref) {
-            name = "<b>" + step.name + " (" + step.ref + ")</b>";
-          } else if (step.name) {
-            name = "<b>" + step.name + "</b>";
-          } else if (step.ref) {
-            name = "<b>" + step.ref + "</b>";
-          } else {
-            name = OSM.i18n.t(instrPrefix + "unnamed");
-            namedRoad = false;
-          }
+        if (step.name && step.ref) {
+          name = "<b>" + step.name + " (" + step.ref + ")</b>";
+        } else if (step.name) {
+          name = "<b>" + step.name + "</b>";
+        } else if (step.ref) {
+          name = "<b>" + step.ref + "</b>";
+        } 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 {
             } 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 });
           }
           } 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,
 
       return {
         line: steps.flatMap(step => step[4]),
         steps,
-        distance: route.distance,
-        time: route.duration
+        distance: leg.distance,
+        time: leg.duration
       };
     }
 
       };
     }
 
           .then(response => {
             if (response.code !== "Ok") throw new Error();
             cachedHints = response.waypoints.map(wp => wp.hint);
           .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]);
           });
       }
     };
           });
       }
     };
index 48b3ad64abeb532dc60a5dad6cf96c5844b36fbf..cc230f34899b1554b1b6ce38455729e4920daa25 100644 (file)
       "merge-left" // kMergeLeft = 38;
     ];
 
       "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,
 
       return {
         line: line,
         steps: steps,
-        distance: distance * 1000,
-        time: time
+        distance: leg.summary.length * 1000,
+        time: leg.summary.time
       };
     }
 
       };
     }
 
           .then(response => response.json())
           .then(({ trip }) => {
             if (trip.status !== 0) throw new Error();
           .then(response => response.json())
           .then(({ trip }) => {
             if (trip.status !== 0) throw new Error();
-            return _processDirections(trip.legs);
+            return _processDirections(trip.legs[0]);
           });
       }
     };
           });
       }
     };