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();
});
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);
};
$("#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);
}