mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Sprites for helicopters, ground vehicles, stations and vessel types; history to live without an empty map; model parts in Cesium
Aircraft icons are one size; helicopters turn a three-frame rotor while airborne or moving; ADS-B ground vehicles share one amber sprite and stations/obstacles one mast; vessels get hull sprites by type and one buoy. Going live keeps contacts until the first live answer and replaces them by id; fast playback holds before the loaded positions end and prefetches ahead. Cesium models move their parts from the optional model part state.
This commit is contained in:
1 parent
624c229bc2
commit
7186f720df
97 files changed
+6586
-343
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 };
|
||||
}
|
||||
@@ -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,
|
||||
@@ -425,9 +424,7 @@ export function createMotion({
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -123,9 +123,14 @@ export class FlightRecords {
|
||||
stickyText(callsign, prevMeta?.callsign),
|
||||
);
|
||||
const feedType = observation.typeCode || null;
|
||||
const typeCode =
|
||||
airframe?.typeCode ??
|
||||
(feedType && groundModel(feedType) ? feedType : null);
|
||||
// The feed's type is kept for what it names itself, not for a surface
|
||||
// category: a C1 contact whose feed names an airliner type stays a vehicle.
|
||||
const keepFeedType =
|
||||
Boolean(feedType) &&
|
||||
(groundCategory(category)
|
||||
? GROUND_FEED_TYPES.has(feedType.trim().toUpperCase())
|
||||
: groundModel(feedType));
|
||||
const typeCode = airframe?.typeCode ?? (keepFeedType ? feedType : null);
|
||||
const onGround =
|
||||
on_ground === true ||
|
||||
(!Number.isFinite(baro_alt) &&
|
||||
@@ -280,7 +285,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.
|
||||
@@ -325,11 +331,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,
|
||||
}),
|
||||
// An adsbdb-enriched type code outranks the coarse OpenSky category;
|
||||
// a feed's own ground type (ZVEH, GRND) classes it 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
|
||||
@@ -452,13 +456,46 @@ 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;
|
||||
}
|
||||
|
||||
/** The types a feed gives airport vehicles (ZVEH) and ground stations (GRND). */
|
||||
const GROUND_FEED_TYPES = new Set(['ZVEH', 'GRND']);
|
||||
|
||||
/** 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 +504,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);
|
||||
|
||||
@@ -312,12 +312,83 @@ test('a ground vehicle or station with no altitude stands on the ground; an airc
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(reported.onGround, false);
|
||||
// Before the model set loads nothing is grounded by its model.
|
||||
const unloaded = records().receive(
|
||||
// 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', ...noAltitude }),
|
||||
view(),
|
||||
).meta;
|
||||
assert.equal(unloaded.onGround, false);
|
||||
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, null);
|
||||
});
|
||||
|
||||
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;
|
||||
assert.equal(klass({ id: 'v1', typeCode: 'ZVEH' }), 'vehicle');
|
||||
assert.equal(
|
||||
klass({ id: 'v2', typeCode: 'ZVEH', callsign: 'FIRE 2' }),
|
||||
'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 still waits for the airframe lookup.
|
||||
assert.equal(
|
||||
klass({ id: 'p1', typeCode: 'A320', category: 'A7' }),
|
||||
'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', () => {
|
||||
|
||||
@@ -2,11 +2,11 @@ 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,
|
||||
@@ -32,14 +32,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 +55,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. */
|
||||
|
||||
@@ -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();
|
||||
@@ -254,7 +262,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 +302,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 +326,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 +361,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 &&
|
||||
|
||||
@@ -912,10 +912,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,
|
||||
};
|
||||
@@ -1092,6 +1089,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,
|
||||
|
||||
Reference in new issue
Block a user