]> git.openstreetmap.org Git - rails.git/commitdiff
Register startinglocation listener as a named function
authorAnton Khorev <tony29@yandex.ru>
Sat, 1 Mar 2025 07:51:46 +0000 (10:51 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 1 Mar 2025 08:29:19 +0000 (11:29 +0300)
The listener is not going to be run once if it's constructed inside the locateactivate listener. It's going to be run however many times locateactivate happens.

app/assets/javascripts/index/directions.js

index c6f83a575e04bc2cc9f0a84a95bdf35666306f81..83995fee3f7a0339302af32cc09295fc158cd305 100644 (file)
@@ -273,13 +273,15 @@ OSM.Directions = function (map) {
     map.fire("startinglocation", { latlng: [lat, lng] });
   }
 
+  function startingLocationListener({ latlng }) {
+    if (endpoints[0].value) return;
+    endpoints[0].setValue(latlng.join(", "));
+  }
+
   map.on("locationfound", ({ latlng: { lat, lng } }) =>
     lastLocation = [lat, lng]
   ).on("locateactivate", () => {
-    map.once("startinglocation", ({ latlng }) => {
-      if (endpoints[0].value) return;
-      endpoints[0].setValue(latlng.join(", "));
-    });
+    map.once("startinglocation", startingLocationListener);
   });
 
   const page = {};