GNSS follow glides the marker and the camera linearly to each fix over the poll interval instead of jumping; the simulation sends a fix every 0.5 s
This commit is contained in:
1 parent
8680cdbee7
commit
fbccb2acc9
3 files changed
+22
-6
No files matched your search
+19
-3
@@ -14,16 +14,32 @@ const POLL_INTERVAL_MS = 1500;
|
||||
// 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) {
|
||||
// duration (ms): a linear glide over that long — the time until the next
|
||||
// fix, so a 1 Hz receiver moves the camera smoothly, not in 10 m jumps.
|
||||
export function followPosition(map, lngLat, heading, speed, duration) {
|
||||
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 }),
|
||||
...(duration != null && { duration, easing: (t) => t }),
|
||||
});
|
||||
}
|
||||
|
||||
// The marker moved to lngLat the same way: a linear glide over duration ms.
|
||||
function glideMarker(marker, lngLat, duration) {
|
||||
cancelAnimationFrame(marker._glide);
|
||||
const from = marker.getLngLat();
|
||||
const start = performance.now();
|
||||
const step = (now) => {
|
||||
const t = Math.min(1, (now - start) / duration);
|
||||
marker.setLngLat([from.lng + (lngLat[0] - from.lng) * t, from.lat + (lngLat[1] - from.lat) * t]);
|
||||
if (t < 1) marker._glide = requestAnimationFrame(step);
|
||||
};
|
||||
marker._glide = requestAnimationFrame(step);
|
||||
}
|
||||
|
||||
export class GnssControl {
|
||||
constructor(map) {
|
||||
this._map = map;
|
||||
@@ -122,8 +138,8 @@ export class GnssControl {
|
||||
this._marker = new Marker({ element: el }).setLngLat(lngLat).addTo(this._map);
|
||||
this._map.flyTo({ center: lngLat, zoom: Math.max(this._map.getZoom(), 15) });
|
||||
} else {
|
||||
this._marker.setLngLat(lngLat);
|
||||
followPosition(this._map, lngLat, data.track, data.speed);
|
||||
glideMarker(this._marker, lngLat, POLL_INTERVAL_MS);
|
||||
followPosition(this._map, lngLat, data.track, data.speed, POLL_INTERVAL_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user