Desktop after the artboard, the panels too: the rail dark like the topbar (the open panel's item on a lighter band with an accent edge), side panels 400 px, the map's buttons as white cards of 40 px; Route laid out as drawn — Reverse/Clear in the head, each point with a grip to drag it elsewhere, its letter (the same on the marker), name and role, the leg to it as a dashed line between, + Search / Saved point / My position chips, the totals as a card (distance, time, climb, arrival; descent and steepest grade under it), vehicle and avoid as chips, Directions and Reach folded with their counts, Save to library and Elevation profile at the bottom; On the map: the Online/Offline choice and the legend are the first group of the Overlays panel, renamed On the map — no Base map item or panel of its own. TODO: copy the cursor's position, the scale back over the map
CI / check (push) Successful in 24s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-03 09:20:27 +01:00
1 parent 258d35a7a1
commit d559f76b4a
6 files changed
+536 -142

No files matched your search

+68 -21
View File
@@ -1,5 +1,5 @@
import { Marker } from "/vendor/maplibre-gl/maplibre-gl.mjs";
import { ROUTE_ICON, POSITION_ICON, SAVED_POINT_ICON, REVERSE_ICON, CLEAR_ICON, SAVE_ICON } from "/js/icons.js";
import { ROUTE_ICON, REVERSE_ICON, CLEAR_ICON } from "/js/icons.js";
import { notifySidePanelOpen, onlyOneSidePanelOpen, notifyGpxStoreChanged, onRoutePoint, onRouteEdit, notifyRouteChanged, onReroute, onRouteProgress } from "/js/panels.js";
import { isLoggedIn } from "/js/auth.js";
import { wirePreview } from "/js/preview.js";
@@ -103,7 +103,9 @@ export class RoutePanelControl {
});
this._panel.querySelector('[data-action="clear"]').addEventListener("click", () => this._clear());
this._panel.querySelector('[data-action="position"]').addEventListener("click", () => this._addPosition());
const icons = { position: POSITION_ICON, "saved-point": SAVED_POINT_ICON, reverse: REVERSE_ICON, clear: CLEAR_ICON, save: SAVE_ICON };
this._panel.querySelector('[data-action="search"]').addEventListener("click", () => document.querySelector(".search-panel__input")?.focus());
this._totals = this._panel.querySelector(".route-panel__totals");
const icons = { reverse: REVERSE_ICON, clear: CLEAR_ICON };
for (const [action, icon] of Object.entries(icons)) this._panel.querySelector(`[data-action="${action}"]`).insertAdjacentHTML("afterbegin", icon);
this._setupSavedPoints();
this._editingNote = this._panel.querySelector(".route-panel__editing");
@@ -357,25 +359,52 @@ export class RoutePanelControl {
this._fetchRoute();
}
// The Desktop artboard's list: a grip to drag the point to another place,
// its letter (the same on its marker), name and role, then the leg to the
// next one as a dashed line between them.
_renderPoints() {
this._list.innerHTML = "";
const last = this._points.length - 1;
this._points.forEach((point, index) => {
const label = index === 0 ? "Start" : index === this._points.length - 1 ? "End" : `Via ${index}`;
point.marker.getElement().textContent = index === 0 ? "S" : index === this._points.length - 1 ? "E" : String(index);
const letter = String.fromCharCode(65 + (index % 26));
const role = index === 0 ? "Start" : index === last ? "End" : `Via ${index}`;
point.marker.getElement().textContent = letter;
const leg = this._leg(index);
if (leg) {
this._list.appendChild(Object.assign(document.createElement("li"), {
className: "route-panel__leg",
textContent: `${leg.km.toFixed(1)} km${leg.s != null ? ` · ${formatDuration(leg.s)}` : ""}`,
}));
}
const li = document.createElement("li");
li.className = "route-panel__stop";
li.classList.toggle("route-panel__passed", !!point.passed || this._behind(index));
const grip = Object.assign(document.createElement("span"), { className: "route-panel__grip", textContent: "⋮⋮", title: "Drag to reorder" });
li.draggable = true;
li.addEventListener("dragstart", (event) => {
this._dragging = point;
event.dataTransfer.effectAllowed = "move";
li.classList.add("route-panel__dragging");
});
li.addEventListener("dragend", () => li.classList.remove("route-panel__dragging"));
li.addEventListener("dragover", (event) => event.preventDefault());
li.addEventListener("drop", (event) => {
event.preventDefault();
const from = this._points.indexOf(this._dragging);
this._dragging = null;
if (from < 0 || from === index) return;
this._points.splice(index, 0, ...this._points.splice(from, 1));
this._changed();
});
const badge = Object.assign(document.createElement("span"), { className: "route-panel__badge", textContent: letter });
badge.classList.toggle("route-panel__badge--end", index === last && last > 0);
const text = document.createElement("span");
text.className = "route-panel__point";
text.textContent = `${label} · ${point.name || `${point.lngLat[1].toFixed(5)}, ${point.lngLat[0].toFixed(5)}`}`;
const leg = this._leg(index);
if (leg) text.append(Object.assign(document.createElement("small"), { className: "route-panel__leg", textContent: `+${leg.km.toFixed(1)} km${leg.s != null ? ` · ${formatDuration(leg.s)}` : ""}` }));
li.append(
text,
this._navButton(point, label),
this._pointButton("↑", "Move up", index > 0, () => this._move(point, -1)),
this._pointButton("↓", "Move down", index < this._points.length - 1, () => this._move(point, 1)),
this._pointButton("×", "Remove", true, () => this._removePoint(point)),
text.append(
Object.assign(document.createElement("span"), { className: "route-panel__name", textContent: point.name || `${point.lngLat[1].toFixed(5)}, ${point.lngLat[0].toFixed(5)}` }),
Object.assign(document.createElement("small"), { className: "route-panel__role", textContent: role }),
);
li.append(grip, badge, text, this._navButton(point, role), this._pointButton("×", "Remove", true, () => this._removePoint(point)));
// Hover/hold previews the point; a click on its name commits.
wirePreview(this._map, text, () => ({ lngLat: point.lngLat }));
text.addEventListener("click", () => this._map.easeTo({ center: point.lngLat, zoom: Math.max(this._map.getZoom(), 14) }));
@@ -387,6 +416,25 @@ export class RoutePanelControl {
this._saveButton.textContent = this._editing ? "Save changes" : "Save to library";
}
// The totals card: distance, time, climb (once the terrain's sampled),
// arrival if leaving now.
_renderTotals(route) {
this._totals.hidden = !route;
if (!route) return;
const { distance_km: km, time_s: seconds } = route.properties;
const arrive = new Date(Date.now() + seconds * 1000).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
const cells = [
[`${km.toFixed(km < 10 ? 1 : 0)} km`, "distance"],
[formatDuration(seconds), "time"],
[route.elevation ? `${Math.round(route.elevation.gain)} m` : "…", "climb"],
[arrive, "arrive"],
];
this._totals.innerHTML = cells.map(([value, key]) => `<span><b>${value}</b><small>${key}</small></span>`).join("");
if (route.elevation) {
this._totals.insertAdjacentHTML("beforeend", `<span class="route-panel__totals-more">↓ ${Math.round(route.elevation.loss)} m · steepest ${route.elevation.maxGrade.toFixed(0)} %</span>`);
}
}
// Toggles whether the point is saved into the route as a navigation
// point (a course point on a Garmin); an unnamed one asks for a name.
_navButton(point, label) {
@@ -457,13 +505,12 @@ export class RoutePanelControl {
this._directions.hidden = !route;
this._profileButton.hidden = true;
this._showCountries(route?.properties.countries);
if (!route) {
this._summary.textContent = message;
return;
}
this._renderTotals(route);
this._summary.textContent = message;
if (!route) return;
const { distance_km: km, time_s: seconds, maneuvers } = route.properties;
this._summary.textContent = `${km.toFixed(1)} km · ${formatDuration(seconds)}`;
const { maneuvers } = route.properties;
this._directions.querySelector(".route-panel__fold-meta").textContent = `${maneuvers.length} steps`;
const list = this._directions.querySelector("ol");
list.innerHTML = "";
maneuvers.forEach(({ text, km: length }) => {
@@ -481,7 +528,7 @@ export class RoutePanelControl {
if (this._route !== route || !profile) return;
route.elevation = profile;
this._summary.textContent += ` · ↑ ${Math.round(profile.gain)} m ↓ ${Math.round(profile.loss)} m · max ${profile.maxGrade.toFixed(0)} %`;
this._renderTotals(route);
this._profileButton.hidden = false;
}
@@ -638,7 +685,7 @@ export class RoutePanelControl {
notifyGpxStoreChanged(path);
this._editing = { key: path, id: editing?.id ?? (await this._savedId(path)), name: name.trim() };
this._renderPoints();
this._summary.textContent += " · saved";
this._summary.textContent = "Saved to the library";
}
// The route's points marked 📍 as points inside the route item (marked