mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
Merge main into fix/earthquake-click-details
Resolves conflicts with main: a world focus target's own range past its framed radius replaces the kind's range (#1832), so a quake asks for its own range only past M6 and the earthquake framing stays its floor; FIRMS keeps main's marker stand-in under the card-on-top rule; launches keep main's label click and also read the card on top through the pick registry.
This commit is contained in:
commit
e87aa5190d
1337 files changed
+38638
-9950
No files matched your search
@@ -27,6 +27,60 @@ export function createClockFollow({ flightState, services, parts }) {
|
||||
flightState._lastCamPoseSig = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* The contacts drawn now that the first live snapshot after the clock came
|
||||
* back to live lacks (the tracked one too): the snapshot judges them as a
|
||||
* poll judges any absence (see the snapshot renderer).
|
||||
* @param {{records: Array<{id: string}>}} snapshot
|
||||
* @returns {Set<string>}
|
||||
*/
|
||||
function absentAtHandover(snapshot) {
|
||||
const present = new Set(snapshot.records.map((record) => record.id));
|
||||
const drawn = [...(flightState._icons?.ids() ?? [])];
|
||||
if (flightState._trackedIcao) drawn.push(flightState._trackedIcao);
|
||||
return new Set(drawn.filter((id) => !present.has(id)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Back at live: forget how every contact moved, as at a jump, but keep the
|
||||
* tracked trail, and keep the contacts `kept` (absentAtHandover) as they
|
||||
* were: their record, fixes and course. Each was last seen at its newest
|
||||
* fix, not when it was loaded, so absence judges how old it really is.
|
||||
* @param {Set<string>} kept
|
||||
*/
|
||||
function handOverMotion(kept) {
|
||||
const held = [];
|
||||
for (const id of kept)
|
||||
held.push([
|
||||
id,
|
||||
flightState.records.data.get(id),
|
||||
flightState._positionHistory.get(id),
|
||||
flightState._displayCourse.get(id),
|
||||
]);
|
||||
forgetPlacedAircraft(
|
||||
services?.placement,
|
||||
[...flightState._positionHistory.keys()].filter((id) => !kept.has(id)),
|
||||
);
|
||||
flightState.records.reset();
|
||||
flightState._positionHistory.clear();
|
||||
flightState._displayCourse.clear();
|
||||
flightState._groundSnap.clear();
|
||||
flightState._displayFloorState.clear();
|
||||
flightState._drReconcileValid = false;
|
||||
flightState._cachedDRFrame = -1;
|
||||
flightState._cachedDRPosition = null;
|
||||
flightState._lastCamPoseSig = '';
|
||||
for (const [id, meta, history, course] of held) {
|
||||
if (meta)
|
||||
flightState.records.data.set(id, {
|
||||
...meta,
|
||||
observedReceiptMs: meta.newestFixMs ?? meta.observedReceiptMs,
|
||||
});
|
||||
if (history) flightState._positionHistory.set(id, history);
|
||||
if (course !== undefined) flightState._displayCourse.set(id, course);
|
||||
}
|
||||
}
|
||||
|
||||
/** Drop every contact: the time has none to show, or the clock went live. */
|
||||
function clear() {
|
||||
if (flightState._trackedIcao)
|
||||
@@ -40,5 +94,5 @@ export function createClockFollow({ flightState, services, parts }) {
|
||||
flightState.feed._lastUpdate = null;
|
||||
}
|
||||
|
||||
return { resetMotion, clear };
|
||||
return { resetMotion, absentAtHandover, handOverMotion, clear };
|
||||
}
|
||||
@@ -156,7 +156,11 @@ export function createEnrichment({
|
||||
(data) => {
|
||||
const meta = flightState.records.data.get(icao24);
|
||||
if (!meta) return; // evicted while the lookup was in flight
|
||||
meta.typeCode = data.typeCode || meta.typeCode;
|
||||
// A looked-up type outranks the feed's own from now on.
|
||||
if (data.typeCode) {
|
||||
meta.typeCode = data.typeCode;
|
||||
meta.typeLookedUp = true;
|
||||
}
|
||||
meta.typeName = data.typeName || meta.typeName;
|
||||
meta.registration = data.registration || meta.registration;
|
||||
if (meta.typeCode) {
|
||||
|
||||
@@ -12,7 +12,10 @@ import { createEvidence } from './evidence.js';
|
||||
import { createTesting } from './testing.js';
|
||||
import { createQueries } from './queries.js';
|
||||
import { createClockFollow } from './clockFollow.js';
|
||||
import { createSnapshotTimeline } from '../../time/snapshotTimeline.js';
|
||||
import {
|
||||
createSnapshotTimeline,
|
||||
snapshotAnswer,
|
||||
} from '../../time/snapshotTimeline.js';
|
||||
import { worldClock } from '../../time/worldClock.js';
|
||||
/** Compose one civil-flight layer with application-owned scene services. */
|
||||
export function createCivilFlightLayer({
|
||||
@@ -53,10 +56,19 @@ export function createCivilFlightLayer({
|
||||
getQuery: (viewer) =>
|
||||
parts.controller._flightQuery(viewer || flightState._viewer),
|
||||
applySnapshot: (snapshot, viewer, options) => {
|
||||
// At another time the snapshot takes the place of every contact: how
|
||||
// each moved belongs to the time the clock left. Back at live too, but
|
||||
// the contacts it lacks are kept as they were for it to judge.
|
||||
if (options?.replace) parts.clockFollow.resetMotion();
|
||||
if (options?.handover) {
|
||||
parts.clockFollow.handOverMotion(
|
||||
parts.clockFollow.absentAtHandover(snapshot),
|
||||
);
|
||||
}
|
||||
return applySnapshot(snapshot, viewer, options);
|
||||
},
|
||||
followsClock: () => flightState.timeline.active(),
|
||||
timedAnswer: snapshotAnswer,
|
||||
setSourceLabel: (source) => {
|
||||
layer.source = source;
|
||||
},
|
||||
@@ -72,9 +84,7 @@ export function createCivilFlightLayer({
|
||||
load: (atMs, { signal, replace }) =>
|
||||
parts.ingestion.methods.loadAt(atMs, { signal, replace }),
|
||||
clear: () => parts.clockFollow.clear(),
|
||||
resumeLive: () => {
|
||||
layer.update(flightState._viewer).catch(() => {});
|
||||
},
|
||||
resumeLive: () => parts.ingestion.methods.resumeLive(flightState._viewer),
|
||||
});
|
||||
|
||||
Object.assign(
|
||||
|
||||
@@ -12,6 +12,7 @@ export function createIngestion({
|
||||
setSourceLabel,
|
||||
applyPendingTrackingRestore,
|
||||
followsClock = () => false,
|
||||
timedAnswer = () => true,
|
||||
}) {
|
||||
const methods = {
|
||||
async update(viewer, { signal = null } = {}) {
|
||||
@@ -21,13 +22,27 @@ export function createIngestion({
|
||||
await acquire(viewer, { signal });
|
||||
},
|
||||
|
||||
/**
|
||||
* Back at live from another time: poll at once, and let this live
|
||||
* snapshot stand in for every contact. Those it has keep their
|
||||
* icon and model and move on from where they are drawn; those it lacks
|
||||
* go. Resolves true once it is applied, else false (nothing to poll yet,
|
||||
* or the poll failed); rejects with an AbortError when it was dropped.
|
||||
* @param {object} [viewer]
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async resumeLive(viewer) {
|
||||
return (await acquire(viewer, { handover: true })) === true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply the source's snapshot at world time `atMs` (its timeline says it
|
||||
* can answer one), in place of every contact when `replace`. Resolves
|
||||
* whether it was applied.
|
||||
* whether it was applied: `{ reachMs }`, the newest fix its records
|
||||
* carry, when they carry fixes; else true, or false when it was not.
|
||||
* @param {number} atMs
|
||||
* @param {{signal?: AbortSignal|null, replace?: boolean, viewer?: object}} [options]
|
||||
* @returns {Promise<boolean>}
|
||||
* @returns {Promise<boolean|{reachMs: number}>}
|
||||
*/
|
||||
async loadAt(atMs, { signal = null, replace = false, viewer = null } = {}) {
|
||||
// Whatever polls or loads for another time no longer applies.
|
||||
@@ -38,7 +53,10 @@ export function createIngestion({
|
||||
},
|
||||
};
|
||||
|
||||
async function acquire(viewer, { signal = null, atMs, replace = false }) {
|
||||
async function acquire(
|
||||
viewer,
|
||||
{ signal = null, atMs, replace = false, handover = false },
|
||||
) {
|
||||
const nowMs = Date.now();
|
||||
const timed = atMs !== undefined;
|
||||
const trackingRefreshEpoch = ++feed._trackingRefreshEpoch;
|
||||
@@ -85,7 +103,9 @@ export function createIngestion({
|
||||
setSourceLabel(feed._lastSource);
|
||||
const accepted = timed
|
||||
? applySnapshot(snapshot, viewer, { replace })
|
||||
: applySnapshot(snapshot, viewer);
|
||||
: handover
|
||||
? applySnapshot(snapshot, viewer, { handover: true })
|
||||
: applySnapshot(snapshot, viewer);
|
||||
feed._count = accepted.count;
|
||||
// Freshness belongs to the source snapshot, not the moment this browser
|
||||
// received a cached 200 response.
|
||||
@@ -99,7 +119,8 @@ export function createIngestion({
|
||||
};
|
||||
console.log(`[Data:Flights] Updated: ${feed._count} aircraft`);
|
||||
applyPendingTrackingRestore();
|
||||
return true;
|
||||
// At a time, what the clock's follower is told of it.
|
||||
return timed ? timedAnswer(snapshot) : true;
|
||||
} catch (e) {
|
||||
if (updateSignal.aborted || e?.name === 'AbortError') {
|
||||
throw new DOMException('Flights update aborted', 'AbortError');
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createFlightSnapshotRenderer } from './snapshotRenderer.js';
|
||||
import { createMotion } from './motion.js';
|
||||
import { createFlightState } from './state.js';
|
||||
import { createFlightFeed, createIngestion } from './ingestion.js';
|
||||
import { createClockFollow } from './clockFollow.js';
|
||||
|
||||
// Back at live from another time, the first live snapshot stands in for
|
||||
// every contact: those it has keep their icon and ease on from where they
|
||||
// are drawn, and only those it lacks go (src/time/snapshotTimeline.js).
|
||||
|
||||
/** Any property is a no-op function unless given. */
|
||||
function stub(overrides = {}) {
|
||||
return new Proxy(overrides, {
|
||||
get: (target, key) => (key in target ? target[key] : () => undefined),
|
||||
});
|
||||
}
|
||||
|
||||
function harness() {
|
||||
const iconIds = new Set();
|
||||
const calls = [];
|
||||
const landed = new Set();
|
||||
const groundFloor = stub({
|
||||
cachedGroundFloor: () => null,
|
||||
floorAltitudeM: (altitude) => altitude,
|
||||
GROUND_FLOOR_LIFT_M: 0.5,
|
||||
});
|
||||
const services = stub({
|
||||
geoid: { geoidHeight: () => 0 },
|
||||
camera: stub(),
|
||||
focus: stub(),
|
||||
groundFloor,
|
||||
meshFloor: stub(),
|
||||
groundSnap: stub({ createGroundSnap: () => stub() }),
|
||||
placement: null,
|
||||
});
|
||||
const flightState = createFlightState({
|
||||
services,
|
||||
source: { label: 'Fixture aircraft' },
|
||||
});
|
||||
flightState._icons = {
|
||||
has: (id) => iconIds.has(id),
|
||||
ids: () => [...iconIds],
|
||||
get count() {
|
||||
return iconIds.size;
|
||||
},
|
||||
};
|
||||
const parts = {
|
||||
rendering: stub({ _modelOwnsVisual: () => false }),
|
||||
icons: stub({
|
||||
_addIcon: (id) => {
|
||||
calls.push(['add', id]);
|
||||
iconIds.add(id);
|
||||
},
|
||||
_forgetContact: (id) => {
|
||||
calls.push(['forget', id]);
|
||||
iconIds.delete(id);
|
||||
},
|
||||
_planIcon: (id, options) => calls.push(['plan', id, options]),
|
||||
}),
|
||||
tracking: stub({
|
||||
_militaryLayerSuppresses: () => false,
|
||||
_appendTrailFix: () => calls.push(['trail-append']),
|
||||
_startTrail: (id) => calls.push(['trail-start', id]),
|
||||
_clearTrail: () => calls.push(['trail-clear']),
|
||||
}),
|
||||
};
|
||||
parts.motion = createMotion({ flightState, services, parts, layer: {} });
|
||||
const apply = createFlightSnapshotRenderer({
|
||||
flightState,
|
||||
records: flightState.records,
|
||||
militaryRegistry: stub({ isMilitaryIcao: () => false }),
|
||||
groundFloor,
|
||||
rendering: parts.rendering,
|
||||
tracking: parts.tracking,
|
||||
motion: parts.motion,
|
||||
icons: parts.icons,
|
||||
enrichment: stub(),
|
||||
queries: stub({ _likelyLanded: (id) => landed.has(id) }),
|
||||
});
|
||||
const clockFollow = createClockFollow({ flightState, services, parts });
|
||||
return {
|
||||
calls,
|
||||
iconIds,
|
||||
flightState,
|
||||
clockFollow,
|
||||
landed,
|
||||
// `ids`: an id, or [id, fix age ms, on the ground].
|
||||
snapshot: (ids, fields = {}) => ({
|
||||
observedAtMs: Date.now(),
|
||||
records: ids.map((entry, k) => {
|
||||
const [id, ageMs = 5_000, onGround = false] = [entry].flat();
|
||||
return {
|
||||
id,
|
||||
reference: id,
|
||||
longitude: -115 + k,
|
||||
latitude: 36,
|
||||
callsign: 'TEST1',
|
||||
baroAltitudeM: onGround ? 0 : 9_000,
|
||||
onGround,
|
||||
speedMps: onGround ? 5 : 220,
|
||||
courseDeg: 90,
|
||||
positionTimeMs: Date.now() - ageMs,
|
||||
};
|
||||
}),
|
||||
complete: true,
|
||||
...fields,
|
||||
}),
|
||||
apply(ids, options, fields) {
|
||||
calls.length = 0;
|
||||
return apply(this.snapshot(ids, fields), null, options);
|
||||
},
|
||||
// Back at live, as the layer applies its first live snapshot.
|
||||
handOver(ids, fields) {
|
||||
calls.length = 0;
|
||||
const snapshot = this.snapshot(ids, fields);
|
||||
clockFollow.handOverMotion(clockFollow.absentAtHandover(snapshot));
|
||||
return apply(snapshot, null, { handover: true });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test('the first live snapshot keeps the icons of contacts it has and drops only those it lacks', () => {
|
||||
const h = harness();
|
||||
h.apply(['a00001', 'a00002']);
|
||||
assert.deepEqual([...h.iconIds].sort(), ['a00001', 'a00002']);
|
||||
|
||||
const accepted = h.handOver(['a00001', 'a00003']);
|
||||
assert.deepEqual([...h.iconIds].sort(), ['a00001', 'a00003']);
|
||||
assert.equal(accepted.count, 2);
|
||||
// The contact it has keeps its icon: no remove and add, and its motion is
|
||||
// planned as a handover, easing from where it is drawn.
|
||||
assert.equal(
|
||||
h.calls.some(
|
||||
([kind, id]) => id === 'a00001' && (kind === 'add' || kind === 'forget'),
|
||||
),
|
||||
false,
|
||||
);
|
||||
assert.deepEqual(
|
||||
h.calls.find(([kind, id]) => kind === 'plan' && id === 'a00001'),
|
||||
['plan', 'a00001', { handover: true }],
|
||||
);
|
||||
assert.ok(h.calls.some(([kind, id]) => kind === 'forget' && id === 'a00002'));
|
||||
assert.ok(h.calls.some(([kind, id]) => kind === 'add' && id === 'a00003'));
|
||||
});
|
||||
|
||||
test('a plain live poll keeps a missing contact as its absence rules say', () => {
|
||||
const h = harness();
|
||||
h.apply(['a00001', 'a00002']);
|
||||
h.apply(['a00001']);
|
||||
assert.deepEqual([...h.iconIds].sort(), ['a00001', 'a00002']);
|
||||
assert.deepEqual(
|
||||
h.calls.find(([kind]) => kind === 'plan'),
|
||||
['plan', 'a00001', undefined],
|
||||
);
|
||||
});
|
||||
|
||||
test('back at live, only the first live snapshot applied takes over; a failed poll says so', async () => {
|
||||
const applied = [];
|
||||
let fail = false;
|
||||
const feed = createFlightFeed({
|
||||
async getSnapshot() {
|
||||
if (fail) throw new Error('down');
|
||||
return { records: [], observedAtMs: Date.now(), freshness: 'current' };
|
||||
},
|
||||
});
|
||||
const { methods } = createIngestion({
|
||||
feed,
|
||||
getQuery: () => ({}),
|
||||
applySnapshot: (_snapshot, _viewer, options) => {
|
||||
applied.push(options);
|
||||
return { count: 0, ids: new Set() };
|
||||
},
|
||||
setSourceLabel: () => {},
|
||||
applyPendingTrackingRestore: () => {},
|
||||
});
|
||||
assert.equal(await methods.resumeLive(null), true);
|
||||
await methods.update(null);
|
||||
assert.deepEqual(applied, [{ handover: true }, undefined]);
|
||||
|
||||
fail = true;
|
||||
const warn = console.warn;
|
||||
console.warn = () => {};
|
||||
try {
|
||||
assert.equal(await methods.resumeLive(null), false);
|
||||
} finally {
|
||||
console.warn = warn;
|
||||
}
|
||||
});
|
||||
|
||||
test('back at live, the tracked contact and those the snapshot retains stay, stale, and a partial snapshot drops none', () => {
|
||||
const h = harness();
|
||||
h.apply(['a00001', 'a00002', 'a00003', 'a00004']);
|
||||
h.flightState._trackedIcao = 'a00001';
|
||||
const history = [{ epochMs: Date.now() - 60_000 }];
|
||||
h.flightState._positionHistory.set('a00001', history);
|
||||
h.handOver(['a00004'], { retainIds: new Set(['a00002']) });
|
||||
assert.deepEqual([...h.iconIds].sort(), ['a00001', 'a00002', 'a00004']);
|
||||
assert.equal(
|
||||
h.flightState._positionHistory.get('a00001'),
|
||||
history,
|
||||
'the tracked contact keeps its fixes for the next poll to judge',
|
||||
);
|
||||
assert.ok(h.flightState.records.data.has('a00001'));
|
||||
assert.equal(
|
||||
h.calls.some(([kind]) => kind === 'trail-clear' || kind === 'trail-start'),
|
||||
false,
|
||||
'its trail goes on',
|
||||
);
|
||||
|
||||
const partial = harness();
|
||||
partial.apply(['a00001', 'a00002']);
|
||||
partial.handOver(['a00003'], { complete: false });
|
||||
assert.deepEqual([...partial.iconIds].sort(), ['a00001', 'a00002', 'a00003']);
|
||||
});
|
||||
|
||||
test('back at live, the tracked contact the snapshot has goes on adding to its trail', () => {
|
||||
const h = harness();
|
||||
h.apply(['a00001']);
|
||||
h.flightState._trackedIcao = 'a00001';
|
||||
h.handOver(['a00001']);
|
||||
assert.deepEqual(
|
||||
h.calls.filter(([kind]) => kind.startsWith('trail')),
|
||||
[['trail-append']],
|
||||
);
|
||||
});
|
||||
|
||||
const HOURS_3 = 3 * 3_600_000;
|
||||
|
||||
test('back at live, a partial snapshot keeps only contacts whose newest fix is recent, by the real absence rules', () => {
|
||||
const h = harness();
|
||||
// Shown from a time three hours back, and one from a minute ago.
|
||||
h.apply([
|
||||
['a00001', HOURS_3],
|
||||
['a00002', 60_000],
|
||||
]);
|
||||
h.handOver(['a00003'], { complete: false });
|
||||
assert.deepEqual(
|
||||
[...h.iconIds].sort(),
|
||||
['a00002', 'a00003'],
|
||||
'the three-hour-old contact is no ghost',
|
||||
);
|
||||
});
|
||||
|
||||
test('back at live, a tracked aircraft is kept only while its newest fix is recent and it has not landed', () => {
|
||||
for (const [label, setUp, kept] of [
|
||||
['recent', (h) => h.apply([['a00001', 60_000]]), true],
|
||||
['three hours old', (h) => h.apply([['a00001', HOURS_3]]), false],
|
||||
[
|
||||
'landed',
|
||||
(h) => {
|
||||
h.apply([['a00001', 120_000]]);
|
||||
h.apply([['a00001', 60_000, true]]);
|
||||
h.landed.add('a00001');
|
||||
},
|
||||
false,
|
||||
],
|
||||
]) {
|
||||
const h = harness();
|
||||
setUp(h);
|
||||
h.flightState._trackedIcao = 'a00001';
|
||||
h.handOver(['a00002']);
|
||||
assert.equal(h.iconIds.has('a00001'), kept, label);
|
||||
}
|
||||
});
|
||||
@@ -42,7 +42,6 @@ import {
|
||||
limitCourseStep,
|
||||
corridorPathLatLon,
|
||||
} from '../../data/motionModel.js';
|
||||
import { CLASS_SCALE_2D } from '../../data/aircraftClass.js';
|
||||
import { placeLiveAircraft } from './placed.js';
|
||||
import {
|
||||
modelVisualAnchor,
|
||||
@@ -50,7 +49,6 @@ import {
|
||||
} from '../../data/modelVisualAnchor.js';
|
||||
import {
|
||||
FOCUS_EVIDENCE_DEV,
|
||||
MODEL_MIN_PX,
|
||||
TRACKED_BILLBOARD_SCALE_BY_DISTANCE,
|
||||
DR_CORRECTION_MS,
|
||||
COURSE_SLEW_DT_MAX_SEC,
|
||||
@@ -415,19 +413,17 @@ export function createMotion({
|
||||
const spec = parts.rendering._modelSpec(
|
||||
flightState.records.data.get(icao24),
|
||||
);
|
||||
// Drawn as the fleet draws it: its own size, never under MODEL_MIN_PX.
|
||||
// Drawn as the fleet draws it: at its true size.
|
||||
const focalLengthPx = viewportHeightPx / (2 * Math.tan(pose.fovy / 2));
|
||||
const projectedDiameterPx =
|
||||
(2 * spec.nativeRadiusM * spec.scale * focalLengthPx) / rangeM;
|
||||
return Math.max(MODEL_MIN_PX, projectedDiameterPx);
|
||||
return projectedDiameterPx;
|
||||
}
|
||||
|
||||
const sprite = readEntityRecord(flightState._trackedEntity)?.sprite;
|
||||
const width = sprite?.width ?? 28;
|
||||
const height = sprite?.height ?? 28;
|
||||
const scale =
|
||||
sprite?.scale ??
|
||||
(CLASS_SCALE_2D[flightState.records.data.get(icao24)?.klass] || 1);
|
||||
const scale = sprite?.scale ?? 1;
|
||||
const scaleByDistance =
|
||||
sprite?.scaleByDistance ?? TRACKED_BILLBOARD_SCALE_BY_DISTANCE;
|
||||
const distanceScale = nearFarScalarValueAtDistance(scaleByDistance, rangeM);
|
||||
@@ -456,6 +452,8 @@ export function createMotion({
|
||||
const sameTrack =
|
||||
flightState._drReconcileValid && flightState._drReconcileIcao === icao24;
|
||||
const raw = _deadReckon(icao24, flightState._scratchDrRaw);
|
||||
flightState._cachedDRPlaced =
|
||||
Boolean(raw) && flightState._drSpeedPlaced === true;
|
||||
flightState._cachedDRCourse = flightState._drCourseDeg;
|
||||
flightState._cachedDRSpeedMps = flightState._drSpeedMps;
|
||||
flightState._cachedDRHold = flightState._drCourseHold;
|
||||
@@ -601,6 +599,16 @@ export function createMotion({
|
||||
* against the now-stable plane (the model's jitter fix, resurfacing in the labels). Returns null when
|
||||
* there's no valid fix for the tracked aircraft, so callers fall back to the icon position. */
|
||||
|
||||
/** Whether a host-supplied placement placed the tracked aircraft where
|
||||
* `_trackedDisplayCached` holds it this frame, rather than this layer's
|
||||
* own motion at its display delay. */
|
||||
|
||||
function _trackedPlaced() {
|
||||
return (
|
||||
_trackedDisplayCached() !== null && flightState._cachedDRPlaced === true
|
||||
);
|
||||
}
|
||||
|
||||
function _trackedDisplayCached() {
|
||||
return flightState._drReconcileValid &&
|
||||
flightState._drReconcileIcao === flightState._trackedIcao
|
||||
@@ -645,9 +653,8 @@ export function createMotion({
|
||||
/** Trail endpoint for the rendered tracked owner. Brackets/readouts stay on
|
||||
* the visual centre; only the trail moves to the model's lower-centre hardpoint. */
|
||||
/** The tracked model's rendered bounding radius (m), or 0 when no model of this
|
||||
* contact is drawing. Carries the scale it is drawn at, which may be
|
||||
* above `scale` to satisfy its pixel floor — the trail head has to be judged
|
||||
* against the size the operator SEES, not the nominal one. */
|
||||
* contact is drawing, at the scale it is drawn at — the trail head has to
|
||||
* be judged against the size the operator SEES. */
|
||||
/** World-space origin of the tracked model, or null when no model of this
|
||||
* contact is drawing. This is the centre the rendered bounding sphere is
|
||||
* measured from, so the trail clip and the envelope agree on one frame. */
|
||||
@@ -1222,6 +1229,7 @@ export function createMotion({
|
||||
_trackedFocusSizePx,
|
||||
_trackedDisplayPosition,
|
||||
_trackedDisplayCached,
|
||||
_trackedPlaced,
|
||||
_trackedVisualCached,
|
||||
_trackedModelCenterWorld,
|
||||
_trackedModelEnvelopeM,
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as Cesium from 'cesium';
|
||||
import { createMotion } from './motion.js';
|
||||
import { arcOffsetEnu } from '../../data/motionModel.js';
|
||||
import { createMotion as createMilitaryMotion } from '../military/motion.js';
|
||||
import { createQueries } from './queries.js';
|
||||
import { createQueries as createMilitaryQueries } from '../military/queries.js';
|
||||
import { layerPlacement } from '../../data/placementProvider.js';
|
||||
import { observeLiveAircraft } from './placed.js';
|
||||
|
||||
@@ -248,18 +250,77 @@ const declining = (asked) =>
|
||||
);
|
||||
|
||||
// Each kind's record carries only its own kinematics fields.
|
||||
for (const [name, create, record] of [
|
||||
for (const [name, create, record, queriesOf] of [
|
||||
[
|
||||
'civil',
|
||||
createMotion,
|
||||
{ velocity: 100, true_track: 90, renderAltitudeM: 1234 },
|
||||
createQueries,
|
||||
],
|
||||
[
|
||||
'military',
|
||||
createMilitaryMotion,
|
||||
{ speedMps: 100, track: 90, renderAltitudeM: 1234 },
|
||||
createMilitaryQueries,
|
||||
],
|
||||
]) {
|
||||
test(`${name} aircraft waiting where a placement holds them still show their reported speed`, () => {
|
||||
// Drawn standing (speed 0) while its fixes catch up: the aircraft has
|
||||
// not stopped, and the panels say what it reports.
|
||||
const placement = layerPlacement(
|
||||
{
|
||||
layer: () => ({
|
||||
place: () => ({
|
||||
lat: 30.5,
|
||||
lon: -96.5,
|
||||
altitudeM: 2000,
|
||||
courseDeg: 90,
|
||||
speedMps: 0,
|
||||
extrapolating: false,
|
||||
}),
|
||||
}),
|
||||
},
|
||||
'aircraft',
|
||||
);
|
||||
const { flightState, motion, start } = placedScenario(
|
||||
create,
|
||||
placement,
|
||||
record,
|
||||
);
|
||||
flightState.now = () => start + 2000;
|
||||
flightState.feed = {};
|
||||
flightState.records.missingPolls = new Map();
|
||||
const describe = (kinematics) => {
|
||||
flightState.records.data.set('abc123', { ...record, ...kinematics });
|
||||
return queriesOf({
|
||||
flightState,
|
||||
services: {
|
||||
aircraftPresentation: {
|
||||
tr3bTypeLabel: (_, label) => label,
|
||||
tr3bAircraftClass: () => null,
|
||||
},
|
||||
labels: { formatFlightLevel: String },
|
||||
militaryRegistry: {},
|
||||
focus: {},
|
||||
recession: {},
|
||||
},
|
||||
parts: {
|
||||
motion,
|
||||
icons: { _iconPosition: () => null },
|
||||
tracking: { _routeIsPlausible: () => false },
|
||||
testing: {},
|
||||
},
|
||||
})._describeFlight('abc123');
|
||||
};
|
||||
const waiting = describe({});
|
||||
assert.equal(flightState._drSpeedMps, 0);
|
||||
assert.equal(waiting.velocityMps, 100);
|
||||
// Nothing reported: the speed it is drawn at.
|
||||
const unreported =
|
||||
name === 'civil' ? { velocity: undefined } : { speedMps: undefined };
|
||||
assert.equal(describe(unreported).velocityMps, 0);
|
||||
});
|
||||
|
||||
test(`${name} aircraft move as before without a placement or with one that places nothing`, () => {
|
||||
const own = placedScenario(create, null, record).drawn;
|
||||
const asked = [];
|
||||
@@ -338,14 +399,20 @@ test('an aircraft fix is told to the placement live, with its drawn height', ()
|
||||
'aircraft',
|
||||
);
|
||||
const state = { timeline: { active: () => false } };
|
||||
const meta = { rawLat: 1, rawLon: 2, renderAltitudeM: 300, onGround: false };
|
||||
const meta = {
|
||||
rawLat: 1,
|
||||
rawLon: 2,
|
||||
renderAltitudeM: 300,
|
||||
groundM: 1656,
|
||||
onGround: false,
|
||||
};
|
||||
observeLiveAircraft(state, placement, 'abc123', 5000, meta, 80, 270);
|
||||
observeLiveAircraft(
|
||||
state,
|
||||
placement,
|
||||
'abc123',
|
||||
6000,
|
||||
{ ...meta, renderAltitudeInvented: true, onGround: true },
|
||||
{ ...meta, renderAltitudeInvented: true, groundM: null, onGround: true },
|
||||
null,
|
||||
undefined,
|
||||
);
|
||||
@@ -360,12 +427,15 @@ test('an aircraft fix is told to the placement live, with its drawn height', ()
|
||||
lat: 1,
|
||||
lon: 2,
|
||||
altitudeM: 300,
|
||||
groundM: 1656,
|
||||
speedMps: 80,
|
||||
courseDeg: 270,
|
||||
headingDeg: NaN,
|
||||
onGround: false,
|
||||
},
|
||||
]);
|
||||
// Where the layer does not know the ground, it says so.
|
||||
assert.ok(Number.isNaN(told[1][1].groundM));
|
||||
assert.ok(Number.isNaN(told[1][1].altitudeM));
|
||||
assert.ok(Number.isNaN(told[1][1].speedMps));
|
||||
assert.ok(Number.isNaN(told[1][1].courseDeg));
|
||||
|
||||
@@ -654,3 +654,75 @@ test("another layer's card over an aircraft keeps the click", (t) => {
|
||||
input.tap({ x: 10, y: 10 });
|
||||
assert.ok(picks > 0, 'open map: the click reaches the scene');
|
||||
});
|
||||
|
||||
test("a type lookup overrides the feed's type and fills the type name", async () => {
|
||||
const queries = [];
|
||||
const source = {
|
||||
getEnrichment(query) {
|
||||
queries.push(query);
|
||||
return Promise.resolve({
|
||||
found: true,
|
||||
typeCode: 'B738',
|
||||
typeName: 'Boeing 737-800',
|
||||
registration: 'N123AB',
|
||||
});
|
||||
},
|
||||
};
|
||||
const flightState = createFlightState({ source, services: services() });
|
||||
const view = {
|
||||
viewerLatDeg: null,
|
||||
viewerLonDeg: null,
|
||||
trackedId: null,
|
||||
floorWarmPoints: [],
|
||||
};
|
||||
const { meta } = flightState.records.receive(
|
||||
{
|
||||
id: 'abc123',
|
||||
reference: 'abc123',
|
||||
longitude: -77,
|
||||
latitude: 39,
|
||||
callsign: 'TEST1',
|
||||
baroAltitudeM: 1000,
|
||||
typeCode: 'EC45',
|
||||
},
|
||||
view,
|
||||
);
|
||||
assert.equal(meta.klass, 'helicopter', 'classed by the feed type at once');
|
||||
const restyled = [];
|
||||
const synced = [];
|
||||
const enrichment = createEnrichment({
|
||||
flightState,
|
||||
services: enrichServices(),
|
||||
parts: {
|
||||
icons: { _applyIconPresentation: (id) => restyled.push(id) },
|
||||
rendering: { _syncModelToClass: (id) => synced.push(id) },
|
||||
},
|
||||
});
|
||||
// A present feed type does not skip the lookup.
|
||||
enrichment._requestTypeEnrichment('abc123', true);
|
||||
await new Promise((done) => setImmediate(done));
|
||||
assert.deepEqual(queries, [{ kind: 'type', id: 'abc123' }]);
|
||||
const looked = flightState.records.data.get('abc123');
|
||||
assert.equal(looked.typeCode, 'B738');
|
||||
assert.equal(looked.typeName, 'Boeing 737-800');
|
||||
assert.equal(looked.registration, 'N123AB');
|
||||
assert.equal(looked.klass, 'airliner');
|
||||
assert.deepEqual(restyled, ['abc123']);
|
||||
assert.deepEqual(synced, ['abc123']);
|
||||
// The next poll's feed type no longer wins.
|
||||
const next = flightState.records.receive(
|
||||
{
|
||||
id: 'abc123',
|
||||
reference: 'abc123',
|
||||
longitude: -77,
|
||||
latitude: 39,
|
||||
callsign: 'TEST1',
|
||||
baroAltitudeM: 1000,
|
||||
typeCode: 'EC45',
|
||||
},
|
||||
view,
|
||||
).meta;
|
||||
assert.equal(next.typeCode, 'B738');
|
||||
assert.equal(next.klass, 'airliner');
|
||||
flightState.lifetime.abort();
|
||||
});
|
||||
@@ -61,6 +61,7 @@ export function placeLiveAircraft(
|
||||
history,
|
||||
out,
|
||||
) {
|
||||
flightState._drSpeedPlaced = false;
|
||||
if (!placement || followsClock(flightState)) return false;
|
||||
const placed = placeAircraftAt(
|
||||
placement,
|
||||
@@ -73,6 +74,7 @@ export function placeLiveAircraft(
|
||||
if (!placed) return false;
|
||||
flightState._drCourseDeg = placed.courseDeg;
|
||||
flightState._drSpeedMps = placed.speedMps;
|
||||
flightState._drSpeedPlaced = true;
|
||||
flightState._drCourseHold = placed.speedMps < COURSE_HOLD_SPEED_MPS;
|
||||
flightState._drExtrapolating = placed.extrapolating;
|
||||
return true;
|
||||
@@ -93,13 +95,15 @@ export function forgetPlacedAircraft(placement, ids) {
|
||||
* Tell the host-supplied placement an aircraft's fix as the layer took it
|
||||
* (nothing while the layer follows the world clock): its own time, its
|
||||
* position, the height the layer draws it at (NaN when that height is
|
||||
* invented), and its reported speed, course and ground state.
|
||||
* invented), the ground under it in that height's reference (NaN where the
|
||||
* layer does not know it), and its reported speed, course and ground state.
|
||||
* @param {object} flightState
|
||||
* @param {object|null|undefined} placement
|
||||
* @param {string} icao24
|
||||
* @param {number} fixEpochMs
|
||||
* @param {{rawLat: number, rawLon: number, renderAltitudeM: number,
|
||||
* renderAltitudeInvented?: boolean, onGround?: boolean}} meta
|
||||
* renderAltitudeInvented?: boolean, groundM?: number|null,
|
||||
* onGround?: boolean}} meta
|
||||
* @param {number|null|undefined} speedMps
|
||||
* @param {number|null|undefined} courseDeg
|
||||
*/
|
||||
@@ -119,6 +123,7 @@ export function observeLiveAircraft(
|
||||
lon: meta.rawLon,
|
||||
altitudeM:
|
||||
meta.renderAltitudeInvented === true ? NaN : meta.renderAltitudeM,
|
||||
groundM: Number.isFinite(meta.groundM) ? meta.groundM : NaN,
|
||||
speedMps: Number.isFinite(speedMps) ? speedMps : NaN,
|
||||
courseDeg: Number.isFinite(courseDeg) ? courseDeg : NaN,
|
||||
headingDeg: NaN,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { EMERGENCY_TINT_CSS } from '../../data/aircraftEmergency.js';
|
||||
import { cssColor } from '../../render/color.js';
|
||||
import { VEHICLE_TINT_CSS } from '../../data/aircraftClass.js';
|
||||
|
||||
/** A CSS colour as frozen `[r, g, b, a]`, 0..1 (the renderer's `Color`). */
|
||||
const rgba = (css, alpha) =>
|
||||
@@ -13,6 +14,10 @@ export const FOCUS_EVIDENCE_DEV = import.meta.env?.DEV === true;
|
||||
|
||||
export const MIL_TINT = rgba('#FFB800');
|
||||
|
||||
/** Amber tint for airport vehicles (type ZVEH, emitter C1/C2), apart from aircraft. */
|
||||
|
||||
export const VEHICLE_TINT = rgba(VEHICLE_TINT_CSS);
|
||||
|
||||
/** Red tint for aircraft broadcasting an emergency (7500/7600/7700 or ADS-B status). */
|
||||
|
||||
export const EMERGENCY_TINT = rgba(EMERGENCY_TINT_CSS);
|
||||
@@ -39,18 +44,27 @@ export const EMERGENCY_TINT = rgba(EMERGENCY_TINT_CSS);
|
||||
export const GROUND_SCALE = 0.8;
|
||||
|
||||
// --- 3D model rendering (B3) ---------------------------------------------------------
|
||||
// When enabled, aircraft render as 3D glTF models once the camera is below MODEL_ALT_CEIL_M
|
||||
// (zoomed in); higher up they stay flat billboards. Eligibility is FRUSTUM-based (on-screen), and
|
||||
// the slots go to either the nearest planes ('proximity') or every in-view plane ('all'), each
|
||||
// backed by a hard cap so a draw-call explosion can't tank the frame (no instancing yet).
|
||||
// When enabled, an aircraft draws as its 3D glTF model only within MODEL_ADD_M of the camera
|
||||
// (eye to aircraft); farther away it stays its icon. Models are drawn at their true size, with no
|
||||
// minimum pixel size, so a model never balloons past its real extent. Eligibility is distance-based
|
||||
// with on-screen priority, and the slots go to either the nearest planes ('proximity') or every
|
||||
// in-range plane ('all'): the two modes share the radius and differ by their caps, each a hard
|
||||
// bound on the frame cost (every model is its own draw call).
|
||||
|
||||
export const MODEL_ALT_CEIL_M = 800000;
|
||||
// m: below this camera altitude, draw 3D models (raised so it's easy to trigger)
|
||||
export const MODEL_ADD_M = 3000;
|
||||
// model NEW planes within 3 km of the camera
|
||||
|
||||
export const MODEL_MIN_PX = 24;
|
||||
// floor so distant models stay visible WITHOUT ballooning into a giant
|
||||
// min-pixel blob (was 54 — far planes at the All radius became white
|
||||
// star-bursts); ~matches the 2D icon size so the model↔billboard read is consistent
|
||||
export const MODEL_KEEP_M = 3600;
|
||||
// KEEP modeled planes out to 3.6 km: the hysteresis band (KEEP > ADD) stops a plane on the edge
|
||||
// from releasing and reloading its model as the camera moves (the zoom/pan flicker)
|
||||
|
||||
export const MODEL_HIGHEST_CONTACT_M = 30000;
|
||||
// m above the ellipsoid: no aircraft the layers draw flies higher (airliners cruise near 12 km,
|
||||
// the highest-flying aircraft near 21 km)
|
||||
|
||||
export const MODEL_ALT_CEIL_M = MODEL_HIGHEST_CONTACT_M + MODEL_KEEP_M;
|
||||
// m: above this camera altitude no contact can be within MODEL_KEEP_M, so no model is
|
||||
// considered at all (the eligibility pass is skipped)
|
||||
|
||||
// Per-mode caps. Each model is its own draw call (no instancing yet), so these bound the frame cost.
|
||||
|
||||
@@ -58,29 +72,22 @@ export const MODEL_MAX = 150;
|
||||
// 'proximity' cap (the planes immediately around you)
|
||||
|
||||
export const MODEL_MAX_ALL = 350;
|
||||
// 'all' cap (everything out to ~the horizon)
|
||||
// Per-mode ADD / KEEP radii. The two modes differ by RADIUS, not just cap — otherwise they look
|
||||
// IDENTICAL whenever fewer than a cap's worth of planes are in range (field bug: Proximity and All
|
||||
// rendered the same). 'proximity' = a tight ring; 'all' = roughly to the horizon (state-scale). Each
|
||||
// band has hysteresis (KEEP > ADD) so a plane doesn't release+reload its model when it straddles the
|
||||
// add edge (the zoom/pan flicker). Beyond ADD a model would force-clamp to minimumPixelSize into a
|
||||
// giant floating blob (the old 422 km airport-cluster bug), so far planes stay 2D dots; the cap +
|
||||
// on-screen priority then spend the model slots on planes you can actually see.
|
||||
|
||||
export const MODEL_PROX_ADD_M = 150000;
|
||||
// proximity: model NEW planes within 150 km
|
||||
|
||||
export const MODEL_PROX_KEEP_M = 185000;
|
||||
// proximity: KEEP modeled planes out to 185 km
|
||||
// 'all' cap (every plane in range)
|
||||
|
||||
export const COCKPIT_MODEL_MAX = 60;
|
||||
// max concurrent GLBs in cockpit (never raises the map cap)
|
||||
|
||||
export const MODEL_ALL_ADD_M = 400000;
|
||||
// all: model NEW planes within 400 km (~to the horizon)
|
||||
// Cockpit's AIR band: contacts within it draw as aircraft silhouettes, beyond
|
||||
// it as compact dots. Independent of the 3D model radius; per 3D mode, each
|
||||
// with its keep hysteresis.
|
||||
|
||||
export const MODEL_ALL_KEEP_M = 450000;
|
||||
// all: KEEP modeled planes out to 450 km
|
||||
export const COCKPIT_AIR_PROX_ADD_M = 150000;
|
||||
|
||||
export const COCKPIT_AIR_PROX_KEEP_M = 185000;
|
||||
|
||||
export const COCKPIT_AIR_ALL_ADD_M = 400000;
|
||||
|
||||
export const COCKPIT_AIR_ALL_KEEP_M = 450000;
|
||||
|
||||
export const MODEL_HEADING_OFFSET_DEG = 180;
|
||||
// every fleet model is nose -X: opposite the renderer's heading 0
|
||||
@@ -88,9 +95,6 @@ export const MODEL_HEADING_OFFSET_DEG = 180;
|
||||
/** A model's colour where it draws its mesh's own (`aircraftModelBlend`). */
|
||||
export const MODEL_WHITE = rgba('#FFFFFF');
|
||||
|
||||
/** The tracked contact's tint, and its billboard once a model takes over. */
|
||||
export const TRACKED_CYAN = rgba('#00FFFF');
|
||||
export const CYAN_TRANSPARENT = rgba('#00FFFF', 0);
|
||||
/** An ordinary fleet contact's tint. */
|
||||
export const FLEET_TINT = rgba('#FFFFFF');
|
||||
|
||||
@@ -201,18 +205,15 @@ export const FLEET_DR_INTERVAL_MS = 80;
|
||||
/**
|
||||
* The icon-to-model rules the aircraft layers follow, as the Vessels, Transit
|
||||
* and Rail layers take them (`createFleetModelLayer`): the same altitude
|
||||
* ceiling, minimum pixel size, proximity/all caps, add/keep radii and
|
||||
* eligibility cadence, so every layer turns icons into models at one distance.
|
||||
* ceiling, proximity/all caps, add/keep radii and eligibility cadence, so
|
||||
* every layer turns icons into models at one distance, drawn at true size.
|
||||
*/
|
||||
export const FLEET_MODEL_POLICY = Object.freeze({
|
||||
altitudeCeilingM: MODEL_ALT_CEIL_M,
|
||||
minimumPixelSize: MODEL_MIN_PX,
|
||||
cap: MODEL_MAX,
|
||||
capAll: MODEL_MAX_ALL,
|
||||
addM: MODEL_PROX_ADD_M,
|
||||
addAllM: MODEL_ALL_ADD_M,
|
||||
keepM: MODEL_PROX_KEEP_M,
|
||||
keepAllM: MODEL_ALL_KEEP_M,
|
||||
addM: MODEL_ADD_M,
|
||||
keepM: MODEL_KEEP_M,
|
||||
intervalMs: FLEET_DR_INTERVAL_MS,
|
||||
});
|
||||
|
||||
|
||||
@@ -145,6 +145,7 @@ export function createQueries({
|
||||
derivedSpeedMps: flightState._drSpeedMps,
|
||||
derivedTrackDeg: flightState._drCourseDeg,
|
||||
reportedSpeedMps: info?.velocity,
|
||||
derivedFromPlacement: flightState._drSpeedPlaced === true,
|
||||
reportedTrackDeg: info?.true_track,
|
||||
});
|
||||
const carto = toLonLatH(basePos);
|
||||
@@ -345,11 +346,11 @@ export function createQueries({
|
||||
|
||||
/**
|
||||
* Live layer params.
|
||||
* `models3d` toggles 3D glTF model rendering for the FLEET (altitude-gated): when on,
|
||||
* surrounding aircraft become 3D models once the camera is zoomed in past MODEL_ALT_CEIL_M.
|
||||
* `models3d` toggles 3D glTF model rendering for the FLEET: when on, aircraft within
|
||||
* MODEL_ADD_M (3 km) of the camera become 3D models, drawn at their true size.
|
||||
* The TRACKED contact follows the same rule (`_trackedModelRegimeActive`), so selecting
|
||||
* a contact never turns its icon into a model or its model into an icon.
|
||||
* `models3dMode` is 'proximity' (nearest MODEL_MAX in view) or 'all' (every in-view plane).
|
||||
* `models3dMode` is 'proximity' (cap MODEL_MAX) or 'all' (cap MODEL_MAX_ALL); both use the 3 km radius.
|
||||
* @param {{models3d?: boolean, models3dMode?: 'proximity'|'all', selectedFlightsTrackingId?: string|null}} params
|
||||
*/
|
||||
setParams(params = {}, { origin = 'programmatic' } = {}) {
|
||||
|
||||
@@ -92,11 +92,11 @@ export class FlightRecords {
|
||||
originCountry: origin_country,
|
||||
longitude: lon,
|
||||
latitude: lat,
|
||||
baroAltitudeM: baro_alt,
|
||||
baroAltitudeM: reportedBaroAlt,
|
||||
onGround: on_ground,
|
||||
speedMps: velocity,
|
||||
courseDeg: true_track,
|
||||
ellipsoidAltitudeM: geo_alt,
|
||||
ellipsoidAltitudeM: reportedGeoAlt,
|
||||
category,
|
||||
verticalRateMps: vertical_rate,
|
||||
} = observation;
|
||||
@@ -110,11 +110,12 @@ export class FlightRecords {
|
||||
// The airframe's facts: this record's, or those kept across a reset.
|
||||
const airframe = prevMeta ?? this.airframes.get(icao24);
|
||||
this.airframes.delete(icao24);
|
||||
// A ground vehicle or ground station (a feed's ZVEH or GRND: a model
|
||||
// built standing, catalog category `other`) takes the feed's own type,
|
||||
// which no airframe lookup knows; every other aircraft keeps waiting for
|
||||
// its looked-up type. With no altitude at all it stands on the ground,
|
||||
// where it is, instead of at the airborne default.
|
||||
// The feed's own ICAO type classes the contact and picks its model from
|
||||
// the first fix; a looked-up type outranks it once one has answered.
|
||||
// A ground vehicle or ground station (a feed's ZVEH or GRND) is known
|
||||
// from its feed type alone, which no airframe lookup knows. With no
|
||||
// altitude at all, a contact drawn with a model built standing is on the
|
||||
// ground, where it is, instead of at the airborne default.
|
||||
const groundModel = (typeCode) =>
|
||||
drawnAsGroundModel(
|
||||
this.fleetModels(),
|
||||
@@ -122,12 +123,33 @@ export class FlightRecords {
|
||||
category,
|
||||
stickyText(callsign, prevMeta?.callsign),
|
||||
);
|
||||
const feedType = observation.typeCode || null;
|
||||
const typeCode =
|
||||
airframe?.typeCode ??
|
||||
(feedType && groundModel(feedType) ? feedType : null);
|
||||
const feedType = cleanType(observation.typeCode);
|
||||
// A surface category keeps only a feed's ground type: a C1 contact whose
|
||||
// feed names an airliner type stays a vehicle.
|
||||
// A feed's ground type holds only for a contact that behaves as one: an
|
||||
// airport vehicle reported airborne, or faster than a vehicle drives (a
|
||||
// test transponder, a drone), is classed as any other aircraft.
|
||||
const driving =
|
||||
!(Number.isFinite(velocity) && velocity > VEHICLE_MAX_SPEED_MPS) &&
|
||||
(on_ground === true ||
|
||||
(!Number.isFinite(reportedBaroAlt) &&
|
||||
!Number.isFinite(reportedGeoAlt)));
|
||||
const keepFeedType =
|
||||
Boolean(feedType) &&
|
||||
(feedType !== 'ZVEH' || driving) &&
|
||||
(!groundCategory(category) || GROUND_FEED_TYPES.has(feedType));
|
||||
// A ground station is fixed: it stands on the ground whatever height its
|
||||
// reports carry, as if they carried none.
|
||||
const station = keepFeedType && feedType === 'GRND';
|
||||
const baro_alt = station ? null : reportedBaroAlt;
|
||||
const geo_alt = station ? null : reportedGeoAlt;
|
||||
const typeLookedUp = airframe?.typeLookedUp === true;
|
||||
const typeCode = typeLookedUp
|
||||
? airframe.typeCode
|
||||
: ((keepFeedType ? feedType : null) ?? airframe?.typeCode ?? null);
|
||||
const onGround =
|
||||
on_ground === true ||
|
||||
station ||
|
||||
(!Number.isFinite(baro_alt) &&
|
||||
!Number.isFinite(geo_alt) &&
|
||||
groundModel(typeCode));
|
||||
@@ -261,6 +283,10 @@ export class FlightRecords {
|
||||
// within GROUND_FLOOR_CLAMP_RADIUS_KM of the viewer — the only ones
|
||||
// whose burial is visible. Cells warm in one batch after the loop.
|
||||
// Airborne only (grounded planes keep the surface-cache path above).
|
||||
// The ground under the contact in its render height's reference, where
|
||||
// the warm cache knows it: the surface it stands on, or the floor under a
|
||||
// low contact near the view. A landing is judged above it.
|
||||
let groundM = onGround ? surfaceM : null;
|
||||
if (
|
||||
!onGround &&
|
||||
renderAltitudeM < GROUND_FLOOR_WARM_MAX_ALT_M &&
|
||||
@@ -269,10 +295,8 @@ export class FlightRecords {
|
||||
approxDistanceKm(viewerLatDeg, viewerLonDeg, lat, lon) <=
|
||||
GROUND_FLOOR_CLAMP_RADIUS_KM))
|
||||
) {
|
||||
renderAltitudeM = floorAltitudeM(
|
||||
renderAltitudeM,
|
||||
cachedGroundFloor(lat, lon),
|
||||
);
|
||||
groundM = cachedGroundFloor(lat, lon);
|
||||
renderAltitudeM = floorAltitudeM(renderAltitudeM, groundM);
|
||||
floorWarmPoints.push({ lat, lon });
|
||||
}
|
||||
|
||||
@@ -280,7 +304,8 @@ export class FlightRecords {
|
||||
const groundFlipped =
|
||||
!!prevMeta && (prevMeta.onGround === true) !== onGround;
|
||||
// Store flight metadata for click-to-track labels
|
||||
const cat = stickyNumber(category, prevMeta?.category, null);
|
||||
// OpenSky's integer category, or a feed's ADS-B emitter category ("C1").
|
||||
const cat = stickyCategory(category, prevMeta?.category);
|
||||
const nextCallsign = stickyText(callsign, prevMeta?.callsign);
|
||||
// A route (and its airline) belongs to the callsign it was looked up for;
|
||||
// a new callsign drops it, so an old flight's route never shows under it.
|
||||
@@ -311,6 +336,10 @@ export class FlightRecords {
|
||||
geoAltitudeM,
|
||||
renderAltitudeM,
|
||||
renderAltitudeInvented,
|
||||
// The feed estimated this position: it places the aircraft, and stands
|
||||
// in on the tracked trail only until the next received report.
|
||||
estimated: observation.estimated === true,
|
||||
groundM: Number.isFinite(groundM) ? groundM : null,
|
||||
onGround,
|
||||
// Round 7: sticky airborne history — the landed fast-cull only
|
||||
// applies to contacts that actually flew this session.
|
||||
@@ -325,11 +354,9 @@ export class FlightRecords {
|
||||
),
|
||||
courseAnchor: course.anchor,
|
||||
category: cat,
|
||||
// An adsbdb-enriched type code outranks the coarse OpenSky category.
|
||||
klass: classifyAircraft({
|
||||
typeCode: airframe?.typeCode ?? null,
|
||||
category: cat,
|
||||
}),
|
||||
// A type code (the feed's, or a looked-up one) outranks the coarse
|
||||
// emitter category, from the first fix.
|
||||
klass: classifyAircraft({ typeCode, category: cat }),
|
||||
turnRateDps: prevMeta?.turnRateDps || 0,
|
||||
verticalRate: stickyNumber(vertical_rate, prevMeta?.verticalRate, null),
|
||||
// Analyst seam: OpenSky origin_country (state[2]) — additive, sticky
|
||||
@@ -362,8 +389,9 @@ export class FlightRecords {
|
||||
null,
|
||||
),
|
||||
// adsbdb enrichment — written by the enrichment callbacks, carried
|
||||
// across polls; a ground vehicle's or station's from the feed:
|
||||
// across polls; the type is the feed's own until a lookup answers:
|
||||
typeCode,
|
||||
typeLookedUp,
|
||||
typeName: airframe?.typeName ?? null,
|
||||
registration: airframe?.registration ?? null,
|
||||
airline: routeHeld ? (airframe.airline ?? null) : null,
|
||||
@@ -428,6 +456,7 @@ export class FlightRecords {
|
||||
for (const [id, meta] of this.data) {
|
||||
this.airframes.set(id, {
|
||||
typeCode: meta.typeCode,
|
||||
typeLookedUp: meta.typeLookedUp,
|
||||
typeName: meta.typeName,
|
||||
registration: meta.registration,
|
||||
airline: meta.airline,
|
||||
@@ -452,13 +481,54 @@ export class FlightRecords {
|
||||
}
|
||||
}
|
||||
|
||||
/** An ADS-B emitter category as a feed gives it ("A3", "C1"). */
|
||||
const EMITTER_CATEGORY = /^[A-D][0-7]$/;
|
||||
|
||||
/**
|
||||
* A contact's category, kept across polls that omit it: OpenSky's integer
|
||||
* category or an ADS-B emitter category string, else the last one, else null.
|
||||
* @param {*} next
|
||||
* @param {*} prev
|
||||
* @returns {number|string|null}
|
||||
*/
|
||||
function stickyCategory(next, prev) {
|
||||
if (Number.isFinite(next)) return next;
|
||||
const text = typeof next === 'string' ? next.trim().toUpperCase() : '';
|
||||
if (EMITTER_CATEGORY.test(text)) return text;
|
||||
return prev ?? null;
|
||||
}
|
||||
|
||||
/** A feed's ICAO type designator, upper case, or null. */
|
||||
function cleanType(value) {
|
||||
const text = typeof value === 'string' ? value.trim().toUpperCase() : '';
|
||||
return text || null;
|
||||
}
|
||||
|
||||
/** The types a feed gives airport vehicles (ZVEH) and ground stations (GRND). */
|
||||
const GROUND_FEED_TYPES = new Set(['ZVEH', 'GRND']);
|
||||
/** The fastest an airport vehicle drives, m/s (144 km/h); faster, it is no vehicle. */
|
||||
const VEHICLE_MAX_SPEED_MPS = 40;
|
||||
|
||||
/** Per loaded fleet model set: whether a type, category and callsign rule draw a ground model. */
|
||||
const groundModelCaches = new WeakMap();
|
||||
|
||||
/**
|
||||
* Whether an emitter category is a surface one: a vehicle or an obstacle
|
||||
* (ADS-B C1 to C5, OpenSky 16 to 20).
|
||||
* @param {string|number|null} category
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function groundCategory(category) {
|
||||
if (Number.isInteger(category)) return category >= 16 && category <= 20;
|
||||
return typeof category === 'string' && /^C[1-5]$/i.test(category.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an aircraft of this type, emitter category and callsign is drawn
|
||||
* with a model built standing on the ground (catalog category `other`: an
|
||||
* airport vehicle, a ground station's mast). False before the set loads.
|
||||
* airport vehicle, a ground station's mast). A surface emitter category
|
||||
* (C1 to C5, OpenSky 16 to 20) always is. Otherwise, before the set loads,
|
||||
* whether the type is one a feed gives ground vehicles and stations.
|
||||
* Answered once per type, category and callsign rule matched.
|
||||
* @param {object|null} set The loaded fleet model set.
|
||||
* @param {string|null} typeCode
|
||||
@@ -467,7 +537,11 @@ const groundModelCaches = new WeakMap();
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function drawnAsGroundModel(set, typeCode, category, callsign) {
|
||||
if (!set || !typeCode) return false;
|
||||
if (groundCategory(category)) return true;
|
||||
if (!typeCode) return false;
|
||||
// Before the set loads, the feed's own ground types: an airport vehicle
|
||||
// must not be drawn as an aircraft until the set says what it is.
|
||||
if (!set) return GROUND_FEED_TYPES.has(typeCode.trim().toUpperCase());
|
||||
let cache = groundModelCaches.get(set);
|
||||
if (!cache) groundModelCaches.set(set, (cache = new Map()));
|
||||
const rule = aircraftCallsignRule(set.types, typeCode, callsign);
|
||||
|
||||
@@ -283,6 +283,7 @@ test('a ground vehicle or station with no altitude stands on the ground; an airc
|
||||
observation({
|
||||
id: 'v1',
|
||||
typeCode: 'ZVEH',
|
||||
speedMps: 8,
|
||||
callsign: 'FIRE 2',
|
||||
...noAltitude,
|
||||
}),
|
||||
@@ -298,26 +299,175 @@ test('a ground vehicle or station with no altitude stands on the ground; an airc
|
||||
assert.equal(mast.onGround, true);
|
||||
assert.equal(mast.typeCode, 'GRND');
|
||||
// An airliner with no altitude keeps the airborne default, and its feed
|
||||
// type still waits for the airframe lookup.
|
||||
// type from the first fix.
|
||||
const plane = store.receive(
|
||||
observation({ id: 'p1', typeCode: 'A320', ...noAltitude }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(plane.onGround, false);
|
||||
assert.equal(plane.altitude, 10000);
|
||||
assert.equal(plane.typeCode, null);
|
||||
// A vehicle reporting an altitude is placed by it.
|
||||
assert.equal(plane.typeCode, 'A320');
|
||||
// An "airport vehicle" reported airborne is no vehicle (a drone, a test
|
||||
// transponder): it is placed by its altitude and classed as an aircraft.
|
||||
const reported = store.receive(
|
||||
observation({ id: 'v2', typeCode: 'ZVEH', baroAltitudeM: 12 }),
|
||||
observation({ id: 'v2', typeCode: 'ZVEH', baroAltitudeM: 762 }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(reported.onGround, false);
|
||||
// Before the model set loads nothing is grounded by its model.
|
||||
const unloaded = records().receive(
|
||||
observation({ id: 'v3', typeCode: 'ZVEH', ...noAltitude }),
|
||||
assert.equal(reported.typeCode, null);
|
||||
assert.notEqual(reported.klass, 'vehicle');
|
||||
// Nor is one on the ground faster than a vehicle drives.
|
||||
const fast = store.receive(
|
||||
observation({
|
||||
id: 'v4',
|
||||
typeCode: 'ZVEH',
|
||||
onGround: true,
|
||||
speedMps: 77,
|
||||
...noAltitude,
|
||||
}),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(unloaded.onGround, false);
|
||||
assert.notEqual(fast.klass, 'vehicle');
|
||||
// A ground station stands on the ground whatever height it reports.
|
||||
const high = store.receive(
|
||||
observation({ id: 'm2', typeCode: 'GRND', baroAltitudeM: 11880 }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(high.onGround, true);
|
||||
assert.equal(high.klass, 'station');
|
||||
assert.equal(high.altitude, 0);
|
||||
assert.ok(
|
||||
!(high.renderAltitudeM > 1000),
|
||||
`drawn at ${high.renderAltitudeM} m`,
|
||||
);
|
||||
// Before the model set loads, the feed's ground types already count: an
|
||||
// airport vehicle is never drawn as an aircraft first.
|
||||
const early = records();
|
||||
const unloaded = early.receive(
|
||||
observation({ id: 'v3', typeCode: 'ZVEH', speedMps: 8, ...noAltitude }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(unloaded.onGround, true);
|
||||
assert.equal(unloaded.typeCode, 'ZVEH');
|
||||
const earlyPlane = early.receive(
|
||||
observation({ id: 'p2', typeCode: 'A320', ...noAltitude }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(earlyPlane.onGround, false);
|
||||
assert.equal(earlyPlane.typeCode, 'A320');
|
||||
});
|
||||
|
||||
test('airport vehicles and ground stations take their class from the first fix', () => {
|
||||
// Before the model set loads, and after.
|
||||
for (const store of [records(), records(() => fleetSet)]) {
|
||||
const klass = (fields) =>
|
||||
store.receive(observation({ callsign: '', ...fields }), view()).meta
|
||||
.klass;
|
||||
// An airport vehicle reports itself on the ground, at a vehicle's speed.
|
||||
const driving = { onGround: true, speedMps: 8 };
|
||||
assert.equal(klass({ id: 'v1', typeCode: 'ZVEH', ...driving }), 'vehicle');
|
||||
assert.equal(
|
||||
klass({ id: 'v2', typeCode: 'ZVEH', callsign: 'FIRE 2', ...driving }),
|
||||
'vehicle',
|
||||
);
|
||||
assert.equal(klass({ id: 'v3', category: 'C1' }), 'vehicle');
|
||||
assert.equal(klass({ id: 'v4', category: 'C2' }), 'vehicle');
|
||||
assert.equal(klass({ id: 'm1', typeCode: 'GRND' }), 'station');
|
||||
assert.equal(klass({ id: 'm2', category: 'C4' }), 'station');
|
||||
// An aircraft's feed type outranks its emitter category.
|
||||
assert.equal(
|
||||
klass({ id: 'p1', typeCode: 'A320', category: 'A7' }),
|
||||
'airliner',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("an aircraft's feed type classes it from the first fix, until a lookup answers", () => {
|
||||
for (const store of [records(), records(() => fleetSet)]) {
|
||||
// A helicopter whose feed names its type, with an airliner-like category.
|
||||
const first = store.receive(
|
||||
observation({
|
||||
id: 'h1',
|
||||
callsign: 'NHC47',
|
||||
typeCode: 'ec45',
|
||||
category: 'A3',
|
||||
}),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(first.typeCode, 'EC45');
|
||||
assert.equal(first.klass, 'helicopter');
|
||||
assert.equal(first.typeLookedUp, false);
|
||||
// A later row without the type keeps it.
|
||||
const quiet = store.receive(
|
||||
observation({ id: 'h1', callsign: 'NHC47', category: 'A3' }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(quiet.klass, 'helicopter');
|
||||
assert.equal(quiet.typeCode, 'EC45');
|
||||
// A looked-up type outranks the feed's on every later poll and reset.
|
||||
quiet.typeCode = 'EC35';
|
||||
quiet.typeLookedUp = true;
|
||||
quiet.typeName = 'Airbus Helicopters H135';
|
||||
const after = store.receive(
|
||||
observation({ id: 'h1', callsign: 'NHC47', typeCode: 'B738' }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(after.typeCode, 'EC35');
|
||||
assert.equal(after.typeName, 'Airbus Helicopters H135');
|
||||
assert.equal(after.klass, 'helicopter');
|
||||
store.reset();
|
||||
const again = store.receive(
|
||||
observation({ id: 'h1', callsign: 'NHC47', typeCode: 'B738' }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(again.typeCode, 'EC35');
|
||||
// No type anywhere: the emitter category classes it.
|
||||
const bare = store.receive(
|
||||
observation({ id: 'h2', category: 'A7' }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(bare.typeCode, null);
|
||||
assert.equal(bare.klass, 'helicopter');
|
||||
}
|
||||
});
|
||||
|
||||
test('a surface emitter category stands on the ground, before and after the model set loads', () => {
|
||||
const noAltitude = { baroAltitudeM: null, ellipsoidAltitudeM: null };
|
||||
for (const store of [records(), records(() => fleetSet)]) {
|
||||
for (const [id, category] of [
|
||||
['c1', 'C1'],
|
||||
['c2', 'C2'],
|
||||
['c3', 'C3'],
|
||||
['c5', 'C5'],
|
||||
['o16', 16],
|
||||
['o20', 20],
|
||||
]) {
|
||||
const meta = store.receive(
|
||||
observation({ id, category, callsign: '', ...noAltitude }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(meta.onGround, true, `${id} stands on the ground`);
|
||||
assert.equal(meta.altitude, 0, id);
|
||||
}
|
||||
// An aircraft category with no altitude keeps the airborne default.
|
||||
const plane = store.receive(
|
||||
observation({ id: 'a3', category: 'A3', ...noAltitude }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(plane.onGround, false);
|
||||
// A feed's aircraft type on a surface category does not make it an aircraft.
|
||||
const odd = store.receive(
|
||||
observation({
|
||||
id: 'c9',
|
||||
category: 'C1',
|
||||
typeCode: 'A320',
|
||||
...noAltitude,
|
||||
}),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(odd.klass, 'vehicle');
|
||||
assert.equal(odd.onGround, true);
|
||||
}
|
||||
});
|
||||
|
||||
test('a contact reported with no course faces the way its newer fixes went', () => {
|
||||
@@ -365,3 +515,38 @@ test('a contact reported with no course faces the way its newer fixes went', ()
|
||||
taxi(30.188, 20);
|
||||
assert.equal(course(), 0);
|
||||
});
|
||||
|
||||
test('a low contact near the view carries the ground under it; others carry none', () => {
|
||||
const store = new FlightRecords({
|
||||
geoidHeight: () => 40,
|
||||
cachedGroundFloor: () => 1656,
|
||||
floorAltitudeM: (altitude, ground) =>
|
||||
Math.max(altitude, ground ?? -Infinity),
|
||||
fleetModels: () => null,
|
||||
});
|
||||
const denver = { latitude: 39.85, longitude: -104.67 };
|
||||
const near = { ...view(), viewerLatDeg: 39.8, viewerLonDeg: -104.7 };
|
||||
// Landing at Denver: 1,900 m above the ellipsoid over 1,656 m ground.
|
||||
const landing = store.receive(
|
||||
observation({ id: 'l1', ...denver, ellipsoidAltitudeM: 1900 }),
|
||||
near,
|
||||
).meta;
|
||||
assert.equal(landing.groundM, 1656);
|
||||
// At cruise the ground is not read.
|
||||
const cruise = store.receive(
|
||||
observation({
|
||||
id: 'c1',
|
||||
...denver,
|
||||
ellipsoidAltitudeM: 11000,
|
||||
baroAltitudeM: 11000,
|
||||
}),
|
||||
near,
|
||||
).meta;
|
||||
assert.equal(cruise.groundM, null);
|
||||
// Nor without a view to be near.
|
||||
const away = store.receive(
|
||||
observation({ id: 'a1', ...denver, ellipsoidAltitudeM: 1900 }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(away.groundM, null);
|
||||
});
|
||||
@@ -2,13 +2,12 @@ import {
|
||||
aircraftLayerModelSpec,
|
||||
aircraftModelSpecCacheKey,
|
||||
} from './modelSpec.js';
|
||||
import { CLASS_SCALE_2D } from '../../data/aircraftClass.js';
|
||||
import { isEmergency } from '../../data/aircraftEmergency.js';
|
||||
import {
|
||||
MIL_TINT,
|
||||
EMERGENCY_TINT,
|
||||
VEHICLE_TINT,
|
||||
FLEET_TINT,
|
||||
TRACKED_CYAN,
|
||||
GROUND_SCALE,
|
||||
COCKPIT_CIVILIAN_COLOR,
|
||||
} from './policy.js';
|
||||
@@ -32,14 +31,16 @@ export function createRendering({
|
||||
}
|
||||
|
||||
/** Fleet (untracked) billboard tint: red while broadcasting an emergency,
|
||||
* amber for known-military, white otherwise.
|
||||
* Ground traffic gets NO special tint (owner verdict 2026-07-03 field test). */
|
||||
* orange amber for an airport vehicle, amber for known-military, white
|
||||
* otherwise. Grounded aircraft get NO special tint (owner verdict
|
||||
* 2026-07-03 field test). */
|
||||
|
||||
function _fleetBillboardColor(
|
||||
icao24,
|
||||
info = flightState.records.data.get(icao24),
|
||||
) {
|
||||
if (_isEmergency(icao24, info)) return EMERGENCY_TINT;
|
||||
if (info?.klass === 'vehicle') return VEHICLE_TINT;
|
||||
return isMilitaryIcao(icao24) ? MIL_TINT : FLEET_TINT;
|
||||
}
|
||||
|
||||
@@ -53,13 +54,10 @@ export function createRendering({
|
||||
return isMilitaryIcao(icao24) ? MIL_TINT : COCKPIT_CIVILIAN_COLOR;
|
||||
}
|
||||
|
||||
/** Fleet billboard scale: per-class scale, ×GROUND_SCALE while grounded. */
|
||||
/** Fleet billboard scale: one size for every class, ×GROUND_SCALE while grounded. */
|
||||
|
||||
function _fleetBillboardScale(icao24, klass) {
|
||||
return (
|
||||
(CLASS_SCALE_2D[klass] || 1) *
|
||||
(flightState.records.data.get(icao24)?.onGround ? GROUND_SCALE : 1)
|
||||
);
|
||||
function _fleetBillboardScale(icao24) {
|
||||
return flightState.records.data.get(icao24)?.onGround ? GROUND_SCALE : 1;
|
||||
}
|
||||
|
||||
/** The fleet model an aircraft draws with, by its type and emitter category. */
|
||||
@@ -82,11 +80,10 @@ export function createRendering({
|
||||
const _iconKind = (icao24, klass) =>
|
||||
tr3bIconKind(icao24, klass, { hot: flightState._irBoost });
|
||||
|
||||
/** Model colour: the mesh's own (white), tinted cyan while tracked and red
|
||||
* while broadcasting an emergency. */
|
||||
/** Model colour: the mesh's own (white), tinted red while broadcasting an
|
||||
* emergency. Tracking never recolours it. */
|
||||
|
||||
function _modelColor(icao24) {
|
||||
if (icao24 === flightState._trackedIcao) return TRACKED_CYAN;
|
||||
return _isEmergency(icao24) ? EMERGENCY_TINT : policy.MODEL_WHITE;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// src/layers/flights/rendering.test.mjs
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { createRendering as createFlightsRendering } from './rendering.js';
|
||||
import { createRendering as createMilitaryRendering } from '../military/rendering.js';
|
||||
|
||||
function rendering(create) {
|
||||
const data = new Map([
|
||||
['light', { klass: 'light' }],
|
||||
['quadjet', { klass: 'quadjet' }],
|
||||
['vehicle', { klass: 'vehicle' }],
|
||||
['parked', { klass: 'quadjet', onGround: true }],
|
||||
]);
|
||||
return create({
|
||||
flightState: { records: { data } },
|
||||
services: {
|
||||
militaryRegistry: { isMilitaryIcao: () => false },
|
||||
aircraftPresentation: { tr3bIconKind: () => null },
|
||||
focus: { focusNowMs: () => 0, getFocusTarget: () => null },
|
||||
},
|
||||
parts: {},
|
||||
layer: {},
|
||||
resolveAsset: (url) => url,
|
||||
});
|
||||
}
|
||||
|
||||
test('Flights draws every class at one size, smaller on the ground', () => {
|
||||
const r = rendering(createFlightsRendering);
|
||||
for (const id of ['light', 'quadjet', 'vehicle']) {
|
||||
assert.equal(r._fleetBillboardScale(id), 1, id);
|
||||
}
|
||||
assert.equal(r._fleetBillboardScale('parked'), 0.8);
|
||||
});
|
||||
|
||||
test('Military draws every class at its one size, smaller on the ground', () => {
|
||||
const r = rendering(createMilitaryRendering);
|
||||
const size = r._fleetBillboardScale('light');
|
||||
for (const id of ['quadjet', 'vehicle']) {
|
||||
assert.equal(r._fleetBillboardScale(id), size, id);
|
||||
}
|
||||
assert.ok(Math.abs(r._fleetBillboardScale('parked') - size * 0.8) < 1e-12);
|
||||
});
|
||||
@@ -56,8 +56,16 @@ export function createFlightSnapshotRenderer({
|
||||
/**
|
||||
* `replace`: the snapshot is the world at another time (the world clock
|
||||
* jumped), so it stands in for every contact: one it lacks is gone at once.
|
||||
* `handover`: the first live snapshot after the clock came back to live: it
|
||||
* stands in for every contact too, and those it has keep their icon and
|
||||
* model and ease on from where they are drawn; of those it lacks, only
|
||||
* those absence keeps (judged by their newest fix) stay.
|
||||
*/
|
||||
return function applySnapshot(snapshot, viewer, { replace = false } = {}) {
|
||||
return function applySnapshot(
|
||||
snapshot,
|
||||
viewer,
|
||||
{ replace = false, handover = false } = {},
|
||||
) {
|
||||
// Before init (or after destroy) there is no icon set to draw into.
|
||||
if (!flightState._icons) return { count: 0, ids: new Set() };
|
||||
const currentIcaos = new Set();
|
||||
@@ -209,6 +217,7 @@ export function createFlightSnapshotRenderer({
|
||||
{
|
||||
nullAltitude: meta.renderAltitudeInvented === true,
|
||||
track: meta.true_track,
|
||||
estimated: meta.estimated === true,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
@@ -254,7 +263,7 @@ export function createFlightSnapshotRenderer({
|
||||
// freshness change and the cockpit contract all land on the row's
|
||||
// style; motion re-plans from the updated history.
|
||||
icons._applyIconPresentation(icao24);
|
||||
icons._planIcon(icao24);
|
||||
icons._planIcon(icao24, handover ? { handover } : undefined);
|
||||
// Poll-path type or category change: same model resync rule as the
|
||||
// enrichment path — the fleet model or its scale may have changed.
|
||||
if (
|
||||
@@ -294,6 +303,23 @@ export function createFlightSnapshotRenderer({
|
||||
// EXCEPTION: likely-landed planes (last fix low + slow) get only
|
||||
// LANDED_MISSING_POLL_LIMIT — their disappearance means "landed", not a
|
||||
// feed gap, and the full grace left phantom planes parked at airports.
|
||||
// Back at live, a contact it lacks is from the time the clock left: it
|
||||
// goes at once, unless absence keeps it as any poll would (a partial or
|
||||
// retaining snapshot, the tracked aircraft), judged by its newest fix.
|
||||
// No missed-poll grace, and a landed tracked aircraft is not kept.
|
||||
const absenceAtHandover = (icao24) => {
|
||||
const likelyLanded = queries._likelyLanded(icao24);
|
||||
const judged = records.absence(icao24, {
|
||||
complete: snapshot.complete,
|
||||
retainIds: snapshot.retainIds,
|
||||
likelyLanded,
|
||||
tracked: icao24 === flightState._trackedIcao && !likelyLanded,
|
||||
nowMs: flightState.now?.(),
|
||||
});
|
||||
return judged === 'stale' && icao24 !== flightState._trackedIcao
|
||||
? 'remove'
|
||||
: judged;
|
||||
};
|
||||
const absentIds = [];
|
||||
for (const icao24 of flightState._icons.ids()) {
|
||||
if (!currentIcaos.has(icao24)) absentIds.push(icao24);
|
||||
@@ -301,13 +327,15 @@ export function createFlightSnapshotRenderer({
|
||||
for (const icao24 of absentIds) {
|
||||
const absence = replace
|
||||
? 'remove'
|
||||
: records.absence(icao24, {
|
||||
complete: snapshot.complete,
|
||||
retainIds: snapshot.retainIds,
|
||||
likelyLanded: queries._likelyLanded(icao24),
|
||||
tracked: icao24 === flightState._trackedIcao,
|
||||
nowMs: flightState.now?.(),
|
||||
});
|
||||
: handover
|
||||
? absenceAtHandover(icao24)
|
||||
: records.absence(icao24, {
|
||||
complete: snapshot.complete,
|
||||
retainIds: snapshot.retainIds,
|
||||
likelyLanded: queries._likelyLanded(icao24),
|
||||
tracked: icao24 === flightState._trackedIcao,
|
||||
nowMs: flightState.now?.(),
|
||||
});
|
||||
if (absence === 'retain') continue;
|
||||
if (absence === 'stale') {
|
||||
icons._applyIconPresentation(icao24); // the faded freshness alpha
|
||||
@@ -334,7 +362,8 @@ export function createFlightSnapshotRenderer({
|
||||
icons._forgetContact(icao24); // aged out: its 3D model goes too (no orphan / cap leak)
|
||||
}
|
||||
|
||||
// The tracked contact at the new time: its trail starts there.
|
||||
// The tracked contact at the new time: its trail starts there. Back at
|
||||
// live its trail goes on.
|
||||
if (
|
||||
replace &&
|
||||
flightState._trackedIcao &&
|
||||
|
||||
@@ -266,6 +266,18 @@ export function createFlightState({ source, services }) {
|
||||
|
||||
flightState._drSpeedMps = null;
|
||||
|
||||
/** Sibling scratch: whether `_drSpeedMps` is a host-supplied placement's,
|
||||
* the speed it is drawn at (0 while it waits for its fixes), for motion
|
||||
* only; panels show the reported ground speed (`displayedKinematics`). */
|
||||
|
||||
flightState._drSpeedPlaced = false;
|
||||
|
||||
/** Sibling of `_cachedDRPosition`: whether a host-supplied placement placed
|
||||
* it (`_drSpeedPlaced` as the tracked aircraft was drawn), so its trail
|
||||
* ends where it is drawn rather than at the layer's display delay. */
|
||||
|
||||
flightState._cachedDRPlaced = false;
|
||||
|
||||
flightState._drCourseHold = false;
|
||||
|
||||
/** Sibling scratch: whether the position `_deadReckon` just returned came from
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CYAN_TRANSPARENT, TRACKED_CYAN } from './policy.js';
|
||||
import { trackedIconColor } from '../../data/trackedAircraftIcon.js';
|
||||
import { createModelRecord } from '../../data/modelRecord.js';
|
||||
import {
|
||||
aircraftIconTestSeams,
|
||||
@@ -217,9 +217,11 @@ export function createTesting({
|
||||
/** Evaluate the production tracked-billboard handoff colour for focused tests. */
|
||||
|
||||
function _trackedBillboardColorForTest() {
|
||||
return parts.rendering._modelOwnsVisual(flightState._trackedIcao)
|
||||
? CYAN_TRANSPARENT
|
||||
: TRACKED_CYAN;
|
||||
const icao24 = flightState._trackedIcao;
|
||||
const color = parts.rendering._fleetBillboardColor(icao24);
|
||||
return parts.rendering._modelOwnsVisual(icao24)
|
||||
? trackedIconColor(color, 0)
|
||||
: color;
|
||||
}
|
||||
|
||||
/** Drive the exact fleet icon-to-model handoff used by `_fleetTick`. */
|
||||
@@ -254,15 +256,20 @@ export function createTesting({
|
||||
}
|
||||
|
||||
/** How the tracked billboard is drawn (`_trackedBillboardLook`,
|
||||
* `_trackedSprite`) next to how the contact's fleet icon is (`_fleetLook`). */
|
||||
* `_trackedSprite`, `_trackedIconColor`) next to how the contact's fleet
|
||||
* icon is (`_fleetLook`, `_fleetBillboardColor`). */
|
||||
|
||||
function _trackedIconLookForTest(icao24) {
|
||||
return {
|
||||
tracked: {
|
||||
...parts.tracking._trackedBillboardLook(),
|
||||
sprite: parts.tracking._trackedSprite(icao24),
|
||||
color: parts.tracking._trackedIconColor(),
|
||||
},
|
||||
fleet: {
|
||||
...parts.icons._fleetLook(icao24),
|
||||
color: parts.rendering._fleetBillboardColor(icao24),
|
||||
},
|
||||
fleet: parts.icons._fleetLook(icao24),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
createTrackedAircraftIcon,
|
||||
isOtherTrackedIconSet,
|
||||
trackedContactHolder,
|
||||
trackedIconColor,
|
||||
} from '../../data/trackedAircraftIcon.js';
|
||||
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
|
||||
import { julianToEpochMs } from '../../geo/julian.js';
|
||||
@@ -28,10 +29,12 @@ import {
|
||||
} from '../../data/trackingClickGesture.js';
|
||||
import { inputFor } from '../../input/dispatcher.js';
|
||||
import {
|
||||
COCKPIT_AIR_ALL_ADD_M,
|
||||
COCKPIT_AIR_ALL_KEEP_M,
|
||||
COCKPIT_AIR_PROX_ADD_M,
|
||||
COCKPIT_AIR_PROX_KEEP_M,
|
||||
TRAIL_MAX_POINTS,
|
||||
TRAIL_COLOR,
|
||||
CYAN_TRANSPARENT,
|
||||
TRACKED_CYAN,
|
||||
STALE_ALPHA,
|
||||
displayDelayMs,
|
||||
followsClock,
|
||||
@@ -46,6 +49,7 @@ import {
|
||||
trailBodySegments,
|
||||
trailHeadCurvePoints,
|
||||
trailHeadStartFix,
|
||||
trailTimeAt,
|
||||
} from '../../data/trailContinuity.js';
|
||||
import { roundHeadingDegrees } from '../../data/headingDegrees.js';
|
||||
import { entityRecord } from '../../data/entityRecords.js';
|
||||
@@ -61,8 +65,6 @@ function aircraftPickId(hit) {
|
||||
return isOtherTrackedIconSet(hit.set, 'flights') ? undefined : hit.id;
|
||||
}
|
||||
|
||||
const STALE_CYAN = Object.freeze([...TRACKED_CYAN.slice(0, 3), STALE_ALPHA]);
|
||||
|
||||
export function createTracking({
|
||||
flightState,
|
||||
services,
|
||||
@@ -223,11 +225,13 @@ export function createTracking({
|
||||
);
|
||||
distancesSquared.push([icao24, distanceSquared(eye, position)]);
|
||||
}
|
||||
// The AIR band follows the 3D mode, not the 3D model radius.
|
||||
const all = flightState._models3dMode === 'all';
|
||||
const next = nextCockpitNearContacts(
|
||||
previous,
|
||||
distancesSquared,
|
||||
parts.rendering._modelAddDistM(),
|
||||
parts.rendering._modelKeepDistM(),
|
||||
all ? COCKPIT_AIR_ALL_ADD_M : COCKPIT_AIR_PROX_ADD_M,
|
||||
all ? COCKPIT_AIR_ALL_KEEP_M : COCKPIT_AIR_PROX_KEEP_M,
|
||||
);
|
||||
flightState._cockpitNearContacts = next;
|
||||
for (const icao24 of previous)
|
||||
@@ -333,15 +337,17 @@ export function createTracking({
|
||||
* @param {{x: number, y: number, z: number}} position - The report's ECEF position.
|
||||
* @param {number} [epochMs] - The report's time; defaults to the tracked
|
||||
* aircraft's newest position-history fix, which every caller has just pushed.
|
||||
* @param {{nullAltitude?: boolean, track?: number}} [options] - `nullAltitude`:
|
||||
* @param {{nullAltitude?: boolean, track?: number, estimated?: boolean}} [options] - `nullAltitude`:
|
||||
* the report had no altitude, so its position is not kept and the line
|
||||
* breaks there; `track`: its reported track, which the line leaves it along.
|
||||
* breaks there; `track`: its reported track, which the line leaves it along;
|
||||
* `estimated`: the feed estimated it, so it stands in only until the next
|
||||
* received report.
|
||||
*/
|
||||
|
||||
function _appendTrailFix(
|
||||
position,
|
||||
epochMs,
|
||||
{ nullAltitude = false, track = undefined } = {},
|
||||
{ nullAltitude = false, track = undefined, estimated = false } = {},
|
||||
) {
|
||||
const history = flightState._positionHistory.get(flightState._trackedIcao);
|
||||
const timeMs = Number.isFinite(epochMs)
|
||||
@@ -352,7 +358,7 @@ export function createTracking({
|
||||
position,
|
||||
timeMs,
|
||||
TRAIL_MAX_POINTS,
|
||||
{ nullAltitude, track },
|
||||
{ nullAltitude, track, estimated },
|
||||
);
|
||||
_refreshTrailDisplay();
|
||||
}
|
||||
@@ -391,12 +397,46 @@ export function createTracking({
|
||||
);
|
||||
}
|
||||
|
||||
/** Reports at or before the time the aircraft is drawn (now − the display delay). */
|
||||
/** Reports at or before the time the aircraft is drawn (`_trailDisplayMs`). */
|
||||
|
||||
function _trailBodyCountNow() {
|
||||
return trailBodyCount(
|
||||
return trailBodyCount(flightState._trailFixes, _trailDisplayMs());
|
||||
}
|
||||
|
||||
/**
|
||||
* The time on its trail at which a host-supplied placement draws the
|
||||
* aircraft, read off the trail where it is drawn (`trailTimeAt`): such a
|
||||
* placement draws at a delay of its own, not this layer's. NaN when this
|
||||
* layer's own motion draws it, or the trail has no pair to read.
|
||||
* @returns {number} Epoch ms or NaN.
|
||||
*/
|
||||
function _placedTrailMs() {
|
||||
if (!parts.motion._trackedPlaced?.()) return NaN;
|
||||
return trailTimeAt(
|
||||
flightState._trailFixes,
|
||||
flightState.now() - displayDelayMs(flightState),
|
||||
parts.motion._trackedDisplayCached(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The time the trail runs up to: the time the aircraft is drawn at, now −
|
||||
* the display delay, or where a placement draws it. Otherwise the trail
|
||||
* ends short of a placed aircraft, or runs on ahead of it.
|
||||
* @returns {number} Epoch ms.
|
||||
*/
|
||||
function _trailDisplayMs() {
|
||||
const placedMs = _placedTrailMs();
|
||||
return Number.isFinite(placedMs)
|
||||
? placedMs
|
||||
: flightState.now() - displayDelayMs(flightState);
|
||||
}
|
||||
|
||||
/** Whether the trail holds no report behind the aircraft yet: this
|
||||
* layer's own motion draws it before its oldest fix. Never for an
|
||||
* aircraft a placement draws: its trail is read where it is drawn. */
|
||||
function _trailWarmingUp() {
|
||||
return (
|
||||
!Number.isFinite(_placedTrailMs()) && parts.motion._isTrackWarmingUp()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -413,7 +453,7 @@ export function createTracking({
|
||||
if (
|
||||
!flightState._trackedIcao ||
|
||||
!flightState._trailFixes.length ||
|
||||
parts.motion._isTrackWarmingUp()
|
||||
_trailWarmingUp()
|
||||
)
|
||||
return [];
|
||||
const head =
|
||||
@@ -436,7 +476,7 @@ export function createTracking({
|
||||
trailHeadCurvePoints(
|
||||
flightState._trailFixes,
|
||||
flightState._trailBodyCount,
|
||||
flightState.now() - displayDelayMs(flightState),
|
||||
_trailDisplayMs(),
|
||||
),
|
||||
head,
|
||||
parts.motion._trackedModelCenterWorld(),
|
||||
@@ -698,10 +738,11 @@ export function createTracking({
|
||||
// Hand the contact back to its icon only now: settling floors a grounded
|
||||
// contact, and while it still read as tracked its tracked model owned the
|
||||
// visual, so the floor would have stepped aside.
|
||||
if (flightState._icons?.has(clearedIcao)) {
|
||||
flightState._icons.setShown(clearedIcao, true);
|
||||
// Its fleet model, kept loaded while it was selected, takes it back in
|
||||
// this frame; the icon shows only when there is no loaded one.
|
||||
parts.rendering._handBackDeselected(clearedIcao);
|
||||
if (flightState._icons?.has(clearedIcao))
|
||||
parts.icons._settleIcon(clearedIcao, { fromCourseDeg: trackedCourseDeg });
|
||||
}
|
||||
parts.icons._applyIconPresentation(clearedIcao);
|
||||
clearTrackedSubjectContext('flights');
|
||||
_emitAwarenessEvent('gev:awareness-subject-cleared', {
|
||||
@@ -814,14 +855,18 @@ export function createTracking({
|
||||
return { text: '', dimmed: false };
|
||||
}
|
||||
|
||||
/** The tracked billboard's colour: cyan, faded while stale, clear while the 3D model is the visual. */
|
||||
/** The tracked billboard's colour: the contact's own fleet colour (tracking
|
||||
* never recolours it), faded while stale, clear while the 3D model is the
|
||||
* visual. */
|
||||
|
||||
function _trackedIconColor() {
|
||||
if (parts.rendering._modelOwnsVisual(flightState._trackedIcao))
|
||||
return CYAN_TRANSPARENT;
|
||||
return _trackedStaleCue(flightState._trackedIcao).dimmed
|
||||
? STALE_CYAN
|
||||
: TRACKED_CYAN;
|
||||
const icao24 = flightState._trackedIcao;
|
||||
const color = parts.rendering._fleetBillboardColor(icao24);
|
||||
if (parts.rendering._modelOwnsVisual(icao24))
|
||||
return trackedIconColor(color, 0);
|
||||
return _trackedStaleCue(icao24).dimmed
|
||||
? trackedIconColor(color, STALE_ALPHA)
|
||||
: color;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -913,10 +958,7 @@ export function createTracking({
|
||||
width: look.size[0],
|
||||
height: look.size[1],
|
||||
get scale() {
|
||||
return parts.rendering._fleetBillboardScale(
|
||||
icao24,
|
||||
flightState.records.data.get(icao24)?.klass,
|
||||
);
|
||||
return parts.rendering._fleetBillboardScale(icao24);
|
||||
},
|
||||
scaleByDistance: look.scaleByDistance,
|
||||
};
|
||||
@@ -1079,13 +1121,13 @@ export function createTracking({
|
||||
imageLod: _trackedBillboardLook().imageLod,
|
||||
sprite,
|
||||
position: getTrackedPosition,
|
||||
// Solid cyan (faded while stale) when the billboard is the visual (zoomed out, 3D off,
|
||||
// Its own colour (faded while stale) when the billboard is the visual (zoomed out, 3D off,
|
||||
// or model still loading); transparent once the tracked model is actually up.
|
||||
color: _trackedIconColor,
|
||||
// Screen-projected rotation, evaluated per frame on the camera's own
|
||||
// axes, so it stays exact through a tracked orbit. The tracked target
|
||||
// must never vanish into tile geometry — tracking a taxiing plane at
|
||||
// street level would otherwise bury the cyan icon inside the runway
|
||||
// street level would otherwise bury the icon inside the runway
|
||||
// skin, so it draws over depth like the fleet icon set; its
|
||||
// shared-host tracked card is top-composited separately.
|
||||
rotation: () => {
|
||||
@@ -1093,6 +1135,8 @@ export function createTracking({
|
||||
const pos = getTrackedPosition();
|
||||
if (!tracked || !pos || !flightState._viewer)
|
||||
return flightState._lastTrackedRotation;
|
||||
// A ground station's mast stands upright.
|
||||
if (tracked.klass === 'station') return 0;
|
||||
const projected = courseScreenRotation(
|
||||
_pose(),
|
||||
pos,
|
||||
|
||||
@@ -4,7 +4,12 @@ import * as Cesium from 'cesium';
|
||||
import { createFlightState } from './state.js';
|
||||
import { createTracking } from './tracking.js';
|
||||
import { TRAIL_MAX_POINTS } from './policy.js';
|
||||
import { trailHeadJoins, trailPairBreaks } from '../../data/trailContinuity.js';
|
||||
import {
|
||||
insertTrailFix,
|
||||
trailHeadJoins,
|
||||
trailPairBreaks,
|
||||
trailTimeAt,
|
||||
} from '../../data/trailContinuity.js';
|
||||
|
||||
const MINUTE = 60_000;
|
||||
const HOUR = 60 * MINUTE;
|
||||
@@ -92,6 +97,8 @@ function trackedHarness({
|
||||
nowMs,
|
||||
floor,
|
||||
head = null,
|
||||
placed = false,
|
||||
warmingUp = false,
|
||||
} = {}) {
|
||||
const trail = recordingTrail();
|
||||
const svc = services({ trails: trail, floor });
|
||||
@@ -122,7 +129,9 @@ function trackedHarness({
|
||||
services: svc,
|
||||
parts: {
|
||||
motion: {
|
||||
_isTrackWarmingUp: () => false,
|
||||
_isTrackWarmingUp: () => warmingUp,
|
||||
_trackedPlaced: () => placed,
|
||||
_trackedDisplayCached: () => head,
|
||||
_trackedTrailCached: () => head,
|
||||
_trackedDisplayPosition: () => head,
|
||||
_trackedModelCenterWorld: () => null,
|
||||
@@ -410,3 +419,136 @@ test('every waypoint of a 24 h history survives, and the trail stays within TRAI
|
||||
// The oldest go first: the newest live fix is still the last point.
|
||||
assert.equal(fixes[fixes.length - 1].timeMs, liveStart);
|
||||
});
|
||||
|
||||
/** A trail of `count` reports one minute apart flying east from (50, 1). */
|
||||
function eastTrail(t0, count) {
|
||||
const fixes = [];
|
||||
for (let i = 0; i < count; i++)
|
||||
insertTrailFix(
|
||||
fixes,
|
||||
Cesium.Cartesian3.fromDegrees(1 + i * 0.12, 50, 10_000),
|
||||
t0 + i * MINUTE,
|
||||
TRAIL_MAX_POINTS,
|
||||
);
|
||||
return fixes;
|
||||
}
|
||||
|
||||
test('the time on the trail is read where the aircraft is drawn', () => {
|
||||
const t0 = Date.UTC(2026, 10, 8, 0, 0);
|
||||
const fixes = eastTrail(t0, 4);
|
||||
const at = (lon) =>
|
||||
trailTimeAt(fixes, Cesium.Cartesian3.fromDegrees(lon, 50, 10_000));
|
||||
// Halfway between the second and third reports.
|
||||
assert.ok(Math.abs(at(1.18) - (t0 + 1.5 * MINUTE)) < 2_000);
|
||||
// On a report.
|
||||
assert.ok(Math.abs(at(1.24) - (t0 + 2 * MINUTE)) < 2_000);
|
||||
// Past the newest report the time runs on; before the oldest it runs back.
|
||||
assert.ok(Math.abs(at(1.42) - (t0 + 3.5 * MINUTE)) < 2_000);
|
||||
assert.ok(Math.abs(at(0.94) - (t0 - 0.5 * MINUTE)) < 2_000);
|
||||
// Nothing to read without a pair of reports, or without a position.
|
||||
assert.ok(Number.isNaN(trailTimeAt(fixes.slice(0, 1), fixes[0].position)));
|
||||
assert.ok(Number.isNaN(trailTimeAt(fixes, null)));
|
||||
});
|
||||
|
||||
test('the time on the trail is never read across a break', () => {
|
||||
const t0 = Date.UTC(2026, 10, 8, 0, 0);
|
||||
const fixes = eastTrail(t0, 2);
|
||||
// An hour later, far on: a new segment.
|
||||
insertTrailFix(
|
||||
fixes,
|
||||
Cesium.Cartesian3.fromDegrees(20, 50, 10_000),
|
||||
t0 + HOUR,
|
||||
TRAIL_MAX_POINTS,
|
||||
);
|
||||
insertTrailFix(
|
||||
fixes,
|
||||
Cesium.Cartesian3.fromDegrees(20.12, 50, 10_000),
|
||||
t0 + HOUR + MINUTE,
|
||||
TRAIL_MAX_POINTS,
|
||||
);
|
||||
assert.equal(fixes[2].breakBefore, true);
|
||||
// Halfway along the gap is not on the trail: it is read on the newest pair.
|
||||
const at = trailTimeAt(fixes, Cesium.Cartesian3.fromDegrees(10, 50, 10_000));
|
||||
assert.ok(at <= t0 + HOUR, `read ${at - t0} ms in, across the break`);
|
||||
});
|
||||
|
||||
test('a placed aircraft drawn ahead of the display delay keeps its trail joined to it', () => {
|
||||
const t0 = Date.UTC(2026, 10, 8, 0, 0);
|
||||
const liveFixes = [0, 1, 2, 3].map((i) => ({
|
||||
timeMs: t0 + i * MINUTE,
|
||||
lat: 50,
|
||||
lon: 1 + i * 0.12,
|
||||
}));
|
||||
// The layer's own delay puts the aircraft before its first fix (warming
|
||||
// up), but the placement draws it between the third and fourth reports.
|
||||
const near = Cesium.Cartesian3.fromDegrees(1.3, 50, 10_000);
|
||||
const placed = trackedHarness({
|
||||
liveFixes,
|
||||
nowMs: t0 + 3.5 * MINUTE,
|
||||
head: near,
|
||||
placed: true,
|
||||
warmingUp: true,
|
||||
});
|
||||
placed.flightState._displayDelay = { currentMs: 10 * MINUTE };
|
||||
placed.tracking._startTrail('abc123');
|
||||
// The body runs to the last report behind the aircraft, none ahead of it.
|
||||
assert.deepEqual(
|
||||
placed.trail.last().map((segment) => segment.length > 0),
|
||||
[true],
|
||||
);
|
||||
const body = placed.trail.last()[0];
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.distance(
|
||||
body[body.length - 1],
|
||||
Cesium.Cartesian3.fromDegrees(1.24, 50, 10_000),
|
||||
) < 1,
|
||||
);
|
||||
// The head joins it to the aircraft.
|
||||
const drawn = headPositions(placed);
|
||||
assert.ok(drawn.length >= 2);
|
||||
assert.ok(Cesium.Cartesian3.distance(drawn[0], body[body.length - 1]) < 1);
|
||||
assert.ok(Cesium.Cartesian3.distance(drawn[drawn.length - 1], near) < 1e-6);
|
||||
|
||||
// The layer's own motion, warming up, draws no head and no body.
|
||||
const own = trackedHarness({
|
||||
liveFixes,
|
||||
nowMs: t0 + 3.5 * MINUTE,
|
||||
head: near,
|
||||
warmingUp: true,
|
||||
});
|
||||
own.flightState._displayDelay = { currentMs: 10 * MINUTE };
|
||||
own.tracking._startTrail('abc123');
|
||||
assert.deepEqual(own.trail.last(), []);
|
||||
assert.deepEqual(headPositions(own), []);
|
||||
});
|
||||
|
||||
test('a placed aircraft drawn behind the display delay has no trail ahead of it', () => {
|
||||
const t0 = Date.UTC(2026, 10, 8, 0, 0);
|
||||
const liveFixes = [0, 1, 2, 3].map((i) => ({
|
||||
timeMs: t0 + i * MINUTE,
|
||||
lat: 50,
|
||||
lon: 1 + i * 0.12,
|
||||
}));
|
||||
// The layer's delay would draw every report; the placement holds the
|
||||
// aircraft between the first and second.
|
||||
const behind = Cesium.Cartesian3.fromDegrees(1.06, 50, 10_000);
|
||||
const { trail, tracking, flightState } = trackedHarness({
|
||||
liveFixes,
|
||||
nowMs: t0 + 4 * MINUTE,
|
||||
head: behind,
|
||||
placed: true,
|
||||
});
|
||||
flightState._displayDelay = { currentMs: 0 };
|
||||
tracking._startTrail('abc123');
|
||||
// One report behind it: no line yet, and nothing ahead of the aircraft.
|
||||
assert.deepEqual(trail.last(), []);
|
||||
const drawn = headPositions({ tracking });
|
||||
assert.equal(drawn.length, 2);
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.distance(
|
||||
drawn[0],
|
||||
Cesium.Cartesian3.fromDegrees(1, 50, 10_000),
|
||||
) < 1,
|
||||
);
|
||||
assert.ok(Cesium.Cartesian3.distance(drawn[1], behind) < 1e-6);
|
||||
});
|
||||
@@ -6,7 +6,7 @@ import { createStubRenderer } from '../../render/stub/index.js';
|
||||
import { createMotion } from './motion.js';
|
||||
import { createFlightState } from './state.js';
|
||||
import { createTracking } from './tracking.js';
|
||||
import { RENDER_DELAY_SEC, STALE_ALPHA } from './policy.js';
|
||||
import { FLEET_TINT, RENDER_DELAY_SEC, STALE_ALPHA } from './policy.js';
|
||||
|
||||
// A tracked trail is the aircraft's reports joined along the curve the icon
|
||||
// is drawn along between them, so the icon always sits on its trail and a
|
||||
@@ -116,7 +116,11 @@ function harness({
|
||||
flightState.now = () => clock;
|
||||
flightState._positionHistory.set(ICAO, fixes);
|
||||
const parts = {
|
||||
rendering: { _modelOwnsVisual: () => false, _modelSpec: () => ({}) },
|
||||
rendering: {
|
||||
_modelOwnsVisual: () => false,
|
||||
_modelSpec: () => ({}),
|
||||
_fleetBillboardColor: () => FLEET_TINT,
|
||||
},
|
||||
queries: { _contactLabel: (id, info) => info?.callsign || id },
|
||||
};
|
||||
parts.motion = createMotion({ flightState, services: svc, parts });
|
||||
@@ -797,6 +801,11 @@ test('a stalled feed dims the tracked plane as STALE', () => {
|
||||
dimmed: true,
|
||||
});
|
||||
assert.equal(h.tracking._trackedIconColor()[3], STALE_ALPHA);
|
||||
assert.deepEqual(
|
||||
h.tracking._trackedIconColor().slice(0, 3),
|
||||
FLEET_TINT.slice(0, 3),
|
||||
'faded in its own colour, never recoloured',
|
||||
);
|
||||
assert.equal(h.flightState.records.missingPolls.has(ICAO), false);
|
||||
} finally {
|
||||
h.restore();
|
||||
|
||||
Reference in new issue
Block a user