mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-06 11:24:00 +00:00
Format extracted vessel components
This commit is contained in:
1 parent
2f4839e8f2
commit
a0b2d9f6aa
17 files changed
+1195
-887
No files matched your search
+71
-218
@@ -10,47 +10,27 @@
|
||||
"src/data/localGeojsonCore.js",
|
||||
"src/data/localGeojsonLod.js"
|
||||
],
|
||||
"external": [
|
||||
"cesium"
|
||||
]
|
||||
"external": ["cesium"]
|
||||
},
|
||||
"application": {
|
||||
"exports": [
|
||||
"./application"
|
||||
],
|
||||
"modules": [
|
||||
"src/app/application.js"
|
||||
],
|
||||
"exports": ["./application"],
|
||||
"modules": ["src/app/application.js"],
|
||||
"external": []
|
||||
},
|
||||
"viewer": {
|
||||
"exports": [
|
||||
"./application/viewer"
|
||||
],
|
||||
"modules": [
|
||||
"src/app/viewer.js"
|
||||
],
|
||||
"external": [
|
||||
"cesium"
|
||||
]
|
||||
"exports": ["./application/viewer"],
|
||||
"modules": ["src/app/viewer.js"],
|
||||
"external": ["cesium"]
|
||||
},
|
||||
"vite-build": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./build/vite"
|
||||
],
|
||||
"modules": [
|
||||
"build/vite.js"
|
||||
],
|
||||
"external": [
|
||||
"vite-plugin-cesium"
|
||||
]
|
||||
"exports": ["./build/vite"],
|
||||
"modules": ["build/vite.js"],
|
||||
"external": ["vite-plugin-cesium"]
|
||||
},
|
||||
"live-providers": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/live"
|
||||
],
|
||||
"exports": ["./server/providers/live"],
|
||||
"modules": [
|
||||
"server/providers/live.js",
|
||||
"server/providers/common/http.js",
|
||||
@@ -65,24 +45,16 @@
|
||||
"src/data/aisStreamAdapter.js",
|
||||
"src/data/aisWatchdog.js"
|
||||
],
|
||||
"external": [
|
||||
"ws"
|
||||
]
|
||||
"external": ["ws"]
|
||||
},
|
||||
"adsb-lol-source": {
|
||||
"exports": [
|
||||
"./sources/adsb-lol"
|
||||
],
|
||||
"modules": [
|
||||
"src/data/adsbLolFallback.js"
|
||||
],
|
||||
"exports": ["./sources/adsb-lol"],
|
||||
"modules": ["src/data/adsbLolFallback.js"],
|
||||
"external": []
|
||||
},
|
||||
"place-providers": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/places"
|
||||
],
|
||||
"exports": ["./server/providers/places"],
|
||||
"modules": [
|
||||
"server/providers/places.js",
|
||||
"server/providers/places/google.js",
|
||||
@@ -97,19 +69,13 @@
|
||||
"external": []
|
||||
},
|
||||
"place-payloads": {
|
||||
"exports": [
|
||||
"./sources/places"
|
||||
],
|
||||
"modules": [
|
||||
"src/data/placeProviderPayloads.js"
|
||||
],
|
||||
"exports": ["./sources/places"],
|
||||
"modules": ["src/data/placeProviderPayloads.js"],
|
||||
"external": []
|
||||
},
|
||||
"space-providers": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/space"
|
||||
],
|
||||
"exports": ["./server/providers/space"],
|
||||
"modules": [
|
||||
"server/providers/space.js",
|
||||
"server/providers/space/celestrak.js",
|
||||
@@ -120,19 +86,13 @@
|
||||
"external": []
|
||||
},
|
||||
"space-requests": {
|
||||
"exports": [
|
||||
"./sources/space"
|
||||
],
|
||||
"modules": [
|
||||
"src/data/spaceProviderRequests.js"
|
||||
],
|
||||
"exports": ["./sources/space"],
|
||||
"modules": ["src/data/spaceProviderRequests.js"],
|
||||
"external": []
|
||||
},
|
||||
"terrain-provider": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/terrain"
|
||||
],
|
||||
"exports": ["./server/providers/terrain"],
|
||||
"modules": [
|
||||
"server/providers/terrain.js",
|
||||
"src/data/terrainHeightsProxy.js"
|
||||
@@ -140,50 +100,30 @@
|
||||
"external": []
|
||||
},
|
||||
"terrain-source": {
|
||||
"exports": [
|
||||
"./sources/terrain"
|
||||
],
|
||||
"modules": [
|
||||
"src/data/terrainHeightsProxy.js"
|
||||
],
|
||||
"exports": ["./sources/terrain"],
|
||||
"modules": ["src/data/terrainHeightsProxy.js"],
|
||||
"external": []
|
||||
},
|
||||
"traffic-provider": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/traffic"
|
||||
],
|
||||
"modules": [
|
||||
"server/providers/traffic.js",
|
||||
"src/data/tomtomTiles.js"
|
||||
],
|
||||
"exports": ["./server/providers/traffic"],
|
||||
"modules": ["server/providers/traffic.js", "src/data/tomtomTiles.js"],
|
||||
"external": []
|
||||
},
|
||||
"traffic-source": {
|
||||
"exports": [
|
||||
"./sources/traffic"
|
||||
],
|
||||
"modules": [
|
||||
"src/data/tomtomTiles.js"
|
||||
],
|
||||
"exports": ["./sources/traffic"],
|
||||
"modules": ["src/data/tomtomTiles.js"],
|
||||
"external": []
|
||||
},
|
||||
"firms-provider": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/firms"
|
||||
],
|
||||
"modules": [
|
||||
"server/providers/firms.js",
|
||||
"src/data/firmsCsv.js"
|
||||
],
|
||||
"exports": ["./server/providers/firms"],
|
||||
"modules": ["server/providers/firms.js", "src/data/firmsCsv.js"],
|
||||
"external": []
|
||||
},
|
||||
"gbfs-provider": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/gbfs"
|
||||
],
|
||||
"exports": ["./server/providers/gbfs"],
|
||||
"modules": [
|
||||
"server/providers/gbfs.js",
|
||||
"server/providers/common/http.js",
|
||||
@@ -192,19 +132,13 @@
|
||||
"external": []
|
||||
},
|
||||
"gbfs-source": {
|
||||
"exports": [
|
||||
"./sources/gbfs"
|
||||
],
|
||||
"modules": [
|
||||
"src/data/gbfsSource.js"
|
||||
],
|
||||
"exports": ["./sources/gbfs"],
|
||||
"modules": ["src/data/gbfsSource.js"],
|
||||
"external": []
|
||||
},
|
||||
"cctv-provider": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/cctv"
|
||||
],
|
||||
"exports": ["./server/providers/cctv"],
|
||||
"modules": [
|
||||
"server/providers/cctv.js",
|
||||
"server/providers/cctv/catalog.js",
|
||||
@@ -221,9 +155,7 @@
|
||||
},
|
||||
"radio-provider": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/radio"
|
||||
],
|
||||
"exports": ["./server/providers/radio"],
|
||||
"modules": [
|
||||
"server/providers/radio.js",
|
||||
"server/providers/radio/catalog.js",
|
||||
@@ -237,9 +169,7 @@
|
||||
},
|
||||
"overpass-provider": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/overpass"
|
||||
],
|
||||
"exports": ["./server/providers/overpass"],
|
||||
"modules": [
|
||||
"server/providers/common/geo.js",
|
||||
"server/providers/common/http.js",
|
||||
@@ -258,9 +188,7 @@
|
||||
},
|
||||
"military-installations-provider": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/military-installations"
|
||||
],
|
||||
"exports": ["./server/providers/military-installations"],
|
||||
"modules": [
|
||||
"server/providers/common/http.js",
|
||||
"server/providers/common/query.js",
|
||||
@@ -277,9 +205,7 @@
|
||||
},
|
||||
"regional-provider": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/regional"
|
||||
],
|
||||
"exports": ["./server/providers/regional"],
|
||||
"modules": [
|
||||
"server/providers/common/http.js",
|
||||
"server/providers/common/query.js",
|
||||
@@ -298,9 +224,7 @@
|
||||
},
|
||||
"openai-provider": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/providers/openai"
|
||||
],
|
||||
"exports": ["./server/providers/openai"],
|
||||
"modules": [
|
||||
"server/providers/common/rate-limit.js",
|
||||
"server/providers/common/request.js",
|
||||
@@ -320,9 +244,7 @@
|
||||
},
|
||||
"standalone-key-setup": {
|
||||
"runtime": "node",
|
||||
"exports": [
|
||||
"./server/standalone/key-setup"
|
||||
],
|
||||
"exports": ["./server/standalone/key-setup"],
|
||||
"modules": [
|
||||
"scripts/pinokio-environment.mjs",
|
||||
"server/providers/common/source-root.js",
|
||||
@@ -333,9 +255,7 @@
|
||||
"external": []
|
||||
},
|
||||
"place-search": {
|
||||
"exports": [
|
||||
"./search"
|
||||
],
|
||||
"exports": ["./search"],
|
||||
"modules": [
|
||||
"src/search/index.js",
|
||||
"src/search/placeSearch.js",
|
||||
@@ -345,27 +265,17 @@
|
||||
"external": []
|
||||
},
|
||||
"panel-disclosure": {
|
||||
"exports": [
|
||||
"./ui/panels"
|
||||
],
|
||||
"modules": [
|
||||
"src/ui/panelDisclosure.js"
|
||||
],
|
||||
"exports": ["./ui/panels"],
|
||||
"modules": ["src/ui/panelDisclosure.js"],
|
||||
"external": []
|
||||
},
|
||||
"surface-keyboard": {
|
||||
"exports": [
|
||||
"./ui/surfaces"
|
||||
],
|
||||
"modules": [
|
||||
"src/ui/surfaceKeyboard.js"
|
||||
],
|
||||
"exports": ["./ui/surfaces"],
|
||||
"modules": ["src/ui/surfaceKeyboard.js"],
|
||||
"external": []
|
||||
},
|
||||
"panel-rail-layout": {
|
||||
"exports": [
|
||||
"./ui/layout"
|
||||
],
|
||||
"exports": ["./ui/layout"],
|
||||
"modules": [
|
||||
"src/ui/panelRails.js",
|
||||
"src/ui/leftPanelRail.js",
|
||||
@@ -377,9 +287,7 @@
|
||||
"external": []
|
||||
},
|
||||
"visual-input": {
|
||||
"exports": [
|
||||
"./ui/input"
|
||||
],
|
||||
"exports": ["./ui/input"],
|
||||
"modules": [
|
||||
"src/ui/visualInput.js",
|
||||
"src/ui/applicationShortcuts.js",
|
||||
@@ -388,19 +296,12 @@
|
||||
"external": []
|
||||
},
|
||||
"display-controls": {
|
||||
"exports": [
|
||||
"./ui/display"
|
||||
],
|
||||
"modules": [
|
||||
"src/ui/displayControls.js"
|
||||
],
|
||||
"exports": ["./ui/display"],
|
||||
"modules": ["src/ui/displayControls.js"],
|
||||
"external": []
|
||||
},
|
||||
"visual-effects": {
|
||||
"exports": [
|
||||
"./ui/effects",
|
||||
"./ui/effects/bloom"
|
||||
],
|
||||
"exports": ["./ui/effects", "./ui/effects/bloom"],
|
||||
"modules": [
|
||||
"src/ui/effects.js",
|
||||
"src/ui/visualEffects.js",
|
||||
@@ -413,14 +314,10 @@
|
||||
"src/styles/noir.js",
|
||||
"src/styles/snow.js"
|
||||
],
|
||||
"external": [
|
||||
"cesium"
|
||||
]
|
||||
"external": ["cesium"]
|
||||
},
|
||||
"map-source-controls": {
|
||||
"exports": [
|
||||
"./ui/maps"
|
||||
],
|
||||
"exports": ["./ui/maps"],
|
||||
"modules": [
|
||||
"src/ui/mapSource.js",
|
||||
"src/ui/mapSourceControls.js",
|
||||
@@ -430,10 +327,7 @@
|
||||
"external": []
|
||||
},
|
||||
"layer-panel": {
|
||||
"exports": [
|
||||
"./ui/layers",
|
||||
"./ui/layers/feedback"
|
||||
],
|
||||
"exports": ["./ui/layers", "./ui/layers/feedback"],
|
||||
"modules": [
|
||||
"src/ui/layers.js",
|
||||
"src/ui/layerPanel.js",
|
||||
@@ -444,9 +338,7 @@
|
||||
"external": []
|
||||
},
|
||||
"location-controls": {
|
||||
"exports": [
|
||||
"./ui/location"
|
||||
],
|
||||
"exports": ["./ui/location"],
|
||||
"modules": [
|
||||
"src/ui/location.js",
|
||||
"src/ui/locationControls.js",
|
||||
@@ -457,9 +349,7 @@
|
||||
"external": []
|
||||
},
|
||||
"radio-controls": {
|
||||
"exports": [
|
||||
"./ui/radio"
|
||||
],
|
||||
"exports": ["./ui/radio"],
|
||||
"modules": [
|
||||
"src/ui/radio.js",
|
||||
"src/ui/radioControls.js",
|
||||
@@ -470,9 +360,7 @@
|
||||
"external": []
|
||||
},
|
||||
"cctv-controls": {
|
||||
"exports": [
|
||||
"./ui/cctv"
|
||||
],
|
||||
"exports": ["./ui/cctv"],
|
||||
"modules": [
|
||||
"src/ui/cctv.js",
|
||||
"src/ui/cctvBindings.js",
|
||||
@@ -484,10 +372,7 @@
|
||||
"external": []
|
||||
},
|
||||
"context-controls": {
|
||||
"exports": [
|
||||
"./ui/context",
|
||||
"./ui/context/policy"
|
||||
],
|
||||
"exports": ["./ui/context", "./ui/context/policy"],
|
||||
"modules": [
|
||||
"src/ui/context.js",
|
||||
"src/ui/contextActions.js",
|
||||
@@ -529,14 +414,10 @@
|
||||
"src/cockpitVisionPolicy.js",
|
||||
"src/ui/panelRailGeometry.js"
|
||||
],
|
||||
"external": [
|
||||
"cesium"
|
||||
]
|
||||
"external": ["cesium"]
|
||||
},
|
||||
"scene-controls": {
|
||||
"exports": [
|
||||
"./ui/scenes"
|
||||
],
|
||||
"exports": ["./ui/scenes"],
|
||||
"modules": [
|
||||
"src/ui/scenes.js",
|
||||
"src/ui/sceneControls.js",
|
||||
@@ -545,9 +426,7 @@
|
||||
"external": []
|
||||
},
|
||||
"ui-shell": {
|
||||
"exports": [
|
||||
"./ui/shell"
|
||||
],
|
||||
"exports": ["./ui/shell"],
|
||||
"modules": [
|
||||
"src/bloom.js",
|
||||
"src/cctvFocusPolicy.js",
|
||||
@@ -643,14 +522,10 @@
|
||||
"src/ui/uiLifetime.js",
|
||||
"src/app/stateChannel.js"
|
||||
],
|
||||
"external": [
|
||||
"cesium"
|
||||
]
|
||||
"external": ["cesium"]
|
||||
},
|
||||
"ui-styles": {
|
||||
"exports": [
|
||||
"./ui/styles"
|
||||
],
|
||||
"exports": ["./ui/styles"],
|
||||
"modules": [
|
||||
"src/ui/styles.js",
|
||||
"style.css",
|
||||
@@ -677,9 +552,7 @@
|
||||
"external": []
|
||||
},
|
||||
"scenes": {
|
||||
"exports": [
|
||||
"./scenes"
|
||||
],
|
||||
"exports": ["./scenes"],
|
||||
"modules": [
|
||||
"src/scenes/director.js",
|
||||
"src/scenes/recipes.js",
|
||||
@@ -691,14 +564,10 @@
|
||||
"src/ui/scenePresentation.js",
|
||||
"src/contextModePolicy.js"
|
||||
],
|
||||
"external": [
|
||||
"cesium"
|
||||
]
|
||||
"external": ["cesium"]
|
||||
},
|
||||
"live-observations": {
|
||||
"exports": [
|
||||
"./sources/live"
|
||||
],
|
||||
"exports": ["./sources/live"],
|
||||
"modules": [
|
||||
"src/sources/live/aircraft.js",
|
||||
"src/sources/live/contract.js",
|
||||
@@ -709,9 +578,7 @@
|
||||
"external": []
|
||||
},
|
||||
"civil-flights": {
|
||||
"exports": [
|
||||
"./layers/flights"
|
||||
],
|
||||
"exports": ["./layers/flights"],
|
||||
"modules": [
|
||||
"src/data/aircraftClass.js",
|
||||
"src/data/aircraftIcons.js",
|
||||
@@ -742,14 +609,10 @@
|
||||
"src/layers/flights/testing.js",
|
||||
"src/layers/flights/tracking.js"
|
||||
],
|
||||
"external": [
|
||||
"cesium"
|
||||
]
|
||||
"external": ["cesium"]
|
||||
},
|
||||
"military-flights": {
|
||||
"exports": [
|
||||
"./layers/military"
|
||||
],
|
||||
"exports": ["./layers/military"],
|
||||
"modules": [
|
||||
"src/data/aircraftClass.js",
|
||||
"src/data/aircraftIcons.js",
|
||||
@@ -777,14 +640,10 @@
|
||||
"src/layers/military/testing.js",
|
||||
"src/layers/military/tracking.js"
|
||||
],
|
||||
"external": [
|
||||
"cesium"
|
||||
]
|
||||
"external": ["cesium"]
|
||||
},
|
||||
"aircraft-mechanics": {
|
||||
"exports": [
|
||||
"./aircraft"
|
||||
],
|
||||
"exports": ["./aircraft"],
|
||||
"modules": [
|
||||
"src/data/aircraftClass.js",
|
||||
"src/data/aircraftIcons.js",
|
||||
@@ -804,14 +663,10 @@
|
||||
"src/layers/aircraft/classification.js",
|
||||
"src/layers/aircraft/index.js"
|
||||
],
|
||||
"external": [
|
||||
"cesium"
|
||||
]
|
||||
"external": ["cesium"]
|
||||
},
|
||||
"vessel-layer": {
|
||||
"exports": [
|
||||
"./layers/vessels"
|
||||
],
|
||||
"exports": ["./layers/vessels"],
|
||||
"modules": [
|
||||
"src/layers/vessels/cards.js",
|
||||
"src/layers/vessels/evidence.js",
|
||||
@@ -829,8 +684,6 @@
|
||||
"src/data/iconOrientation.js",
|
||||
"src/data/vesselLabels.js"
|
||||
],
|
||||
"external": [
|
||||
"cesium"
|
||||
]
|
||||
"external": ["cesium"]
|
||||
}
|
||||
}
|
||||
+49
-15
@@ -11,26 +11,60 @@ import * as focus from './focusDeemphasis.js';
|
||||
import * as worldFocus from '../worldFocus.js';
|
||||
import * as render from '../renderGovernor.js';
|
||||
|
||||
const aisLiveVesselsLayer = createVesselLayer({ source: createAisStreamSource({ apiUrl: import.meta.env?.VITE_AIS_LIVE_API_URL || '/api/ais-live' }), options: { maxRows: import.meta.env?.VITE_AIS_LIVE_MAX_ROWS, maxLabels: import.meta.env?.VITE_AIS_LIVE_LABEL_MAX_ROWS }, services: { context, trails, labels, picking, overlay, geoid, sprites, focus, worldFocus, render } });
|
||||
const aisLiveVesselsLayer = createVesselLayer({
|
||||
source: createAisStreamSource({
|
||||
apiUrl: import.meta.env?.VITE_AIS_LIVE_API_URL || '/api/ais-live',
|
||||
}),
|
||||
options: {
|
||||
maxRows: import.meta.env?.VITE_AIS_LIVE_MAX_ROWS,
|
||||
maxLabels: import.meta.env?.VITE_AIS_LIVE_LABEL_MAX_ROWS,
|
||||
},
|
||||
services: {
|
||||
context,
|
||||
trails,
|
||||
labels,
|
||||
picking,
|
||||
overlay,
|
||||
geoid,
|
||||
sprites,
|
||||
focus,
|
||||
worldFocus,
|
||||
render,
|
||||
},
|
||||
});
|
||||
export { AIS_FIRST_CONNECT_GRACE_MS } from '../layers/vessels/policy.js';
|
||||
export const deriveAisFeedError = aisLiveVesselsLayer.deriveAisFeedError;
|
||||
export const classifyAisFeedSnapshot = aisLiveVesselsLayer.classifyAisFeedSnapshot;
|
||||
export const classifyAisFeedSnapshot =
|
||||
aisLiveVesselsLayer.classifyAisFeedSnapshot;
|
||||
export const mapAnalystRecord = aisLiveVesselsLayer.mapAnalystRecord;
|
||||
export const vesselDatumHeightM = aisLiveVesselsLayer.vesselDatumHeightM;
|
||||
export const reduceVesselSelection = aisLiveVesselsLayer.reduceVesselSelection;
|
||||
export const applyVesselFocusDeemphasis = aisLiveVesselsLayer.applyVesselFocusDeemphasis;
|
||||
export const applyVesselFocusDeemphasis =
|
||||
aisLiveVesselsLayer.applyVesselFocusDeemphasis;
|
||||
export const buildVesselCard = aisLiveVesselsLayer.buildVesselCard;
|
||||
export const buildSelectedVesselCard = aisLiveVesselsLayer.buildSelectedVesselCard;
|
||||
export const buildSelectedVesselCard =
|
||||
aisLiveVesselsLayer.buildSelectedVesselCard;
|
||||
export const cardScreenSeparated = aisLiveVesselsLayer.cardScreenSeparated;
|
||||
export const _bindVesselInteractionForTest = aisLiveVesselsLayer.testing._bindVesselInteractionForTest;
|
||||
export const _setVesselStateForTest = aisLiveVesselsLayer.testing._setVesselStateForTest;
|
||||
export const _setVesselOverlayHostForTest = aisLiveVesselsLayer.testing._setVesselOverlayHostForTest;
|
||||
export const _updateVesselCardsForTest = aisLiveVesselsLayer.testing._updateVesselCardsForTest;
|
||||
export const _reconcileVesselsForTest = aisLiveVesselsLayer.testing._reconcileVesselsForTest;
|
||||
export const _applyAisFeedSnapshotForTest = aisLiveVesselsLayer.testing._applyAisFeedSnapshotForTest;
|
||||
export const _loadLivePositionsForTest = aisLiveVesselsLayer.testing._loadLivePositionsForTest;
|
||||
export const _beginAisSessionForTest = aisLiveVesselsLayer.testing._beginAisSessionForTest;
|
||||
export const _setAisRuntimeForTest = aisLiveVesselsLayer.testing._setAisRuntimeForTest;
|
||||
export const _getVesselFeedStateForTest = aisLiveVesselsLayer.testing._getVesselFeedStateForTest;
|
||||
export const _getVesselStateForTest = aisLiveVesselsLayer.testing._getVesselStateForTest;
|
||||
export const _bindVesselInteractionForTest =
|
||||
aisLiveVesselsLayer.testing._bindVesselInteractionForTest;
|
||||
export const _setVesselStateForTest =
|
||||
aisLiveVesselsLayer.testing._setVesselStateForTest;
|
||||
export const _setVesselOverlayHostForTest =
|
||||
aisLiveVesselsLayer.testing._setVesselOverlayHostForTest;
|
||||
export const _updateVesselCardsForTest =
|
||||
aisLiveVesselsLayer.testing._updateVesselCardsForTest;
|
||||
export const _reconcileVesselsForTest =
|
||||
aisLiveVesselsLayer.testing._reconcileVesselsForTest;
|
||||
export const _applyAisFeedSnapshotForTest =
|
||||
aisLiveVesselsLayer.testing._applyAisFeedSnapshotForTest;
|
||||
export const _loadLivePositionsForTest =
|
||||
aisLiveVesselsLayer.testing._loadLivePositionsForTest;
|
||||
export const _beginAisSessionForTest =
|
||||
aisLiveVesselsLayer.testing._beginAisSessionForTest;
|
||||
export const _setAisRuntimeForTest =
|
||||
aisLiveVesselsLayer.testing._setAisRuntimeForTest;
|
||||
export const _getVesselFeedStateForTest =
|
||||
aisLiveVesselsLayer.testing._getVesselFeedStateForTest;
|
||||
export const _getVesselStateForTest =
|
||||
aisLiveVesselsLayer.testing._getVesselStateForTest;
|
||||
export default aisLiveVesselsLayer;
|
||||
+67
-57
@@ -1,11 +1,18 @@
|
||||
import { accentForVesselType, normalizeVesselType } from '../../data/vesselLabels.js';
|
||||
import {
|
||||
accentForVesselType,
|
||||
normalizeVesselType,
|
||||
} from '../../data/vesselLabels.js';
|
||||
|
||||
export function createCards({ vesselState, services, parts: components, layer, options }) {
|
||||
const { state } = vesselState;
|
||||
export function createCards({
|
||||
vesselState,
|
||||
services,
|
||||
parts: components,
|
||||
layer,
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
|
||||
|
||||
|
||||
function updateSelectedVesselHud(record) {
|
||||
function updateSelectedVesselHud(record) {
|
||||
const el = document.getElementById('hud-ais-vessel');
|
||||
if (!el) return;
|
||||
|
||||
@@ -17,26 +24,23 @@ function updateSelectedVesselHud(record) {
|
||||
`${trimHudValue(record.type || 'VESSEL', 24)} SPD: ${formatSpeed(record.speed)} HDG: ${formatHeading(record.heading ?? record.course)}`,
|
||||
`MMSI: ${record.mmsi || '--'} ${formatPositionTime(record)}${stale ? ' · STALE' : ''}`,
|
||||
].join('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function resetSelectedVesselHud() {
|
||||
function resetSelectedVesselHud() {
|
||||
const el = document.getElementById('hud-ais-vessel');
|
||||
if (!el) return;
|
||||
el.classList.remove('active');
|
||||
el.textContent = 'AIS: --';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function trimHudValue(value, maxLength) {
|
||||
function trimHudValue(value, maxLength) {
|
||||
const text = String(value || '--').trim() || '--';
|
||||
return text.length > maxLength ? `${text.slice(0, maxLength - 3)}...` : text;
|
||||
}
|
||||
return text.length > maxLength
|
||||
? `${text.slice(0, maxLength - 3)}...`
|
||||
: text;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Card model for an ambient (decluttered-in) vessel — name title plus one
|
||||
* compact type/speed/heading detail line, anchored at the record's current
|
||||
* rendered position (height-datum caveat: no datum work here). Pure —
|
||||
@@ -45,11 +49,12 @@ function trimHudValue(value, maxLength) {
|
||||
* @returns {Object} vesselLabels entry.
|
||||
*/
|
||||
|
||||
function buildVesselCard(record) {
|
||||
function buildVesselCard(record) {
|
||||
const parts = [];
|
||||
const type = vesselTypeShort(record);
|
||||
if (type) parts.push(type);
|
||||
if (record.speed !== null && record.speed !== undefined) parts.push(formatSpeed(record.speed));
|
||||
if (record.speed !== null && record.speed !== undefined)
|
||||
parts.push(formatSpeed(record.speed));
|
||||
const direction = record.heading ?? record.course;
|
||||
if (Number.isFinite(direction)) parts.push(`${Math.round(direction)}°`);
|
||||
return {
|
||||
@@ -63,10 +68,9 @@ function buildVesselCard(record) {
|
||||
selected: false,
|
||||
priority: components.rendering.labelPriority(record, null),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Card model for the click-selected vessel — the full-detail card, drawn last
|
||||
* (on top) and never distance-faded by the overlay. Pinned-but-vanished
|
||||
* vessels carry a STALE marker (mirrors the HUD readout). Pure — exported
|
||||
@@ -75,17 +79,21 @@ function buildVesselCard(record) {
|
||||
* @returns {Object} vesselLabels entry.
|
||||
*/
|
||||
|
||||
function buildSelectedVesselCard(record) {
|
||||
function buildSelectedVesselCard(record) {
|
||||
const direction = record.heading ?? record.course;
|
||||
const details = [[
|
||||
const details = [
|
||||
[
|
||||
vesselTypeShort(record) || 'VESSEL',
|
||||
formatSpeed(record.speed),
|
||||
Number.isFinite(direction) ? `${Math.round(direction)}°` : '--°',
|
||||
].join(' · ')];
|
||||
].join(' · '),
|
||||
];
|
||||
const destination = String(record.destination || '').trim();
|
||||
if (destination) details.push(`→ ${trimHudValue(destination, 24)}`);
|
||||
const stale = (record.missedRefreshes || 0) > 0;
|
||||
details.push(`MMSI ${record.mmsi || '--'} · ${formatPositionTime(record)}${stale ? ' · STALE' : ''}`);
|
||||
details.push(
|
||||
`MMSI ${record.mmsi || '--'} · ${formatPositionTime(record)}${stale ? ' · STALE' : ''}`,
|
||||
);
|
||||
return {
|
||||
id: vesselOverlayEntryId(record),
|
||||
actionable: Boolean(record?.mmsi),
|
||||
@@ -97,29 +105,26 @@ function buildSelectedVesselCard(record) {
|
||||
selected: true,
|
||||
priority: 100000,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** Stable overlay identity for MMSI-keyed and source-retained unkeyed rows. */
|
||||
|
||||
/** Stable overlay identity for MMSI-keyed and source-retained unkeyed rows. */
|
||||
|
||||
function vesselOverlayEntryId(record) {
|
||||
function vesselOverlayEntryId(record) {
|
||||
const mmsi = String(record?.mmsi || '').trim();
|
||||
if (mmsi) return `vessel:${mmsi}`;
|
||||
const name = String(record?.name || 'VESSEL').trim() || 'VESSEL';
|
||||
const lat = Number.isFinite(record?.lat) ? record.lat.toFixed(5) : 'x';
|
||||
const lon = Number.isFinite(record?.lon) ? record.lon.toFixed(5) : 'x';
|
||||
return `vessel:unkeyed:${name}:${lat}:${lon}`;
|
||||
}
|
||||
}
|
||||
|
||||
/** Uppercased, card-width-bounded AIS type (empty string when unknown). */
|
||||
|
||||
/** Uppercased, card-width-bounded AIS type (empty string when unknown). */
|
||||
|
||||
function vesselTypeShort(record) {
|
||||
function vesselTypeShort(record) {
|
||||
return normalizeVesselType(record.type).toUpperCase().slice(0, 14);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* True when `screen` is at least `minSepPx` away from every accepted screen
|
||||
* position (greedy card-declutter accept test, mirroring the FIRMS pass).
|
||||
* Exported for unit tests.
|
||||
@@ -129,7 +134,7 @@ function vesselTypeShort(record) {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
function cardScreenSeparated(accepted, screen, minSepPx) {
|
||||
function cardScreenSeparated(accepted, screen, minSepPx) {
|
||||
const minSq = minSepPx * minSepPx;
|
||||
for (let i = 0; i < accepted.length; i += 1) {
|
||||
const dx = screen.x - accepted[i].x;
|
||||
@@ -137,35 +142,40 @@ function cardScreenSeparated(accepted, screen, minSepPx) {
|
||||
if (dx * dx + dy * dy < minSq) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function displayVesselName(record) {
|
||||
function displayVesselName(record) {
|
||||
const name = String(record.name || '').trim();
|
||||
if (name && name !== 'VESSEL' && name !== record.mmsi) return name;
|
||||
return record.mmsi ? `MMSI ${record.mmsi}` : 'VESSEL';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function formatSpeed(speed) {
|
||||
function formatSpeed(speed) {
|
||||
return speed === null ? '--KT' : `${speed.toFixed(1)}KT`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function formatHeading(heading) {
|
||||
function formatHeading(heading) {
|
||||
return Number.isFinite(heading) ? `${Math.round(heading)}DEG` : '--DEG';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function formatPositionTime(record) {
|
||||
function formatPositionTime(record) {
|
||||
if (!record.lastPositionUtc) return 'POS: LIVE';
|
||||
const date = new Date(record.lastPositionUtc);
|
||||
if (Number.isNaN(date.getTime())) return 'POS: LIVE';
|
||||
return `POS: ${date.toISOString().slice(11, 19)}Z`;
|
||||
}
|
||||
return { updateSelectedVesselHud, resetSelectedVesselHud, trimHudValue, buildVesselCard, buildSelectedVesselCard, vesselOverlayEntryId, vesselTypeShort, cardScreenSeparated, displayVesselName, formatSpeed, formatHeading, formatPositionTime };
|
||||
}
|
||||
return {
|
||||
updateSelectedVesselHud,
|
||||
resetSelectedVesselHud,
|
||||
trimHudValue,
|
||||
buildVesselCard,
|
||||
buildSelectedVesselCard,
|
||||
vesselOverlayEntryId,
|
||||
vesselTypeShort,
|
||||
cardScreenSeparated,
|
||||
displayVesselName,
|
||||
formatSpeed,
|
||||
formatHeading,
|
||||
formatPositionTime,
|
||||
};
|
||||
}
|
||||
@@ -1,18 +1,26 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { FOCUS_EVIDENCE_DEV } from './policy.js';
|
||||
|
||||
export function createEvidence({ vesselState, services, parts: components, layer, options }) {
|
||||
const { state } = vesselState;
|
||||
export function createEvidence({
|
||||
vesselState,
|
||||
services,
|
||||
parts: components,
|
||||
layer,
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
|
||||
/** Replace live AIS rows through the production reconciliation path (DEV only). */
|
||||
|
||||
/** Replace live AIS rows through the production reconciliation path (DEV only). */
|
||||
|
||||
function _setFocusEvidenceVessels(rows = []) {
|
||||
function _setFocusEvidenceVessels(rows = []) {
|
||||
if (!FOCUS_EVIDENCE_DEV || !state.viewer || !state.billboardCollection) {
|
||||
return { ok: false, count: 0 };
|
||||
}
|
||||
components.selection.clearVesselInspection();
|
||||
components.store.reconcileVessels(state.viewer, Array.isArray(rows) ? rows : []);
|
||||
components.store.reconcileVessels(
|
||||
state.viewer,
|
||||
Array.isArray(rows) ? rows : [],
|
||||
);
|
||||
state.count = state.vesselRecords.length;
|
||||
state.loaded = true;
|
||||
state.error = null;
|
||||
@@ -23,17 +31,19 @@ function _setFocusEvidenceVessels(rows = []) {
|
||||
state.rawRowCount = Array.isArray(rows) ? rows.length : 0;
|
||||
state.acceptedRowCount = state.count;
|
||||
return { ok: true, count: state.count };
|
||||
}
|
||||
}
|
||||
|
||||
/** JSON-safe vessel alpha/position snapshot for the evidence report. */
|
||||
|
||||
/** JSON-safe vessel alpha/position snapshot for the evidence report. */
|
||||
|
||||
function _focusEvidenceVesselSnapshot() {
|
||||
function _focusEvidenceVesselSnapshot() {
|
||||
if (!FOCUS_EVIDENCE_DEV || !state.viewer) return [];
|
||||
return state.vesselRecords.map((record) => {
|
||||
const bb = record.billboard;
|
||||
const screen = bb?.position
|
||||
? Cesium.SceneTransforms.worldToWindowCoordinates(state.viewer.scene, bb.position)
|
||||
? Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
state.viewer.scene,
|
||||
bb.position,
|
||||
)
|
||||
: null;
|
||||
return {
|
||||
id: record.mmsi,
|
||||
@@ -43,6 +53,6 @@ function _focusEvidenceVesselSnapshot() {
|
||||
y: screen?.y ?? null,
|
||||
};
|
||||
});
|
||||
}
|
||||
return { _setFocusEvidenceVessels, _focusEvidenceVesselSnapshot };
|
||||
}
|
||||
return { _setFocusEvidenceVessels, _focusEvidenceVesselSnapshot };
|
||||
}
|
||||
+39
-22
@@ -11,29 +11,46 @@ import { createEvidence } from './evidence.js';
|
||||
import { createQueries } from './queries.js';
|
||||
/** Compose one vessel layer with application-owned scene services. */
|
||||
export function createVesselLayer({ source, services, options = {} } = {}) {
|
||||
const vesselState = createVesselState({ source, services });
|
||||
const parts = {};
|
||||
const layer = {};
|
||||
const context = { vesselState, services, parts, layer, options };
|
||||
parts.lifecycle = createLifecycle(context);
|
||||
parts.ingestion = createIngestion(context);
|
||||
parts.store = createStore(context);
|
||||
parts.rendering = createRendering(context);
|
||||
parts.selection = createSelection(context);
|
||||
parts.tracking = createTracking(context);
|
||||
parts.cards = createCards(context);
|
||||
parts.testing = createTesting(context);
|
||||
parts.evidence = createEvidence(context);
|
||||
parts.queries = createQueries(context);
|
||||
Object.assign(layer, parts.queries.methods, parts.lifecycle.methods, parts.ingestion.methods);
|
||||
layer.source = source?.label || 'Vessels';
|
||||
Object.assign(layer, { applyVesselFocusDeemphasis: parts.rendering.applyVesselFocusDeemphasis, buildVesselCard: parts.cards.buildVesselCard, buildSelectedVesselCard: parts.cards.buildSelectedVesselCard, cardScreenSeparated: parts.cards.cardScreenSeparated });
|
||||
Object.defineProperty(layer, 'testing', { value: parts.testing });
|
||||
return layer;
|
||||
const vesselState = createVesselState({ source, services });
|
||||
const parts = {};
|
||||
const layer = {};
|
||||
const context = { vesselState, services, parts, layer, options };
|
||||
parts.lifecycle = createLifecycle(context);
|
||||
parts.ingestion = createIngestion(context);
|
||||
parts.store = createStore(context);
|
||||
parts.rendering = createRendering(context);
|
||||
parts.selection = createSelection(context);
|
||||
parts.tracking = createTracking(context);
|
||||
parts.cards = createCards(context);
|
||||
parts.testing = createTesting(context);
|
||||
parts.evidence = createEvidence(context);
|
||||
parts.queries = createQueries(context);
|
||||
Object.assign(
|
||||
layer,
|
||||
parts.queries.methods,
|
||||
parts.lifecycle.methods,
|
||||
parts.ingestion.methods,
|
||||
);
|
||||
layer.source = source?.label || 'Vessels';
|
||||
Object.assign(layer, {
|
||||
applyVesselFocusDeemphasis: parts.rendering.applyVesselFocusDeemphasis,
|
||||
buildVesselCard: parts.cards.buildVesselCard,
|
||||
buildSelectedVesselCard: parts.cards.buildSelectedVesselCard,
|
||||
cardScreenSeparated: parts.cards.cardScreenSeparated,
|
||||
});
|
||||
Object.defineProperty(layer, 'testing', { value: parts.testing });
|
||||
return layer;
|
||||
}
|
||||
export { AIS_FIRST_CONNECT_GRACE_MS } from './policy.js';
|
||||
export {
|
||||
VESSEL_OVERLAY_SOURCE_ID, VESSEL_LABEL_GRID_PX, VESSEL_DEFAULT_LABEL_LIMIT,
|
||||
VESSEL_OVERLAY_MAX_COHORT, VESSEL_CARD_FADE_DISTANCE_M, normalizeVesselType,
|
||||
vesselTypeCss, accentForVesselType, vesselOverlayCohortLimit, applyVesselOverlayPolicy,
|
||||
VESSEL_OVERLAY_SOURCE_ID,
|
||||
VESSEL_LABEL_GRID_PX,
|
||||
VESSEL_DEFAULT_LABEL_LIMIT,
|
||||
VESSEL_OVERLAY_MAX_COHORT,
|
||||
VESSEL_CARD_FADE_DISTANCE_M,
|
||||
normalizeVesselType,
|
||||
vesselTypeCss,
|
||||
accentForVesselType,
|
||||
vesselOverlayCohortLimit,
|
||||
applyVesselOverlayPolicy,
|
||||
} from '../../data/vesselLabels.js';
|
||||
+107
-53
@@ -1,12 +1,16 @@
|
||||
import { AIS_FIRST_CONNECT_LABEL } from './policy.js';
|
||||
|
||||
export function createIngestion({ vesselState, services, parts: components, layer, options }) {
|
||||
const { state } = vesselState;
|
||||
const aisLiveVesselsLayer = layer;
|
||||
export function createIngestion({
|
||||
vesselState,
|
||||
services,
|
||||
parts: components,
|
||||
layer,
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
const aisLiveVesselsLayer = layer;
|
||||
|
||||
|
||||
|
||||
async function loadLivePositions(viewer) {
|
||||
async function loadLivePositions(viewer) {
|
||||
if (!viewer || state.loading) return;
|
||||
state.loading = true;
|
||||
state.loadingLabel = state.loaded ? 'refreshing...' : 'loading...';
|
||||
@@ -17,49 +21,75 @@ async function loadLivePositions(viewer) {
|
||||
try {
|
||||
// Combine the layer's teardown-abort with a hard timeout so a hung upstream
|
||||
// can't wedge the poll indefinitely (parity with the track fetch + flights).
|
||||
const signal = typeof AbortSignal.any === 'function'
|
||||
? AbortSignal.any([requestController.signal, AbortSignal.timeout(10000)])
|
||||
const signal =
|
||||
typeof AbortSignal.any === 'function'
|
||||
? AbortSignal.any([
|
||||
requestController.signal,
|
||||
AbortSignal.timeout(10000),
|
||||
])
|
||||
: requestController.signal;
|
||||
const snapshot = await vesselState._source.getSnapshot({ maxRows: components.rendering.renderRowLimit() }, { signal });
|
||||
const snapshot = await vesselState._source.getSnapshot(
|
||||
{ maxRows: components.rendering.renderRowLimit() },
|
||||
{ signal },
|
||||
);
|
||||
if (!ownsAisRequest(requestController, requestSessionId)) return;
|
||||
aisLiveVesselsLayer.source = snapshot.source;
|
||||
// Map observations into the existing display store; source fields stop here.
|
||||
applyAisFeedSnapshot(viewer, {
|
||||
rows: snapshot.records.map(vesselDisplayRow), observedAtMs: snapshot.observedAtMs, freshness: snapshot.freshness, complete: snapshot.complete, rawRowCount: snapshot.rawRowCount, reason: snapshot.reason, status: snapshot.transportStatus,
|
||||
lastMessageAt: snapshot.lastMessageAt, nextAttemptAt: snapshot.nextAttemptAt,
|
||||
refreshing: snapshot.stale, newestPositionAt: snapshot.observedAtMs == null ? null : new Date(snapshot.observedAtMs).toISOString(),
|
||||
silentForMs: snapshot.silentForMs, reconnectAttempt: snapshot.reconnectAttempt,
|
||||
rows: snapshot.records.map(vesselDisplayRow),
|
||||
observedAtMs: snapshot.observedAtMs,
|
||||
freshness: snapshot.freshness,
|
||||
complete: snapshot.complete,
|
||||
rawRowCount: snapshot.rawRowCount,
|
||||
reason: snapshot.reason,
|
||||
status: snapshot.transportStatus,
|
||||
lastMessageAt: snapshot.lastMessageAt,
|
||||
nextAttemptAt: snapshot.nextAttemptAt,
|
||||
refreshing: snapshot.stale,
|
||||
newestPositionAt:
|
||||
snapshot.observedAtMs == null
|
||||
? null
|
||||
: new Date(snapshot.observedAtMs).toISOString(),
|
||||
silentForMs: snapshot.silentForMs,
|
||||
reconnectAttempt: snapshot.reconnectAttempt,
|
||||
});
|
||||
} catch (error) {
|
||||
if (ownsAisRequest(requestController, requestSessionId) && error?.name !== 'AbortError') {
|
||||
components.lifecycle.markAisUnavailable(error?.message || 'AIS live load failed');
|
||||
if (
|
||||
ownsAisRequest(requestController, requestSessionId) &&
|
||||
error?.name !== 'AbortError'
|
||||
) {
|
||||
components.lifecycle.markAisUnavailable(
|
||||
error?.message || 'AIS live load failed',
|
||||
);
|
||||
console.warn('[Data:ais-live-vessels]', state.error, error);
|
||||
}
|
||||
} finally {
|
||||
if (state.abort === requestController && state.sessionId === requestSessionId) {
|
||||
if (
|
||||
state.abort === requestController &&
|
||||
state.sessionId === requestSessionId
|
||||
) {
|
||||
state.loading = false;
|
||||
state.loadingLabel = state.firstConnectPhase === 'loading'
|
||||
? AIS_FIRST_CONNECT_LABEL
|
||||
: '';
|
||||
state.loadingLabel =
|
||||
state.firstConnectPhase === 'loading' ? AIS_FIRST_CONNECT_LABEL : '';
|
||||
state.abort = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** True while a request still owns this enabled layer lifecycle. */
|
||||
|
||||
/** True while a request still owns this enabled layer lifecycle. */
|
||||
function ownsAisRequest(controller, sessionId) {
|
||||
return (
|
||||
state.enabled &&
|
||||
state.sessionId === sessionId &&
|
||||
state.abort === controller &&
|
||||
!controller.signal.aborted
|
||||
);
|
||||
}
|
||||
|
||||
function ownsAisRequest(controller, sessionId) {
|
||||
return state.enabled
|
||||
&& state.sessionId === sessionId
|
||||
&& state.abort === controller
|
||||
&& !controller.signal.aborted;
|
||||
}
|
||||
/** Apply a classified snapshot while preserving warm state on zero accepted rows. */
|
||||
|
||||
|
||||
/** Apply a classified snapshot while preserving warm state on zero accepted rows. */
|
||||
|
||||
function applyAisFeedSnapshot(viewer, payload) {
|
||||
function applyAisFeedSnapshot(viewer, payload) {
|
||||
const snapshot = components.queries.classifyAisFeedSnapshot(payload);
|
||||
state.loaded = true;
|
||||
state.loadingLabel = '';
|
||||
@@ -72,13 +102,17 @@ function applyAisFeedSnapshot(viewer, payload) {
|
||||
if (snapshot.acceptedRowCount === 0) {
|
||||
state.count = state.vesselRecords.length;
|
||||
state.stale = state.count > 0 || Boolean(payload?.refreshing);
|
||||
if (components.lifecycle.isDefinitiveTransportFailure(snapshot.transportStatus)) {
|
||||
if (
|
||||
components.lifecycle.isDefinitiveTransportFailure(
|
||||
snapshot.transportStatus,
|
||||
)
|
||||
) {
|
||||
components.lifecycle.markAisUnavailable(snapshot.error);
|
||||
return { reconciled: false, ...snapshot };
|
||||
}
|
||||
if (
|
||||
state.firstConnectPhase === 'loading'
|
||||
&& components.lifecycle.isGraceEligibleTransport(snapshot.transportStatus)
|
||||
state.firstConnectPhase === 'loading' &&
|
||||
components.lifecycle.isGraceEligibleTransport(snapshot.transportStatus)
|
||||
) {
|
||||
state.error = null;
|
||||
state.loadingLabel = AIS_FIRST_CONNECT_LABEL;
|
||||
@@ -93,38 +127,58 @@ function applyAisFeedSnapshot(viewer, payload) {
|
||||
}
|
||||
|
||||
components.lifecycle.settleFirstConnectPhase('ready');
|
||||
components.store.reconcileVessels(viewer, snapshot.acceptedRows, { complete: payload?.complete !== false });
|
||||
components.store.reconcileVessels(viewer, snapshot.acceptedRows, {
|
||||
complete: payload?.complete !== false,
|
||||
});
|
||||
state.count = state.vesselRecords.length;
|
||||
state.stale = Boolean(payload?.refreshing) || payload?.complete === false || payload?.freshness === 'unknown';
|
||||
state.stale =
|
||||
Boolean(payload?.refreshing) ||
|
||||
payload?.complete === false ||
|
||||
payload?.freshness === 'unknown';
|
||||
state.newestPositionAt = payload?.newestPositionAt || null;
|
||||
// Not unconditionally null: a degraded feed keeps its reason even though the
|
||||
// cached vessels are still drawable, so the chip cannot go quiet on an
|
||||
// outage the user is still looking at.
|
||||
state.error = snapshot.error || payload?.reason || null;
|
||||
state.lastUpdate = Object.hasOwn(payload, 'observedAtMs') ? payload.observedAtMs : vesselState._aisRuntime.now();
|
||||
state.lastUpdate = Object.hasOwn(payload, 'observedAtMs')
|
||||
? payload.observedAtMs
|
||||
: vesselState._aisRuntime.now();
|
||||
return { reconciled: true, ...snapshot };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function vesselDisplayRow(record) {
|
||||
function vesselDisplayRow(record) {
|
||||
return {
|
||||
mmsi: record.id, reference: record.reference, lat: record.latitude, lon: record.longitude,
|
||||
name: record.name, imo: record.imo, type: record.type, destination: record.destination,
|
||||
mmsi: record.id,
|
||||
reference: record.reference,
|
||||
lat: record.latitude,
|
||||
lon: record.longitude,
|
||||
name: record.name,
|
||||
imo: record.imo,
|
||||
type: record.type,
|
||||
destination: record.destination,
|
||||
speed: record.speedMps == null ? null : record.speedMps / 0.514444,
|
||||
course: record.courseDeg, heading: record.headingDeg,
|
||||
last_position_epoch: record.observedAtMs == null ? null : record.observedAtMs / 1000,
|
||||
last_position_UTC: record.observedAtMs == null ? '' : new Date(record.observedAtMs).toISOString(),
|
||||
course: record.courseDeg,
|
||||
heading: record.headingDeg,
|
||||
last_position_epoch:
|
||||
record.observedAtMs == null ? null : record.observedAtMs / 1000,
|
||||
last_position_UTC:
|
||||
record.observedAtMs == null
|
||||
? ''
|
||||
: new Date(record.observedAtMs).toISOString(),
|
||||
};
|
||||
}
|
||||
const methods = {
|
||||
|
||||
|
||||
}
|
||||
const methods = {
|
||||
update(viewer) {
|
||||
if (!state.enabled) return Promise.resolve();
|
||||
return loadLivePositions(viewer || state.viewer);
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
return { loadLivePositions, ownsAisRequest, applyAisFeedSnapshot, vesselDisplayRow, methods };
|
||||
return {
|
||||
loadLivePositions,
|
||||
ownsAisRequest,
|
||||
applyAisFeedSnapshot,
|
||||
vesselDisplayRow,
|
||||
methods,
|
||||
};
|
||||
}
|
||||
@@ -1,34 +1,38 @@
|
||||
import { VESSEL_OVERLAY_SOURCE_ID } from '../../data/vesselLabels.js';
|
||||
import { AIS_FIRST_CONNECT_GRACE_MS, AIS_FIRST_CONNECT_LABEL, AIS_HEALTHY_STATUSES } from './policy.js';
|
||||
import {
|
||||
AIS_FIRST_CONNECT_GRACE_MS,
|
||||
AIS_FIRST_CONNECT_LABEL,
|
||||
AIS_HEALTHY_STATUSES,
|
||||
} from './policy.js';
|
||||
|
||||
export function createLifecycle({ vesselState, services, parts: components, layer, options }) {
|
||||
const { state } = vesselState;
|
||||
const { restoreSpriteOrder, restoreSpriteOrderOnEnable } = services.sprites;
|
||||
const { holdContinuousRender, releaseContinuousRender } = services.render;
|
||||
const { ensureGeoidReady } = services.geoid;
|
||||
const { registerPickOwner, unregisterPickOwner } = services.picking;
|
||||
export function createLifecycle({
|
||||
vesselState,
|
||||
services,
|
||||
parts: components,
|
||||
layer,
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
const { restoreSpriteOrder, restoreSpriteOrderOnEnable } = services.sprites;
|
||||
const { holdContinuousRender, releaseContinuousRender } = services.render;
|
||||
const { ensureGeoidReady } = services.geoid;
|
||||
const { registerPickOwner, unregisterPickOwner } = services.picking;
|
||||
|
||||
|
||||
|
||||
function clearFirstConnectTimer() {
|
||||
function clearFirstConnectTimer() {
|
||||
if (state.firstConnectTimer === null) return;
|
||||
vesselState._aisRuntime.clearTimeout(state.firstConnectTimer);
|
||||
state.firstConnectTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function invalidateAisSession() {
|
||||
function invalidateAisSession() {
|
||||
clearFirstConnectTimer();
|
||||
state.sessionId = ++vesselState._aisSessionSequence;
|
||||
state.firstConnectPhase = 'idle';
|
||||
state.firstConnectStartedAt = null;
|
||||
state.firstConnectDeadline = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function beginAisSession() {
|
||||
function beginAisSession() {
|
||||
clearFirstConnectTimer();
|
||||
const sessionId = ++vesselState._aisSessionSequence;
|
||||
const startedAt = vesselState._aisRuntime.now();
|
||||
@@ -39,18 +43,18 @@ function beginAisSession() {
|
||||
state.error = null;
|
||||
state.loadingLabel = AIS_FIRST_CONNECT_LABEL;
|
||||
scheduleFirstConnectExpiry(sessionId, AIS_FIRST_CONNECT_GRACE_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function scheduleFirstConnectExpiry(sessionId, delayMs) {
|
||||
function scheduleFirstConnectExpiry(sessionId, delayMs) {
|
||||
state.firstConnectTimer = vesselState._aisRuntime.setTimeout(() => {
|
||||
if (
|
||||
!state.enabled
|
||||
|| state.sessionId !== sessionId
|
||||
|| state.firstConnectPhase !== 'loading'
|
||||
) return;
|
||||
const remainingMs = state.firstConnectDeadline - vesselState._aisRuntime.now();
|
||||
!state.enabled ||
|
||||
state.sessionId !== sessionId ||
|
||||
state.firstConnectPhase !== 'loading'
|
||||
)
|
||||
return;
|
||||
const remainingMs =
|
||||
state.firstConnectDeadline - vesselState._aisRuntime.now();
|
||||
if (remainingMs > 0) {
|
||||
scheduleFirstConnectExpiry(sessionId, remainingMs);
|
||||
return;
|
||||
@@ -63,39 +67,29 @@ function scheduleFirstConnectExpiry(sessionId, delayMs) {
|
||||
: 'awaiting first AIS message…';
|
||||
state.stale = state.count > 0;
|
||||
}, delayMs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function settleFirstConnectPhase(phase) {
|
||||
function settleFirstConnectPhase(phase) {
|
||||
clearFirstConnectTimer();
|
||||
state.firstConnectPhase = phase;
|
||||
state.loadingLabel = '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function isGraceEligibleTransport(status) {
|
||||
function isGraceEligibleTransport(status) {
|
||||
return AIS_HEALTHY_STATUSES.has(status) || status === 'connecting';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function isDefinitiveTransportFailure(status) {
|
||||
function isDefinitiveTransportFailure(status) {
|
||||
return Boolean(status) && !isGraceEligibleTransport(status);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function markAisUnavailable(reason) {
|
||||
function markAisUnavailable(reason) {
|
||||
settleFirstConnectPhase('unavailable');
|
||||
state.error = reason || 'AIS live load failed';
|
||||
state.stale = state.count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function resetState() {
|
||||
function resetState() {
|
||||
state.abort?.abort();
|
||||
state.trailAbort?.abort();
|
||||
state.trailAbort = null;
|
||||
@@ -141,30 +135,32 @@ function resetState() {
|
||||
state.trailPositions = [];
|
||||
state.trailMmsi = null;
|
||||
state.trailBackfillToken = 0;
|
||||
}
|
||||
const methods = {
|
||||
|
||||
|
||||
}
|
||||
const methods = {
|
||||
/** Configure the source before initialization; an active layer keeps its owner. */
|
||||
setSource(source) {
|
||||
if (state.viewer) throw new Error('Configure the source before layer initialization');
|
||||
if (typeof source?.getSnapshot !== 'function') throw new TypeError('A snapshot source is required');
|
||||
if (state.viewer)
|
||||
throw new Error('Configure the source before layer initialization');
|
||||
if (typeof source?.getSnapshot !== 'function')
|
||||
throw new TypeError('A snapshot source is required');
|
||||
vesselState._source = source;
|
||||
this.source = source.label || this.source;
|
||||
},
|
||||
|
||||
|
||||
init(viewer) {
|
||||
if (typeof vesselState._source?.getSnapshot !== 'function') throw new TypeError('A snapshot source is required');
|
||||
if (typeof vesselState._source?.getSnapshot !== 'function')
|
||||
throw new TypeError('A snapshot source is required');
|
||||
state.viewer = viewer;
|
||||
components.rendering.ensureCollections(viewer);
|
||||
vesselState._vesselOverlayHost.setVisible(VESSEL_OVERLAY_SOURCE_ID, false);
|
||||
vesselState._vesselOverlayHost.setVisible(
|
||||
VESSEL_OVERLAY_SOURCE_ID,
|
||||
false,
|
||||
);
|
||||
components.selection.installInteraction(viewer);
|
||||
components.rendering.installRuntime(viewer);
|
||||
restoreSpriteOrder(viewer);
|
||||
},
|
||||
|
||||
|
||||
enable(viewer) {
|
||||
const wasEnabled = state.enabled;
|
||||
state.enabled = true;
|
||||
@@ -187,16 +183,19 @@ const methods = {
|
||||
vesselState._geoidReady = true;
|
||||
components.tracking.refloorVesselRecords();
|
||||
})
|
||||
.catch(() => { /* grid failed to load — anchors stay at ellipsoid 0 */ });
|
||||
.catch(() => {
|
||||
/* grid failed to load — anchors stay at ellipsoid 0 */
|
||||
});
|
||||
}
|
||||
// Pick-ownership (H2): vessel picks carry the record OBJECT as their id;
|
||||
// the registry resolver reduces it to the record's mmsi (a string key).
|
||||
registerPickOwner('ais-live-vessels', (pickedId) => state.vesselMap.has(pickedId));
|
||||
registerPickOwner('ais-live-vessels', (pickedId) =>
|
||||
state.vesselMap.has(pickedId),
|
||||
);
|
||||
restoreSpriteOrderOnEnable('ais', activeViewer);
|
||||
return components.ingestion.loadLivePositions(activeViewer);
|
||||
},
|
||||
|
||||
|
||||
disable() {
|
||||
state.enabled = false;
|
||||
invalidateAisSession();
|
||||
@@ -215,7 +214,6 @@ const methods = {
|
||||
state.loadingLabel = '';
|
||||
},
|
||||
|
||||
|
||||
destroy(viewer) {
|
||||
const activeViewer = viewer || state.viewer;
|
||||
invalidateAisSession();
|
||||
@@ -228,14 +226,28 @@ const methods = {
|
||||
activeViewer.scene.primitives.remove(state.billboardCollection);
|
||||
}
|
||||
vesselState._vesselOverlayHost.clearSource(VESSEL_OVERLAY_SOURCE_ID);
|
||||
vesselState._vesselOverlayHost.setVisible(VESSEL_OVERLAY_SOURCE_ID, false);
|
||||
vesselState._vesselOverlayHost.setVisible(
|
||||
VESSEL_OVERLAY_SOURCE_ID,
|
||||
false,
|
||||
);
|
||||
components.selection.removeVesselInteraction();
|
||||
if (state.preRenderRemover) {
|
||||
state.preRenderRemover();
|
||||
}
|
||||
resetState();
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
return { clearFirstConnectTimer, invalidateAisSession, beginAisSession, scheduleFirstConnectExpiry, settleFirstConnectPhase, isGraceEligibleTransport, isDefinitiveTransportFailure, markAisUnavailable, resetState, methods };
|
||||
return {
|
||||
clearFirstConnectTimer,
|
||||
invalidateAisSession,
|
||||
beginAisSession,
|
||||
scheduleFirstConnectExpiry,
|
||||
settleFirstConnectPhase,
|
||||
isGraceEligibleTransport,
|
||||
isDefinitiveTransportFailure,
|
||||
markAisUnavailable,
|
||||
resetState,
|
||||
methods,
|
||||
};
|
||||
}
|
||||
@@ -6,32 +6,85 @@ import { createVesselState } from './state.js';
|
||||
const noop = () => {};
|
||||
function services() {
|
||||
return {
|
||||
context: { clearSelectedEntityContextForLayer: noop, registerEntityContext: () => null },
|
||||
trails: { createTrail: () => ({ setPositions: noop, clear: noop, destroy: noop }) },
|
||||
context: {
|
||||
clearSelectedEntityContextForLayer: noop,
|
||||
registerEntityContext: () => null,
|
||||
},
|
||||
trails: {
|
||||
createTrail: () => ({ setPositions: noop, clear: noop, destroy: noop }),
|
||||
},
|
||||
labels: {},
|
||||
picking: { unregisterPickOwner: noop },
|
||||
overlay: { setOverlayEntries: noop, setOverlaySourceVisible: noop, clearOverlaySource: noop },
|
||||
geoid: {}, sprites: {},
|
||||
focus: { focusNowMs: (now) => now, getFocusTarget: () => null, focusPassIsNeeded: () => false, forgetSpriteFocus: noop },
|
||||
worldFocus: {}, render: { releaseContinuousRender: noop },
|
||||
overlay: {
|
||||
setOverlayEntries: noop,
|
||||
setOverlaySourceVisible: noop,
|
||||
clearOverlaySource: noop,
|
||||
},
|
||||
geoid: {},
|
||||
sprites: {},
|
||||
focus: {
|
||||
focusNowMs: (now) => now,
|
||||
getFocusTarget: () => null,
|
||||
focusPassIsNeeded: () => false,
|
||||
forgetSpriteFocus: noop,
|
||||
},
|
||||
worldFocus: {},
|
||||
render: { releaseContinuousRender: noop },
|
||||
};
|
||||
}
|
||||
function setup(source, options = {}) {
|
||||
const layer = createVesselLayer({ source, services: services(), options });
|
||||
layer.testing._setVesselStateForTest({ viewer: {}, billboardCollection: { add: (options) => ({ ...options }), remove: noop } });
|
||||
layer.testing._setVesselStateForTest({
|
||||
viewer: {},
|
||||
billboardCollection: { add: (options) => ({ ...options }), remove: noop },
|
||||
});
|
||||
let now = 1000;
|
||||
layer.testing._setAisRuntimeForTest({ now: () => now, setTimeout, clearTimeout });
|
||||
return { layer, advance: (ms) => { now += ms; } };
|
||||
layer.testing._setAisRuntimeForTest({
|
||||
now: () => now,
|
||||
setTimeout,
|
||||
clearTimeout,
|
||||
});
|
||||
return {
|
||||
layer,
|
||||
advance: (ms) => {
|
||||
now += ms;
|
||||
},
|
||||
};
|
||||
}
|
||||
const observation = (id, reference = id) => ({ id, reference, latitude: 51.93, longitude: 4.05, name: id, observedAtMs: 500, speedMps: 4, headingDeg: 180, courseDeg: 170 });
|
||||
const snapshot = (records, extra = {}) => ({ records, source: 'Fixture vessels', complete: true, stale: false, freshness: 'current', observedAtMs: 500, transportStatus: 'live', rawRowCount: records.length, ...extra });
|
||||
const observation = (id, reference = id) => ({
|
||||
id,
|
||||
reference,
|
||||
latitude: 51.93,
|
||||
longitude: 4.05,
|
||||
name: id,
|
||||
observedAtMs: 500,
|
||||
speedMps: 4,
|
||||
headingDeg: 180,
|
||||
courseDeg: 170,
|
||||
});
|
||||
const snapshot = (records, extra = {}) => ({
|
||||
records,
|
||||
source: 'Fixture vessels',
|
||||
complete: true,
|
||||
stale: false,
|
||||
freshness: 'current',
|
||||
observedAtMs: 500,
|
||||
transportStatus: 'live',
|
||||
rawRowCount: records.length,
|
||||
...extra,
|
||||
});
|
||||
|
||||
test('vessel construction is inert and each instance owns its records, icon cache and clock', () => {
|
||||
let requested = 0;
|
||||
const source = { getSnapshot() { requested++; } };
|
||||
const source = {
|
||||
getSnapshot() {
|
||||
requested++;
|
||||
},
|
||||
};
|
||||
const one = createVesselState({ source, services: services() });
|
||||
const two = createVesselState({ source, services: services() });
|
||||
for (const key of ['state', 'shipIconCache', '_scratchFocusScreen']) assert.notEqual(one[key], two[key]);
|
||||
for (const key of ['state', 'shipIconCache', '_scratchFocusScreen'])
|
||||
assert.notEqual(one[key], two[key]);
|
||||
assert.notEqual(one.state.vesselMap, two.state.vesselMap);
|
||||
assert.notEqual(one.state.trailPositions, two.state.trailPositions);
|
||||
const { layer } = setup(source);
|
||||
@@ -50,7 +103,11 @@ test('missing vessel source fails before mutating the viewer', () => {
|
||||
|
||||
test('partial observations retain missing contacts only until their receipt deadline', async () => {
|
||||
let current = snapshot([observation('111'), observation('222')]);
|
||||
const { layer, advance } = setup({ async getSnapshot() { return current; } });
|
||||
const { layer, advance } = setup({
|
||||
async getSnapshot() {
|
||||
return current;
|
||||
},
|
||||
});
|
||||
await layer.update();
|
||||
current = snapshot([observation('111')], { complete: false, rawRowCount: 2 });
|
||||
await layer.update();
|
||||
@@ -66,7 +123,11 @@ test('partial observations retain missing contacts only until their receipt dead
|
||||
|
||||
test('a complete feed still removes an absent unselected vessel immediately', async () => {
|
||||
let current = snapshot([observation('111'), observation('222')]);
|
||||
const { layer } = setup({ async getSnapshot() { return current; } });
|
||||
const { layer } = setup({
|
||||
async getSnapshot() {
|
||||
return current;
|
||||
},
|
||||
});
|
||||
await layer.update();
|
||||
current = snapshot([observation('111')]);
|
||||
await layer.update();
|
||||
@@ -74,10 +135,22 @@ test('a complete feed still removes an absent unselected vessel immediately', as
|
||||
});
|
||||
|
||||
test('an incomplete feed bounds its retained union to the configured row budget', async () => {
|
||||
let current = snapshot(Array.from({ length: 500 }, (_, i) => observation(String(i + 1000))));
|
||||
const { layer } = setup({ async getSnapshot() { return current; } }, { maxRows: 500 });
|
||||
let current = snapshot(
|
||||
Array.from({ length: 500 }, (_, i) => observation(String(i + 1000))),
|
||||
);
|
||||
const { layer } = setup(
|
||||
{
|
||||
async getSnapshot() {
|
||||
return current;
|
||||
},
|
||||
},
|
||||
{ maxRows: 500 },
|
||||
);
|
||||
await layer.update();
|
||||
current = snapshot(Array.from({ length: 500 }, (_, i) => observation(String(i + 2000))), { complete: false });
|
||||
current = snapshot(
|
||||
Array.from({ length: 500 }, (_, i) => observation(String(i + 2000))),
|
||||
{ complete: false },
|
||||
);
|
||||
await layer.update();
|
||||
assert.equal(layer.getStats().count, 500);
|
||||
assert.equal(layer.hasContact('1000'), false);
|
||||
@@ -85,7 +158,14 @@ test('an incomplete feed bounds its retained union to the configured row budget'
|
||||
});
|
||||
|
||||
test('unknown source time does not become fresh at the time of receipt', async () => {
|
||||
const { layer } = setup({ async getSnapshot() { return snapshot([observation('111')], { observedAtMs: null, freshness: 'unknown' }); } });
|
||||
const { layer } = setup({
|
||||
async getSnapshot() {
|
||||
return snapshot([observation('111')], {
|
||||
observedAtMs: null,
|
||||
freshness: 'unknown',
|
||||
});
|
||||
},
|
||||
});
|
||||
await layer.update();
|
||||
assert.equal(layer.getStats().lastUpdate, null);
|
||||
assert.equal(layer.getStats().stale, true);
|
||||
@@ -94,13 +174,23 @@ test('unknown source time does not become fresh at the time of receipt', async (
|
||||
test('refresh replaces the history reference and clearing selection cancels late history', async (t) => {
|
||||
const originalDocument = globalThis.document;
|
||||
globalThis.document = { getElementById: () => null };
|
||||
t.after(() => { if (originalDocument === undefined) delete globalThis.document; else globalThis.document = originalDocument; });
|
||||
t.after(() => {
|
||||
if (originalDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = originalDocument;
|
||||
});
|
||||
let current = snapshot([observation('111', 'old-reference')]);
|
||||
let request;
|
||||
let resolveTrack;
|
||||
const { layer } = setup({
|
||||
async getSnapshot() { return current; },
|
||||
getTrack(reference, { signal }) { request = { reference, signal }; return new Promise((resolve) => { resolveTrack = resolve; }); },
|
||||
async getSnapshot() {
|
||||
return current;
|
||||
},
|
||||
getTrack(reference, { signal }) {
|
||||
request = { reference, signal };
|
||||
return new Promise((resolve) => {
|
||||
resolveTrack = resolve;
|
||||
});
|
||||
},
|
||||
});
|
||||
await layer.update();
|
||||
current = snapshot([observation('111', 'new-reference')]);
|
||||
@@ -117,10 +207,20 @@ test('refresh replaces the history reference and clearing selection cancels late
|
||||
test('destroy cancels pending observations and ignores their later completion', async (t) => {
|
||||
const originalDocument = globalThis.document;
|
||||
globalThis.document = { getElementById: () => null };
|
||||
t.after(() => { if (originalDocument === undefined) delete globalThis.document; else globalThis.document = originalDocument; });
|
||||
t.after(() => {
|
||||
if (originalDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = originalDocument;
|
||||
});
|
||||
let requestSignal;
|
||||
let resolve;
|
||||
const { layer } = setup({ getSnapshot(_query, { signal }) { requestSignal = signal; return new Promise((done) => { resolve = done; }); } });
|
||||
const { layer } = setup({
|
||||
getSnapshot(_query, { signal }) {
|
||||
requestSignal = signal;
|
||||
return new Promise((done) => {
|
||||
resolve = done;
|
||||
});
|
||||
},
|
||||
});
|
||||
const pending = layer.update();
|
||||
layer.destroy();
|
||||
assert.equal(requestSignal.aborted, true);
|
||||
@@ -130,17 +230,26 @@ test('destroy cancels pending observations and ignores their later completion',
|
||||
assert.equal(layer.hasContact('111'), null);
|
||||
});
|
||||
|
||||
|
||||
test('partial-feed expiry releases a selected vessel and its pending trail', async (t) => {
|
||||
const originalDocument = globalThis.document;
|
||||
globalThis.document = { getElementById: () => null };
|
||||
t.after(() => { if (originalDocument === undefined) delete globalThis.document; else globalThis.document = originalDocument; });
|
||||
t.after(() => {
|
||||
if (originalDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = originalDocument;
|
||||
});
|
||||
let current = snapshot([observation('111'), observation('222')]);
|
||||
let signal;
|
||||
let finish;
|
||||
const { layer, advance } = setup({
|
||||
async getSnapshot() { return current; },
|
||||
getTrack(_reference, options) { signal = options.signal; return new Promise((resolve) => { finish = resolve; }); },
|
||||
async getSnapshot() {
|
||||
return current;
|
||||
},
|
||||
getTrack(_reference, options) {
|
||||
signal = options.signal;
|
||||
return new Promise((resolve) => {
|
||||
finish = resolve;
|
||||
});
|
||||
},
|
||||
});
|
||||
await layer.update();
|
||||
layer.selectById('222');
|
||||
|
||||
@@ -1,34 +1,25 @@
|
||||
import { VESSEL_LABEL_GRID_PX } from '../../data/vesselLabels.js';
|
||||
|
||||
|
||||
|
||||
export const FOCUS_EVIDENCE_DEV = import.meta.env?.DEV === true;
|
||||
|
||||
|
||||
|
||||
export const DEFAULT_RENDER_ROWS = 12000;
|
||||
|
||||
|
||||
export const DEFAULT_ACTIVE_LABELS = 900;
|
||||
|
||||
|
||||
export const REFRESH_MS = 60000;
|
||||
|
||||
/** Bounded wait for the first accepted vessel position in one enabled session. */
|
||||
|
||||
export const AIS_FIRST_CONNECT_GRACE_MS = 30000;
|
||||
|
||||
|
||||
export const AIS_FIRST_CONNECT_LABEL = 'awaiting first AIS position…';
|
||||
|
||||
|
||||
export const VISIBILITY_UPDATE_MS = 800;
|
||||
|
||||
/** Focus alpha alone samples faster inside the existing preRender pass. */
|
||||
|
||||
export const FOCUS_UPDATE_MS = 80;
|
||||
|
||||
|
||||
export const LABEL_GRID_PX = VESSEL_LABEL_GRID_PX;
|
||||
|
||||
/**
|
||||
@@ -67,15 +58,12 @@ export const TRAIL_MAX_POINTS = 400;
|
||||
|
||||
export const TRAIL_MIN_MOVE_M = 25;
|
||||
|
||||
|
||||
|
||||
export const DEFAULT_AIS_RUNTIME = Object.freeze({
|
||||
now: () => Date.now(),
|
||||
setTimeout: (callback, delayMs) => setTimeout(callback, delayMs),
|
||||
clearTimeout: (timer) => clearTimeout(timer),
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Human-readable reasons for a non-'open' AISStream feed status, keyed to the
|
||||
* server's `_aisStreamStatus` values (see vite.config.js). Surfaced verbatim in
|
||||
@@ -92,7 +80,6 @@ export const AIS_STATUS_REASON = {
|
||||
idle: 'feed idle',
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Statuses in which fresh data is flowing. 'open' is the pre-watchdog spelling
|
||||
* and is still accepted so a cached bundle and a restarted server never
|
||||
@@ -101,14 +88,18 @@ export const AIS_STATUS_REASON = {
|
||||
|
||||
export const AIS_HEALTHY_STATUSES = new Set(['live', 'open']);
|
||||
|
||||
|
||||
/**
|
||||
* Server statuses meaning "the feed is not delivering right now". These are
|
||||
* surfaced even while cached vessels are still drawn: rows retained from
|
||||
* before the outage must never make a dead feed read as a healthy one.
|
||||
*/
|
||||
|
||||
export const AIS_DEGRADED_STATUSES = new Set(['stale', 'reconnecting', 'down', 'auth-failed']);
|
||||
export const AIS_DEGRADED_STATUSES = new Set([
|
||||
'stale',
|
||||
'reconnecting',
|
||||
'down',
|
||||
'auth-failed',
|
||||
]);
|
||||
|
||||
/** Missing records in an incomplete observation are retained for at most five minutes. */
|
||||
export const PARTIAL_RETENTION_MS = 5 * 60 * 1000;
|
||||
+134
-85
@@ -1,35 +1,46 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { AIS_DEGRADED_STATUSES, AIS_HEALTHY_STATUSES, AIS_STATUS_REASON, REFRESH_MS, FOCUS_EVIDENCE_DEV, AIS_FIRST_CONNECT_LABEL } from './policy.js';
|
||||
import {
|
||||
AIS_DEGRADED_STATUSES,
|
||||
AIS_HEALTHY_STATUSES,
|
||||
AIS_STATUS_REASON,
|
||||
REFRESH_MS,
|
||||
FOCUS_EVIDENCE_DEV,
|
||||
AIS_FIRST_CONNECT_LABEL,
|
||||
} from './policy.js';
|
||||
|
||||
export function createQueries({ vesselState, services, parts: components, layer, options }) {
|
||||
const { state } = vesselState;
|
||||
const { formatKnots } = services.labels;
|
||||
export function createQueries({
|
||||
vesselState,
|
||||
services,
|
||||
parts: components,
|
||||
layer,
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
const { formatKnots } = services.labels;
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Seconds until the server's next reconnect attempt, or 0 when none is
|
||||
* scheduled. Mirrors the flights layer's `retryInSec` chip affordance.
|
||||
* @returns {number}
|
||||
*/
|
||||
|
||||
function aisRetryInSec() {
|
||||
function aisRetryInSec() {
|
||||
// A rejected key is terminal until someone changes it; an hour-long
|
||||
// countdown would imply waiting is the fix.
|
||||
if (state.transportStatus === 'auth-failed') return 0;
|
||||
const at = Number(state.nextAttemptAt);
|
||||
if (!Number.isFinite(at) || at <= 0) return 0;
|
||||
return Math.max(0, Math.ceil((at - vesselState._aisRuntime.now()) / 1000));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Chip text for a feed the server has reported as not delivering.
|
||||
* @param {string} status - 'stale' | 'reconnecting' | 'down'
|
||||
* @param {Object} payload - Parsed /api/ais-live JSON.
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
function describeDegradedAisFeed(status, payload) {
|
||||
function describeDegradedAisFeed(status, payload) {
|
||||
if (status === 'auth-failed') {
|
||||
// Actionable, not a countdown: retrying cannot fix a rejected credential,
|
||||
// so the chip asks the operator to do the one thing that can.
|
||||
@@ -42,14 +53,14 @@ function describeDegradedAisFeed(status, payload) {
|
||||
: 'feed silent — no AIS data';
|
||||
}
|
||||
const attempt = Number(payload?.reconnectAttempt);
|
||||
const suffix = Number.isFinite(attempt) && attempt >= 1 ? ` (attempt ${attempt})` : '';
|
||||
const suffix =
|
||||
Number.isFinite(attempt) && attempt >= 1 ? ` (attempt ${attempt})` : '';
|
||||
return status === 'down'
|
||||
? `feed down — retrying slowly${suffix}`
|
||||
: `reconnecting to feed…${suffix}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Derive a surfaced error string from an /api/ais-live payload, or null when the
|
||||
* feed has accepted product data. Socket transport, message receipt, and usable
|
||||
* vessel positions are separate health stages: an open socket with no message
|
||||
@@ -60,8 +71,9 @@ function describeDegradedAisFeed(status, payload) {
|
||||
* @returns {string|null} A short reason for the chip, or null if healthy.
|
||||
*/
|
||||
|
||||
function deriveAisFeedError(payload, acceptedRowCount) {
|
||||
const status = payload && typeof payload.status === 'string' ? payload.status : null;
|
||||
function deriveAisFeedError(payload, acceptedRowCount) {
|
||||
const status =
|
||||
payload && typeof payload.status === 'string' ? payload.status : null;
|
||||
// A feed the server reports as not delivering outranks the row count: the
|
||||
// cached vessels on screen are exactly what makes an outage invisible.
|
||||
if (status && AIS_DEGRADED_STATUSES.has(status)) {
|
||||
@@ -74,20 +86,25 @@ function deriveAisFeedError(payload, acceptedRowCount) {
|
||||
: 'awaiting first AIS message…';
|
||||
}
|
||||
if (!status) return null;
|
||||
const detail = typeof payload.error === 'string' && payload.error.trim() ? payload.error.trim() : '';
|
||||
const detail =
|
||||
typeof payload.error === 'string' && payload.error.trim()
|
||||
? payload.error.trim()
|
||||
: '';
|
||||
const reason = AIS_STATUS_REASON[status] || 'feed unavailable';
|
||||
return detail && !AIS_STATUS_REASON[status] ? `${reason} (${detail})` : reason;
|
||||
}
|
||||
return detail && !AIS_STATUS_REASON[status]
|
||||
? `${reason} (${detail})`
|
||||
: reason;
|
||||
}
|
||||
|
||||
/** True when a raw AIS row can enter the production vessel normalizer. */
|
||||
|
||||
/** True when a raw AIS row can enter the production vessel normalizer. */
|
||||
function hasUsableVesselCoordinates(row) {
|
||||
return (
|
||||
Number.isFinite(Number(row?.lat)) && Number.isFinite(Number(row?.lon))
|
||||
);
|
||||
}
|
||||
|
||||
function hasUsableVesselCoordinates(row) {
|
||||
return Number.isFinite(Number(row?.lat)) && Number.isFinite(Number(row?.lon));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Classify one server snapshot before any destructive reconciliation.
|
||||
* @param {Object|null|undefined} payload - Parsed /api/ais-live payload.
|
||||
* @returns {{transportStatus: string|null, lastMessageAt: number|string|null,
|
||||
@@ -95,10 +112,11 @@ function hasUsableVesselCoordinates(row) {
|
||||
* acceptedRowCount: number, error: string|null}}
|
||||
*/
|
||||
|
||||
function classifyAisFeedSnapshot(payload) {
|
||||
function classifyAisFeedSnapshot(payload) {
|
||||
const rawRows = Array.isArray(payload?.rows) ? payload.rows : [];
|
||||
const acceptedRows = rawRows.filter(hasUsableVesselCoordinates);
|
||||
const transportStatus = typeof payload?.status === 'string' ? payload.status : null;
|
||||
const transportStatus =
|
||||
typeof payload?.status === 'string' ? payload.status : null;
|
||||
const lastMessageAt = payload?.lastMessageAt ?? null;
|
||||
const acceptedRowCount = acceptedRows.length;
|
||||
return {
|
||||
@@ -106,15 +124,19 @@ function classifyAisFeedSnapshot(payload) {
|
||||
lastMessageAt,
|
||||
rawRows,
|
||||
acceptedRows,
|
||||
rawRowCount: Number.isInteger(payload?.rawRowCount) && payload.rawRowCount >= rawRows.length ? payload.rawRowCount : rawRows.length,
|
||||
rawRowCount:
|
||||
Number.isInteger(payload?.rawRowCount) &&
|
||||
payload.rawRowCount >= rawRows.length
|
||||
? payload.rawRowCount
|
||||
: rawRows.length,
|
||||
acceptedRowCount,
|
||||
error: deriveAisFeedError(payload, acceptedRowCount)
|
||||
|| (acceptedRowCount === 0 ? 'awaiting usable AIS positions…' : null),
|
||||
error:
|
||||
deriveAisFeedError(payload, acceptedRowCount) ||
|
||||
(acceptedRowCount === 0 ? 'awaiting usable AIS positions…' : null),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Map one internal vessel record to a plain JSON-safe analyst record
|
||||
* (analyst query engine seam). Pure — no Cesium types. Missing/unknown
|
||||
* fields are null, never NaN/undefined. navStatus is always null: the
|
||||
@@ -127,9 +149,12 @@ function classifyAisFeedSnapshot(payload) {
|
||||
* navStatus: null}}
|
||||
*/
|
||||
|
||||
function mapAnalystRecord(record) {
|
||||
function mapAnalystRecord(record) {
|
||||
const num = (v) => (Number.isFinite(v) ? v : null);
|
||||
const text = (v) => { const t = String(v ?? '').trim(); return t || null; };
|
||||
const text = (v) => {
|
||||
const t = String(v ?? '').trim();
|
||||
return t || null;
|
||||
};
|
||||
const mmsi = text(record?.mmsi);
|
||||
const name = text(record?.name);
|
||||
return {
|
||||
@@ -144,10 +169,9 @@ function mapAnalystRecord(record) {
|
||||
destination: text(record?.destination),
|
||||
navStatus: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Ellipsoidal render height (m) for a sea-surface object: the local geoid
|
||||
* undulation N plus a small lift. The sea surface ≈ the geoid, which sits
|
||||
* −106…+85 m off the WGS84 ellipsoid worldwide (Rotterdam ≈ +45 m — at
|
||||
@@ -158,12 +182,11 @@ function mapAnalystRecord(record) {
|
||||
* @returns {number} Ellipsoidal height h = N + lift (N treated as 0 when absent).
|
||||
*/
|
||||
|
||||
function vesselDatumHeightM(geoidN, liftM) {
|
||||
function vesselDatumHeightM(geoidN, liftM) {
|
||||
return (Number.isFinite(geoidN) ? geoidN : 0) + liftM;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Reduce one vessel-selection gesture to the layer-owned action it should
|
||||
* perform. The interaction handler reserves only vessel-record residuals and
|
||||
* trail picks as no-ops. The interaction wire also reserves sibling-owned
|
||||
@@ -174,15 +197,13 @@ function vesselDatumHeightM(geoidN, liftM) {
|
||||
* @returns {{action: 'none'|'select'|'deselect'}}
|
||||
*/
|
||||
|
||||
function reduceVesselSelection(input = {}) {
|
||||
function reduceVesselSelection(input = {}) {
|
||||
const selectedMmsi = normalizeSelectionMmsi(input.selectedMmsi);
|
||||
const pickedMmsi = normalizeSelectionMmsi(input.pickedMmsi);
|
||||
const gesture = input.gesture || 'click';
|
||||
|
||||
if (gesture === 'escape') {
|
||||
return selectedMmsi
|
||||
? { action: 'deselect' }
|
||||
: { action: 'none' };
|
||||
return selectedMmsi ? { action: 'deselect' } : { action: 'none' };
|
||||
}
|
||||
if (gesture !== 'click') {
|
||||
return { action: 'none' };
|
||||
@@ -193,19 +214,20 @@ function reduceVesselSelection(input = {}) {
|
||||
}
|
||||
return { action: 'select' };
|
||||
}
|
||||
return selectedMmsi
|
||||
? { action: 'deselect' }
|
||||
: { action: 'none' };
|
||||
}
|
||||
return selectedMmsi ? { action: 'deselect' } : { action: 'none' };
|
||||
}
|
||||
|
||||
|
||||
|
||||
function normalizeSelectionMmsi(value) {
|
||||
function normalizeSelectionMmsi(value) {
|
||||
if (value === null || value === undefined) return null;
|
||||
const text = String(value).trim();
|
||||
return text || null;
|
||||
}
|
||||
const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot, vesselDatumHeightM, reduceVesselSelection,
|
||||
}
|
||||
const methods = {
|
||||
mapAnalystRecord,
|
||||
deriveAisFeedError,
|
||||
classifyAisFeedSnapshot,
|
||||
vesselDatumHeightM,
|
||||
reduceVesselSelection,
|
||||
|
||||
id: 'ais-live-vessels',
|
||||
|
||||
@@ -219,7 +241,6 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
|
||||
statsRefreshInterval: 1000,
|
||||
|
||||
|
||||
/**
|
||||
* Find a vessel by exact MMSI or case-insensitive name substring.
|
||||
* @param {string|number} query MMSI or partial vessel name.
|
||||
@@ -238,7 +259,12 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
}
|
||||
if (!record) {
|
||||
const lower = q.toLowerCase();
|
||||
record = records.find((r) => String(r.name || '').toLowerCase().includes(lower)) || null;
|
||||
record =
|
||||
records.find((r) =>
|
||||
String(r.name || '')
|
||||
.toLowerCase()
|
||||
.includes(lower),
|
||||
) || null;
|
||||
}
|
||||
if (!record) return null;
|
||||
|
||||
@@ -256,7 +282,6 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Get vessels within a range of a point, sorted nearest-first.
|
||||
* @param {Cesium.Cartesian3} centerCartesian Center of the search.
|
||||
@@ -266,24 +291,31 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
*/
|
||||
getNearby(centerCartesian, rangeM, maxCount = 25) {
|
||||
const records = state.vesselRecords;
|
||||
if (!centerCartesian || !Array.isArray(records) || !records.length) return [];
|
||||
if (!centerCartesian || !Array.isArray(records) || !records.length)
|
||||
return [];
|
||||
const range = Number.isFinite(rangeM) && rangeM > 0 ? rangeM : Infinity;
|
||||
const cap = Number.isFinite(maxCount) && maxCount > 0 ? Math.floor(maxCount) : 25;
|
||||
const cap =
|
||||
Number.isFinite(maxCount) && maxCount > 0 ? Math.floor(maxCount) : 25;
|
||||
|
||||
const entries = [];
|
||||
for (const record of records) {
|
||||
if (!Number.isFinite(record.lat) || !Number.isFinite(record.lon)) continue;
|
||||
if (!Number.isFinite(record.lat) || !Number.isFinite(record.lon))
|
||||
continue;
|
||||
const position = record.billboard?.position || record.position;
|
||||
if (!position) continue;
|
||||
const distanceM = Cesium.Cartesian3.distance(centerCartesian, position);
|
||||
if (!Number.isFinite(distanceM) || distanceM > range) continue;
|
||||
entries.push({ mmsi: record.mmsi, name: record.name, position, distanceM });
|
||||
entries.push({
|
||||
mmsi: record.mmsi,
|
||||
name: record.name,
|
||||
position,
|
||||
distanceM,
|
||||
});
|
||||
}
|
||||
entries.sort((a, b) => a.distanceM - b.distanceM);
|
||||
return entries.slice(0, cap);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Get positions of all currently loaded vessels.
|
||||
* @param {number} [maxCount=800] Maximum entries to return.
|
||||
@@ -301,17 +333,18 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
* holds no data and therefore cannot answer.
|
||||
*/
|
||||
hasContact(mmsi) {
|
||||
if (!state.enabled || !state.vesselMap || state.vesselMap.size === 0) return null;
|
||||
if (!state.enabled || !state.vesselMap || state.vesselMap.size === 0)
|
||||
return null;
|
||||
if (!mmsi) return false;
|
||||
return state.vesselMap.has(String(mmsi).trim());
|
||||
},
|
||||
|
||||
|
||||
getAllPositions(maxCount = 800) {
|
||||
const result = [];
|
||||
const records = state.vesselRecords;
|
||||
if (!Array.isArray(records)) return result;
|
||||
const cap = Number.isFinite(maxCount) && maxCount > 0 ? Math.floor(maxCount) : 800;
|
||||
const cap =
|
||||
Number.isFinite(maxCount) && maxCount > 0 ? Math.floor(maxCount) : 800;
|
||||
|
||||
for (const record of records) {
|
||||
if (result.length >= cap) break;
|
||||
@@ -328,7 +361,6 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
return result;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Snapshot the layer's in-memory vessel records as plain JSON-safe
|
||||
* objects for the analyst query engine. On-demand only (called at most
|
||||
@@ -341,7 +373,9 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
if (!state.enabled) return [];
|
||||
const records = state.vesselRecords;
|
||||
if (!Array.isArray(records) || !records.length) return [];
|
||||
const limit = Number.isFinite(maxCount) ? Math.max(1, Math.floor(maxCount)) : 2000;
|
||||
const limit = Number.isFinite(maxCount)
|
||||
? Math.max(1, Math.floor(maxCount))
|
||||
: 2000;
|
||||
const result = [];
|
||||
for (const record of records) {
|
||||
if (result.length >= limit) break;
|
||||
@@ -350,7 +384,6 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
return result;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Select a vessel by MMSI via the same path as a map click
|
||||
* (highlight + HUD update).
|
||||
@@ -367,7 +400,6 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
return true;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Clear the current vessel selection and reset the HUD readout.
|
||||
* @returns {boolean} Always true.
|
||||
@@ -377,7 +409,6 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
return true;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Get info about the currently selected vessel.
|
||||
* @returns {{ mmsi: string, name: string, latitude: number, longitude: number, speedKt: number|null, course: number|null, type: string }|null}
|
||||
@@ -396,7 +427,6 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Return a subset of vessels for the universal detection overlay.
|
||||
* Deterministic stride sampling distributes selections evenly across the
|
||||
@@ -407,7 +437,12 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
* @returns {Array<{position: Cesium.Cartesian3, id: string, type: string, skipLabel: boolean}>}
|
||||
*/
|
||||
getDetectableObjects(options = {}) {
|
||||
if (!state.enabled || !state.billboardCollection || !state.billboardCollection.show) return [];
|
||||
if (
|
||||
!state.enabled ||
|
||||
!state.billboardCollection ||
|
||||
!state.billboardCollection.show
|
||||
)
|
||||
return [];
|
||||
const records = state.vesselRecords;
|
||||
if (!Array.isArray(records) || !records.length) return [];
|
||||
|
||||
@@ -422,7 +457,7 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
const selected = state.selectedRecord;
|
||||
const result = [];
|
||||
for (let idx = 0; idx < records.length; idx += 1) {
|
||||
if (((idx - start) % stride) !== 0) continue;
|
||||
if ((idx - start) % stride !== 0) continue;
|
||||
const record = records[idx];
|
||||
if (record.billboard && !record.billboard.show) continue;
|
||||
const position = record.billboard?.position || record.position;
|
||||
@@ -433,7 +468,9 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
id: record.name || record.mmsi || 'VESSEL',
|
||||
type: 'SEA',
|
||||
skipLabel: record === selected,
|
||||
klass: record.type ? String(record.type).toUpperCase().slice(0, 14) : undefined,
|
||||
klass: record.type
|
||||
? String(record.type).toUpperCase().slice(0, 14)
|
||||
: undefined,
|
||||
metric: formatKnots(record.speed), // record.speed is knots
|
||||
});
|
||||
if (result.length >= maxCount) break;
|
||||
@@ -441,14 +478,14 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
return result;
|
||||
},
|
||||
|
||||
|
||||
...(FOCUS_EVIDENCE_DEV ? {
|
||||
...(FOCUS_EVIDENCE_DEV
|
||||
? {
|
||||
__focusEvidence: Object.freeze({
|
||||
setVessels: components.evidence._setFocusEvidenceVessels,
|
||||
snapshot: components.evidence._focusEvidenceVesselSnapshot,
|
||||
}),
|
||||
} : {}),
|
||||
|
||||
}
|
||||
: {}),
|
||||
|
||||
getStats() {
|
||||
const waitingForFirstPosition = state.firstConnectPhase === 'loading';
|
||||
@@ -461,7 +498,8 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
: state.loadingLabel,
|
||||
error: state.error,
|
||||
stale: state.stale,
|
||||
status: state.firstConnectPhase === 'unavailable' ? 'unavailable' : undefined,
|
||||
status:
|
||||
state.firstConnectPhase === 'unavailable' ? 'unavailable' : undefined,
|
||||
transportStatus: state.transportStatus,
|
||||
lastMessageAt: state.lastMessageAt,
|
||||
rawRowCount: state.rawRowCount,
|
||||
@@ -471,8 +509,19 @@ const methods = { mapAnalystRecord, deriveAisFeedError, classifyAisFeedSnapshot,
|
||||
// the user to guess whether anything is still happening.
|
||||
retryInSec: aisRetryInSec(),
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
return { aisRetryInSec, describeDegradedAisFeed, deriveAisFeedError, hasUsableVesselCoordinates, classifyAisFeedSnapshot, mapAnalystRecord, vesselDatumHeightM, reduceVesselSelection, normalizeSelectionMmsi, methods };
|
||||
return {
|
||||
aisRetryInSec,
|
||||
describeDegradedAisFeed,
|
||||
deriveAisFeedError,
|
||||
hasUsableVesselCoordinates,
|
||||
classifyAisFeedSnapshot,
|
||||
mapAnalystRecord,
|
||||
vesselDatumHeightM,
|
||||
reduceVesselSelection,
|
||||
normalizeSelectionMmsi,
|
||||
methods,
|
||||
};
|
||||
}
|
||||
+171
-102
@@ -1,36 +1,59 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { vesselTypeCss, vesselOverlayCohortLimit, VESSEL_OVERLAY_SOURCE_ID, applyVesselOverlayPolicy, VESSEL_CARD_FADE_DISTANCE_M } from '../../data/vesselLabels.js';
|
||||
import { cameraPoseSignature, screenProjectedRotation } from '../../data/iconOrientation.js';
|
||||
import { DEFAULT_RENDER_ROWS, DEFAULT_ACTIVE_LABELS, VISIBILITY_UPDATE_MS, FOCUS_UPDATE_MS, LABEL_GRID_PX, CARD_MIN_SEP_PX } from './policy.js';
|
||||
import {
|
||||
vesselTypeCss,
|
||||
vesselOverlayCohortLimit,
|
||||
VESSEL_OVERLAY_SOURCE_ID,
|
||||
applyVesselOverlayPolicy,
|
||||
VESSEL_CARD_FADE_DISTANCE_M,
|
||||
} from '../../data/vesselLabels.js';
|
||||
import {
|
||||
cameraPoseSignature,
|
||||
screenProjectedRotation,
|
||||
} from '../../data/iconOrientation.js';
|
||||
import {
|
||||
DEFAULT_RENDER_ROWS,
|
||||
DEFAULT_ACTIVE_LABELS,
|
||||
VISIBILITY_UPDATE_MS,
|
||||
FOCUS_UPDATE_MS,
|
||||
LABEL_GRID_PX,
|
||||
CARD_MIN_SEP_PX,
|
||||
} from './policy.js';
|
||||
|
||||
export function createRendering({ vesselState, services, parts: components, layer, options }) {
|
||||
const { state } = vesselState;
|
||||
const { registerSpriteCollection } = services.sprites;
|
||||
const { forgetSpriteFocus, focusNowMs, getFocusTarget, focusPassIsNeeded, advanceSpriteFocus, focusAlphaNeedsWrite } = services.focus;
|
||||
export function createRendering({
|
||||
vesselState,
|
||||
services,
|
||||
parts: components,
|
||||
layer,
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
const { registerSpriteCollection } = services.sprites;
|
||||
const {
|
||||
forgetSpriteFocus,
|
||||
focusNowMs,
|
||||
getFocusTarget,
|
||||
focusPassIsNeeded,
|
||||
advanceSpriteFocus,
|
||||
focusAlphaNeedsWrite,
|
||||
} = services.focus;
|
||||
|
||||
|
||||
|
||||
function renderRowLimit() {
|
||||
function renderRowLimit() {
|
||||
const configured = Number(options.maxRows);
|
||||
if (Number.isFinite(configured) && configured > 0) {
|
||||
return Math.max(500, Math.min(50000, Math.round(configured)));
|
||||
}
|
||||
return DEFAULT_RENDER_ROWS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function labelRowLimit() {
|
||||
function labelRowLimit() {
|
||||
const configured = Number(options.maxLabels);
|
||||
if (Number.isFinite(configured) && configured >= 0) {
|
||||
return Math.max(0, Math.min(renderRowLimit(), Math.round(configured)));
|
||||
}
|
||||
return Math.min(DEFAULT_ACTIVE_LABELS, renderRowLimit());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function ensureCollections(viewer) {
|
||||
function ensureCollections(viewer) {
|
||||
if (!viewer || state.billboardCollection) return;
|
||||
state.billboardCollection = new Cesium.BillboardCollection({
|
||||
blendOption: Cesium.BlendOption.TRANSLUCENT,
|
||||
@@ -38,10 +61,9 @@ function ensureCollections(viewer) {
|
||||
state.billboardCollection.show = state.enabled;
|
||||
viewer.scene.primitives.add(state.billboardCollection);
|
||||
registerSpriteCollection('ais', state.billboardCollection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Create the billboard primitive for a freshly added vessel record. Map labels
|
||||
* are canvas cards (vesselLabels.js) rebuilt by the declutter pass — no
|
||||
* per-record label primitive exists anymore.
|
||||
@@ -49,8 +71,9 @@ function ensureCollections(viewer) {
|
||||
* @param {Cesium.EllipsoidalOccluder|null} occluder - Horizon occluder for initial visibility.
|
||||
*/
|
||||
|
||||
function addRecordPrimitives(record, occluder) {
|
||||
const visible = state.enabled && isVisible(record.surfacePosition, occluder);
|
||||
function addRecordPrimitives(record, occluder) {
|
||||
const visible =
|
||||
state.enabled && isVisible(record.surfacePosition, occluder);
|
||||
record.billboard = state.billboardCollection.add({
|
||||
position: record.position,
|
||||
show: visible,
|
||||
@@ -68,34 +91,30 @@ function addRecordPrimitives(record, occluder) {
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
id: record,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Remove a record's billboard primitive from its collection.
|
||||
* @param {Object} record - Vessel record to tear down.
|
||||
*/
|
||||
|
||||
function removeRecordPrimitives(record) {
|
||||
function removeRecordPrimitives(record) {
|
||||
if (!record) return;
|
||||
if (record.billboard && state.billboardCollection) {
|
||||
forgetSpriteFocus(record.billboard);
|
||||
state.billboardCollection.remove(record.billboard);
|
||||
}
|
||||
record.billboard = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function shipScale(record) {
|
||||
function shipScale(record) {
|
||||
const speed = Number(record.speed || 0);
|
||||
if (speed >= 18) return 0.78;
|
||||
if (speed >= 8) return 0.68;
|
||||
return 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Best available real-world direction of travel for a vessel, degrees
|
||||
* clockwise from north (true heading preferred, course-over-ground fallback).
|
||||
* Screen rotation is computed from this by the shared projected-rotation
|
||||
@@ -104,13 +123,12 @@ function shipScale(record) {
|
||||
* @returns {number} Course in degrees (0 when unknown).
|
||||
*/
|
||||
|
||||
function vesselCourseDeg(record) {
|
||||
function vesselCourseDeg(record) {
|
||||
const direction = record.heading ?? record.course;
|
||||
return Number.isFinite(direction) ? direction : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Build (and cache) a chevron/delta-wing SVG data URL tinted for the vessel.
|
||||
* The shape points north (up) so billboard rotation maps directly to heading.
|
||||
* One icon is generated per color+variant and reused across all billboards.
|
||||
@@ -119,10 +137,11 @@ function vesselCourseDeg(record) {
|
||||
* @returns {string} SVG data URL.
|
||||
*/
|
||||
|
||||
function shipIcon(record, selected) {
|
||||
function shipIcon(record, selected) {
|
||||
const cssColor = selected ? '#ffffff' : vesselTypeCss(record.type);
|
||||
const key = `${cssColor}:${selected ? 'selected' : 'normal'}`;
|
||||
if (vesselState.shipIconCache.has(key)) return vesselState.shipIconCache.get(key);
|
||||
if (vesselState.shipIconCache.has(key))
|
||||
return vesselState.shipIconCache.get(key);
|
||||
|
||||
const stroke = selected ? 'rgba(6,26,32,0.95)' : 'rgba(4,18,24,0.9)';
|
||||
const strokeWidth = selected ? 1.1 : 0.7;
|
||||
@@ -134,24 +153,24 @@ function shipIcon(record, selected) {
|
||||
const icon = 'data:image/svg+xml;base64,' + btoa(svg);
|
||||
vesselState.shipIconCache.set(key, icon);
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function installRuntime(viewer) {
|
||||
function installRuntime(viewer) {
|
||||
if (state.preRenderRemover || !viewer) return;
|
||||
state.preRenderRemover = viewer.scene.preRender.addEventListener(() => updateVisibility());
|
||||
}
|
||||
state.preRenderRemover = viewer.scene.preRender.addEventListener(() =>
|
||||
updateVisibility(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function updateVisibility(force = false) {
|
||||
function updateVisibility(force = false) {
|
||||
if (!state.enabled) return;
|
||||
const now = focusNowMs(performance.now());
|
||||
const focusTarget = getFocusTarget();
|
||||
const regularPass = force || now - state.lastVisibilityUpdate >= VISIBILITY_UPDATE_MS;
|
||||
const focusPass = focusPassIsNeeded(focusTarget, state.activeFocusCount)
|
||||
&& (force || now - state.lastFocusUpdate >= FOCUS_UPDATE_MS);
|
||||
const regularPass =
|
||||
force || now - state.lastVisibilityUpdate >= VISIBILITY_UPDATE_MS;
|
||||
const focusPass =
|
||||
focusPassIsNeeded(focusTarget, state.activeFocusCount) &&
|
||||
(force || now - state.lastFocusUpdate >= FOCUS_UPDATE_MS);
|
||||
if (!regularPass && !focusPass) return;
|
||||
if (regularPass) state.lastVisibilityUpdate = now;
|
||||
if (focusPass) state.lastFocusUpdate = now;
|
||||
@@ -178,9 +197,15 @@ function updateVisibility(force = false) {
|
||||
record.billboard.show = visible;
|
||||
if (visible && doRotations && scene) {
|
||||
const rot = screenProjectedRotation(
|
||||
scene, record.position, vesselCourseDeg(record), record.billboard.rotation
|
||||
scene,
|
||||
record.position,
|
||||
vesselCourseDeg(record),
|
||||
record.billboard.rotation,
|
||||
);
|
||||
if (rot !== null && Math.abs(rot - record.billboard.rotation) > 0.002) {
|
||||
if (
|
||||
rot !== null &&
|
||||
Math.abs(rot - record.billboard.rotation) > 0.002
|
||||
) {
|
||||
record.billboard.rotation = rot;
|
||||
}
|
||||
}
|
||||
@@ -195,24 +220,27 @@ function updateVisibility(force = false) {
|
||||
target: focusTarget,
|
||||
previousActiveCount: state.activeFocusCount,
|
||||
nowMs: now,
|
||||
screenPositionFor: (position) => (
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates(scene, position, vesselState._scratchFocusScreen)
|
||||
screenPositionFor: (position) =>
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene,
|
||||
position,
|
||||
vesselState._scratchFocusScreen,
|
||||
),
|
||||
cameraDistanceFor: (position) => Cesium.Cartesian3.distance(camera.positionWC, position),
|
||||
cameraDistanceFor: (position) =>
|
||||
Cesium.Cartesian3.distance(camera.positionWC, position),
|
||||
});
|
||||
state.activeFocusCount = result.activeCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Apply focus alpha to vessel sprites. Kept as a production wire seam so the
|
||||
* animation/deadband contract can be tested without constructing WebGL.
|
||||
* @param {object} input
|
||||
* @returns {{writes:number,transitioning:boolean,activeCount:number,ran:boolean}}
|
||||
*/
|
||||
|
||||
function applyVesselFocusDeemphasis({
|
||||
function applyVesselFocusDeemphasis({
|
||||
records,
|
||||
target,
|
||||
previousActiveCount = 0,
|
||||
@@ -220,7 +248,7 @@ function applyVesselFocusDeemphasis({
|
||||
screenPositionFor,
|
||||
cameraDistanceFor,
|
||||
params,
|
||||
}) {
|
||||
}) {
|
||||
if (!focusPassIsNeeded(target, previousActiveCount)) {
|
||||
return { writes: 0, transitioning: false, activeCount: 0, ran: false };
|
||||
}
|
||||
@@ -257,25 +285,23 @@ function applyVesselFocusDeemphasis({
|
||||
}
|
||||
}
|
||||
return { writes, transitioning, activeCount, ran: true };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function makeOccluder() {
|
||||
function makeOccluder() {
|
||||
const cameraPosition = state.viewer?.camera?.positionWC;
|
||||
if (!cameraPosition) return null;
|
||||
return new Cesium.EllipsoidalOccluder(Cesium.Ellipsoid.WGS84, cameraPosition);
|
||||
}
|
||||
return new Cesium.EllipsoidalOccluder(
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
cameraPosition,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function isVisible(surfacePosition, occluder) {
|
||||
function isVisible(surfacePosition, occluder) {
|
||||
if (!surfacePosition || !occluder) return true;
|
||||
return occluder.isPointVisible(surfacePosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Source selector for the shared world-overlay pipeline: the
|
||||
* grid declutter picks which vessels get cards — one winner per screen-space
|
||||
* grid cell, priority-ranked, capped — and publishes presentation entries to
|
||||
@@ -286,11 +312,13 @@ function isVisible(surfacePosition, occluder) {
|
||||
* @param {Array<Object>} records - Horizon-visible vessel records.
|
||||
*/
|
||||
|
||||
function updateClusteredLabels(records) {
|
||||
function updateClusteredLabels(records) {
|
||||
const viewer = state.viewer;
|
||||
const scene = viewer?.scene;
|
||||
const selected = state.selectedRecord;
|
||||
const entries = selected ? [components.cards.buildSelectedVesselCard(selected)] : [];
|
||||
const entries = selected
|
||||
? [components.cards.buildSelectedVesselCard(selected)]
|
||||
: [];
|
||||
const maxLabels = labelRowLimit();
|
||||
|
||||
if (!scene || !records.length || maxLabels <= 0) {
|
||||
@@ -302,10 +330,18 @@ function updateClusteredLabels(records) {
|
||||
const cells = new Map();
|
||||
for (const record of records) {
|
||||
if (record === selected) continue;
|
||||
const screen = Cesium.SceneTransforms.worldToWindowCoordinates(scene, record.position);
|
||||
const screen = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene,
|
||||
record.position,
|
||||
);
|
||||
if (!screen) continue;
|
||||
const key = `${Math.floor(screen.x / LABEL_GRID_PX)}:${Math.floor(screen.y / LABEL_GRID_PX)}`;
|
||||
const candidate = { record, score: labelPriority(record, selected), x: screen.x, y: screen.y };
|
||||
const candidate = {
|
||||
record,
|
||||
score: labelPriority(record, selected),
|
||||
x: screen.x,
|
||||
y: screen.y,
|
||||
};
|
||||
const existing = cells.get(key);
|
||||
if (!existing || candidate.score > existing.score) {
|
||||
cells.set(key, candidate);
|
||||
@@ -317,38 +353,52 @@ function updateClusteredLabels(records) {
|
||||
const accepted = [];
|
||||
if (selected) {
|
||||
const screen = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene, selected.billboard?.position || selected.position
|
||||
scene,
|
||||
selected.billboard?.position || selected.position,
|
||||
);
|
||||
if (screen) accepted.push({ x: screen.x, y: screen.y });
|
||||
}
|
||||
const ranked = [...cells.values()].sort((a, b) => b.score - a.score);
|
||||
for (const candidate of ranked) {
|
||||
if (entries.length >= maxLabels) break;
|
||||
if (!components.cards.cardScreenSeparated(accepted, candidate, CARD_MIN_SEP_PX)) continue;
|
||||
if (
|
||||
!components.cards.cardScreenSeparated(
|
||||
accepted,
|
||||
candidate,
|
||||
CARD_MIN_SEP_PX,
|
||||
)
|
||||
)
|
||||
continue;
|
||||
accepted.push({ x: candidate.x, y: candidate.y });
|
||||
entries.push(components.cards.buildVesselCard(candidate.record));
|
||||
}
|
||||
state.activeLabelCount = entries.length;
|
||||
publishVesselOverlayEntries(entries);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Publish a complete, bounded source snapshot to the shared host. The source
|
||||
* selector remains authoritative for the 118 px grid and 150 px separation;
|
||||
* the host then composes this demand with sibling ambient-card sources.
|
||||
* @param {Object[]} entries Formatted vessel card entries.
|
||||
*/
|
||||
|
||||
function publishVesselOverlayEntries(entries) {
|
||||
function publishVesselOverlayEntries(entries) {
|
||||
const canvas = state.viewer?.scene?.canvas || state.viewer?.canvas;
|
||||
const width = Number(canvas?.clientWidth) || 0;
|
||||
const height = Number(canvas?.clientHeight) || 0;
|
||||
const ambientLimit = vesselOverlayCohortLimit(width, height, labelRowLimit());
|
||||
const ambientLimit = vesselOverlayCohortLimit(
|
||||
width,
|
||||
height,
|
||||
labelRowLimit(),
|
||||
);
|
||||
vesselState._vesselOverlayHost.setEntries(
|
||||
VESSEL_OVERLAY_SOURCE_ID,
|
||||
entries.map((entry) => {
|
||||
const card = applyVesselOverlayPolicy(entry, VESSEL_CARD_FADE_DISTANCE_M);
|
||||
const card = applyVesselOverlayPolicy(
|
||||
entry,
|
||||
VESSEL_CARD_FADE_DISTANCE_M,
|
||||
);
|
||||
if (!card.interactive) return card;
|
||||
const mmsi = String(card.id || '').startsWith('vessel:')
|
||||
? card.id.slice('vessel:'.length)
|
||||
@@ -370,34 +420,53 @@ function publishVesselOverlayEntries(entries) {
|
||||
moving: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function labelPriority(record, selected) {
|
||||
function labelPriority(record, selected) {
|
||||
if (record === selected) return 100000;
|
||||
let score = 0;
|
||||
if (hasUsefulName(record)) score += 1000;
|
||||
if (record.speed !== null) score += Math.min(400, Math.max(0, record.speed) * 20);
|
||||
if (record.speed !== null)
|
||||
score += Math.min(400, Math.max(0, record.speed) * 20);
|
||||
if (record.heading !== null || record.course !== null) score += 80;
|
||||
if (record.type) score += 40;
|
||||
return score;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function hasUsefulName(record) {
|
||||
function hasUsefulName(record) {
|
||||
const text = String(record.name || '').trim();
|
||||
return Boolean(text && text !== 'VESSEL' && !/^MMSI\s*\d+$/i.test(text) && text !== record.mmsi);
|
||||
}
|
||||
return Boolean(
|
||||
text &&
|
||||
text !== 'VESSEL' &&
|
||||
!/^MMSI\s*\d+$/i.test(text) &&
|
||||
text !== record.mmsi,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function setVisible(show) {
|
||||
function setVisible(show) {
|
||||
if (state.billboardCollection) {
|
||||
state.billboardCollection.show = show;
|
||||
}
|
||||
vesselState._vesselOverlayHost.setVisible(VESSEL_OVERLAY_SOURCE_ID, show);
|
||||
}
|
||||
return { renderRowLimit, labelRowLimit, ensureCollections, addRecordPrimitives, removeRecordPrimitives, shipScale, vesselCourseDeg, shipIcon, installRuntime, updateVisibility, applyVesselFocusDeemphasis, makeOccluder, isVisible, updateClusteredLabels, publishVesselOverlayEntries, labelPriority, hasUsefulName, setVisible };
|
||||
}
|
||||
return {
|
||||
renderRowLimit,
|
||||
labelRowLimit,
|
||||
ensureCollections,
|
||||
addRecordPrimitives,
|
||||
removeRecordPrimitives,
|
||||
shipScale,
|
||||
vesselCourseDeg,
|
||||
shipIcon,
|
||||
installRuntime,
|
||||
updateVisibility,
|
||||
applyVesselFocusDeemphasis,
|
||||
makeOccluder,
|
||||
isVisible,
|
||||
updateClusteredLabels,
|
||||
publishVesselOverlayEntries,
|
||||
labelPriority,
|
||||
hasUsefulName,
|
||||
setVisible,
|
||||
};
|
||||
}
|
||||
@@ -1,26 +1,36 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { VESSEL_OVERLAY_SOURCE_ID } from '../../data/vesselLabels.js';
|
||||
|
||||
export function createSelection({ vesselState, services, parts: components, layer, options }) {
|
||||
const { state } = vesselState;
|
||||
const { resolvePickId, isOwnedByOtherLayer } = services.picking;
|
||||
const { requestWorldFocus } = services.worldFocus;
|
||||
const { selectEntityContext, registerEntityContext, clearSelectedEntityContextForLayer } = services.context;
|
||||
const aisLiveVesselsLayer = layer;
|
||||
export function createSelection({
|
||||
vesselState,
|
||||
services,
|
||||
parts: components,
|
||||
layer,
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
const { resolvePickId, isOwnedByOtherLayer } = services.picking;
|
||||
const { requestWorldFocus } = services.worldFocus;
|
||||
const {
|
||||
selectEntityContext,
|
||||
registerEntityContext,
|
||||
clearSelectedEntityContextForLayer,
|
||||
} = services.context;
|
||||
const aisLiveVesselsLayer = layer;
|
||||
|
||||
|
||||
|
||||
function installInteraction(viewer) {
|
||||
function installInteraction(viewer) {
|
||||
if (state.clickHandler || !viewer) return;
|
||||
const handler = state.interactionHandlerFactory
|
||||
? state.interactionHandlerFactory(viewer)
|
||||
: new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
|
||||
bindVesselInteraction(viewer, handler, state.interactionKeyTarget || document);
|
||||
}
|
||||
bindVesselInteraction(
|
||||
viewer,
|
||||
handler,
|
||||
state.interactionKeyTarget || document,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function bindVesselInteraction(viewer, handler, keyTarget) {
|
||||
function bindVesselInteraction(viewer, handler, keyTarget) {
|
||||
state.clickHandler = handler;
|
||||
handler.setInputAction((click) => {
|
||||
if (!state.enabled) return;
|
||||
@@ -28,14 +38,16 @@ function bindVesselInteraction(viewer, handler, keyTarget) {
|
||||
const pickedId = resolvePickId(picked);
|
||||
let record = pickedId ? state.vesselMap.get(pickedId) : null;
|
||||
const rawId = picked?.id ?? picked?.primitive?.id;
|
||||
const ownRecordPick = rawId && typeof rawId === 'object' && Object.hasOwn(rawId, 'mmsi');
|
||||
const ownRecordPick =
|
||||
rawId && typeof rawId === 'object' && Object.hasOwn(rawId, 'mmsi');
|
||||
|
||||
// An own-layer record without a live map key is a strict no-op (FB-1
|
||||
// residual). Trails carry no layer identity and hug their contacts, so any
|
||||
// `gev-trail:*` pick is also a no-op. Every other non-vessel pick — sibling
|
||||
// unowned scene picks dismiss the current vessel inspection.
|
||||
if (ownRecordPick && (!pickedId || !record)) return;
|
||||
if (pickedId && !record && String(pickedId).startsWith('gev-trail:')) return;
|
||||
if (pickedId && !record && String(pickedId).startsWith('gev-trail:'))
|
||||
return;
|
||||
|
||||
// A sibling layer already owns this click. Preserve the current vessel
|
||||
// selection and do not compete with its camera command.
|
||||
@@ -45,9 +57,13 @@ function bindVesselInteraction(viewer, handler, keyTarget) {
|
||||
// usually terrain behind the card. Resolve against the host's current
|
||||
// actionable hit rectangles before treating the click as empty space.
|
||||
const cardHit = !record
|
||||
? vesselState._vesselOverlayHost.hitTest?.(click.position?.x, click.position?.y, {
|
||||
? vesselState._vesselOverlayHost.hitTest?.(
|
||||
click.position?.x,
|
||||
click.position?.y,
|
||||
{
|
||||
sourceId: VESSEL_OVERLAY_SOURCE_ID,
|
||||
})
|
||||
},
|
||||
)
|
||||
: null;
|
||||
if (!record && cardHit) {
|
||||
const mmsi = String(cardHit.entryId || '').startsWith('vessel:')
|
||||
@@ -77,15 +93,17 @@ function bindVesselInteraction(viewer, handler, keyTarget) {
|
||||
keyTarget.addEventListener('keydown', state.keydownHandler);
|
||||
// Vessels never set viewer.trackedEntity, so any new tracked entity belongs
|
||||
// to another layer and takes interaction ownership of the scene.
|
||||
state.trackedEntityRemover = viewer.trackedEntityChanged.addEventListener(() => {
|
||||
if (viewer.trackedEntity && state.selectedRecord) clearVesselInspection();
|
||||
});
|
||||
}
|
||||
state.trackedEntityRemover = viewer.trackedEntityChanged.addEventListener(
|
||||
() => {
|
||||
if (viewer.trackedEntity && state.selectedRecord)
|
||||
clearVesselInspection();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/** Select one live vessel and request one UI-owned camera transfer. */
|
||||
|
||||
/** Select one live vessel and request one UI-owned camera transfer. */
|
||||
|
||||
function selectAndFocusVessel(record) {
|
||||
function selectAndFocusVessel(record) {
|
||||
if (!record?.mmsi) return false;
|
||||
const transition = components.queries.reduceVesselSelection({
|
||||
selectedMmsi: state.selectedRecord?.mmsi,
|
||||
@@ -100,11 +118,9 @@ function selectAndFocusVessel(record) {
|
||||
position: record.billboard?.position || record.position,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function removeVesselInteraction() {
|
||||
function removeVesselInteraction() {
|
||||
if (state.clickHandler) {
|
||||
state.clickHandler.destroy();
|
||||
state.clickHandler = null;
|
||||
@@ -118,11 +134,9 @@ function removeVesselInteraction() {
|
||||
state.trackedEntityRemover();
|
||||
state.trackedEntityRemover = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function onVesselKeyDown(event) {
|
||||
function onVesselKeyDown(event) {
|
||||
if (!state.enabled || event.key !== 'Escape') return;
|
||||
const transition = components.queries.reduceVesselSelection({
|
||||
selectedMmsi: state.selectedRecord?.mmsi,
|
||||
@@ -131,11 +145,9 @@ function onVesselKeyDown(event) {
|
||||
if (transition.action === 'deselect') {
|
||||
clearVesselInspection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function selectVessel(record) {
|
||||
function selectVessel(record) {
|
||||
if (!record?.mmsi) return;
|
||||
const reuseTrail = state.trailMmsi === record.mmsi;
|
||||
clearSelection({ preserveTrail: reuseTrail });
|
||||
@@ -159,17 +171,16 @@ function selectVessel(record) {
|
||||
} else {
|
||||
components.tracking.startSelectedVesselTrail(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Register (or refresh) the selected vessel in the shared context store so
|
||||
* the realtime/voice layer can describe what the user has selected.
|
||||
* @param {Object} record - Selected vessel record.
|
||||
* @returns {Object|null} The context record, or null if registration failed.
|
||||
*/
|
||||
|
||||
function registerSelectedContext(record) {
|
||||
function registerSelectedContext(record) {
|
||||
if (!record?.mmsi) return null;
|
||||
try {
|
||||
return registerEntityContext(record, {
|
||||
@@ -192,11 +203,9 @@ function registerSelectedContext(record) {
|
||||
console.warn('[Data:ais-live-vessels] context register failed', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function clearSelection({ preserveTrail = false, evicted = false } = {}) {
|
||||
function clearSelection({ preserveTrail = false, evicted = false } = {}) {
|
||||
const record = state.selectedRecord;
|
||||
if (record?.billboard) {
|
||||
record.billboard.image = components.rendering.shipIcon(record, false);
|
||||
@@ -212,18 +221,27 @@ function clearSelection({ preserveTrail = false, evicted = false } = {}) {
|
||||
} catch (error) {
|
||||
console.warn('[Data:ais-live-vessels] context clear failed', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param {object} [options] Clear origin.
|
||||
* @param {boolean} [options.evicted=false] The vessel aged out of the feed
|
||||
* rather than being deselected.
|
||||
*/
|
||||
|
||||
function clearVesselInspection({ evicted = false } = {}) {
|
||||
function clearVesselInspection({ evicted = false } = {}) {
|
||||
clearSelection({ evicted });
|
||||
components.cards.resetSelectedVesselHud();
|
||||
}
|
||||
return { installInteraction, bindVesselInteraction, selectAndFocusVessel, removeVesselInteraction, onVesselKeyDown, selectVessel, registerSelectedContext, clearSelection, clearVesselInspection };
|
||||
}
|
||||
return {
|
||||
installInteraction,
|
||||
bindVesselInteraction,
|
||||
selectAndFocusVessel,
|
||||
removeVesselInteraction,
|
||||
onVesselKeyDown,
|
||||
selectVessel,
|
||||
registerSelectedContext,
|
||||
clearSelection,
|
||||
clearVesselInspection,
|
||||
};
|
||||
}
|
||||
+23
-31
@@ -2,57 +2,49 @@ import * as Cesium from 'cesium';
|
||||
import { DEFAULT_AIS_RUNTIME } from './policy.js';
|
||||
|
||||
export function createVesselState({ source, services }) {
|
||||
const { setOverlayEntries, setOverlaySourceVisible, clearOverlaySource, hitTestWorldOverlay } = services.overlay;
|
||||
const vesselState = {};
|
||||
const {
|
||||
setOverlayEntries,
|
||||
setOverlaySourceVisible,
|
||||
clearOverlaySource,
|
||||
hitTestWorldOverlay,
|
||||
} = services.overlay;
|
||||
const vesselState = {};
|
||||
|
||||
vesselState._source = source;
|
||||
|
||||
/** Camera pose signature at the last vessel rotation pass. */
|
||||
|
||||
vesselState._source = source;
|
||||
vesselState._lastCamPoseSig = '';
|
||||
|
||||
vesselState._scratchFocusScreen = new Cesium.Cartesian2();
|
||||
|
||||
/** Camera pose signature at the last vessel rotation pass. */
|
||||
|
||||
vesselState._lastCamPoseSig = '';
|
||||
|
||||
|
||||
vesselState._scratchFocusScreen = new Cesium.Cartesian2();
|
||||
|
||||
|
||||
|
||||
vesselState.DEFAULT_VESSEL_OVERLAY_HOST = Object.freeze({
|
||||
vesselState.DEFAULT_VESSEL_OVERLAY_HOST = Object.freeze({
|
||||
setEntries: setOverlayEntries,
|
||||
setVisible: setOverlaySourceVisible,
|
||||
clearSource: clearOverlaySource,
|
||||
hitTest: hitTestWorldOverlay,
|
||||
});
|
||||
});
|
||||
|
||||
vesselState._vesselOverlayHost = vesselState.DEFAULT_VESSEL_OVERLAY_HOST;
|
||||
|
||||
vesselState._vesselOverlayHost = vesselState.DEFAULT_VESSEL_OVERLAY_HOST;
|
||||
vesselState._aisRuntime = DEFAULT_AIS_RUNTIME;
|
||||
|
||||
vesselState._aisSessionSequence = 0;
|
||||
|
||||
vesselState._aisRuntime = DEFAULT_AIS_RUNTIME;
|
||||
|
||||
|
||||
vesselState._aisSessionSequence = 0;
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* True once the EGM96 geoid grid has loaded (fire-and-forget warm at
|
||||
* enable(), aircraft idiom — see militaryFlights.js). Gates all synchronous
|
||||
* geoidHeight() reads so a poll can never throw pre-load.
|
||||
* @type {boolean}
|
||||
*/
|
||||
|
||||
vesselState._geoidReady = false;
|
||||
vesselState._geoidReady = false;
|
||||
|
||||
/** @type {Map<string, string>} `${cssColor}:${variant}` -> chevron SVG data URL */
|
||||
|
||||
/** @type {Map<string, string>} `${cssColor}:${variant}` -> chevron SVG data URL */
|
||||
vesselState.shipIconCache = new Map();
|
||||
|
||||
vesselState.shipIconCache = new Map();
|
||||
|
||||
|
||||
|
||||
vesselState.state = {
|
||||
vesselState.state = {
|
||||
viewer: null,
|
||||
enabled: false,
|
||||
loading: false,
|
||||
@@ -111,6 +103,6 @@ vesselState.state = {
|
||||
/** @type {number} Monotonic token — invalidates in-flight backfill responses */
|
||||
trailBackfillToken: 0,
|
||||
trailAbort: null,
|
||||
};
|
||||
return vesselState;
|
||||
};
|
||||
return vesselState;
|
||||
}
|
||||
+47
-26
@@ -2,11 +2,16 @@ import * as Cesium from 'cesium';
|
||||
import { PARTIAL_RETENTION_MS } from './policy.js';
|
||||
import { SELECTED_PIN_REFRESHES, VESSEL_LIFT_M } from './policy.js';
|
||||
|
||||
export function createStore({ vesselState, services, parts: components, layer, options }) {
|
||||
const { state } = vesselState;
|
||||
export function createStore({
|
||||
vesselState,
|
||||
services,
|
||||
parts: components,
|
||||
layer,
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Reconcile the incoming AIS rows against the MMSI-keyed record map.
|
||||
* Existing records are updated in place (position/heading/label) so identity
|
||||
* and selection survive refreshes; new vessels are added; vanished vessels are
|
||||
@@ -17,7 +22,7 @@ const { state } = vesselState;
|
||||
* @param {Array<Object>} rows - Raw AIS rows from the live API.
|
||||
*/
|
||||
|
||||
function reconcileVessels(viewer, rows, { complete = true } = {}) {
|
||||
function reconcileVessels(viewer, rows, { complete = true } = {}) {
|
||||
const receivedAtMs = vesselState._aisRuntime.now();
|
||||
components.rendering.ensureCollections(viewer);
|
||||
|
||||
@@ -54,7 +59,11 @@ function reconcileVessels(viewer, rows, { complete = true } = {}) {
|
||||
// Remove vanished vessels, pinning the selected one for a few refreshes.
|
||||
for (const [mmsi, record] of state.vesselMap) {
|
||||
if (seen.has(mmsi)) continue;
|
||||
if (!complete && Number.isFinite(record.receivedAtMs) && receivedAtMs - record.receivedAtMs < PARTIAL_RETENTION_MS) {
|
||||
if (
|
||||
!complete &&
|
||||
Number.isFinite(record.receivedAtMs) &&
|
||||
receivedAtMs - record.receivedAtMs < PARTIAL_RETENTION_MS
|
||||
) {
|
||||
if (record === state.selectedRecord) {
|
||||
record.missedRefreshes = Math.max(1, record.missedRefreshes || 0);
|
||||
components.cards.updateSelectedVesselHud(record);
|
||||
@@ -74,7 +83,8 @@ function reconcileVessels(viewer, rows, { complete = true } = {}) {
|
||||
state.vesselMap.delete(mmsi);
|
||||
// Defensive lifecycle closure: a trail may outlive selection state during
|
||||
// asynchronous handoff/refresh ordering, but never its owning record.
|
||||
if (state.trailMmsi === mmsi) components.tracking.clearSelectedVesselTrail();
|
||||
if (state.trailMmsi === mmsi)
|
||||
components.tracking.clearSelectedVesselTrail();
|
||||
}
|
||||
|
||||
const cap = components.rendering.renderRowLimit();
|
||||
@@ -84,16 +94,19 @@ function reconcileVessels(viewer, rows, { complete = true } = {}) {
|
||||
if (seen.has(mmsi) || record === state.selectedRecord) continue;
|
||||
components.rendering.removeRecordPrimitives(record);
|
||||
state.vesselMap.delete(mmsi);
|
||||
if (state.trailMmsi === mmsi) components.tracking.clearSelectedVesselTrail();
|
||||
if (state.trailMmsi === mmsi)
|
||||
components.tracking.clearSelectedVesselTrail();
|
||||
}
|
||||
}
|
||||
state.vesselRecords = [...state.vesselMap.values(), ...state.unkeyedRecords];
|
||||
state.vesselRecords = [
|
||||
...state.vesselMap.values(),
|
||||
...state.unkeyedRecords,
|
||||
];
|
||||
state.lastVisibilityUpdate = 0;
|
||||
components.rendering.updateVisibility(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Update an existing record (and its primitives) from a freshly normalized row,
|
||||
* preserving object identity so selection and the click-pick id stay valid.
|
||||
* Billboard image is only reassigned when the resolved icon actually changes
|
||||
@@ -102,7 +115,7 @@ function reconcileVessels(viewer, rows, { complete = true } = {}) {
|
||||
* @param {Object} next - Freshly normalized record for the same MMSI.
|
||||
*/
|
||||
|
||||
function updateRecordInPlace(record, next) {
|
||||
function updateRecordInPlace(record, next) {
|
||||
const selected = record === state.selectedRecord;
|
||||
const prevIcon = components.rendering.shipIcon(record, selected);
|
||||
|
||||
@@ -127,7 +140,8 @@ function updateRecordInPlace(record, next) {
|
||||
if (record.billboard) {
|
||||
record.billboard.position = record.position;
|
||||
// Rotation is owned by the projected-rotation pass (updateVisibility).
|
||||
record.billboard.scale = components.rendering.shipScale(record) * (selected ? 1.2 : 1);
|
||||
record.billboard.scale =
|
||||
components.rendering.shipScale(record) * (selected ? 1.2 : 1);
|
||||
const nextIcon = components.rendering.shipIcon(record, selected);
|
||||
if (nextIcon !== prevIcon) {
|
||||
record.billboard.image = nextIcon;
|
||||
@@ -140,22 +154,26 @@ function updateRecordInPlace(record, next) {
|
||||
components.cards.updateSelectedVesselHud(record);
|
||||
components.selection.registerSelectedContext(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function normalizeVessel(row) {
|
||||
function normalizeVessel(row) {
|
||||
const lat = Number(row.lat);
|
||||
const lon = Number(row.lon);
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null;
|
||||
// Vertical datum: anchor at the SEA SURFACE (geoid, h = N + lift), not the
|
||||
// ellipsoid — at height 0 everything that projects record.position (clicks,
|
||||
// detection brackets, cards, getNearby) points up to ~45 m under the water.
|
||||
const heightM = components.queries.vesselDatumHeightM(components.tracking.currentGeoidN(lat, lon), VESSEL_LIFT_M);
|
||||
const heightM = components.queries.vesselDatumHeightM(
|
||||
components.tracking.currentGeoidN(lat, lon),
|
||||
VESSEL_LIFT_M,
|
||||
);
|
||||
const position = Cesium.Cartesian3.fromDegrees(lon, lat, heightM);
|
||||
// Surface normal at this position — used as alignedAxis so billboard
|
||||
// rotation operates in the local tangent plane (true world heading)
|
||||
const normal = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(position, new Cesium.Cartesian3());
|
||||
const normal = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(
|
||||
position,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
return {
|
||||
lat,
|
||||
lon,
|
||||
@@ -178,14 +196,17 @@ function normalizeVessel(row) {
|
||||
missedRefreshes: 0,
|
||||
billboard: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function finiteNumber(value) {
|
||||
function finiteNumber(value) {
|
||||
if (value === null || value === undefined || value === '') return null;
|
||||
const number = Number(value);
|
||||
return Number.isFinite(number) ? number : null;
|
||||
}
|
||||
return { reconcileVessels, updateRecordInPlace, normalizeVessel, finiteNumber };
|
||||
}
|
||||
return {
|
||||
reconcileVessels,
|
||||
updateRecordInPlace,
|
||||
normalizeVessel,
|
||||
finiteNumber,
|
||||
};
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
import { DEFAULT_AIS_RUNTIME } from './policy.js';
|
||||
|
||||
export function createTesting({ vesselState, services, parts: components, layer, options }) {
|
||||
const { state } = vesselState;
|
||||
const aisLiveVesselsLayer = layer;
|
||||
export function createTesting({
|
||||
vesselState,
|
||||
services,
|
||||
parts: components,
|
||||
layer,
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
const aisLiveVesselsLayer = layer;
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Bind the production interaction callbacks to mockable viewer/handler
|
||||
* surfaces. Test-only seam; behavior is shared with installInteraction().
|
||||
* @param {Object} viewer - Viewer-like object with scene.pick().
|
||||
@@ -14,18 +19,17 @@ const aisLiveVesselsLayer = layer;
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
function _bindVesselInteractionForTest(viewer, handler, keyTarget) {
|
||||
function _bindVesselInteractionForTest(viewer, handler, keyTarget) {
|
||||
components.selection.bindVesselInteraction(viewer, handler, keyTarget);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Prime the minimum live state needed by interaction/lifecycle wire tests.
|
||||
* @param {Object} [options={}] - Test state values.
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
function _setVesselStateForTest(options = {}) {
|
||||
function _setVesselStateForTest(options = {}) {
|
||||
components.lifecycle.resetState();
|
||||
const records = Array.isArray(options.records) ? options.records : [];
|
||||
state.viewer = options.viewer || null;
|
||||
@@ -38,75 +42,77 @@ function _setVesselStateForTest(options = {}) {
|
||||
state.vesselRecords = records;
|
||||
state.count = records.length;
|
||||
state.vesselMap = new Map(
|
||||
records.filter((record) => record?.mmsi).map((record) => [record.mmsi, record])
|
||||
records
|
||||
.filter((record) => record?.mmsi)
|
||||
.map((record) => [record.mmsi, record]),
|
||||
);
|
||||
state.selectedRecord = options.selectedRecord || null;
|
||||
state.billboardCollection = options.billboardCollection || { remove() {} };
|
||||
state.trail = options.trail || null;
|
||||
state.trailMmsi = options.trailMmsi || null;
|
||||
state.trailPositions = Array.isArray(options.trailPositions) ? [...options.trailPositions] : [];
|
||||
state.trailPositions = Array.isArray(options.trailPositions)
|
||||
? [...options.trailPositions]
|
||||
: [];
|
||||
state.transportStatus = options.transportStatus || null;
|
||||
state.lastMessageAt = options.lastMessageAt ?? null;
|
||||
state.rawRowCount = Number.isFinite(options.rawRowCount) ? options.rawRowCount : 0;
|
||||
state.acceptedRowCount = Number.isFinite(options.acceptedRowCount) ? options.acceptedRowCount : records.length;
|
||||
state.rawRowCount = Number.isFinite(options.rawRowCount)
|
||||
? options.rawRowCount
|
||||
: 0;
|
||||
state.acceptedRowCount = Number.isFinite(options.acceptedRowCount)
|
||||
? options.acceptedRowCount
|
||||
: records.length;
|
||||
state.firstConnectPhase = options.firstConnectPhase || 'idle';
|
||||
state.firstConnectStartedAt = options.firstConnectStartedAt ?? null;
|
||||
state.firstConnectDeadline = options.firstConnectDeadline ?? null;
|
||||
state.interactionHandlerFactory = options.interactionHandlerFactory || null;
|
||||
state.interactionKeyTarget = options.interactionKeyTarget || null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Inject a host recorder for lifecycle/contract tests; null restores production. */
|
||||
|
||||
/** Inject a host recorder for lifecycle/contract tests; null restores production. */
|
||||
function _setVesselOverlayHostForTest(host = null) {
|
||||
vesselState._vesselOverlayHost =
|
||||
host || vesselState.DEFAULT_VESSEL_OVERLAY_HOST;
|
||||
}
|
||||
|
||||
function _setVesselOverlayHostForTest(host = null) {
|
||||
vesselState._vesselOverlayHost = host || vesselState.DEFAULT_VESSEL_OVERLAY_HOST;
|
||||
}
|
||||
/** Exercise the production selector/publisher through a test-owned state. */
|
||||
|
||||
|
||||
/** Exercise the production selector/publisher through a test-owned state. */
|
||||
|
||||
function _updateVesselCardsForTest(records = []) {
|
||||
function _updateVesselCardsForTest(records = []) {
|
||||
components.rendering.updateClusteredLabels(records);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Reconcile AIS rows through the production lifecycle. Test-only seam.
|
||||
* @param {Object} viewer - Viewer-like object.
|
||||
* @param {Array<Object>} rows - Raw AIS rows.
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
function _reconcileVesselsForTest(viewer, rows) {
|
||||
function _reconcileVesselsForTest(viewer, rows) {
|
||||
components.store.reconcileVessels(viewer, rows);
|
||||
}
|
||||
}
|
||||
|
||||
/** Apply one server snapshot through the production pre-reconcile health gate. */
|
||||
|
||||
/** Apply one server snapshot through the production pre-reconcile health gate. */
|
||||
|
||||
function _applyAisFeedSnapshotForTest(viewer, payload) {
|
||||
function _applyAisFeedSnapshotForTest(viewer, payload) {
|
||||
return components.ingestion.applyAisFeedSnapshot(viewer, payload);
|
||||
}
|
||||
}
|
||||
|
||||
/** Exercise the request-owned live loader with a test-controlled fetch. */
|
||||
|
||||
/** Exercise the request-owned live loader with a test-controlled fetch. */
|
||||
|
||||
function _loadLivePositionsForTest(viewer) {
|
||||
function _loadLivePositionsForTest(viewer) {
|
||||
return components.ingestion.loadLivePositions(viewer);
|
||||
}
|
||||
}
|
||||
|
||||
/** Start the production first-connect grace state without installing UI. */
|
||||
|
||||
/** Start the production first-connect grace state without installing UI. */
|
||||
|
||||
function _beginAisSessionForTest() {
|
||||
function _beginAisSessionForTest() {
|
||||
components.lifecycle.beginAisSession();
|
||||
}
|
||||
}
|
||||
|
||||
/** Inject a deterministic clock/scheduler; null restores production runtime. */
|
||||
|
||||
/** Inject a deterministic clock/scheduler; null restores production runtime. */
|
||||
|
||||
function _setAisRuntimeForTest(runtime = null) {
|
||||
function _setAisRuntimeForTest(runtime = null) {
|
||||
components.lifecycle.clearFirstConnectTimer();
|
||||
vesselState._aisRuntime = runtime
|
||||
? {
|
||||
@@ -115,12 +121,11 @@ function _setAisRuntimeForTest(runtime = null) {
|
||||
clearTimeout: runtime.clearTimeout,
|
||||
}
|
||||
: DEFAULT_AIS_RUNTIME;
|
||||
}
|
||||
}
|
||||
|
||||
/** Read feed-health fields without exposing mutable production state. */
|
||||
|
||||
/** Read feed-health fields without exposing mutable production state. */
|
||||
|
||||
function _getVesselFeedStateForTest() {
|
||||
function _getVesselFeedStateForTest() {
|
||||
const stats = aisLiveVesselsLayer.getStats();
|
||||
return {
|
||||
count: state.count,
|
||||
@@ -143,21 +148,32 @@ function _getVesselFeedStateForTest() {
|
||||
firstConnectStartedAt: state.firstConnectStartedAt,
|
||||
firstConnectDeadline: state.firstConnectDeadline,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Read lifecycle ownership state without exposing the mutable state object.
|
||||
* Test-only seam.
|
||||
* @returns {{trailMmsi: string|null, trailPositionCount: number, vesselCount: number}}
|
||||
*/
|
||||
|
||||
function _getVesselStateForTest() {
|
||||
function _getVesselStateForTest() {
|
||||
return {
|
||||
trailMmsi: state.trailMmsi,
|
||||
trailPositionCount: state.trailPositions.length,
|
||||
vesselCount: state.vesselMap.size,
|
||||
};
|
||||
}
|
||||
return { _bindVesselInteractionForTest, _setVesselStateForTest, _setVesselOverlayHostForTest, _updateVesselCardsForTest, _reconcileVesselsForTest, _applyAisFeedSnapshotForTest, _loadLivePositionsForTest, _beginAisSessionForTest, _setAisRuntimeForTest, _getVesselFeedStateForTest, _getVesselStateForTest };
|
||||
}
|
||||
return {
|
||||
_bindVesselInteractionForTest,
|
||||
_setVesselStateForTest,
|
||||
_setVesselOverlayHostForTest,
|
||||
_updateVesselCardsForTest,
|
||||
_reconcileVesselsForTest,
|
||||
_applyAisFeedSnapshotForTest,
|
||||
_loadLivePositionsForTest,
|
||||
_beginAisSessionForTest,
|
||||
_setAisRuntimeForTest,
|
||||
_getVesselFeedStateForTest,
|
||||
_getVesselStateForTest,
|
||||
};
|
||||
}
|
||||
@@ -1,25 +1,35 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { TRAIL_HEIGHT_M, VESSEL_LIFT_M, TRAIL_COLOR, TRAIL_MAX_POINTS, TRAIL_MIN_MOVE_M } from './policy.js';
|
||||
import {
|
||||
TRAIL_HEIGHT_M,
|
||||
VESSEL_LIFT_M,
|
||||
TRAIL_COLOR,
|
||||
TRAIL_MAX_POINTS,
|
||||
TRAIL_MIN_MOVE_M,
|
||||
} from './policy.js';
|
||||
|
||||
export function createTracking({ vesselState, services, parts: components, layer, options }) {
|
||||
const { state } = vesselState;
|
||||
const { geoidHeight } = services.geoid;
|
||||
const { createTrail } = services.trails;
|
||||
export function createTracking({
|
||||
vesselState,
|
||||
services,
|
||||
parts: components,
|
||||
layer,
|
||||
options,
|
||||
}) {
|
||||
const { state } = vesselState;
|
||||
const { geoidHeight } = services.geoid;
|
||||
const { createTrail } = services.trails;
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Geoid undulation N at (lat, lon), or null until the grid has loaded.
|
||||
* @param {number} lat
|
||||
* @param {number} lon
|
||||
* @returns {number|null}
|
||||
*/
|
||||
|
||||
function currentGeoidN(lat, lon) {
|
||||
function currentGeoidN(lat, lon) {
|
||||
return vesselState._geoidReady ? geoidHeight(lat, lon) : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Build a slightly lifted trail vertex for a vessel record — raised
|
||||
* TRAIL_HEIGHT_M above the sea surface (geoid, same datum as the anchor)
|
||||
* to avoid z-fighting.
|
||||
@@ -27,14 +37,17 @@ function currentGeoidN(lat, lon) {
|
||||
* @returns {Cesium.Cartesian3|null} Lifted position, or null without a fix.
|
||||
*/
|
||||
|
||||
function vesselTrailPosition(record) {
|
||||
if (!Number.isFinite(record?.lat) || !Number.isFinite(record?.lon)) return null;
|
||||
const heightM = components.queries.vesselDatumHeightM(currentGeoidN(record.lat, record.lon), TRAIL_HEIGHT_M);
|
||||
function vesselTrailPosition(record) {
|
||||
if (!Number.isFinite(record?.lat) || !Number.isFinite(record?.lon))
|
||||
return null;
|
||||
const heightM = components.queries.vesselDatumHeightM(
|
||||
currentGeoidN(record.lat, record.lon),
|
||||
TRAIL_HEIGHT_M,
|
||||
);
|
||||
return Cesium.Cartesian3.fromDegrees(record.lon, record.lat, heightM);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* One-shot datum re-lift when the geoid grid warms mid-session: the first
|
||||
* refresh can land before ensureGeoidReady() resolves (anchors at N = 0) and
|
||||
* the next refresh is up to REFRESH_MS out — re-derive every record's
|
||||
@@ -43,24 +56,31 @@ function vesselTrailPosition(record) {
|
||||
* needs a rendered pick — so trail vertices are not revisited.)
|
||||
*/
|
||||
|
||||
function refloorVesselRecords() {
|
||||
function refloorVesselRecords() {
|
||||
if (!state.vesselRecords.length) return;
|
||||
for (const record of state.vesselRecords) {
|
||||
if (!Number.isFinite(record.lat) || !Number.isFinite(record.lon)) continue;
|
||||
const heightM = components.queries.vesselDatumHeightM(currentGeoidN(record.lat, record.lon), VESSEL_LIFT_M);
|
||||
record.position = Cesium.Cartesian3.fromDegrees(record.lon, record.lat, heightM);
|
||||
if (!Number.isFinite(record.lat) || !Number.isFinite(record.lon))
|
||||
continue;
|
||||
const heightM = components.queries.vesselDatumHeightM(
|
||||
currentGeoidN(record.lat, record.lon),
|
||||
VESSEL_LIFT_M,
|
||||
);
|
||||
record.position = Cesium.Cartesian3.fromDegrees(
|
||||
record.lon,
|
||||
record.lat,
|
||||
heightM,
|
||||
);
|
||||
if (record.billboard) record.billboard.position = record.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Start (or restart) the selected vessel's trail: seed with the current
|
||||
* position, render, then fire-and-forget the server ring-buffer backfill.
|
||||
* @param {Object} record - Freshly selected vessel record.
|
||||
*/
|
||||
|
||||
function startSelectedVesselTrail(record) {
|
||||
function startSelectedVesselTrail(record) {
|
||||
state.trailAbort?.abort();
|
||||
state.trailAbort = new AbortController();
|
||||
state.trailBackfillToken += 1;
|
||||
@@ -69,14 +89,20 @@ function startSelectedVesselTrail(record) {
|
||||
const current = vesselTrailPosition(record);
|
||||
if (current) state.trailPositions.push(current);
|
||||
if (!state.trail && state.viewer) {
|
||||
state.trail = createTrail(state.viewer, { color: TRAIL_COLOR, width: 2.5 });
|
||||
state.trail = createTrail(state.viewer, {
|
||||
color: TRAIL_COLOR,
|
||||
width: 2.5,
|
||||
});
|
||||
}
|
||||
if (state.trail) state.trail.setPositions(state.trailPositions);
|
||||
backfillVesselTrail(record.mmsi, state.trailBackfillToken, record.reference);
|
||||
}
|
||||
backfillVesselTrail(
|
||||
record.mmsi,
|
||||
state.trailBackfillToken,
|
||||
record.reference,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Fire-and-forget backfill from the server-side per-MMSI ring buffer
|
||||
* (PRD F3 — "recent path" since server boot, not voyage history). Older
|
||||
* samples are spliced AHEAD of the live accumulation, capped at
|
||||
@@ -87,9 +113,11 @@ function startSelectedVesselTrail(record) {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
|
||||
async function backfillVesselTrail(mmsi, token, reference = mmsi) {
|
||||
async function backfillVesselTrail(mmsi, token, reference = mmsi) {
|
||||
const owner = state.trailAbort;
|
||||
const signal = owner ? AbortSignal.any([owner.signal, AbortSignal.timeout(8000)]) : AbortSignal.timeout(8000);
|
||||
const signal = owner
|
||||
? AbortSignal.any([owner.signal, AbortSignal.timeout(8000)])
|
||||
: AbortSignal.timeout(8000);
|
||||
let samples = null;
|
||||
try {
|
||||
const track = await vesselState._source.getTrack?.(reference, { signal });
|
||||
@@ -97,7 +125,13 @@ async function backfillVesselTrail(mmsi, token, reference = mmsi) {
|
||||
} catch {
|
||||
return; // silent — keep the live-accumulated trail
|
||||
}
|
||||
if (signal.aborted || owner !== state.trailAbort || !samples || token !== state.trailBackfillToken) return;
|
||||
if (
|
||||
signal.aborted ||
|
||||
owner !== state.trailAbort ||
|
||||
!samples ||
|
||||
token !== state.trailBackfillToken
|
||||
)
|
||||
return;
|
||||
if (state.trailMmsi !== mmsi) return;
|
||||
|
||||
const older = [];
|
||||
@@ -107,61 +141,74 @@ async function backfillVesselTrail(mmsi, token, reference = mmsi) {
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lon)) continue;
|
||||
// Per-sample N (≤ TRAIL_MAX_POINTS lookups) — same sea-surface datum as
|
||||
// the live vertices so the spliced trail is height-continuous.
|
||||
const heightM = components.queries.vesselDatumHeightM(currentGeoidN(lat, lon), TRAIL_HEIGHT_M);
|
||||
const heightM = components.queries.vesselDatumHeightM(
|
||||
currentGeoidN(lat, lon),
|
||||
TRAIL_HEIGHT_M,
|
||||
);
|
||||
older.push(Cesium.Cartesian3.fromDegrees(lon, lat, heightM));
|
||||
}
|
||||
if (!older.length) return;
|
||||
|
||||
state.trailPositions = older.concat(state.trailPositions);
|
||||
if (state.trailPositions.length > TRAIL_MAX_POINTS) {
|
||||
state.trailPositions = state.trailPositions.slice(state.trailPositions.length - TRAIL_MAX_POINTS);
|
||||
state.trailPositions = state.trailPositions.slice(
|
||||
state.trailPositions.length - TRAIL_MAX_POINTS,
|
||||
);
|
||||
}
|
||||
if (state.trail) state.trail.setPositions(state.trailPositions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Append the selected vessel's refreshed position to its trail when it has
|
||||
* moved more than TRAIL_MIN_MOVE_M from the last trail vertex.
|
||||
* @param {Object} record - Selected vessel record after an in-place update.
|
||||
*/
|
||||
|
||||
function appendSelectedVesselTrailFix(record) {
|
||||
function appendSelectedVesselTrailFix(record) {
|
||||
if (!state.trail) return;
|
||||
const next = vesselTrailPosition(record);
|
||||
if (!next) return;
|
||||
const last = state.trailPositions[state.trailPositions.length - 1];
|
||||
if (last && Cesium.Cartesian3.distance(last, next) <= TRAIL_MIN_MOVE_M) return;
|
||||
if (last && Cesium.Cartesian3.distance(last, next) <= TRAIL_MIN_MOVE_M)
|
||||
return;
|
||||
state.trailPositions.push(next);
|
||||
if (state.trailPositions.length > TRAIL_MAX_POINTS) state.trailPositions.shift();
|
||||
if (state.trailPositions.length > TRAIL_MAX_POINTS)
|
||||
state.trailPositions.shift();
|
||||
state.trail.setPositions(state.trailPositions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Clear the rendered trail and accumulation; invalidate pending backfills.
|
||||
*/
|
||||
|
||||
function clearSelectedVesselTrail() {
|
||||
function clearSelectedVesselTrail() {
|
||||
state.trailAbort?.abort();
|
||||
state.trailAbort = null;
|
||||
state.trailBackfillToken += 1;
|
||||
state.trailMmsi = null;
|
||||
state.trailPositions = [];
|
||||
if (state.trail) state.trail.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Destroy the trail primitive entirely (layer disable/teardown).
|
||||
*/
|
||||
|
||||
function destroySelectedVesselTrail() {
|
||||
function destroySelectedVesselTrail() {
|
||||
clearSelectedVesselTrail();
|
||||
if (state.trail) {
|
||||
state.trail.destroy();
|
||||
state.trail = null;
|
||||
}
|
||||
}
|
||||
return { currentGeoidN, vesselTrailPosition, refloorVesselRecords, startSelectedVesselTrail, backfillVesselTrail, appendSelectedVesselTrailFix, clearSelectedVesselTrail, destroySelectedVesselTrail };
|
||||
}
|
||||
return {
|
||||
currentGeoidN,
|
||||
vesselTrailPosition,
|
||||
refloorVesselRecords,
|
||||
startSelectedVesselTrail,
|
||||
backfillVesselTrail,
|
||||
appendSelectedVesselTrailFix,
|
||||
clearSelectedVesselTrail,
|
||||
destroySelectedVesselTrail,
|
||||
};
|
||||
}
|
||||
@@ -5,13 +5,19 @@ import { fileURLToPath } from 'node:url';
|
||||
/** Read actual component owners for structural regression assertions. */
|
||||
export function readLayerSource(file) {
|
||||
const path = file instanceof URL ? fileURLToPath(file) : file;
|
||||
if (!['flights.js', 'militaryFlights.js', 'aisLiveVessels.js'].includes(basename(path)))
|
||||
if (
|
||||
!['flights.js', 'militaryFlights.js', 'aisLiveVessels.js'].includes(
|
||||
basename(path),
|
||||
)
|
||||
)
|
||||
return readFileSync(path, 'utf8');
|
||||
const directory = join(
|
||||
dirname(path),
|
||||
basename(path) === 'flights.js'
|
||||
? '../layers/flights'
|
||||
: basename(path) === 'militaryFlights.js' ? '../layers/military' : '../layers/vessels',
|
||||
: basename(path) === 'militaryFlights.js'
|
||||
? '../layers/military'
|
||||
: '../layers/vessels',
|
||||
);
|
||||
return readdirSync(directory)
|
||||
.filter((name) => name.endsWith('.js'))
|
||||
|
||||
Reference in new issue
Block a user