]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions.js
Merge remote-tracking branch 'upstream/pull/5744'
[rails.git] / app / assets / javascripts / index / directions.js
index c6f83a575e04bc2cc9f0a84a95bdf35666306f81..40ca85d960fc6f0d29504761a1bb8eeb2b4ab581 100644 (file)
@@ -273,13 +273,15 @@ OSM.Directions = function (map) {
     map.fire("startinglocation", { latlng: [lat, lng] });
   }
 
     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.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 = {};
   });
 
   const page = {};
@@ -344,7 +346,7 @@ OSM.Directions = function (map) {
 OSM.Directions.engines = [];
 
 OSM.Directions.addEngine = function (engine, supportsHTTPS) {
 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);
   }
     engine.id = engine.provider + "_" + engine.mode;
     OSM.Directions.engines.push(engine);
   }