Files
gods-eye-view/src/layers/vessels/snapshotRenderer.js
T
Sameh Khamis 26893ae37e Vessel tracks end at the vessel
The selected vessel's track drew every fix it held. Following the world
clock, it ran ahead of the icon to the vessel's newest fix; live, it
stopped at the last fix while the icon moved on from it. A change of time
restarted it from a single point until the track at the new time arrived,
so it went blank at every step.

- The track draws the fixes at or before the time the vessel is drawn at;
  live, every fix.
- Each frame a head joins its last drawn fix to the icon where it is drawn,
  as flight tracks do; none past TRAIL_HEAD_MAX_M (20 km), where the clock
  has moved beyond the fixes the track holds.
- A change of time keeps the track, drawn up to the new time, until the
  track at that time replaces it.
2026-11-16 13:35:38 -08:00

101 lines
3.1 KiB
JavaScript

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,
selection,
cards,
followsClock = () => false,
}) {
/** `replace`: the rows are the world at another time (see VesselRecords). */
function reconcileVessels(
viewer,
rows,
{ complete = true, replace = false } = {},
) {
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,
{
complete,
selectedRecord: state.selectedRecord,
cap: rendering.renderRowLimit(),
...(replace && { replace }),
...(follow && { follow }),
},
{
add(record) {
observe(record);
rendering.prepareRecordVisual(record);
rendering.addRecordPrimitives(record, occluder);
},
updated(record) {
observe(record);
const selected = record === state.selectedRecord;
rendering.prepareRecordVisual(record);
rendering.syncRecordIcon(record);
if (record.id === state.trailId)
tracking.appendSelectedVesselTrailFix(record);
if (selected) {
cards.updateSelectedVesselHud(record);
selection.registerSelectedContext(record);
}
},
remove(record, evicted) {
if (evicted) selection.clearVesselInspection({ evicted: true });
rendering.removeRecordPrimitives(record);
},
removed(id) {
placement?.forget(id);
if (state.trailId === id) tracking.clearSelectedVesselTrail();
},
staleSelected(record) {
cards.updateSelectedVesselHud(record);
},
},
);
// The selected vessel at the new time: its trail is drawn to it.
if (replace && state.selectedRecord && state.trailId)
tracking.retimeSelectedVesselTrail(state.selectedRecord);
state.lastVisibilityUpdate = 0;
rendering.updateVisibility(true);
}
return { reconcileVessels };
}