" + I18n.t("javascripts.directions.errors.no_route") + "
"); - } - - return; - } - + controller = new AbortController(); + chosenEngine.getRoute(points, controller.signal).then(function (route) { polyline .setLatLngs(route.line) .addTo(map); @@ -254,45 +146,38 @@ OSM.Directions = function (map) { map.fitBounds(polyline.getBounds().pad(0.05)); } - var html = "" + - "" + + const distanceText = $("
").append(
I18n.t("javascripts.directions.distance") + ": " + formatDistance(route.distance) + ". " +
- I18n.t("javascripts.directions.time") + ": " + formatTime(route.time) + ".";
+ I18n.t("javascripts.directions.time") + ": " + formatTime(route.time) + ".");
if (typeof route.ascend !== "undefined" && typeof route.descend !== "undefined") {
- html += "
" +
- I18n.t("javascripts.directions.ascend") + ": " + Math.round(route.ascend) + "m. " +
- I18n.t("javascripts.directions.descend") + ": " + Math.round(route.descend) + "m.";
+ distanceText.append(
+ $("
"),
+ I18n.t("javascripts.directions.ascend") + ": " + formatHeight(route.ascend) + ". " +
+ I18n.t("javascripts.directions.descend") + ": " + formatHeight(route.descend) + ".");
}
- html += "
"); } else { - dist = String(Math.round(dist / 1000)) + "km"; + row.append(" | "); } - - var row = $(" |
"); - row.append(" | " + instruction); - row.append(" | " + dist); + row.append(" | " + instruction); + row.append(" | " + getDistText(dist));
row.on("click", function () {
popup
@@ -309,31 +194,60 @@ OSM.Directions = function (map) {
map.removeLayer(highlight);
});
- $("#turnbyturn").append(row);
+ turnByTurnTable.append(row);
});
- $("#sidebar_content").append(" " + + const blob = new Blob([JSON.stringify(polyline.toGeoJSON())], { type: "application/json" }); + URL.revokeObjectURL(downloadURL); + downloadURL = URL.createObjectURL(blob); + + $("#directions_content").append(` ${ + I18n.t("javascripts.directions.download") + } `); + + $("#directions_content").append("" + I18n.t("javascripts.directions.instructions.courtesy", { link: chosenEngine.creditline }) + " "); - - $("#sidebar_content a.geolink").on("click", function (e) { - e.preventDefault(); - map.removeLayer(polyline); - $("#sidebar_content").html(""); - map.setSidebarOverlaid(true); - // TODO: collapse width of sidebar back to previous - }); + }).catch(function () { + map.removeLayer(polyline); + if (reportErrors) { + $("#directions_content").html("" + I18n.t("javascripts.directions.errors.no_route") + " ");
+ }
+ }).finally(function () {
+ controller = null;
});
+
+ function getDistText(dist) {
+ if (dist < 5) return "";
+ if (dist < 200) return String(Math.round(dist / 10) * 10) + "m";
+ if (dist < 1500) return String(Math.round(dist / 100) * 100) + "m";
+ if (dist < 5000) return String(Math.round(dist / 100) / 10) + "km";
+ return String(Math.round(dist / 1000)) + "km";
+ }
}
- var chosenEngineIndex = findEngine("fossgis_osrm_car");
- if (Cookies.get("_osm_directions_engine")) {
- chosenEngineIndex = findEngine(Cookies.get("_osm_directions_engine"));
+ function hideRoute(e) {
+ e.stopPropagation();
+ map.removeLayer(polyline);
+ $("#directions_content").html("");
+ popup.close();
+ map.setSidebarOverlaid(true);
+ // TODO: collapse width of sidebar back to previous
}
- setEngine(chosenEngineIndex);
+
+ setEngine("fossgis_osrm_car");
+ setEngine(Cookies.get("_osm_directions_engine"));
+
+ modeGroup.on("change", "input[name='modes']", function (e) {
+ setEngine(chosenEngine.provider + "_" + e.target.id);
+ Cookies.set("_osm_directions_engine", chosenEngine.id, { secure: true, expires: expiry, path: "/", samesite: "lax" });
+ getRoute(true, true);
+ });
select.on("change", function (e) {
- chosenEngine = engines[e.target.selectedIndex];
+ setEngine(e.target.value + "_" + chosenEngine.mode);
Cookies.set("_osm_directions_engine", chosenEngine.id, { secure: true, expires: expiry, path: "/", samesite: "lax" });
getRoute(true, true);
});
@@ -343,22 +257,44 @@ OSM.Directions = function (map) {
getRoute(true, true);
});
- $(".routing_marker").on("dragstart", function (e) {
- var dt = e.originalEvent.dataTransfer;
+ $(".routing_marker_column img").on("dragstart", function (e) {
+ const dt = e.originalEvent.dataTransfer;
dt.effectAllowed = "move";
- var dragData = { type: $(this).data("type") };
+ const dragData = { type: $(this).data("type") };
dt.setData("text", JSON.stringify(dragData));
if (dt.setDragImage) {
- var img = $(" |