]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5652'
authorTom Hughes <tom@compton.nu>
Thu, 27 Feb 2025 20:28:47 +0000 (20:28 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 27 Feb 2025 20:28:47 +0000 (20:28 +0000)
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
app/views/layouts/_search.html.erb
config/locales/en.yml

index 3d52ec9fb6b19a853e768f1bf3575d62f4db7e23..07d39974db5b30aa9cce132cd7ff49b5b52837d4 100644 (file)
@@ -41,20 +41,9 @@ OSM.Directions = function (map) {
   const expiry = new Date();
   expiry.setYear(expiry.getFullYear() + 10);
 
-  const engines = OSM.Directions.engines;
-
-  engines.sort(function (a, b) {
-    const localised_a = I18n.t("javascripts.directions.engines." + a.id),
-          localised_b = I18n.t("javascripts.directions.engines." + b.id);
-    return localised_a.localeCompare(localised_b);
-  });
-
+  const modeGroup = $(".routing_modes");
   const select = $("select.routing_engines");
 
-  engines.forEach(function (engine, i) {
-    select.append("<option value='" + i + "'>" + I18n.t("javascripts.directions.engines." + engine.id) + "</option>");
-  });
-
   $(".directions_form .reverse_directions").on("click", function () {
     const coordFrom = endpoints[0].latlng,
           coordTo = endpoints[1].latlng;
@@ -98,15 +87,33 @@ OSM.Directions = function (map) {
     return h + ":" + (m < 10 ? "0" : "") + m;
   }
 
-  function findEngine(id) {
-    return engines.findIndex(function (engine) {
-      return engine.id === id;
-    });
-  }
+  function setEngine(id) {
+    const engines = OSM.Directions.engines;
+    const desired = engines.find(engine => engine.id === id);
+    if (!desired || (chosenEngine && chosenEngine.id === id)) return;
+    chosenEngine = desired;
+
+    const modes = engines
+      .filter(engine => engine.provider === chosenEngine.provider)
+      .map(engine => engine.mode);
+    modeGroup
+      .find("input[id]")
+      .prop("disabled", function () {
+        return !modes.includes(this.id);
+      })
+      .prop("checked", function () {
+        return this.id === chosenEngine.mode;
+      });
 
-  function setEngine(index) {
-    chosenEngine = engines[index];
-    select.val(index);
+    const providers = engines
+      .filter(engine => engine.mode === chosenEngine.mode)
+      .map(engine => engine.provider);
+    select
+      .find("option[value]")
+      .prop("disabled", function () {
+        return !providers.includes(this.value);
+      });
+    select.val(chosenEngine.provider);
   }
 
   function getRoute(fitRoute, reportErrors) {
@@ -230,14 +237,17 @@ OSM.Directions = function (map) {
     }
   }
 
-  let chosenEngineIndex = findEngine("fossgis_osrm_car");
-  if (Cookies.get("_osm_directions_engine")) {
-    chosenEngineIndex = findEngine(Cookies.get("_osm_directions_engine"));
-  }
-  setEngine(chosenEngineIndex);
+  setEngine("fossgis_osrm_car");
+  setEngine(Cookies.get("_osm_directions_engine"));
+
+  modeGroup.on("change", "input[name='modes']", function (e) {
+    setEngine(chosenEngine.provider + "_" + e.target.id);
+    Cookies.set("_osm_directions_engine", chosenEngine.id, { secure: true, expires: expiry, path: "/", samesite: "lax" });
+    getRoute(true, true);
+  });
 
   select.on("change", function (e) {
-    chosenEngine = engines[e.target.selectedIndex];
+    setEngine(e.target.selectedOptions[0].value + "_" + chosenEngine.mode);
     Cookies.set("_osm_directions_engine", chosenEngine.id, { secure: true, expires: expiry, path: "/", samesite: "lax" });
     getRoute(true, true);
   });
@@ -286,13 +296,7 @@ OSM.Directions = function (map) {
     const params = new URLSearchParams(location.search),
           route = (params.get("route") || "").split(";");
 
-    if (params.has("engine")) {
-      const engineIndex = findEngine(params.get("engine"));
-
-      if (engineIndex >= 0) {
-        setEngine(engineIndex);
-      }
-    }
+    if (params.has("engine")) setEngine(params.get("engine"));
 
     endpoints[0].setValue(params.get("from") || route[0] || "");
     endpoints[1].setValue(params.get("to") || route[1] || "");
@@ -324,6 +328,7 @@ OSM.Directions.engines = [];
 
 OSM.Directions.addEngine = function (engine, supportsHTTPS) {
   if (document.location.protocol === "http:" || supportsHTTPS) {
+    engine.id = engine.provider + "_" + engine.mode;
     OSM.Directions.engines.push(engine);
   }
 };
index cd1731247f70c650e3bd49c5341f5f589fd92f4a..2332049befc14691a1843b4d6e78bb3804132122 100644 (file)
@@ -2,7 +2,7 @@
 // Doesn't yet support hints
 
 (function () {
-  function FOSSGISOSRMEngine(id, vehicleType) {
+  function FOSSGISOSRMEngine(modeId, vehicleType) {
     let cachedHints = [];
 
     function _processDirections(route) {
     }
 
     return {
-      id: id,
+      mode: modeId,
+      provider: "fossgis_osrm",
       creditline: "<a href=\"https://routing.openstreetmap.de/about.html\" target=\"_blank\">OSRM (FOSSGIS)</a>",
       draggable: true,
 
     };
   }
 
-  OSM.Directions.addEngine(new FOSSGISOSRMEngine("fossgis_osrm_car", "car"), true);
-  OSM.Directions.addEngine(new FOSSGISOSRMEngine("fossgis_osrm_bike", "bike"), true);
-  OSM.Directions.addEngine(new FOSSGISOSRMEngine("fossgis_osrm_foot", "foot"), true);
+  OSM.Directions.addEngine(new FOSSGISOSRMEngine("car", "car"), true);
+  OSM.Directions.addEngine(new FOSSGISOSRMEngine("bicycle", "bike"), true);
+  OSM.Directions.addEngine(new FOSSGISOSRMEngine("foot", "foot"), true);
 }());
index 41ad6a9725fcb332b3ec63030f36fad0f3c60343..11aa4470b4dfbf64d7204d3dd0aec78890e26168 100644 (file)
@@ -1,5 +1,5 @@
 (function () {
-  function FOSSGISValhallaEngine(id, costing) {
+  function FOSSGISValhallaEngine(modeId, costing) {
     const INSTR_MAP = [
       0, // kNone = 0;
       8, // kStart = 1;
@@ -82,7 +82,8 @@
     }
 
     return {
-      id: id,
+      mode: modeId,
+      provider: "fossgis_valhalla",
       creditline:
       "<a href='https://gis-ops.com/global-open-valhalla-server-online/' target='_blank'>Valhalla (FOSSGIS)</a>",
       draggable: false,
     };
   }
 
-  OSM.Directions.addEngine(new FOSSGISValhallaEngine("fossgis_valhalla_car", "auto"), true);
-  OSM.Directions.addEngine(new FOSSGISValhallaEngine("fossgis_valhalla_bicycle", "bicycle"), true);
-  OSM.Directions.addEngine(new FOSSGISValhallaEngine("fossgis_valhalla_foot", "pedestrian"), true);
+  OSM.Directions.addEngine(new FOSSGISValhallaEngine("car", "auto"), true);
+  OSM.Directions.addEngine(new FOSSGISValhallaEngine("bicycle", "bicycle"), true);
+  OSM.Directions.addEngine(new FOSSGISValhallaEngine("foot", "pedestrian"), true);
 }());
index 729618f2d596441597482dea5f159f99f09357b4..b3194d16c17388240663b18e2a3dcc258fda3ac4 100644 (file)
@@ -1,5 +1,5 @@
 (function () {
-  function GraphHopperEngine(id, vehicleType) {
+  function GraphHopperEngine(modeId, vehicleType) {
     const GH_INSTR_MAP = {
       "-3": 7, // sharp left
       "-2": 6, // left
@@ -47,7 +47,8 @@
     }
 
     return {
-      id: id,
+      mode: modeId,
+      provider: "graphhopper",
       creditline: "<a href=\"https://www.graphhopper.com/\" target=\"_blank\">GraphHopper</a>",
       draggable: false,
 
@@ -73,7 +74,7 @@
     };
   }
 
-  OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_car", "car"), true);
-  OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_bicycle", "bike"), true);
-  OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_foot", "foot"), true);
+  OSM.Directions.addEngine(new GraphHopperEngine("car", "car"), true);
+  OSM.Directions.addEngine(new GraphHopperEngine("bicycle", "bike"), true);
+  OSM.Directions.addEngine(new GraphHopperEngine("foot", "foot"), true);
 }());
index 691e9fa7291e16f5e3cd26aaeecfc678dcc73898..b4e6bf123480b54b8b4c61a1531c9c6dc3e8cde8 100644 (file)
@@ -39,7 +39,7 @@
   <form method="GET" action="<%= directions_path %>" class="directions_form bg-body-secondary pb-2">
     <div class="d-flex flex-row-reverse px-3 pt-3 pb-1"><button type="button" class="btn-close" aria-label="<%= t("javascripts.close") %>"></button></div>
 
-    <div class="d-flex flex-column mx-2 gap-1">
+    <div class="d-flex flex-column mx-2 gap-2">
       <div class="d-flex gap-1 align-items-center">
         <div class="d-flex flex-column gap-1 flex-grow-1">
           <div class="d-flex gap-2 align-items-center">
       </div>
       <div class="d-flex gap-2 align-items-center">
         <div class="routing_marker_column flex-shrink-0"></div>
-        <select class="routing_engines form-select py-1 px-2" name="routing_engines"></select>
+        <div class="btn-group routing_modes" role="group">
+          <input type="radio" class="btn-check" name="modes" id="car" autocomplete="off" disabled>
+          <label class="btn btn-outline-secondary px-2" for="car" title="<%= t("site.search.modes.car") %>">
+            <svg class="d-block" width="16" height="16" fill="currentColor">
+              <path id="icon-car" d="M2.52 3.515A2.5 2.5 0 0 1 4.82 2h6.362c1 0 1.904.596 2.298 1.515l.792 1.848c.075.175.21.319.38.404.5.25.855.715.965 1.262l.335 1.679q.05.242.049.49v.413c0 .814-.39 1.543-1 1.997V13.5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1-.5-.5v-1.338c-1.292.048-2.745.088-4 .088s-2.708-.04-4-.088V13.5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1-.5-.5v-1.892c-.61-.454-1-1.183-1-1.997v-.413a2.5 2.5 0 0 1 .049-.49l.335-1.68c.11-.546.465-1.012.964-1.261a.8.8 0 0 0 .381-.404l.792-1.848ZM3 10a1 1 0 1 0 0-2 1 1 0 0 0 0 2m10 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2M6 8a1 1 0 0 0 0 2h4a1 1 0 1 0 0-2zM2.906 5.189a.51.51 0 0 0 .497.731c.91-.073 3.35-.17 4.597-.17s3.688.097 4.597.17a.51.51 0 0 0 .497-.731l-.956-1.913A.5.5 0 0 0 11.691 3H4.309a.5.5 0 0 0-.447.276L2.906 5.19Z" />
+            </svg>
+          </label>
+          <input type="radio" class="btn-check" name="modes" id="bicycle" autocomplete="off" disabled>
+          <label class="btn btn-outline-secondary px-2" for="bicycle" title="<%= t("site.search.modes.bicycle") %>">
+            <svg class="d-block" width="16" height="16" fill="currentColor">
+              <path id="icon-bicycle" d="M4 4.5a.5.5 0 0 1 .5-.5H6a.5.5 0 0 1 0 1v.5h4.14l.386-1.158A.5.5 0 0 1 11 4h1a.5.5 0 0 1 0 1h-.64l-.311.935.807 1.29a3 3 0 1 1-.848.53l-.508-.812-2.076 3.322A.5.5 0 0 1 8 10.5H5.959a3 3 0 1 1-1.815-3.274L5 5.856V5h-.5a.5.5 0 0 1-.5-.5m1.5 2.443-.508.814c.5.444.85 1.054.967 1.743h1.139zM8 9.057 9.598 6.5H6.402zM4.937 9.5a2 2 0 0 0-.487-.877l-.548.877zM3.603 8.092A2 2 0 1 0 4.937 10.5H3a.5.5 0 0 1-.424-.765zm7.947.53a2 2 0 1 0 .848-.53l1.026 1.643a.5.5 0 1 1-.848.53z" />
+            </svg>
+          </label>
+          <input type="radio" class="btn-check" name="modes" id="foot" autocomplete="off" disabled>
+          <label class="btn btn-outline-secondary px-2" for="foot" title="<%= t("site.search.modes.foot") %>">
+            <svg class="d-block" width="16" height="16" fill="currentColor">
+              <path id="icon-foot" d="M9.5 1.5a1.5 1.5 0 11-3 0 1.5 1.5 0 013 0M6.44 3.752A.75.75 0 017 3.5h1.445c.742 0 1.32.643 1.243 1.38l-.43 4.083a1.8 1.8 0 01-.088.395l-.318.906.213.242a.8.8 0 01.114.175l2 4.25a.75.75 0 11-1.357.638l-1.956-4.154-1.68-1.921A.75.75 0 016 8.96l.138-2.613-.435.489-.464 2.786a.75.75 0 11-1.48-.246l.5-3a.75.75 0 01.18-.375l2-2.25zm-.19 7.993v-1.418l1.204 1.375.261.524a.8.8 0 01-.12.231l-2.5 3.25a.75.75 0 11-1.19-.914zm4.22-4.215-.494-.494.205-1.843.006-.067 1.124 1.124h1.44a.75.75 0 010 1.5H11a.75.75 0 01-.531-.22Z" />
+            </svg>
+          </label>
+        </div>
+        <select class="routing_engines form-select py-1 px-2" name="routing_engines">
+          <option value="graphhopper" disabled><%= t("site.search.providers.graphhopper") %></option>
+          <option value="fossgis_osrm" disabled><%= t("site.search.providers.fossgis_osrm") %></option>
+          <option value="fossgis_valhalla" disabled><%= t("site.search.providers.fossgis_valhalla") %></option>
+        </select>
         <%= submit_tag t("site.search.submit_text"), :class => "routing_go btn btn-primary py-1 px-2", :data => { :disable_with => false } %>
       </div>
     </div>
index 0deb199a38d034a4f8828891046ab418fa841674..b56fb6410c6af3c6460180e2d7921518d247ce7c 100644 (file)
@@ -2382,6 +2382,14 @@ en:
       where_am_i_title: Describe the current location using the search engine
       submit_text: "Go"
       reverse_directions_text: "Reverse Directions"
+      modes:
+        bicycle: "Bicycle"
+        car: "Car"
+        foot: "Foot"
+      providers:
+        fossgis_osrm: "OSRM"
+        graphhopper: "GraphHopper"
+        fossgis_valhalla: "Valhalla"
     key:
       table:
         entry:
@@ -3229,16 +3237,6 @@ en:
     edit_help: Move the map and zoom in on a location you want to edit, then click here.
     directions:
       ascend: "Ascend"
-      engines:
-        fossgis_osrm_bike: "Bicycle (OSRM)"
-        fossgis_osrm_car: "Car (OSRM)"
-        fossgis_osrm_foot: "Foot (OSRM)"
-        graphhopper_bicycle: "Bicycle (GraphHopper)"
-        graphhopper_car: "Car (GraphHopper)"
-        graphhopper_foot: "Foot (GraphHopper)"
-        fossgis_valhalla_bicycle: "Bicycle (Valhalla)"
-        fossgis_valhalla_car: "Car (Valhalla)"
-        fossgis_valhalla_foot: "Foot (Valhalla)"
       descend: "Descend"
       directions: "Directions"
       distance: "Distance"