X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/ddd7b8e58287adb1b69f32b6de98eb28b09e79d2..1c66d7f50fe4d8ef22771f99d8690bc5136f30b7:/app/assets/javascripts/index/directions.js diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 83995fee3..5aa773823 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -284,12 +284,17 @@ OSM.Directions = function (map) { map.once("startinglocation", startingLocationListener); }); - const page = {}; + function initializeFromParams() { + const params = new URLSearchParams(location.search), + route = (params.get("route") || "").split(";"); - page.pushstate = page.popstate = function () { - $(".search_form").hide(); - $(".directions_form").show(); + if (params.has("engine")) setEngine(params.get("engine")); + + endpoints[0].setValue(params.get("from") || route[0] || lastLocation.join(", ")); + endpoints[1].setValue(params.get("to") || route[1] || ""); + } + function enableListeners() { $("#map").on("dragend dragover", function (e) { e.preventDefault(); }); @@ -308,16 +313,19 @@ OSM.Directions = function (map) { 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(";"); + const page = {}; - if (params.has("engine")) setEngine(params.get("engine")); + page.pushstate = page.popstate = function () { + initializeFromParams(); - endpoints[0].setValue(params.get("from") || route[0] || lastLocation.join(", ")); - endpoints[1].setValue(params.get("to") || route[1] || ""); + $(".search_form").hide(); + $(".directions_form").show(); + + enableListeners(); map.setSidebarOverlaid(!endpoints[0].latlng || !endpoints[1].latlng); }; @@ -332,8 +340,11 @@ OSM.Directions = function (map) { $("#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) @@ -346,7 +357,7 @@ OSM.Directions = function (map) { 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); }