From e67139403b514ed48143ec0a3324ba12b10df8e4 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 12 Aug 2024 08:09:54 +0300 Subject: [PATCH] Swap cached reverse geocodes when reversing directions Do this instead of putting reversed input values into url. --- app/assets/javascripts/index/directions-endpoint.js | 9 +++++++++ app/assets/javascripts/index/directions.js | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/index/directions-endpoint.js b/app/assets/javascripts/index/directions-endpoint.js index 48b9bfb33f..9aba7d9f45 100644 --- a/app/assets/javascripts/index/directions-endpoint.js +++ b/app/assets/javascripts/index/directions-endpoint.js @@ -76,6 +76,15 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch map.removeLayer(endpoint.marker); }; + 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 d40416ad9c..998bd6dd80 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 })); });