Draw no buoy for a virtual aid to navigation

A virtual aid (AIS message 21's VirtualAtoN flag) is a mark broadcast
where nothing physical stands, so drawing it as a buoy showed a mark
that is not there. The vessel source record now carries `virtual`
(false unless a source says true; any source may set it), AISStream
sets it from VirtualAtoN, and the vessel layer keeps such an aid's
disc: vesselModelSpec returns null for it and the layer gathers no
model item for it. Its card, selected card and readout add VIRTUAL
after its kind.
This commit is contained in:
Sameh Khamis committed 2026-11-14 11:07:13 -08:00
1 parent 9ae121c7c0
commit 52507a0755
31 files changed
+160 -18

No files matched your search

+12 -2
View File
@@ -24,7 +24,10 @@ export function createCards({
text: [
t('AIS: {name}', { name: trimHudValue(record.name, 32) }),
aid
? trimHudValue(record.type || t('AID TO NAVIGATION'), 24)
? aidKind(
trimHudValue(record.type || t('AID TO NAVIGATION'), 24),
record,
)
: t('{type} SPD: {speed} HDG: {heading}', {
type: trimHudValue(record.type || t('VESSEL'), 24),
speed: formatSpeed(record.speed),
@@ -60,6 +63,7 @@ export function createCards({
const aid = isAidToNavigation(record);
const type = vesselTypeShort(record);
if (type) parts.push(type);
if (record.virtual === true) parts.push(t('VIRTUAL'));
if (!aid && record.speed !== null && record.speed !== undefined)
parts.push(formatSpeed(record.speed));
const direction = record.heading ?? record.course;
@@ -95,7 +99,7 @@ export function createCards({
const direction = record.heading ?? record.course;
const details = [
aid
? vesselTypeShort(record) || t('AID TO NAVIGATION')
? aidKind(vesselTypeShort(record) || t('AID TO NAVIGATION'), record)
: [
vesselTypeShort(record) || t('VESSEL'),
formatSpeed(record.speed),
@@ -125,6 +129,12 @@ export function createCards({
};
}
/** An aid's kind, marked virtual when nothing physical stands there. */
function aidKind(kind, record) {
return record.virtual === true ? `${kind} · ${t('VIRTUAL')}` : kind;
}
/** A card's accent: an aid's disc colour, else its ship type's. */
function vesselAccent(record, aid) {
+1
View File
@@ -218,6 +218,7 @@ export function createIngestion({
speed: record.speedMps == null ? null : record.speedMps / 0.514444,
course: record.courseDeg,
heading: record.headingDeg,
virtual: record.virtual === true,
last_position_epoch:
record.observedAtMs == null ? null : record.observedAtMs / 1000,
last_position_UTC:
+23
View File
@@ -536,6 +536,29 @@ test('an aid to navigation is drawn as a disc, a vessel as its chevron', async (
return atob(primitive.image.split(',')[1]);
};
assert.match(svgOf('993672001'), /<circle/);
// The source's virtual flag reaches the layer's record.
const recordOf = (id) => [...primitives].find((p) => p.id?.id === id).id;
assert.equal(recordOf('993672001').virtual, false);
assert.equal(recordOf('366999002').virtual, false);
assert.doesNotMatch(svgOf('993672001'), /<path/);
assert.match(svgOf('366999002'), /<path/);
});
test('a virtual aid to navigation keeps its disc and its virtual flag', async () => {
const aid = {
...observation('993672009'),
mmsi: '993672009',
type: 'Isolated danger',
virtual: true,
};
const { layer, primitives } = setup({
async getSnapshot() {
return snapshot([aid]);
},
});
await layer.update();
const primitive = [...primitives].find((p) => p.id?.id === '993672009');
assert.ok(primitive);
assert.equal(primitive.id.virtual, true);
assert.match(atob(primitive.image.split(',')[1]), /<circle/);
});
+3
View File
@@ -31,6 +31,8 @@ export function normalizeVessel(row) {
speed: finiteNumber(row.speed),
course: finiteNumber(row.course),
heading: finiteNumber(row.heading),
// A virtual aid to navigation: a mark with nothing physical there.
virtual: row.virtual === true,
lastPositionUtc: String(row.last_position_UTC || ''),
lastPositionEpoch: finiteNumber(row.last_position_epoch),
missedRefreshes: 0,
@@ -160,6 +162,7 @@ export class VesselRecords {
record.speed = next.speed;
record.course = next.course;
record.heading = next.heading;
record.virtual = next.virtual;
record.lastPositionUtc = next.lastPositionUtc;
record.lastPositionEpoch = next.lastPositionEpoch;
record.missedRefreshes = 0;
+12 -4
View File
@@ -274,8 +274,13 @@ export function createRendering({
);
}
/** The model item for `record`, its spec rebuilt only when its type or size changes. */
/**
* The model item for `record`, its spec rebuilt only when its type or size
* changes; null for a virtual aid to navigation, which keeps its disc: no
* buoy stands there (vesselModelSpec).
*/
function modelItem(record, set) {
if (record.virtual === true) return null;
let item = modelItems.get(record.id);
if (!item || item.record !== record)
item = { record, pickId: record, tint: null, modelOwnsVisual: false };
@@ -309,7 +314,8 @@ export function createRendering({
limitSq
)
continue;
into.set(record.id, modelItem(record, set));
const item = modelItem(record, set);
if (item) into.set(record.id, item);
}
}
@@ -345,8 +351,10 @@ export function createRendering({
gatherModelItems(set, next);
} else {
for (const [id, item] of modelItems)
if (state.records.byId.get(id) === item.record)
next.set(id, modelItem(item.record, set));
if (state.records.byId.get(id) === item.record) {
const kept = modelItem(item.record, set);
if (kept) next.set(id, kept);
}
}
for (const [id, item] of modelItems)
if (next.get(id) !== item) handBackVisual(item.record, occluder);