X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/33799121b8a1ea5fdb1508ceda3fa99736db923f..1c66d7f50fe4d8ef22771f99d8690bc5136f30b7:/app/assets/javascripts/index/directions.js?ds=inline diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 40ca85d96..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)