From: Anton Khorev Date: Mon, 12 Aug 2024 05:09:54 +0000 (+0300) Subject: Swap cached reverse geocodes when reversing directions X-Git-Tag: live~205^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/a1051b418e7a838e5dc14f8491f97de5510d1437?ds=sidebyside;hp=-c Swap cached reverse geocodes when reversing directions Do this instead of putting reversed input values into url. --- a1051b418e7a838e5dc14f8491f97de5510d1437 diff --git a/app/assets/javascripts/index/directions-endpoint.js b/app/assets/javascripts/index/directions-endpoint.js index b9dc65748..6cb94f39f 100644 --- a/app/assets/javascripts/index/directions-endpoint.js +++ b/app/assets/javascripts/index/directions-endpoint.js @@ -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(); // ,,, var geocodeUrl = OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox; diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 18f5b0b94..df5677105 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -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 })); });