]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5898'
authorTom Hughes <tom@compton.nu>
Sun, 6 Apr 2025 14:17:05 +0000 (15:17 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 6 Apr 2025 14:17:05 +0000 (15:17 +0100)
app/assets/javascripts/index/directions.js
app/assets/javascripts/index/directions/fossgis_osrm.js
app/assets/javascripts/index/directions/fossgis_valhalla.js
app/assets/javascripts/index/directions/graphhopper.js

index 57def249ac68d1d58800a0a8798e6a986b7e3c56..8b3047b68e5d4802b0ce586a6eb326e5db958fa8 100644 (file)
@@ -184,7 +184,7 @@ OSM.Directions = function (map) {
         );
 
       // Add each row
-      route.steps.forEach(function (step) {
+      for (const [i, step] of route.steps.entries()) {
         const [ll, direction, instruction, dist, lineseg] = step;
 
         const row = $("<tr class='turn'/>");
@@ -193,7 +193,7 @@ OSM.Directions = function (map) {
         } else {
           row.append("<td class='border-0'>");
         }
-        row.append("<td>" + instruction);
+        row.append(`<td><b>${i + 1}.</b> ${instruction}`);
         row.append("<td class='distance text-body-secondary text-end'>" + formatStepDistance(dist));
 
         row.on("click", function () {
@@ -212,7 +212,7 @@ OSM.Directions = function (map) {
         });
 
         turnByTurnTable.append(row);
-      });
+      }
 
       const blob = new Blob([JSON.stringify(polyline.toGeoJSON())], { type: "application/json" });
       URL.revokeObjectURL(downloadURL);
index b2586e68eefc41975d42e3c95e5fd8d745663085..b5faca510617d6031f35beb5f3622ab1ebad43df 100644 (file)
@@ -89,7 +89,7 @@
       }
 
       const steps = route.legs.flatMap(
-        leg => leg.steps.map(function (step, idx) {
+        leg => leg.steps.map(function (step) {
           const maneuver_id = getManeuverId(step.maneuver);
 
           const instrPrefix = "javascripts.directions.instructions.";
@@ -97,7 +97,7 @@
 
           const step_geometry = L.PolylineUtil.decode(step.geometry, { precision: 5 }).map(L.latLng);
 
-          let instText = "<b>" + (idx + 1) + ".</b> ";
+          let instText;
           const destinations = "<b>" + step.destinations + "</b>";
           let namedRoad = true;
           let name;
           }
 
           if (step.maneuver.type.match(/^exit (rotary|roundabout)$/)) {
-            instText += OSM.i18n.t(template, { name: name });
+            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 });
+                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 });
+                instText = OSM.i18n.t(template + "_with_exit", { exit: step.maneuver.exit, name: name });
               }
             } else {
-              instText += OSM.i18n.t(template + "_without_exit", { name: name });
+              instText = OSM.i18n.t(template + "_without_exit", { name: name });
             }
           } else if (step.maneuver.type.match(/^(on ramp|off ramp)$/)) {
             const params = {};
             if (Object.keys(params).length > 0) {
               template = template + "_with_" + Object.keys(params).join("_");
             }
-            instText += OSM.i18n.t(template, params);
+            instText = OSM.i18n.t(template, params);
           } else {
-            instText += OSM.i18n.t(template + "_without_exit", { name: name });
+            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];
         })
index d5e781e4a7b2cfa18942cff7f3e0b7acb4da3be0..48b3ad64abeb532dc60a5dad6cf96c5844b36fbf 100644 (file)
           precision: 6
         });
 
-        const legSteps = leg.maneuvers.map(function (manoeuvre, idx) {
-          const num = `<b>${idx + 1}.</b> `;
+        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],
-            num + manoeuvre.instruction,
+            manoeuvre.instruction,
             manoeuvre.length * 1000,
             lineseg
           ];
index b11c4947204d2ca356d206de66e163775aecba4e..20de38e37c288a483ba821b93d6d6ba544565101 100644 (file)
     function _processDirections(path) {
       const line = L.PolylineUtil.decode(path.points);
 
-      const steps = path.instructions.map(function (instr, i) {
-        const num = `<b>${i + 1}.</b> `;
+      const steps = path.instructions.map(function (instr) {
         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.text,
           instr.distance,
           lineseg
         ]; // TODO does graphhopper map instructions onto line indices?