Dead reckoning in a tunnel: no fix for 3 s (or mode < 2) on the trip's route, the position carried along it (estimated: true, a grey arrow) by the car's CAN speed (vehicle.speed) when there is one, the average speed of the last ~20 s otherwise, up to 10 min (App.gnss_position, TripStore.ahead)

This commit is contained in:
randy committed 2026-12-02 18:24:47 +01:00
1 parent 7fdc0114e6
commit 7204355510
8 files changed
+143 -18

No files matched your search

+2
View File
@@ -3468,6 +3468,8 @@ button.basemap-panel__link[hidden] { display: none; }
/* The GNSS position once it has a course: an arrow, not the dot. */
.gnss-marker--arrow { width: 26px; height: 26px; border: none; border-radius: 0; background: none; box-shadow: none; filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.5)); }
.gnss-marker--arrow svg { display: block; }
/* no fix, the position estimated along the route (a tunnel): greyed */
.gnss-marker--estimated { filter: grayscale(1) opacity(0.7) drop-shadow(0 1px 2px rgb(0 0 0 / 0.5)); }
/* The navigation banner across the top (dashboard.js): the next turn. */
.dash-banner {
+28 -5
View File
@@ -71,6 +71,14 @@ export function resumeFollow(map) {
clearTimeout(state.timer);
}
// The first step of a follow (or a jump after a gap): zoom in to see the
// road ahead. easeTo, not flyTo — flyTo's swoop zooms out over the distance
// first, the wrong way when starting to drive.
export const FOLLOW_ZOOM = 16;
export function startFollow(map, lngLat) {
map.easeTo({ center: lngLat, zoom: Math.max(map.getZoom(), FOLLOW_ZOOM), duration: 1000 });
}
export function followPosition(map, lngLat, heading, speed, duration) {
const free = freeLookState(map);
free.followedAt = Date.now();
@@ -83,14 +91,27 @@ export function followPosition(map, lngLat, heading, speed, duration) {
free.button.hidden = true;
const pitched = map.getPitch() > 0;
const moving = Number.isFinite(heading) && (speed ?? 0) >= 1;
const zoom = moving && autoZoom(map.getZoom(), speed);
map.easeTo({
center: lngLat,
padding: { top: pitched ? map.getContainer().clientHeight * 0.4 : 0 },
...(pitched && moving && { bearing: heading }),
...(zoom && { zoom }),
...(duration != null && { duration, easing: (t) => t }),
});
}
// Auto-zoom like a car navigation: close in town, farther out the faster
// (0 km/h z17, 50 z16.2, 90 z15.6, 130+ z15). Eased toward that by at most
// 0.15 a fix and ignored within 0.25, so speed jitter doesn't pump the map.
// A hand zoom pauses the follow; on resuming it eases back.
export function autoZoom(current, speed) {
const target = Math.min(17, Math.max(15, 17 - speed * 3.6 * 0.0154));
const diff = target - current;
if (Math.abs(diff) < 0.25) return null;
return current + Math.sign(diff) * Math.min(Math.abs(diff), 0.15);
}
// Meters between a MapLibre LngLat and [lon, lat] (equirectangular).
function distanceM({ lng, lat }, [lon2, lat2]) {
return Math.hypot((lon2 - lng) * Math.cos((lat * Math.PI) / 180), lat2 - lat) * 111320;
@@ -189,15 +210,16 @@ export class GnssControl {
return;
}
this._status.textContent = fixLabel(data);
// no fix, carried along the route (a tunnel: App.gnss_position)
this._status.textContent = data.estimated ? "estimated (no fix)" : fixLabel(data);
const lngLat = [data.lon, data.lat];
// Recenters on every fix while enabled — this is the app's own
// receiver, so "GNSS on" means "follow it", the same way LocateControl
// (public/js/locate.js) follows it when GNSS is what it's using too.
// flyTo (with its zoom swoop) only for the first fix, since that's the
// one jumping from wherever the map already was; easeTo for later
// updates, a plain follow rather than repeating that swoop every poll.
// startFollow (zooming in) only for the first fix, since that's the
// one jumping from wherever the map already was; a plain follow for
// later updates, zooming by the speed (autoZoom).
const far = this._marker && distanceM(this._marker.getLngLat(), lngLat) > JUMP_M;
if (far) this._removeMarker();
if (!this._marker) {
@@ -208,7 +230,7 @@ export class GnssControl {
// survives map.setStyle() (switching Online/Offline) with no extra
// re-add handling needed.
this._marker = new Marker({ element: el, rotationAlignment: "map", pitchAlignment: "map" }).setLngLat(lngLat).addTo(this._map);
this._map.flyTo({ center: lngLat, zoom: Math.max(this._map.getZoom(), 15) });
startFollow(this._map, lngLat);
} else {
glideMarker(this._marker, lngLat, POLL_INTERVAL_MS);
followPosition(this._map, lngLat, data.track, data.speed, POLL_INTERVAL_MS);
@@ -222,6 +244,7 @@ export class GnssControl {
}
this._marker.setRotation(data.track);
}
this._marker.getElement().classList.toggle("gnss-marker--estimated", !!data.estimated);
}
_removeMarker() {
+5 -6
View File
@@ -1,5 +1,5 @@
import { Marker } from "/vendor/maplibre-gl/maplibre-gl.mjs";
import { followPosition } from "/js/gnss.js";
import { followPosition, startFollow } from "/js/gnss.js";
// Replaces MapLibre's own GeolocateControl (browser Geolocation API only)
// with one that prefers this app's own GNSS receiver when it's turned on
@@ -96,7 +96,7 @@ export class LocateControl {
_jumpToGnss({ alertIfNoFix = false } = {}) {
const position = this._gnssControl.getPosition();
if (position) {
this._map.flyTo({ center: position, zoom: Math.max(this._map.getZoom(), 15) });
startFollow(this._map, position);
} else if (alertIfNoFix) {
window.alert("Waiting for a GNSS fix…");
}
@@ -118,10 +118,9 @@ export class LocateControl {
}
// Recenters on every fix, following the position the way GeolocateControl
// itself does while tracking — flyTo (with its zoom swoop) only for the
// itself does while tracking — startFollow (zooming in) only for the
// first fix, since that's the one jumping from wherever the map already
// was; easeTo for later updates, a plain pan/zoom-preserving follow
// rather than repeating that same swoop on every update.
// was; a plain follow zooming by the speed (autoZoom) for later updates.
//
// MapLibre's own blue pulsing "user location" dot styling
// (.maplibregl-user-location-dot, maplibre-gl.css — the exact look
@@ -138,7 +137,7 @@ export class LocateControl {
const circleEl = document.createElement("div");
circleEl.className = "maplibregl-user-location-accuracy-circle";
this._circleMarker = new Marker({ element: circleEl, pitchAlignment: "map" }).setLngLat([lon, lat]).addTo(this._map);
this._map.flyTo({ center: [lon, lat], zoom: Math.max(this._map.getZoom(), 15) });
startFollow(this._map, [lon, lat]);
} else {
this._marker.setLngLat([lon, lat]);
this._circleMarker.setLngLat([lon, lat]);