Following the GNSS receiver or the browser's own position turns the map heading-up in the 3D view, position in the lower part of the screen, like a car navigation
This commit is contained in:
1 parent
fdd77986c1
commit
e9c9e96b92
2 files changed
+19
-4
No files matched your search
+15
-1
@@ -10,6 +10,20 @@ const POLL_INTERVAL_MS = 1500;
|
||||
// marker, with fix status in a flyout. Polling rather than a push channel
|
||||
// is deliberate — see the comment in app.rb next to GNSS_LATEST — and fits
|
||||
// gpsd's own ~1Hz report rate fine.
|
||||
// One follow step for a moving position (this receiver, the browser's own
|
||||
// geolocation). In the 3D (pitched) view it turns heading-up like a car
|
||||
// navigation, with the position in the lower part of the screen; the last
|
||||
// heading stays while standing still (speed in m/s, heading in degrees).
|
||||
export function followPosition(map, lngLat, heading, speed) {
|
||||
const pitched = map.getPitch() > 0;
|
||||
const moving = Number.isFinite(heading) && (speed ?? 0) >= 1;
|
||||
map.easeTo({
|
||||
center: lngLat,
|
||||
padding: { top: pitched ? map.getContainer().clientHeight * 0.4 : 0 },
|
||||
...(pitched && moving && { bearing: heading }),
|
||||
});
|
||||
}
|
||||
|
||||
export class GnssControl {
|
||||
constructor(map) {
|
||||
this._map = map;
|
||||
@@ -109,7 +123,7 @@ export class GnssControl {
|
||||
this._map.flyTo({ center: lngLat, zoom: Math.max(this._map.getZoom(), 15) });
|
||||
} else {
|
||||
this._marker.setLngLat(lngLat);
|
||||
this._map.easeTo({ center: lngLat });
|
||||
followPosition(this._map, lngLat, data.track, data.speed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user