From 5a1e3e5c67325c95bdab0e09cd79bda24c426090 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 12 Aug 2024 04:12:05 +0300 Subject: [PATCH] Replace geocode request boolean property with request object --- app/assets/javascripts/index/directions-endpoint.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/index/directions-endpoint.js b/app/assets/javascripts/index/directions-endpoint.js index 3069eb651..9ae7ce84f 100644 --- a/app/assets/javascripts/index/directions-endpoint.js +++ b/app/assets/javascripts/index/directions-endpoint.js @@ -25,6 +25,8 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch input.off("keydown", inputKeydownListener); input.off("change", inputChangeListener); + if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort(); + delete endpoint.geocodeRequest; map.removeLayer(endpoint.marker); }; @@ -63,12 +65,12 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch }; function getGeocode() { - endpoint.awaitingGeocode = true; - var viewbox = map.getBounds().toBBoxString(); // ,,, + var geocodeUrl = OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox; - $.getJSON(OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox, function (json) { - endpoint.awaitingGeocode = false; + if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort(); + endpoint.geocodeRequest = $.getJSON(geocodeUrl, function (json) { + delete endpoint.geocodeRequest; if (json.length === 0) { input.addClass("is-invalid"); alert(I18n.t("javascripts.directions.errors.no_place", { place: endpoint.value })); -- 2.39.5