fix(cockpit): the bridge radar matches the view out of the window

The radar centred on the ship's last AIS fix while the camera rode that fix
dead-reckoned up to 180 s ahead: at 20 kn about a nautical mile apart, so a
ship already passed still showed ahead. Own ship now sits where the camera
rides and each contact is dead-reckoned to the same moment; the query reaches
past the range for ships that have since moved into it.

Ships with no MMSI each get a key of their own instead of all sharing an
empty one on the scope.
This commit is contained in:
Sameh Khamis committed 2026-11-08 14:09:17 -08:00
1 parent 18c15d0352
commit 052731202d
9 files changed
+154 -29

No files matched your search

+19 -2
View File
@@ -13,6 +13,7 @@ import ContextView from './views/ContextView.vue';
import * as Cesium from 'cesium';
import { vesselCockpitInfo } from '../layers/vessels/cockpitSubject.js';
import { VesselRecords } from '../layers/vessels/records.js';
import { RADAR_REACH_M } from '../cockpitRadar.js';
const RECORD = Object.freeze({
mmsi: '211000000',
@@ -327,7 +328,8 @@ test('the bridge radar shows nearby ships without its own and steps its range',
assert.ok(neighbour.x < -0.3 && Math.abs(neighbour.y) < 0.02);
assert.equal(neighbour.relativeCourseDeg, -180);
assert.equal(radar.ownRelativeCourseDeg, 5, 'COG 095 from heading 090');
assert.equal(vessels.radarQueries.at(-1).rangeM, 3 * 1852);
// Past the range by the dead-reckoning reach, for ships moving into it.
assert.equal(vessels.radarQueries.at(-1).rangeM, 3 * 1852 + RADAR_REACH_M);
assert.equal($('#cockpit-radar').hidden, false);
assert.equal($('#cockpit-radar-range').textContent.trim(), '3 NM');
@@ -337,7 +339,7 @@ test('the bridge radar shows nearby ships without its own and steps its range',
$('#cockpit-radar-range').click();
await settle();
assert.equal(store.radar.rangeNm, 6);
assert.equal(vessels.radarQueries.at(-1).rangeM, 6 * 1852);
assert.equal(vessels.radarQueries.at(-1).rangeM, 6 * 1852 + RADAR_REACH_M);
assert.equal($('#cockpit-radar-range').textContent.trim(), '6 NM');
assert.match(
$('#cockpit-radar-range').getAttribute('aria-label'),
@@ -1075,6 +1077,21 @@ test('the water is read where the ship is now, not at its last report', async (t
assert.ok(eastM > 300 && eastM < 450, `probed ${eastM.toFixed(0)} m east`);
});
test('the radar centres where the camera rides, not at the last report', async (t) => {
const clock = manualClock(t, START_MS);
// Reported a minute ago at 12 kn on course 095: since then ~370 m east.
const record = { ...RECORD, lastPositionEpoch: (START_MS - 60_000) / 1000 };
const ship = fixture(t, { record });
ship.cockpit.enter();
await settle();
frames(ship.cockpit, clock, ship.shots, 20);
await settle();
const query = ship.vessels.radarQueries.at(-1);
const eastM =
(query.lon - RECORD.lon) * 111_320 * Math.cos((RECORD.lat * Math.PI) / 180);
assert.ok(eastM > 300 && eastM < 450, `centred ${eastM.toFixed(0)} m east`);
});
test('the radar look line turns the short way across astern', async (t) => {
const clock = manualClock(t, START_MS);
const { $, store } = await bridgeAt(t, clock);
+2
View File
@@ -235,6 +235,8 @@ function updateVessel(nowMs) {
},
Date.now(),
);
// The radar centres here too, so it agrees with the view out the window.
this.vesselFix = fix;
const target = Cesium.Cartesian3.fromDegrees(
fix.longitude,
fix.latitude,
+18 -8
View File
@@ -37,6 +37,8 @@ import {
import { lookIsOffset, lookReadoutParts, wrapLookYaw } from '../cockpitLook.js';
import {
RADAR_MAX_CONTACTS,
RADAR_REACH_M,
deadReckonRadarContacts,
radarPicture,
radarRangeM,
radarRangeNm,
@@ -342,7 +344,9 @@ function updateVesselHud(info, nowMs, forceContext) {
/**
* Publish the bridge radar: nearby AIS vessels drawn heading-up from the
* camera's current heading, within the chosen range.
* camera's current heading, within the chosen range. Own ship sits where
* the camera rides (its fix dead-reckoned), and every contact is
* dead-reckoned to the same moment, so the picture matches the window.
* @param {object} info The vessel subject (`readVesselInfo`).
*/
export function updateRadar(info) {
@@ -352,16 +356,22 @@ export function updateRadar(info) {
return;
}
const rangeNm = radarRangeNm(this.radarRangeNm);
const contacts = layer.getRadarContacts(
info.latitude,
info.longitude,
radarRangeM(rangeNm),
RADAR_MAX_CONTACTS,
const own = this.vesselFix ?? info;
// Ask past the range for ships that have since moved into it; the picture
// trims them to the range once they are dead-reckoned.
const contacts = deadReckonRadarContacts(
layer.getRadarContacts(
own.latitude,
own.longitude,
radarRangeM(rangeNm) + RADAR_REACH_M,
RADAR_MAX_CONTACTS * 4,
),
Date.now(),
);
const picture = radarPicture(
{
latitude: info.latitude,
longitude: info.longitude,
latitude: own.latitude,
longitude: own.longitude,
headingDeg: normalizeHeading(this.heading ?? info.track ?? 0),
courseDeg: info.course,
},
+2
View File
@@ -218,6 +218,7 @@ export function enter({ kind = null } = {}) {
this.subjectKind = subjectKind;
// Each session reads its own water: never a height left from the last.
this.vesselWaterline = null;
this.vesselFix = null;
this.subjectId = vessel ? info.mmsi : null;
this.trackedEntity = entity;
if (entity) {
@@ -329,6 +330,7 @@ export function exit({ restoreTracking = true } = {}) {
this.active = false;
this.subjectKind = null;
this.vesselWaterline = null;
this.vesselFix = null;
this.subjectId = null;
this.services.releaseContinuousRender('cockpit');
this.trackedEntity = null;