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
@@ -1504,6 +1504,21 @@ button.basemap-panel__link[hidden] { display: none; }
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* what's here (map.js): the position, what to do with it, the features folded */
|
||||
.here-popup .maplibregl-popup-content { padding: 0; max-height: 420px; }
|
||||
.here button { font: inherit; color: inherit; cursor: pointer; }
|
||||
.here__position { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 28px 10px 12px; border: none; border-bottom: 1px solid var(--ui-line); background: none; text-align: left; }
|
||||
.here__position > span { flex: 1; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
|
||||
.here__position b { font-size: 15px; }
|
||||
.here__position small, .here__position em { color: var(--ui-muted); font-style: normal; font-size: 12px; }
|
||||
.here__actions { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--ui-line); }
|
||||
.here__actions button { flex: 1; height: 30px; padding: 0 6px; border: 1px solid var(--ui-line); border-radius: 6px; background: none; font-weight: 600; font-size: 12px; white-space: nowrap; }
|
||||
.here__actions button:hover { background: var(--ui-hover, rgba(0, 0, 0, 0.06)); }
|
||||
.here__features { padding: 8px 12px 0; }
|
||||
.here__features summary { font-weight: 600; cursor: pointer; }
|
||||
.here__features .debug-popup__feature:first-of-type { margin-top: 6px; }
|
||||
.here__hint { padding: 6px 12px 8px; font-size: 11px; color: var(--ui-muted); }
|
||||
|
||||
.maplibregl-ctrl-overview-map {
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
|
||||
@@ -39,6 +39,12 @@ const TRACE_STEP_M = 10; // fixes kept for /api/road at least this far apart
|
||||
const LANES_AHEAD_M = 1000; // the next maneuver's lanes from this close
|
||||
const DEFAULT_WIDGETS = { inclinometer: true, speed: true, altitude: true, navigation: true, banner: true };
|
||||
const THEN_M = 300; // the maneuver after the next one shown with it when it follows this closely
|
||||
// Voice prompts (speechSynthesis, Valhalla's verbal instructions), on/off in
|
||||
// drive mode's Menu: "In 400 m, turn right…" from SOON_S ahead, the
|
||||
// instruction itself NOW_S before the maneuver (at least the metres given).
|
||||
export const VOICE_KEY = "maptool.voice";
|
||||
const SOON_S = 25, SOON_M = 400;
|
||||
const NOW_S = 7, NOW_M = 60;
|
||||
const DEFAULT_OPACITY = 0.45; // the card's background, the map shows through
|
||||
|
||||
const load = () => {
|
||||
@@ -187,7 +193,9 @@ export class DashboardControl {
|
||||
this._lastAt = 0;
|
||||
this._offFixes = 0;
|
||||
this._sentKm = undefined; // the new route drawn by the next fix
|
||||
this._said = new Set();
|
||||
}));
|
||||
this._said = new Set(); // voice prompts given: "maneuver index:soon|now"
|
||||
this._trace = []; // [lon, lat] fixes TRACE_STEP_M apart, for /api/road
|
||||
this._road = null; // its last answer
|
||||
this._roadAt = 0;
|
||||
@@ -228,6 +236,21 @@ export class DashboardControl {
|
||||
notifyRouteProgress(km);
|
||||
}
|
||||
|
||||
_speak(index, maneuver, m, speed) {
|
||||
let voiceOn = false;
|
||||
try { voiceOn = localStorage.getItem(VOICE_KEY) === "on"; } catch { /* private window */ }
|
||||
if (!voiceOn || !window.speechSynthesis) return;
|
||||
const now = Math.max(NOW_M, speed * NOW_S);
|
||||
let stage = null, text = null;
|
||||
if (m <= now) [stage, text] = ["now", maneuver.say];
|
||||
else if (m <= Math.max(SOON_M, speed * SOON_S) && m > 2 * now && maneuver.alert) {
|
||||
[stage, text] = ["soon", `In ${distance(m).replace(" m", " meters").replace(" km", " kilometers")}, ${maneuver.alert[0].toLowerCase()}${maneuver.alert.slice(1)}`];
|
||||
}
|
||||
if (!text || this._said.has(`${index}:${stage}`)) return;
|
||||
this._said.add(`${index}:soon`).add(`${index}:${stage}`);
|
||||
speechSynthesis.speak(new SpeechSynthesisUtterance(text));
|
||||
}
|
||||
|
||||
// The limit and what's ahead: from the route while on it, else the road.
|
||||
_navigate() {
|
||||
const { lat, lon, speed } = this._values;
|
||||
@@ -261,6 +284,7 @@ export class DashboardControl {
|
||||
then: maneuver && then && then.at - maneuver.at <= THEN_M / 1000 ? then : null,
|
||||
street: onStreet,
|
||||
};
|
||||
if (maneuver && off <= ON_ROUTE_M) this._speak(index, maneuver, (maneuver.at - at) * 1000, speed ?? 0);
|
||||
return;
|
||||
}
|
||||
this._progress(null);
|
||||
|
||||
+11
-1
@@ -3,7 +3,7 @@ import { requestGnssFollow, onRouteChanged } from "/js/panels.js";
|
||||
import { pauseFollow, resumeFollow, isFollowing } from "/js/gnss.js";
|
||||
import { formatDuration } from "/js/route.js";
|
||||
import { isLoggedIn } from "/js/auth.js";
|
||||
import { watchDashboard, maneuverSvg, distance } from "/js/dashboard.js";
|
||||
import { watchDashboard, maneuverSvg, distance, VOICE_KEY } from "/js/dashboard.js";
|
||||
import { formatSunInfo } from "/js/sun.js";
|
||||
import { pointsMenu, layersMenu, terrainMenu, elevationHtml, cellButton, bindKey, emptyRow as empty, escapeHtml } from "/js/drive_menus.js";
|
||||
|
||||
@@ -104,6 +104,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
|
||||
<button type="button" class="drive-panel__close" aria-label="Close">✕</button>
|
||||
<button type="button" class="drive-menu__row" data-action="overview">The whole route <small>the follow pauses</small></button>
|
||||
<button type="button" class="drive-menu__row" data-action="terrain-auto"></button>
|
||||
<button type="button" class="drive-menu__row" data-action="voice"></button>
|
||||
<button type="button" class="drive-menu__row" data-action="leave">Leave driving mode</button>`;
|
||||
// auto: opens off-road and closes back on the road; stay: opens and stays (the inclinometer all along); hand: neither
|
||||
const TERRAIN_MODES = { auto: "opens and closes by itself", stay: "opens by itself, stays", hand: "by hand" };
|
||||
@@ -117,6 +118,15 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
|
||||
renderAuto();
|
||||
});
|
||||
renderAuto();
|
||||
const voiceButton = menuPanel.querySelector('[data-action="voice"]');
|
||||
const voiceOn = () => { try { return localStorage.getItem(VOICE_KEY) === "on"; } catch { return false; } };
|
||||
const renderVoice = () => { voiceButton.innerHTML = `Voice prompts: ${voiceOn() ? "on" : "off"} <small>tap to switch</small>`; };
|
||||
voiceButton.addEventListener("click", () => {
|
||||
try { localStorage.setItem(VOICE_KEY, voiceOn() ? "off" : "on"); } catch { /* private window: not kept */ }
|
||||
if (voiceOn()) window.speechSynthesis?.speak(new SpeechSynthesisUtterance("Voice prompts on"));
|
||||
renderVoice();
|
||||
});
|
||||
renderVoice();
|
||||
menuPanel.querySelector('[data-action="overview"]').addEventListener("click", overview);
|
||||
menuPanel.querySelector('[data-action="leave"]').addEventListener("click", () => set(false));
|
||||
const crosshair = document.createElement("div");
|
||||
|
||||
+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
|
||||
|
||||
@@ -342,6 +342,14 @@ export class NotesControl {
|
||||
return this._container;
|
||||
}
|
||||
|
||||
// "Save a point" from what's here (map.js): the note's form at that spot.
|
||||
placeAt(lngLat) {
|
||||
if (!this._active) this._setActive(true);
|
||||
this._form.close();
|
||||
this._removeMarker();
|
||||
this._onClick({ lngLat });
|
||||
}
|
||||
|
||||
_removeMarker() {
|
||||
this._marker?.remove();
|
||||
this._marker = null;
|
||||
|
||||
Reference in new issue
Block a user