From 897e8d312ec6178cbcee0c210727bb09eeeb8c3b Mon Sep 17 00:00:00 2001
From: Areeb <011235813phantom@gmail.com>
Date: Fri, 16 Jan 2026 22:47:49 +0530
Subject: [PATCH] Improve readability by adding new lines
---
.../index/directions-route-output.js | 5 ++++
app/assets/javascripts/index/directions.js | 26 +++++++++++++++++++
.../index/directions/fossgis_osrm.js | 11 ++++++++
.../index/directions/graphhopper.js | 3 ++-
4 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/app/assets/javascripts/index/directions-route-output.js b/app/assets/javascripts/index/directions-route-output.js
index 5bb9e9640..3602df2fd 100644
--- a/app/assets/javascripts/index/directions-route-output.js
+++ b/app/assets/javascripts/index/directions-route-output.js
@@ -63,13 +63,16 @@ OSM.DirectionsRouteOutput = function (map) {
function formatTime(s) {
let m = Math.round(s / 60);
const h = Math.floor(m / 60);
+
m -= h * 60;
+
return h + ":" + (m < 10 ? "0" : "") + m;
}
function writeSummary(route) {
$("#directions_route_distance").val(formatTotalDistance(...translateDistanceUnits(route.distance)));
$("#directions_route_time").val(formatTime(route.time));
+
if (typeof route.ascend !== "undefined" && typeof route.descend !== "undefined") {
$("#directions_route_ascend_descend").prop("hidden", false);
$("#directions_route_ascend").val(formatHeight(...translateDistanceUnits(route.ascend)));
@@ -92,6 +95,7 @@ OSM.DirectionsRouteOutput = function (map) {
} else {
row.append("
");
}
+
row.append(` | ${i + 1}. ${instruction}`);
row.append(" | " + formatStepDistance(...translateDistanceUnits(dist)));
@@ -131,6 +135,7 @@ OSM.DirectionsRouteOutput = function (map) {
});
const blob = new Blob([JSON.stringify(polyline.toGeoJSON())], { type: "application/geo+json" });
+
URL.revokeObjectURL(downloadURL);
downloadURL = URL.createObjectURL(blob);
$("#directions_route_download").prop("href", downloadURL);
diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js
index f5dc4e050..42ce0cb5d 100644
--- a/app/assets/javascripts/index/directions.js
+++ b/app/assets/javascripts/index/directions.js
@@ -29,6 +29,7 @@ OSM.Directions = function (map) {
];
const expires = new Date();
+
expires.setFullYear(expires.getFullYear() + 10);
const modeGroup = $(".routing_modes");
@@ -39,12 +40,15 @@ OSM.Directions = function (map) {
coordTo = endpoints[1].latlng;
let routeFrom = "",
routeTo = "";
+
if (coordFrom) {
routeFrom = coordFrom.lat + "," + coordFrom.lng;
}
+
if (coordTo) {
routeTo = coordTo.lat + "," + coordTo.lng;
}
+
endpoints[0].swapCachedReverseGeocodes(endpoints[1]);
OSM.router.route("/directions?" + new URLSearchParams({
@@ -61,12 +65,15 @@ OSM.Directions = function (map) {
function setEngine(id) {
const engines = OSM.Directions.engines;
const desired = engines.find(engine => engine.id === id);
+
if (!desired || (chosenEngine && chosenEngine.id === id)) return;
+
chosenEngine = desired;
const modes = engines
.filter(engine => engine.provider === chosenEngine.provider)
.map(engine => engine.mode);
+
modeGroup
.find("input[id]")
.prop("disabled", function () {
@@ -79,6 +86,7 @@ OSM.Directions = function (map) {
const providers = engines
.filter(engine => engine.mode === chosenEngine.mode)
.map(engine => engine.provider);
+
select
.find("option[value]")
.prop("disabled", function () {
@@ -94,6 +102,7 @@ OSM.Directions = function (map) {
const points = endpoints.map(p => p.latlng);
if (!points[0] || !points[1]) return;
+
$("header").addClass("closed");
OSM.router.replace("/directions?" + new URLSearchParams({
@@ -110,13 +119,16 @@ OSM.Directions = function (map) {
await sidebarLoaded();
$("#directions_route").prop("hidden", false);
routeOutput.write(route);
+
if (fitRoute) {
routeOutput.fit();
}
}).catch(async function (error) {
if (error.name === "AbortError") return;
+
await sidebarLoaded();
routeOutput.remove();
+
if (reportErrors) {
$("#directions_error")
.prop("hidden", false)
@@ -157,12 +169,17 @@ OSM.Directions = function (map) {
$(".routing_marker_column span").on("dragstart", function (e) {
const dt = e.originalEvent.dataTransfer;
+
dt.effectAllowed = "move";
+
const jqthis = $(this);
+
dt.setData("text", JSON.stringify(jqthis.data()));
+
if (dt.setDragImage) {
const img = jqthis.clone()
.appendTo(document.body);
+
img.find("svg")
.toggleClass("position-absolute bottom-100 end-100")
.attr({ width: "25", height: "40" });
@@ -177,6 +194,7 @@ OSM.Directions = function (map) {
function startingLocationListener({ latlng }) {
if (endpoints[0].value) return;
+
endpoints[0].setValue(latlng.join(", "));
}
@@ -205,13 +223,17 @@ OSM.Directions = function (map) {
$("#map").on("drop", function (e) {
e.preventDefault();
+
const oe = e.originalEvent;
const dragData = JSON.parse(oe.dataTransfer.getData("text"));
const type = dragData.type;
const pt = L.DomEvent.getMousePosition(oe, map.getContainer()); // co-ordinates of the mouse pointer at present
+
pt.y += 20;
+
const ll = map.containerPointToLatLng(pt);
const llWithPrecision = OSM.cropLocation(ll, map.getZoom());
+
endpoints[type === "from" ? 0 : 1].setValue(llWithPrecision.join(", "));
});
@@ -226,10 +248,14 @@ OSM.Directions = function (map) {
function sidebarLoaded() {
if ($("#directions_route").length) {
sidebarReadyPromise = null;
+
return Promise.resolve();
}
+
if (sidebarReadyPromise) return sidebarReadyPromise;
+
sidebarReadyPromise = new Promise(resolve => OSM.loadSidebarContent("/directions", resolve));
+
return sidebarReadyPromise;
}
diff --git a/app/assets/javascripts/index/directions/fossgis_osrm.js b/app/assets/javascripts/index/directions/fossgis_osrm.js
index 24304abcd..2cb5ad6f7 100644
--- a/app/assets/javascripts/index/directions/fossgis_osrm.js
+++ b/app/assets/javascripts/index/directions/fossgis_osrm.js
@@ -34,6 +34,7 @@
"depart": "start",
"arrive": "destination"
};
+
function numToWord(num) {
return ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth"][num - 1];
}
@@ -59,25 +60,33 @@
if (step.maneuver.type.match(/^exit (rotary|roundabout)$/)) {
return OSM.i18n.t(template, { name: name });
}
+
if (step.maneuver.type.match(/^(rotary|roundabout)$/)) {
if (!step.maneuver.exit) {
return OSM.i18n.t(template + "_without_exit", { name: name });
}
+
if (step.maneuver.exit > 10) {
return OSM.i18n.t(template + "_with_exit", { exit: step.maneuver.exit, name: name });
}
+
return OSM.i18n.t(template + "_with_exit_ordinal", { exit: OSM.i18n.t(instrPrefix + "exit_counts." + numToWord(step.maneuver.exit)), name: name });
}
+
if (!step.maneuver.type.match(/^(on ramp|off ramp)$/)) {
return OSM.i18n.t(template + "_without_exit", { name: name });
}
+
const params = {};
+
if (step.exits && step.maneuver.type.match(/^(off ramp)$/)) params.exit = step.exits;
if (step.destinations) params.directions = destinations;
if (namedRoad) params.directions = name;
+
if (Object.keys(params).length > 0) {
template = template + "_with_" + Object.keys(params).join("_");
}
+
return OSM.i18n.t(template, params);
}
@@ -86,6 +95,7 @@
// special case handling
if (mode === "ferry") return "ferry";
if (intersections.some(i => i.classes?.includes("ferry"))) return "ferry";
+
switch (maneuver.type) {
case "on ramp":
case "off ramp":
@@ -108,6 +118,7 @@
return "turn " + maneuver.modifier;
}
}
+
const ICON_MAP = {
"continue": "straight",
"merge right": "merge-right",
diff --git a/app/assets/javascripts/index/directions/graphhopper.js b/app/assets/javascripts/index/directions/graphhopper.js
index 9c0c8f615..3a064339d 100644
--- a/app/assets/javascripts/index/directions/graphhopper.js
+++ b/app/assets/javascripts/index/directions/graphhopper.js
@@ -27,6 +27,7 @@
instr.distance,
line.slice(instr.interval[0], instr.interval[1] + 1)
]);
+
steps.at(-1)[0] = "destination";
return {
@@ -71,7 +72,7 @@
.then(({ paths }) => {
if (!paths || paths.length === 0) throw new Error();
- return { ... _processDirections(paths[0]), ...meta };
+ return { ..._processDirections(paths[0]), ...meta };
});
}
};
--
2.39.5
|