mirror of
https://github.com/BigBodyCobain/Shadowbroker.git
synced 2026-12-05 00:53:37 +01:00
fix(map): cap dead-reckoning so stale data can't fling aircraft across the map
After the browser tab sat hidden overnight, every airborne aircraft was drawn
smeared thousands of miles along its last heading (e.g. over open ocean) for
about a minute after waking, until fresh data arrived.
Polling pauses while the tab is hidden, but the interpolation clock keeps
counting from the last data refresh. Since 5ae1e5b the dead-reckoning cap
(interpolatePosition's maxDt, documented as "Cap interpolation time to prevent
runaway drift when data is stale") was overridden with
UNBOUNDED_INTERP_SECONDS = Infinity, so 8 hours stale moved a 500 kt flight
~3,300 nm.
Restore a cap via a shared MAX_INTERP_SECONDS = 180 used by flights, ships and
satellites (useInterpolation) and the worker-side interpolation
(applyDynamicLayerInterp). Live data refreshes every ~15s, so normal animation
is unaffected; stale markers now advance at most ~25 nm, then snap to fresh data.
Also widens a source-slice window in maplibreDecomposition.test.ts that had
zero slack (onClose ended exactly at char 500 with LF; failed on CRLF checkouts).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5e33e0a01a
commit
1c603c8ce1
5 files changed
+43
-10
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { applyDynamicLayerInterp } from '@/components/map/applyDynamicLayerInterp';
|
||||
import type { DynamicMapLayersResult } from '@/components/map/dynamicMapLayers.worker';
|
||||
import { MAX_INTERP_SECONDS } from '@/lib/constants';
|
||||
|
||||
function pointLayer(
|
||||
props: Record<string, unknown>,
|
||||
@@ -56,6 +57,32 @@ describe('applyDynamicLayerInterp', () => {
|
||||
expect(coords && coords.type === 'Point' ? coords.coordinates[1] : null).toBeCloseTo(40, 1);
|
||||
});
|
||||
|
||||
it('caps dead-reckoning when data is stale (tab hidden overnight)', () => {
|
||||
const layer = (): DynamicMapLayersResult => ({
|
||||
commercialFlightsGeoJSON: pointLayer(
|
||||
{ kind: 'flight', baseLat: 40, baseLng: -74, spd: 500, hdg: 90, alt: 35000 },
|
||||
[-74, 40],
|
||||
),
|
||||
privateFlightsGeoJSON: null,
|
||||
privateJetsGeoJSON: null,
|
||||
militaryFlightsGeoJSON: null,
|
||||
trackedFlightsGeoJSON: null,
|
||||
shipsGeoJSON: null,
|
||||
meshtasticGeoJSON: null,
|
||||
aprsGeoJSON: null,
|
||||
});
|
||||
const lngAt = (dt: number) => {
|
||||
const g = applyDynamicLayerInterp(layer(), dt).commercialFlightsGeoJSON?.features[0].geometry;
|
||||
return g && g.type === 'Point' ? g.coordinates[0] : NaN;
|
||||
};
|
||||
const eightHours = lngAt(8 * 3600);
|
||||
// Same position as at the cap: no further drift however stale the data is.
|
||||
expect(eightHours).toBeCloseTo(lngAt(MAX_INTERP_SECONDS), 9);
|
||||
// 500 kt for 180 s ≈ 25 nm ≈ 0.54° of longitude at 40°N — not thousands of miles.
|
||||
expect(eightHours - -74).toBeGreaterThan(0.3);
|
||||
expect(eightHours - -74).toBeLessThan(0.7);
|
||||
});
|
||||
|
||||
it('does not move grounded flights', () => {
|
||||
const layers: DynamicMapLayersResult = {
|
||||
commercialFlightsGeoJSON: pointLayer(
|
||||
|
||||
@@ -157,7 +157,8 @@ describe('MaplibreViewer decomposition — selection and dismissal', () => {
|
||||
it('satellite popup calls onEntityClick(null) on close', () => {
|
||||
const satSection = viewer.slice(
|
||||
viewer.indexOf("selectedEntity?.type === 'satellite'"),
|
||||
viewer.indexOf("selectedEntity?.type === 'satellite'") + 500,
|
||||
// 500 chars left no slack: onClose ended exactly at the window edge (LF) and fell outside on CRLF checkouts.
|
||||
viewer.indexOf("selectedEntity?.type === 'satellite'") + 900,
|
||||
);
|
||||
expect(satSection).toContain('<SatellitePopup');
|
||||
expect(satSection).toContain('onClose={() => onEntityClick?.(null)}');
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { interpolatePosition } from '@/utils/positioning';
|
||||
import type { DynamicMapLayersResult } from '@/components/map/dynamicMapLayers.worker';
|
||||
|
||||
const UNBOUNDED_INTERP_SECONDS = Number.POSITIVE_INFINITY;
|
||||
import { MAX_INTERP_SECONDS } from '@/lib/constants';
|
||||
|
||||
type InterpProps = {
|
||||
baseLat?: number;
|
||||
@@ -32,7 +31,7 @@ function interpCoords(props: InterpProps, dtSeconds: number): [number, number] |
|
||||
spd,
|
||||
dtSeconds,
|
||||
0,
|
||||
UNBOUNDED_INTERP_SECONDS,
|
||||
MAX_INTERP_SECONDS,
|
||||
);
|
||||
return [newLng, newLat];
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
import { useCallback, useRef, useEffect, useState } from 'react';
|
||||
import { interpolatePosition } from '@/utils/positioning';
|
||||
import { INTERP_TICK_MS } from '@/lib/constants';
|
||||
|
||||
const UNBOUNDED_INTERP_SECONDS = Number.POSITIVE_INFINITY;
|
||||
import { INTERP_TICK_MS, MAX_INTERP_SECONDS } from '@/lib/constants';
|
||||
|
||||
/**
|
||||
* Custom hook that provides position interpolation for flights, ships, and satellites.
|
||||
@@ -59,7 +57,7 @@ export function useInterpolation() {
|
||||
f.speed_knots,
|
||||
dt,
|
||||
0,
|
||||
UNBOUNDED_INTERP_SECONDS,
|
||||
MAX_INTERP_SECONDS,
|
||||
);
|
||||
return [newLng, newLat];
|
||||
},
|
||||
@@ -86,7 +84,7 @@ export function useInterpolation() {
|
||||
s.sog,
|
||||
dt,
|
||||
0,
|
||||
UNBOUNDED_INTERP_SECONDS,
|
||||
MAX_INTERP_SECONDS,
|
||||
);
|
||||
return [newLng, newLat];
|
||||
},
|
||||
@@ -105,7 +103,7 @@ export function useInterpolation() {
|
||||
s.speed_knots,
|
||||
dt,
|
||||
0,
|
||||
UNBOUNDED_INTERP_SECONDS,
|
||||
MAX_INTERP_SECONDS,
|
||||
);
|
||||
return [newLng, newLat];
|
||||
},
|
||||
|
||||
@@ -16,6 +16,14 @@ export const NOMINATIM_DEBOUNCE_MS = 350;
|
||||
// ─── Map Interpolation ─────────────────────────────────────────────────────
|
||||
export const INTERP_TICK_MS = 2000;
|
||||
|
||||
/**
|
||||
* Longest stretch, in seconds, that moving markers are dead-reckoned past their last known
|
||||
* position. Live data refreshes every ~15s, so this never limits normal animation; it stops
|
||||
* runaway drift when data goes stale (a tab left hidden overnight pauses polling but not the
|
||||
* interpolation clock, which flung every aircraft thousands of miles along its old heading).
|
||||
*/
|
||||
export const MAX_INTERP_SECONDS = 180;
|
||||
|
||||
// ─── News/Alert Layout ──────────────────────────────────────────────────────
|
||||
export const ALERT_BOX_WIDTH_PX = 280;
|
||||
export const ALERT_MAX_OFFSET_PX = 350;
|
||||
Reference in new issue
Block a user