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 = {};
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(";");
$("#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)
OSM.Directions.engines = [];
OSM.Directions.addEngine = function (engine, supportsHTTPS) {
- if (document.location.protocol === "http:" || supportsHTTPS) {
+ if (location.protocol === "http:" || supportsHTTPS) {
engine.id = engine.provider + "_" + engine.mode;
OSM.Directions.engines.push(engine);
}