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:
1 parent
7fdc0114e6
commit
7204355510
8 files changed
+143
-18
No files matched your search
+28
-5
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user