]> git.openstreetmap.org Git - rails.git/commitdiff
Replace geocode request boolean property with request object
authorAnton Khorev <tony29@yandex.ru>
Mon, 12 Aug 2024 01:12:05 +0000 (04:12 +0300)
committerAnton Khorev <tony29@yandex.ru>
Mon, 19 Aug 2024 16:39:53 +0000 (19:39 +0300)
app/assets/javascripts/index/directions-endpoint.js

index 3069eb651671b54840869ee48ebe506a0599d95c..8489dd6df1780d50ea281e3acfdf01e1866ce0a6 100644 (file)
@@ -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,11 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
   };
 
   function getGeocode() {
-    endpoint.awaitingGeocode = true;
-
     var viewbox = map.getBounds().toBBoxString(); // <sw lon>,<sw lat>,<ne lon>,<ne lat>
+    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;
+    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 }));