From d9b09046f2245a201c462dee382ecb940c0a5293 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 12 Aug 2024 04:43:44 +0300 Subject: [PATCH 1/1] Abort geocoding requests if endpoint value changes --- app/assets/javascripts/index/directions-endpoint.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/index/directions-endpoint.js b/app/assets/javascripts/index/directions-endpoint.js index 7fe4b4ea7..59f0b929d 100644 --- a/app/assets/javascripts/index/directions-endpoint.js +++ b/app/assets/javascripts/index/directions-endpoint.js @@ -36,6 +36,9 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch function markerDragListener(e) { var latlng = convertLatLngToZoomPrecision(e.target.getLatLng()); + if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort(); + delete endpoint.geocodeRequest; + setLatLng(latlng); setInputValueFromLatLng(latlng); endpoint.value = input.val(); @@ -58,6 +61,9 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch input.removeClass("is-invalid"); input.val(value); + if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort(); + delete endpoint.geocodeRequest; + if (latlng) { setLatLng(latlng); setInputValueFromLatLng(latlng); @@ -71,7 +77,6 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch var viewbox = map.getBounds().toBBoxString(); // ,,, var geocodeUrl = OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox; - if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort(); endpoint.geocodeRequest = $.getJSON(geocodeUrl, function (json) { delete endpoint.geocodeRequest; if (json.length === 0) { -- 2.39.5