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.
This commit is contained in:
Anton Khorev 2025-03-01 10:51:46 +03:00
parent c37dc5c56d
commit 614542ad7f

View 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 = {};