]> git.openstreetmap.org Git - rails.git/commitdiff
Separate setting/clearing listeners/values on directions endpoints
authorAnton Khorev <tony29@yandex.ru>
Mon, 3 Feb 2025 13:08:16 +0000 (16:08 +0300)
committerAnton Khorev <tony29@yandex.ru>
Thu, 6 Mar 2025 08:56:15 +0000 (11:56 +0300)
app/assets/javascripts/index/directions-endpoint.js
app/assets/javascripts/index/directions.js

index 0b52d3d4c2c41b3063278207199d0bd9935d5e70..e3f6afa46d4a49a4984a94097347878411b854ff 100644 (file)
@@ -14,23 +14,16 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
     autoPan: true
   });
 
-  endpoint.enable = function () {
+  endpoint.enableListeners = function () {
     endpoint.marker.on("drag dragend", markerDragListener);
     input.on("keydown", inputKeydownListener);
     input.on("change", inputChangeListener);
   };
 
-  endpoint.disable = function () {
+  endpoint.disableListeners = function () {
     endpoint.marker.off("drag dragend", markerDragListener);
     input.off("keydown", inputKeydownListener);
     input.off("change", inputChangeListener);
-
-    if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort();
-    delete endpoint.geocodeRequest;
-    removeLatLng();
-    delete endpoint.value;
-    input.val("");
-    map.removeLayer(endpoint.marker);
   };
 
   function markerDragListener(e) {
@@ -91,6 +84,15 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
     }
   };
 
+  endpoint.clearValue = function () {
+    if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort();
+    delete endpoint.geocodeRequest;
+    removeLatLng();
+    delete endpoint.value;
+    input.val("");
+    map.removeLayer(endpoint.marker);
+  };
+
   endpoint.swapCachedReverseGeocodes = function (otherEndpoint) {
     const g0 = endpoint.cachedReverseGeocode;
     const g1 = otherEndpoint.cachedReverseGeocode;
index 40ca85d960fc6f0d29504761a1bb8eeb2b4ab581..9d25e67a0a9a4d1da4be1ebf1ae9fe4da264b15b 100644 (file)
@@ -308,8 +308,8 @@ OSM.Directions = function (map) {
 
     map.on("locationfound", sendstartinglocation);
 
-    endpoints[0].enable();
-    endpoints[1].enable();
+    endpoints[0].enableListeners();
+    endpoints[1].enableListeners();
 
     const params = new URLSearchParams(location.search),
           route = (params.get("route") || "").split(";");
@@ -332,8 +332,11 @@ OSM.Directions = function (map) {
     $("#map").off("dragend dragover drop");
     map.off("locationfound", sendstartinglocation);
 
-    endpoints[0].disable();
-    endpoints[1].disable();
+    endpoints[0].disableListeners();
+    endpoints[1].disableListeners();
+
+    endpoints[0].clearValue();
+    endpoints[1].clearValue();
 
     map
       .removeLayer(popup)