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

+14 -40
View File
@@ -17,10 +17,10 @@ import { LocateControl } from "/js/locate.js";
import { SearchControl } from "/js/search.js";
import { OfflineDataControl } from "/js/offline_data.js";
import { RoutePanelControl } from "/js/route.js";
import { LAYERS_ICON, WAYPOINT_ICON, SUNRISE_ICON, SUNSET_ICON, PENDING_ICON, LOCK_ICON, UNLOCK_ICON } from "/js/icons.js";
import { WAYPOINT_ICON, SUNRISE_ICON, SUNSET_ICON, PENDING_ICON, LOCK_ICON, UNLOCK_ICON } from "/js/icons.js";
import { formatCoords, formatSunInfo, sunChartHtml } from "/js/sun.js";
import { getPosition } from "/vendor/suncalc/suncalc.js";
import { notifySidePanelOpen, onlyOneSidePanelOpen, setupSidePanelModes } from "/js/panels.js";
import { setupSidePanelModes } from "/js/panels.js";
import { isLoggedIn } from "/js/auth.js";
import { DebugControl } from "/js/debug.js";
import { setupUpdate } from "/js/update.js";
@@ -104,45 +104,20 @@ function offlineStyle() {
return style;
}
// A sidebar icon that opens a full-height side panel (like the GPX one)
// with the Online/Offline choice — modelled after OsmAnd's "Configure map"
// panel, rather than a small dropdown flyout.
// The Online/Offline choice: the first group of the On the map panel
// (the Overlays one, overlays.js), no rail item or panel of its own.
class LayerToggleControl {
constructor(onSelect) {
this._onSelect = onSelect;
this._panel = document.querySelector(".onthemap-map");
}
mount(sidebar) {
this._container = document.createElement("div");
this._container.className = "sidebar-item";
this._container.innerHTML = `<button type="button" class="sidebar-icon" title="Base map" aria-label="Base map">${LAYERS_ICON}</button>`;
this._icon = this._container.querySelector(".sidebar-icon");
this._icon.addEventListener("click", () => this._togglePanel());
this._panel = document.getElementById("basemap-panel");
this._panel
.querySelector(".basemap-panel__close")
.addEventListener("click", () => this._togglePanel(false));
mount() {
this._panel.querySelectorAll(".basemap-panel__option").forEach((button) => {
button.addEventListener("click", () => {
this._onSelect(button.dataset.style);
this._togglePanel(false);
});
button.addEventListener("click", () => this._onSelect(button.dataset.style));
});
onlyOneSidePanelOpen(this._panel, () => this._icon.classList.remove("active"));
sidebar.appendChild(this._container);
}
_togglePanel(force) {
const open = force === undefined ? this._panel.hidden : force;
this._panel.hidden = !open;
this._icon.classList.toggle("active", open);
if (open) notifySidePanelOpen(this._panel);
}
setActive(name) {
this._panel.querySelectorAll(".basemap-panel__option").forEach((button) => {
button.classList.toggle("active", button.dataset.style === name);
@@ -151,8 +126,8 @@ class LayerToggleControl {
// Called once it's known there's no offline map to switch to (see the
// /api/offline-tiles check below) — an Online/Offline switch doesn't make
// sense to show at all when Offline was never going to work. The panel
// itself stays for its legend link.
// sense to show at all when Offline was never going to work. The legend
// link stays.
hideSources() {
this._panel.querySelector(".basemap-panel__sources").hidden = true;
}
@@ -471,15 +446,14 @@ setInterval(updateNight, 60000);
const sidebar = document.getElementById("sidebar");
// The rail of the Design canvas' Desktop, labelled: what's on the map (the
// map, overlays), the library and imports; the route; offline data; live
// (GNSS, LiveTrack); Status pinned at the bottom. Folding Map, Overlays and
// Live into one "On the map" panel is the canvas' next step, not done yet.
// The rail of the Design canvas' Desktop, labelled: On the map (the map,
// overlays), the library and imports; the route; offline data; live
// (GNSS, LiveTrack); Status pinned at the bottom.
const layerToggle = new LayerToggleControl(applyStyle);
const profilePanel = new TrackProfilePanel(map);
profilePanel.mount();
layerToggle.mount(sidebar);
layerToggle.mount();
layerToggle.setActive("online");
const overlaysControl = new OverlaysControl(map);
overlaysControl.mount(sidebar);
@@ -508,7 +482,7 @@ new LiveTrackPanelControl(map).mount(sidebar);
if (isLoggedIn()) new DebugControl().mount(sidebar);
if (isLoggedIn()) setupUpdate(document.querySelector(".topbar__update"), document.querySelector(".debug-panel__update-check"));
// A short name under each icon (CSS ::after), the title stays the tooltip.
const RAIL_LABELS = { "Base map": "Map", "Tracks & Points": "Library", "Import plugins": "Import", "Offline data": "Offline", LiveTrack: "Live", "Status / debug": "Status" };
const RAIL_LABELS = { "Tracks & Points": "Library", "Import plugins": "Import", "Offline data": "Offline", LiveTrack: "Live", "Status / debug": "Status" };
sidebar.querySelectorAll(".sidebar-icon").forEach((icon) => (icon.dataset.label = RAIL_LABELS[icon.title] ?? icon.title));
setupSidePanelModes();
+1 -1
View File
@@ -224,7 +224,7 @@ export class OverlaysControl {
mount(sidebar) {
this._container = document.createElement("div");
this._container.className = "sidebar-item";
this._container.innerHTML = `<button type="button" class="sidebar-icon" title="Overlays" aria-label="Overlays">${OVERLAYS_ICON}</button>`;
this._container.innerHTML = `<button type="button" class="sidebar-icon" title="On the map" aria-label="On the map">${OVERLAYS_ICON}</button>`;
this._icon = this._container.querySelector(".sidebar-icon");
this._icon.addEventListener("click", () => this._togglePanel());
+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