mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Let a host application place live contacts
createApplicationCatalog takes an optional placement provider. Its layer(kind) hands Flights, Military Flights, AIS Vessels, Transit and Rail a place(id, wallMs), and optionally observe(id, fix) and forget(id). While live, each layer tells it every fix it accepts and draws a contact where it places it: position, height (the layer's own when none is given), course and speed. A null answer, a provider that throws, a kind it leaves out, or no provider at all keeps the layer's own motion unchanged, and following the world clock the layers never ask it. A transit vehicle or train it holds still lets the render loop idle and is asked again each second; vessels ask for frames only while it places one, and stop when the layer turns off. Tests show the layers draw and reconcile exactly as before without a provider and with one that places nothing, draw where a provider places them, and idle while it holds them still.
This commit is contained in:
1 parent
e53cfef1d1
commit
6f830a2e70
46 files changed
+1417
-34
No files matched your search
@@ -1,6 +1,30 @@
|
||||
/** Connect portable vessel reconciliation to scene and selection operations. */
|
||||
const KNOT_MPS = 1852 / 3600;
|
||||
const finiteOrNaN = (value) =>
|
||||
typeof value === 'number' && Number.isFinite(value) ? value : NaN;
|
||||
|
||||
/**
|
||||
* A vessel record's fix as a host-supplied placement takes it: its own time
|
||||
* (when it was received, if the row gives none), position, speed in m/s
|
||||
* (rows give knots), course and heading.
|
||||
*/
|
||||
function placementFix(record) {
|
||||
const epoch = record.lastPositionEpoch;
|
||||
return {
|
||||
timeMs: Number.isFinite(epoch) ? epoch * 1000 : record.receivedAtMs,
|
||||
lat: record.lat,
|
||||
lon: record.lon,
|
||||
altitudeM: NaN,
|
||||
speedMps: Number.isFinite(record.speed) ? record.speed * KNOT_MPS : NaN,
|
||||
courseDeg: finiteOrNaN(record.course),
|
||||
headingDeg: finiteOrNaN(record.heading),
|
||||
};
|
||||
}
|
||||
|
||||
/** Connect portable vessel reconciliation to scene and selection operations.
|
||||
* `placement`, a host-supplied placement, is told each live fix. */
|
||||
export function createVesselSnapshotRenderer({
|
||||
state,
|
||||
placement = null,
|
||||
records,
|
||||
rendering,
|
||||
tracking,
|
||||
@@ -17,6 +41,13 @@ export function createVesselSnapshotRenderer({
|
||||
rendering.ensureCollections(viewer);
|
||||
const occluder = rendering.makeOccluder();
|
||||
const follow = followsClock();
|
||||
// Live fixes only: following the clock, the layer places every vessel.
|
||||
const observe =
|
||||
placement && !follow && !replace
|
||||
? (record) => {
|
||||
if (record.id) placement.observe(record.id, placementFix(record));
|
||||
}
|
||||
: () => {};
|
||||
records.reconcile(
|
||||
rows,
|
||||
{
|
||||
@@ -28,6 +59,7 @@ export function createVesselSnapshotRenderer({
|
||||
},
|
||||
{
|
||||
add(record) {
|
||||
observe(record);
|
||||
rendering.prepareRecordVisual(record);
|
||||
rendering.addRecordPrimitives(record, occluder);
|
||||
},
|
||||
@@ -35,6 +67,7 @@ export function createVesselSnapshotRenderer({
|
||||
return rendering.shipIcon(record, record === state.selectedRecord);
|
||||
},
|
||||
updated(record, prevIcon) {
|
||||
observe(record);
|
||||
const selected = record === state.selectedRecord;
|
||||
const visual = rendering.prepareRecordVisual(record);
|
||||
if (visual.billboard) {
|
||||
@@ -56,6 +89,7 @@ export function createVesselSnapshotRenderer({
|
||||
rendering.removeRecordPrimitives(record);
|
||||
},
|
||||
removed(id) {
|
||||
placement?.forget(id);
|
||||
if (state.trailId === id) tracking.clearSelectedVesselTrail();
|
||||
},
|
||||
staleSelected(record) {
|
||||
|
||||
Reference in new issue
Block a user