What's here on a right click / long press / Alt+click (the Design canvas' Desktop): the position on top (a click copies it, with the DMS and the ground's height), Route here / Add to the trip / Save a point, the features' raw properties folded under it; C copies the position under the mouse. Voice prompts while navigating (speechSynthesis, Valhalla's verbal alert and pre-transition instructions, ~25 s and ~7 s ahead), on/off in drive mode's Menu, off by default. TODO: the touch items closed (the Pad7 is fine as it is)
This commit is contained in:
1 parent
f15fbef746
commit
ad975bcf62
8 files changed
+134
-36
No files matched your search
+59
-23
@@ -20,7 +20,7 @@ import { RoutePanelControl } from "/js/route.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 { setupSidePanelModes } from "/js/panels.js";
|
||||
import { addRoutePoint, setupSidePanelModes } from "/js/panels.js";
|
||||
import { isLoggedIn } from "/js/auth.js";
|
||||
import { DebugControl } from "/js/debug.js";
|
||||
import { setupUpdate } from "/js/update.js";
|
||||
@@ -285,7 +285,8 @@ map.addControl(new MeasureControl(), "top-right");
|
||||
// button that can only ever end in a 401 for a logged-out viewer, same
|
||||
// "hide the write-only affordance" story as GpxPanelControl's own
|
||||
// upload/new-folder buttons.
|
||||
if (isLoggedIn()) map.addControl(new NotesControl(), "top-right");
|
||||
let notesControl = null; // what's here's "Save a point" (below)
|
||||
if (isLoggedIn()) map.addControl((notesControl = new NotesControl()), "top-right");
|
||||
map.addControl(new HomeButton({ bounds: SLOVAKIA_BOUNDS }), "top-right");
|
||||
// ...as the artboard's three cards: zoom; the view (compass, north lock, 3D,
|
||||
// my position); the tools (measure, note, home). Each control keeps its own
|
||||
@@ -581,36 +582,71 @@ Promise.allSettled(ready).then(() => {
|
||||
else map.once("idle", restore);
|
||||
});
|
||||
|
||||
// Alt+click, right click or a long press (touch browsers fire
|
||||
// contextmenu for it) anywhere shows every rendered feature at that point — base map
|
||||
// (OSM tags via OpenFreeMap/protomaps), GPX/FIT layers, radar, all of it —
|
||||
// with its raw properties, inspired by NPMap4's infoboxControl (a generic
|
||||
// "show me everything here" debug view, kept separate from the curated
|
||||
// popups those same features already have via their own layer-specific
|
||||
// click handlers, e.g. gpx.js's waypoint popups — both can fire on the same
|
||||
// click, which is fine, this is a power-user/debugging affordance, not
|
||||
// something replacing the normal popups). No dedicated UI for this
|
||||
// deliberately — a keyboard-modified click needs no button, state, or
|
||||
// cursor change of its own.
|
||||
const inspect = (event) => {
|
||||
// Right click, a long press (touch browsers fire contextmenu for it) or
|
||||
// Alt+click: what's here (the Design canvas' Desktop). The position on top,
|
||||
// a click copies it; Route here / Add to the trip / Save a point; every
|
||||
// rendered feature's raw properties folded under it (the debug view it
|
||||
// was). C copies the position under the mouse with no popup.
|
||||
const copyPosition = async ({ lng, lat }) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(`${lat.toFixed(6)}, ${lng.toFixed(6)}`);
|
||||
return true;
|
||||
} catch {
|
||||
return false; // clipboard API unavailable (an insecure context)
|
||||
}
|
||||
};
|
||||
const whatsHere = (event) => {
|
||||
const { lngLat } = event;
|
||||
const features = map.queryRenderedFeatures(event.point);
|
||||
if (features.length === 0) return;
|
||||
|
||||
const html = features
|
||||
const rows = features
|
||||
.map((feature) => {
|
||||
const rows = Object.entries(feature.properties)
|
||||
const cells = Object.entries(feature.properties)
|
||||
.map(([key, value]) => `<tr><th>${escapeHtml(key)}</th><td>${escapeHtml(String(value))}</td></tr>`)
|
||||
.join("");
|
||||
return `<div class="debug-popup__feature"><strong>${escapeHtml(feature.layer.id)}</strong><table>${rows || "<tr><td>(no properties)</td></tr>"}</table></div>`;
|
||||
return `<div class="debug-popup__feature"><strong>${escapeHtml(feature.layer.id)}</strong><table>${cells || "<tr><td>(no properties)</td></tr>"}</table></div>`;
|
||||
})
|
||||
.join("");
|
||||
|
||||
new Popup({ maxWidth: "320px", className: "debug-popup" }).setLngLat(event.lngLat).setHTML(html).addTo(map);
|
||||
const el = document.createElement("div");
|
||||
el.className = "here";
|
||||
el.innerHTML = `
|
||||
<button type="button" class="here__position" title="Copy">
|
||||
<span><b>${lngLat.lat.toFixed(5)}, ${lngLat.lng.toFixed(5)}</b><small>${formatCoords(lngLat.lat, lngLat.lng)}<span class="here__alt"></span></small></span>
|
||||
<em>Copy</em>
|
||||
</button>
|
||||
<div class="here__actions">
|
||||
<button type="button" data-do="route">Route here</button>
|
||||
<button type="button" data-do="trip">Add to the trip</button>
|
||||
${notesControl ? `<button type="button" data-do="note">Save a point</button>` : ""}
|
||||
</div>
|
||||
<details class="here__features"><summary>${features.length} feature${features.length === 1 ? "" : "s"} here</summary>${rows}</details>
|
||||
<div class="here__hint">C copies the position under the cursor</div>`;
|
||||
const popup = new Popup({ maxWidth: "320px", className: "debug-popup here-popup" }).setLngLat(lngLat).setDOMContent(el).addTo(map);
|
||||
elevationAt(lngLat.lng, lngLat.lat, terrainOffline)
|
||||
.then((metres) => metres != null && (el.querySelector(".here__alt").textContent = ` · ${Math.round(metres)} m`))
|
||||
.catch(() => {});
|
||||
el.querySelector(".here__position").addEventListener("click", async () => {
|
||||
if (await copyPosition(lngLat)) el.querySelector(".here__position em").textContent = "Copied ✓";
|
||||
});
|
||||
const at = [lngLat.lng, lngLat.lat];
|
||||
const actions = { route: () => addRoutePoint(at, null), trip: () => routePanel.addStop(at), note: () => notesControl.placeAt(lngLat) };
|
||||
el.querySelector(".here__actions").addEventListener("click", (e) => {
|
||||
const action = actions[e.target.dataset?.do];
|
||||
if (!action) return;
|
||||
popup.remove();
|
||||
action();
|
||||
});
|
||||
};
|
||||
map.on("click", (event) => event.originalEvent.altKey && inspect(event));
|
||||
map.on("click", (event) => event.originalEvent.altKey && whatsHere(event));
|
||||
map.on("contextmenu", (event) => {
|
||||
event.originalEvent.preventDefault();
|
||||
inspect(event);
|
||||
whatsHere(event);
|
||||
});
|
||||
let mouseAt = null;
|
||||
map.on("mousemove", ({ lngLat }) => (mouseAt = lngLat));
|
||||
map.getCanvasContainer().addEventListener("mouseleave", () => (mouseAt = null));
|
||||
document.addEventListener("keydown", async (e) => {
|
||||
if (e.key !== "c" || !mouseAt || e.ctrlKey || e.altKey || e.metaKey || e.target.closest("input, textarea, select, [contenteditable]")) return;
|
||||
if (await copyPosition(mouseAt)) cursorLabel.textContent = "Copied ✓";
|
||||
});
|
||||
|
||||
// Feature properties can come straight from an uploaded GPX/FIT file (an
|
||||
|
||||
Reference in new issue
Block a user