]> git.openstreetmap.org Git - rails.git/commitdiff
Swap cached reverse geocodes when reversing directions
authorAnton Khorev <tony29@yandex.ru>
Mon, 12 Aug 2024 05:09:54 +0000 (08:09 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 8 Sep 2024 07:38:53 +0000 (10:38 +0300)
Do this instead of putting reversed input values into url.

app/assets/javascripts/index/directions-endpoint.js
app/assets/javascripts/index/directions.js

index b9dc65748fbd84904adc7a044138b5e1c049a8ca..6cb94f39ff1ee81ab44d992514c41575956b6a56 100644 (file)
@@ -86,6 +86,15 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
     }
   };
 
+  endpoint.swapCachedReverseGeocodes = function (otherEndpoint) {
+    var g0 = endpoint.cachedReverseGeocode;
+    var g1 = otherEndpoint.cachedReverseGeocode;
+    delete endpoint.cachedReverseGeocode;
+    delete otherEndpoint.cachedReverseGeocode;
+    if (g0) otherEndpoint.cachedReverseGeocode = g0;
+    if (g1) endpoint.cachedReverseGeocode = g1;
+  };
+
   function getGeocode() {
     var viewbox = map.getBounds().toBBoxString(); // <sw lon>,<sw lat>,<ne lon>,<ne lat>
     var geocodeUrl = OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox;
index 18f5b0b943238636d170d2a357b839b0000e2c99..df56771055c51db6870db4c1a016b7a4f399349e 100644 (file)
@@ -65,10 +65,9 @@ OSM.Directions = function (map) {
     if (coordTo) {
       routeTo = coordTo.lat + "," + coordTo.lng;
     }
+    endpoints[0].swapCachedReverseGeocodes(endpoints[1]);
 
     OSM.router.route("/directions?" + Qs.stringify({
-      from: $("#route_to").val(),
-      to: $("#route_from").val(),
       route: routeTo + ";" + routeFrom
     }));
   });