From: Anton Khorev Date: Mon, 12 Aug 2024 01:43:44 +0000 (+0300) Subject: Abort geocoding requests if endpoint value changes X-Git-Tag: live~62^2~6 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/d9b09046f2245a201c462dee382ecb940c0a5293?hp=1fce0c00f12ac6bbb56ad7c05c8c9f53c0d6edb3 Abort geocoding requests if endpoint value changes --- 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) {