Read the awareness layer's camera and frame through ports

The awareness lifecycle and focus parts had left the Cesium allow-list
but still hooked the scene's preRender event and read the Cesium
camera's position and orientation. They now use the frame port and the
camera port's pose, with the same quantized motion signature.
This commit is contained in:
Sameh Khamis committed 2026-11-07 01:04:46 -08:00
1 parent 045267c841
commit 6fc3c78e70
3 files changed
+42 -27

No files matched your search

+17 -11
View File
@@ -49,6 +49,8 @@ import { NAVIGATION_AUTHORITY_EVENT } from '../navigationPolicy.js';
import { withEntityRecord } from './entityRecords.js';
import { framePortFor } from '../testSupport/fakeFramePort.mjs';
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
import { fakeSceneFrame } from '../testSupport/fakeCesiumScene.mjs';
import { bindRenderer } from '../render/rendererOf.js';
import { fakeDrawPort } from '../testSupport/fakeDrawPort.mjs';
const militaryAwarenessSource = readLayerSource(
@@ -185,7 +187,10 @@ function installAwarenessRuntime({
},
container: new FakeElement(),
};
bindFakeCesiumCamera(viewer, { draw: fakeDrawPort() });
bindFakeCesiumCamera(viewer, {
draw: fakeDrawPort(),
frame: fakeSceneFrame(viewer),
});
const layers = new Map(
AWARENESS_DEPENDENCIES.map((layerId) => [
layerId,
@@ -2166,7 +2171,7 @@ test('Context entry tracks a nearer civilian aircraft over a farther military ai
const focused = [];
try {
runtime.viewer.camera = { positionWC: camera };
runtime.viewer.camera.positionWC = camera;
replaceMethod(
flightsLayer,
'trackById',
@@ -2203,7 +2208,7 @@ test('Context entry prefers military aircraft on an exact nearest-distance tie',
const focused = [];
try {
runtime.viewer.camera = { positionWC: camera };
runtime.viewer.camera.positionWC = camera;
replaceMethod(
flightsLayer,
'trackById',
@@ -2238,7 +2243,7 @@ test('Context entry retries once on the next refresh after initially empty feeds
const focused = [];
try {
runtime.viewer.camera = { positionWC: camera };
runtime.viewer.camera.positionWC = camera;
replaceMethod(
flightsLayer,
'trackById',
@@ -2275,7 +2280,7 @@ test('user deselect cancels a pending Context entry auto-focus retry', async ()
const focused = [];
try {
runtime.viewer.camera = { positionWC: camera };
runtime.viewer.camera.positionWC = camera;
replaceMethod(
flightsLayer,
'trackById',
@@ -3719,6 +3724,7 @@ test('runtime listeners exist only while the awareness layer is enabled', () =>
entities: { remove() {} },
container: new FakeElement(),
};
bindRenderer(viewer, { frame: fakeSceneFrame(viewer) });
globalThis.window = fakeWindow;
globalThis.document = {
@@ -3889,12 +3895,12 @@ test('parked Contacts takes no continuous-render hold and requests at most the p
try {
Date.now = () => clockMs;
installRenderGovernor(framePortFor(runtime.viewer.scene));
runtime.viewer.camera = {
Object.assign(runtime.viewer.camera, {
positionWC: new Cesium.Cartesian3(1_000_000, 200_000, 300_000),
heading: 0,
pitch: -0.4,
roll: 0,
};
});
// 1. Enabled, nothing selected, camera parked — Contacts must not be a
// reason the whole scene keeps repainting.
@@ -4025,12 +4031,12 @@ test('a moving view over failed feeds takes no continuous-render hold', () => {
try {
Date.now = () => clockMs;
installRenderGovernor(framePortFor(runtime.viewer.scene));
runtime.viewer.camera = {
Object.assign(runtime.viewer.camera, {
positionWC: new Cesium.Cartesian3(1_000_000, 200_000, 300_000),
heading: 0,
pitch: -0.4,
roll: 0,
};
});
runtime.dispatch(
'gev:awareness-subject-selected',
awarenessSubject('flights', 'subject-flight', position),
@@ -4073,12 +4079,12 @@ test('a moving camera refreshes Contacts more than once inside one parked interv
try {
Date.now = () => clockMs;
runtime.viewer.camera = {
Object.assign(runtime.viewer.camera, {
positionWC: new Cesium.Cartesian3(1_000_000, 200_000, 300_000),
heading: 0,
pitch: -0.4,
roll: 0,
};
});
replaceMethod(
flightsLayer,
'getAllPositions',
+2 -2
View File
@@ -1,5 +1,5 @@
import { VESSEL_FOCUS_RADIUS_M } from './policy.js';
import { cameraOf } from '../../render/rendererOf.js';
import { cameraOf, findCamera } from '../../render/rendererOf.js';
import { clone, distance } from '../../geo/index.js';
export function createFocus({ state: layerState, services, parts, source }) {
@@ -113,7 +113,7 @@ export function createFocus({ state: layerState, services, parts, source }) {
function closestToCurrentView(candidates) {
if (!Array.isArray(candidates) || !candidates.length) return null;
const cameraPosition = layerState.viewer?.camera?.positionWC;
const cameraPosition = findCamera(layerState.viewer)?.pose()?.position;
if (!cameraPosition)
return candidates.find((candidate) => candidate?.position) || null;
+23 -14
View File
@@ -1,4 +1,4 @@
import { cameraPoseSignature } from '../../data/iconOrientation.js';
import { findCamera, findFrame } from '../../render/rendererOf.js';
export function createLifecycle({
state: layerState,
@@ -9,16 +9,22 @@ export function createLifecycle({
const { holdContinuousRender, releaseContinuousRender } = services.render;
/**
* Quantized camera-pose signature, or '' when the camera cannot report a full
* pose yet. An unknown pose reads as PARKED, so a camera that is still coming
* up can never be mistaken for continuous movement.
* @param {Cesium.Camera|null|undefined} camera
* Quantized camera-pose signature (position to ~10 m, angles to ~0.06
* degrees), or '' when the camera cannot report a full pose yet. An unknown
* pose reads as PARKED, so a camera that is still coming up can never be
* mistaken for continuous movement.
* @param {object|null|undefined} viewer
* @returns {string}
*/
function cameraMotionSignature(camera) {
if (!camera?.positionWC || !Number.isFinite(camera.heading)) return '';
return cameraPoseSignature(camera);
function cameraMotionSignature(viewer) {
const pose = findCamera(viewer)?.pose();
const p = pose?.position;
if (!p || !Number.isFinite(pose.heading)) return '';
return (
`${Math.round(p.x / 10)}:${Math.round(p.y / 10)}:${Math.round(p.z / 10)}:` +
`${pose.heading.toFixed(3)}:${pose.pitch.toFixed(3)}:${pose.roll.toFixed(3)}`
);
}
/**
@@ -50,15 +56,17 @@ export function createLifecycle({
'gev:awareness-subject-cleared',
layerState.subjectClearListener,
);
layerState.preRenderRemover =
layerState.viewer.scene.preRender.addEventListener(() => {
layerState.preRenderRemover = findFrame(layerState.viewer)?.on(
'preRender',
() => {
if (!layerState.enabled) return;
const now = Date.now();
// "Did the camera move" uses the SAME quantized pose signature the fleet
// rotation pass gates on (iconOrientation.cameraPoseSignature) rather than
// "Did the camera move" uses the same quantization as the fleet
// rotation pass's iconOrientation.cameraPoseSignature (keep the two
// in step), read from the camera port's pose, rather than
// camera.changed, whose granularity is globally degraded by other layers
// mutating camera.percentageChanged.
const poseSig = cameraMotionSignature(layerState.viewer.camera);
const poseSig = cameraMotionSignature(layerState.viewer);
if (poseSig !== layerState.lastCameraPoseSig) {
layerState.lastCameraPoseSig = poseSig;
layerState.lastCameraPoseChangeMs = now;
@@ -86,7 +94,8 @@ export function createLifecycle({
} else {
parts.rendering.scheduleDirectionOverlayUpdate();
}
});
},
);
layerState.runtimeListenersAttached = true;
}