- page.pushstate = page.popstate = function () {
- $(".search_form").hide();
- $(".directions_form").show();
+ 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", startingLocationListener);
+ });
+
+ function initializeFromParams() {
+ const params = new URLSearchParams(location.search),
+ route = (params.get("route") || "").split(";");
+
+ 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() {
+ $("#sidebar_content").on("click", ".btn-close", hideRoute);