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:
parent
c37dc5c56d
commit
614542ad7f
1 changed files with 6 additions and 4 deletions
|
@ -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 = {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue