mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
feat(vessels): key vessels by their source's stable id, and share a selected vessel
AIS Vessels are keyed by the id their live source gives, with the MMSI as an attribute: an MMSI can be shared, spoofed or reused, so two vessels with one MMSI are now two vessels. Looking a vessel up or selecting it by MMSI still finds it. A share link made while a vessel is selected opens that vessel. A UUID vessel id travels as 16 bytes in a new thing field (13). A shared thing that is not reporting now says so in a sentence per kind, with its id (ICAO, NORAD, MMSI or vessel UUID) on a second line.
This commit is contained in:
1 parent
57ff81f723
commit
cbbf55cacd
74 files changed
+2481
-586
No files matched your search
+59
-6
@@ -2,6 +2,8 @@ import * as Cesium from 'cesium';
|
||||
import { trackedDisplayPositionForCamera } from '../data/trackedCamera.js';
|
||||
import {
|
||||
SHARE_VIEW_ENTITY_KINDS,
|
||||
SHARE_VIEW_FOLLOW_RANGE_MAX_M,
|
||||
followOffsetFor,
|
||||
followOffsetFromEnu,
|
||||
followOffsetToEnu,
|
||||
} from '../share/follow.js';
|
||||
@@ -28,17 +30,68 @@ function enuOffset(origin, position) {
|
||||
return { east: local.x, north: local.y, up: local.z };
|
||||
}
|
||||
|
||||
/** Degrees to the share format's 10⁻⁴-degree coordinate precision. */
|
||||
const toCoordinate = (radians) =>
|
||||
Math.round(Cesium.Math.toDegrees(radians) * 1e4) / 1e4;
|
||||
|
||||
/**
|
||||
* The entity the camera follows as `{ kind, id, offset, lastKnown }`, with
|
||||
* the camera's offset from it and its displayed position as of `nowMs`; null
|
||||
* when the camera follows nothing a share link can name. A selected vessel is
|
||||
* not followed (the camera stays where the user puts it), so a link made then
|
||||
* keeps its own camera.
|
||||
* The selected vessel as a thing view's subject: its drawn position as the
|
||||
* last-known fix, and the follow offset that puts the derived camera
|
||||
* (followCameraFor) where the camera is now. The offset is computed from the
|
||||
* fix at the format's precision, so the opened link's camera matches this
|
||||
* one to within the offset's whole metres and degrees. Null when the offset
|
||||
* cannot carry the camera (it is not above the vessel's horizon, or its range
|
||||
* is outside 1 m to SHARE_VIEW_FOLLOW_RANGE_MAX_M): the link is then a place
|
||||
* view.
|
||||
*/
|
||||
export function readShareFollowSubject({ viewer, nowMs = Date.now() }) {
|
||||
function selectedVesselSubject(cameraPosition, vessel, nowMs) {
|
||||
const id = String(vessel?.id || '');
|
||||
if (!id || !vessel.position) return null;
|
||||
const fixAt = Cesium.Cartographic.fromCartesian(vessel.position);
|
||||
const cameraAt = Cesium.Cartographic.fromCartesian(cameraPosition);
|
||||
if (!fixAt || !cameraAt) return null;
|
||||
const lastKnown = {
|
||||
lat: toCoordinate(fixAt.latitude),
|
||||
lon: toCoordinate(fixAt.longitude),
|
||||
alt: Math.round(fixAt.height),
|
||||
observedAtMs: Number.isFinite(vessel.observedAtMs)
|
||||
? vessel.observedAtMs
|
||||
: nowMs,
|
||||
};
|
||||
const offset = followOffsetFor(lastKnown, {
|
||||
lat: Cesium.Math.toDegrees(cameraAt.latitude),
|
||||
lon: Cesium.Math.toDegrees(cameraAt.longitude),
|
||||
alt: cameraAt.height,
|
||||
});
|
||||
if (
|
||||
!offset ||
|
||||
!(offset.range >= 1 && offset.range <= SHARE_VIEW_FOLLOW_RANGE_MAX_M)
|
||||
)
|
||||
return null;
|
||||
return { kind: 'vessel', id, offset, lastKnown };
|
||||
}
|
||||
|
||||
/**
|
||||
* The entity a share link made now names, as `{ kind, id, offset, lastKnown }`:
|
||||
* the entity the camera follows, with the camera's offset from it and its
|
||||
* displayed position as of `nowMs`; else, while the camera follows nothing,
|
||||
* the selected vessel (`readSelectedVessel()`, the vessel layer's
|
||||
* `getSelectedFix()`). A selected vessel is not followed (the camera stays
|
||||
* where the user puts it), so its offset is the one that derives the camera
|
||||
* where it is now. Null when there is nothing a share link can name.
|
||||
*/
|
||||
export function readShareFollowSubject({
|
||||
viewer,
|
||||
nowMs = Date.now(),
|
||||
readSelectedVessel = null,
|
||||
}) {
|
||||
const cameraPosition = viewer?.camera?.positionWC;
|
||||
if (!cameraPosition) return null;
|
||||
const tracked = viewer.trackedEntity;
|
||||
if (!tracked) {
|
||||
const vessel = readSelectedVessel?.() ?? null;
|
||||
return vessel ? selectedVesselSubject(cameraPosition, vessel, nowMs) : null;
|
||||
}
|
||||
const trackedId = String(tracked?.gevTrackedId || '');
|
||||
const separator = trackedId.indexOf(':');
|
||||
if (separator <= 0) return null;
|
||||
|
||||
Reference in new issue
Block a user