From: Anton Khorev Date: Sat, 1 Mar 2025 07:51:46 +0000 (+0300) Subject: Register startinglocation listener as a named function X-Git-Tag: live~178^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/614542ad7fe896e158384c7b3cf580e1b6fc4435?ds=inline;hp=-c Register startinglocation listener as a named function 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. --- 614542ad7fe896e158384c7b3cf580e1b6fc4435 diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index c6f83a575..83995fee3 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -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 = {};