Files
gods-eye-view/src/layers/vessels/policy.js
T
Sameh Khamis 57ff81f723 feat(live): flights, military and vessels follow the world clock when their source declares a timeline
A live source may now declare a timeline: it can answer a snapshot at a
given time (source.timeline = { coverage(), stepMs, subscribe? }, read by
readSnapshotTimeline). While such a layer is on it follows the world clock
and registers the coverage. At the live edge it polls exactly as before;
away from it the layer asks for getSnapshot({ ...query, atMs }) at the step
at or before the clock time and shows that snapshot instead of polling.

src/time/snapshotTimeline.js owns the following: a seek, time going
backwards or leaving live replaces every contact with the snapshot at the
new time (play waits on it, for at most 8 s); playing on keeps one
snapshot ahead and gates play on it, applying those snapshots as polls so
contacts move smoothly; outside coverage the layer is empty; back at live
it is cleared and polls at once. One load at a time, and a load the
source drops for a newer one is not a failure.

While following, aircraft are drawn at the clock time with no render
delay, records and absences are judged at the clock, track requests carry
atMs, and vessels move between fixes along the great circle. The world
clock counts jumps (seeks and returns to live) in getState().

A source with no timeline never follows the clock, and every layer stays
live, unchanged.
2026-11-10 18:12:53 -08:00

103 lines
3.1 KiB
JavaScript

import { VESSEL_LABEL_GRID_PX } from '../../data/vesselLabels.js';
import { msg } from '../../i18n/index.js';
export const FOCUS_EVIDENCE_DEV = import.meta.env?.DEV === true;
export const DEFAULT_RENDER_ROWS = 12000;
export const DEFAULT_ACTIVE_LABELS = 900;
export const REFRESH_MS = 60000;
/** Bounded wait for the first accepted vessel position in one enabled session. */
export const AIS_FIRST_CONNECT_GRACE_MS = 30000;
export const VISIBILITY_UPDATE_MS = 800;
/** Focus alpha alone samples faster inside the existing preRender pass. */
export const FOCUS_UPDATE_MS = 80;
export const LABEL_GRID_PX = VESSEL_LABEL_GRID_PX;
/**
* Minimum screen-space separation between accepted vessel cards (matches the
* FIRMS card declutter). The 118px grid alone under-spaces the wider canvas
* cards; the greedy pass below enforces true card-scale spacing.
*/
export const CARD_MIN_SEP_PX = 150;
/** Trail hue for the selected vessel (PRD F4, pinned to the AIS teal-green family). */
export const TRAIL_COLOR = '#39ffd5';
/** Slight lift (m) for trail vertices to avoid sea-surface z-fighting. */
export const TRAIL_HEIGHT_M = 3;
/**
* Lift (m) above the local sea surface (geoid) for vessel anchors — locked
* height-datum principle #1: never below the visible surface, slightly above
* is always fine (clears tide/mesh noise in the photoreal sea mesh).
*/
export const VESSEL_LIFT_M = 3;
/** Combined cap on trail vertices (server backfill + live accumulation). */
export const TRAIL_MAX_POINTS = 400;
/** Minimum movement (m) before a reconcile refresh appends a new trail point. */
export const TRAIL_MIN_MOVE_M = 25;
/** Whether the layer shows the world clock's time instead of the live feed:
* its source declares a timeline and the clock is away from live. */
export const followsClock = (vesselState) =>
vesselState.timeline?.active() === true;
export const DEFAULT_AIS_RUNTIME = Object.freeze({
now: () => Date.now(),
setTimeout: (callback, delayMs) => setTimeout(callback, delayMs),
clearTimeout: (timer) => clearTimeout(timer),
});
/**
* Human-readable reasons for a non-'open' AISStream feed status, keyed to the
* server's `_aisStreamStatus` values (see vite.config.js). Surfaced verbatim in
* the layer chip so a dead feed reads "feed down" instead of a healthy-looking
* "just now · 0 vessels".
*/
export const AIS_STATUS_REASON = {
'missing-key': msg('AISSTREAM_API_KEY not set'),
unsupported: msg('live feed unsupported'),
connecting: msg('connecting to feed…'),
closed: msg('feed disconnected'),
error: msg('feed down'),
idle: msg('feed idle'),
};
/**
* Statuses in which fresh data is flowing. 'open' is the pre-watchdog spelling
* and is still accepted so a cached bundle and a restarted server never
* disagree about health.
*/
export const AIS_HEALTHY_STATUSES = new Set(['live', 'open']);
/**
* Server statuses meaning "the feed is not delivering right now". These are
* surfaced even while cached vessels are still drawn: rows retained from
* before the outage must never make a dead feed read as a healthy one.
*/
export const AIS_DEGRADED_STATUSES = new Set([
'stale',
'reconnecting',
'down',
'auth-failed',
]);