OSM.Directions = function (map) {
let controller = null; // the AbortController for the current route request if a route request is in progress
+ let lastLocation = [];
let chosenEngine;
const popup = L.popup({ autoPanPadding: [100, 100] });
OSM.DirectionsEndpoint(map, $("input[name='route_to']"), OSM.MARKER_RED, endpointDragCallback, endpointChangeCallback)
];
+ let downloadURL = null;
+
const expiry = new Date();
expiry.setYear(expiry.getFullYear() + 10);
$(".directions_form .btn-close").on("click", function (e) {
e.preventDefault();
- $(".describe_location").toggle(!endpoints[0].value);
- $(".search_form input[name='query']").val(endpoints[0].value);
+ $(".describe_location").toggle(!endpoints[1].value);
+ $(".search_form input[name='query']").val(endpoints[1].value);
OSM.router.route("/" + OSM.formatHash(map));
});
turnByTurnTable.append(row);
});
+ const blob = new Blob([JSON.stringify(polyline.toGeoJSON())], { type: "application/json" });
+ URL.revokeObjectURL(downloadURL);
+ downloadURL = URL.createObjectURL(blob);
+
+ $("#sidebar_content").append(`<p class="text-center"><a href="${downloadURL}" download="${
+ I18n.t("javascripts.directions.filename")
+ }">${
+ I18n.t("javascripts.directions.download")
+ }</a></p>`);
+
$("#sidebar_content").append("<p class=\"text-center\">" +
I18n.t("javascripts.directions.instructions.courtesy", { link: chosenEngine.creditline }) +
"</p>");
}
});
+ function sendstartinglocation({ latlng: { lat, lng } }) {
+ map.fire("startinglocation", { latlng: [lat, lng] });
+ }
+
+ 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(", "));
+ });
+ });
+
const page = {};
page.pushstate = page.popstate = function () {
endpoints[type === "from" ? 0 : 1].setValue(llWithPrecision.join(", "));
});
+ map.on("locationfound", sendstartinglocation);
+
endpoints[0].enable();
endpoints[1].enable();
}
}
- endpoints[0].setValue(params.get("from") || route[0] || "");
+ endpoints[0].setValue(params.get("from") || route[0] || lastLocation.join(", "));
endpoints[1].setValue(params.get("to") || route[1] || "");
map.setSidebarOverlaid(!endpoints[0].latlng || !endpoints[1].latlng);
$(".search_form").show();
$(".directions_form").hide();
$("#map").off("dragend dragover drop");
+ map.off("locationfound", sendstartinglocation);
endpoints[0].disable();
endpoints[1].disable();