From ed6e21b6f37772fc60f8eb190c94e09dc18c75ce Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 7 Nov 2026 02:35:52 -0800 Subject: [PATCH] Ask the flight feed around the camera port's ground point, and take the flights controller off the Cesium list The flights controller reads the camera's longitude and latitude from the renderer's camera port instead of the Cesium camera, and asks for no area when the pose has no ground point or the viewer is gone. It no longer imports Cesium or reads the viewer's camera, so it leaves the allow-list. The flights entry already loads the Cesium camera factory for viewers with no renderer bound. --- scripts/format-scope.json | 1 + src/layers/flights/controller.js | 13 ++++----- src/layers/flights/controller.test.mjs | 38 ++++++++++++++++++++++++++ src/render/cesiumAllowList.json | 1 - 4 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 src/layers/flights/controller.test.mjs diff --git a/scripts/format-scope.json b/scripts/format-scope.json index 9989193d3..d0ff323e6 100644 --- a/scripts/format-scope.json +++ b/scripts/format-scope.json @@ -745,6 +745,7 @@ "src/layers/flights/snapshotRenderer.js", "src/layers/flights/records.test.mjs", "src/layers/flights/ingestion.test.mjs", + "src/layers/flights/controller.test.mjs", "src/layers/military/records.js", "src/layers/military/recordPolicy.js", "src/layers/military/snapshotRenderer.js", diff --git a/src/layers/flights/controller.js b/src/layers/flights/controller.js index c38ac9175..92e1343b2 100644 --- a/src/layers/flights/controller.js +++ b/src/layers/flights/controller.js @@ -1,4 +1,4 @@ -import * as Cesium from 'cesium'; +import { findCamera } from '../../render/rendererOf.js'; export function createController({ flightState, @@ -13,13 +13,12 @@ export function createController({ flightState.feed._activeUpdateControllers.clear(); } + /** The feed query around the camera's ground point, or {} with none. */ function _flightQuery(viewer) { - const cartographic = viewer?.camera?.positionCartographic; - return cartographic - ? { - latitude: Cesium.Math.toDegrees(cartographic.latitude), - longitude: Cesium.Math.toDegrees(cartographic.longitude), - } + const pose = viewer ? findCamera(viewer)?.pose() : null; + // An eye at the earth's centre has no ground point: the pose gives NaN. + return pose && Number.isFinite(pose.lat) && Number.isFinite(pose.lon) + ? { latitude: pose.lat, longitude: pose.lon } : {}; } return { _abortActiveUpdates, _flightQuery }; diff --git a/src/layers/flights/controller.test.mjs b/src/layers/flights/controller.test.mjs new file mode 100644 index 000000000..60f19ae4a --- /dev/null +++ b/src/layers/flights/controller.test.mjs @@ -0,0 +1,38 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { bindRenderer } from '../../render/rendererOf.js'; +import { createController } from './controller.js'; + +const controller = () => + createController({ flightState: { feed: {} }, parts: {}, layer: {} }); + +test('the feed is asked for the flights around the camera port’s ground point', () => { + let pose = { lon: -97.04, lat: 32.9, height: 9000 }; + const viewer = {}; + const unbind = bindRenderer(viewer, { camera: { pose: () => pose } }); + try { + const { _flightQuery } = controller(); + assert.deepEqual(_flightQuery(viewer), { + latitude: 32.9, + longitude: -97.04, + }); + pose = { lon: NaN, lat: NaN, height: NaN }; + assert.deepEqual(_flightQuery(viewer), {}, 'no ground point: no area'); + pose = { lon: -97.04, lat: NaN, height: 9000 }; + assert.deepEqual(_flightQuery(viewer), {}, 'half a ground point: none'); + } finally { + unbind(); + } +}); + +test('with no viewer or camera the query names no area', () => { + const { _flightQuery } = controller(); + assert.deepEqual(_flightQuery(null), {}); + assert.deepEqual(_flightQuery(undefined), {}); + assert.deepEqual(_flightQuery({}), {}, 'a viewer with no camera'); + assert.deepEqual( + _flightQuery({ isDestroyed: () => true, camera: {} }), + {}, + 'a destroyed viewer', + ); +}); diff --git a/src/render/cesiumAllowList.json b/src/render/cesiumAllowList.json index 94d45f3c7..d406cf17d 100644 --- a/src/render/cesiumAllowList.json +++ b/src/render/cesiumAllowList.json @@ -42,7 +42,6 @@ "src/layers/cctv/rendering.js", "src/layers/directions/index.js", "src/layers/firms/rendering.js", - "src/layers/flights/controller.js", "src/layers/flights/enrichment.js", "src/layers/flights/evidence.js", "src/layers/flights/icons.js",