From 045267c841ce66fe6369b380755216cd0abfb695 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 7 Nov 2026 00:42:41 -0800 Subject: [PATCH] Keep the radio layer's Cesium entities and picks in its rendering part The radio interaction, selection and navigation parts had left the Cesium allow-list but still read pick objects, toggled entity visibility, removed the selection entity, re-ran clustering and read the Cesium camera. Navigation now reads the camera port's pose; the rest moves into the rendering part. --- src/data/radio.test.mjs | 10 ++++- src/layers/radio/index.js | 2 +- src/layers/radio/interaction.js | 34 ++-------------- src/layers/radio/interaction.test.mjs | 3 +- src/layers/radio/navigation.js | 4 +- src/layers/radio/rendering.js | 58 +++++++++++++++++++++++++++ src/layers/radio/selection.js | 17 +------- 7 files changed, 76 insertions(+), 52 deletions(-) diff --git a/src/data/radio.test.mjs b/src/data/radio.test.mjs index 9bf345e0b..46f238c4d 100644 --- a/src/data/radio.test.mjs +++ b/src/data/radio.test.mjs @@ -1,6 +1,10 @@ import assert from 'node:assert/strict'; import test from 'node:test'; -import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs'; +import { + bindFakeCesiumCamera, + fakeCameraPort, +} from '../testSupport/fakeCameraPort.mjs'; +import { bindRenderer } from '../render/rendererOf.js'; import { buildRadioTunerBand, buildRadioTunerTicks, @@ -1652,8 +1656,10 @@ test('Radio recovery preserves closer altitude and caps extreme full-globe zoom' }); test('Radio camera navigation yields to every live tracked-entity owner', () => { - const viewer = { camera: {} }; + const viewer = {}; + bindRenderer(viewer, { camera: fakeCameraPort().port }); assert.equal(radioCameraNavigationAllowed(viewer), true); + assert.equal(radioCameraNavigationAllowed({}), false, 'no camera to move'); for (const trackedId of ['flights:abc123', 'military:def456']) { const trackedEntity = withEntityRecord({}, { trackedId }); viewer.trackedEntity = trackedEntity; diff --git a/src/layers/radio/index.js b/src/layers/radio/index.js index fa84e1054..46736aeef 100644 --- a/src/layers/radio/index.js +++ b/src/layers/radio/index.js @@ -76,7 +76,7 @@ export function createRadioLayer({ services, source }) { rankRadioStationsForRequest: parts.queries.rankRadioStationsForRequest, radioViewIsGlobal: parts.navigation.radioViewIsGlobal, radioRequestIsCurrent: parts.model.radioRequestIsCurrent, - radioStationIdFromPick: parts.interaction.radioStationIdFromPick, + radioStationIdFromPick: parts.rendering.radioStationIdFromPick, radioStationCameraPlan: parts.navigation.radioStationCameraPlan, radioGlobeNeedsRecentering: parts.navigation.radioGlobeNeedsRecentering, radioGlobeRecenterHeight: parts.navigation.radioGlobeRecenterHeight, diff --git a/src/layers/radio/interaction.js b/src/layers/radio/interaction.js index c11a1e94c..caa3165da 100644 --- a/src/layers/radio/interaction.js +++ b/src/layers/radio/interaction.js @@ -20,31 +20,6 @@ export function createInteraction({ } = services.picking; const { setOverlaySourceVisible } = services.overlays; - /** Resolve a station id from ordinary, selected, or Cesium cluster pick shapes. */ - - function radioStationIdFromPick(picked) { - const pending = [picked?.id, picked?.primitive?.id]; - const seen = new Set(); - while (pending.length) { - const value = pending.shift(); - if (typeof value === 'string' || typeof value === 'number') { - const id = String(value); - if (id.startsWith(`${RADIO_PREFIX}selected:`)) - return id.slice(`${RADIO_PREFIX}selected:`.length); - if (id.startsWith(RADIO_PREFIX)) return id.slice(RADIO_PREFIX.length); - continue; - } - if (!value || typeof value !== 'object' || seen.has(value)) continue; - seen.add(value); - if (Array.isArray(value)) pending.push(...value); - else { - pending.push(value.id); - if (value.primitive) pending.push(value.primitive.id); - } - } - return null; - } - /** * The station under a click: the pick itself, then one drill through a * window around it, which also catches a near miss. Both passes are the @@ -56,7 +31,7 @@ export function createInteraction({ if (!event) return null; const stationFromPick = (picked) => { - const stationId = radioStationIdFromPick(picked); + const stationId = parts.rendering.radioStationIdFromPick(picked); return stationId && layerState._stationById.has(stationId) ? stationId : null; @@ -90,7 +65,7 @@ export function createInteraction({ function syncRadioLifecyclePresentation() { const visible = radioPresentationAllowed(); - if (layerState._dataSource) layerState._dataSource.show = visible; + parts.rendering.setStationsShown(visible); setOverlaySourceVisible(RADIO_OVERLAY_SOURCE_ID, visible); if (visible) { installInteraction(); @@ -99,9 +74,7 @@ export function createInteraction({ parts.rendering.scheduleRadioOverlayPublish(); } else { removeInteraction(); - if (layerState._selectedEntity && layerState._viewer) - layerState._viewer.entities.remove(layerState._selectedEntity); - layerState._selectedEntity = null; + parts.rendering.removeSelectionEntity(); } } @@ -142,7 +115,6 @@ export function createInteraction({ layerState._horizonTimer = null; } return { - radioStationIdFromPick, pickedRadioStationAt, radioPresentationAllowed, syncRadioLifecyclePresentation, diff --git a/src/layers/radio/interaction.test.mjs b/src/layers/radio/interaction.test.mjs index cac4e5292..81ef6778f 100644 --- a/src/layers/radio/interaction.test.mjs +++ b/src/layers/radio/interaction.test.mjs @@ -2,6 +2,7 @@ import test from 'node:test'; import assert from 'node:assert/strict'; import { createInteraction } from './interaction.js'; import { RADIO_PICK_WINDOW_PX } from './policy.js'; +import { radioStationIdFromPick } from './rendering.js'; function interaction() { const state = { _stationById: new Map([['kexp', {}]]) }; @@ -16,7 +17,7 @@ function interaction() { }, overlays: { setOverlaySourceVisible() {} }, }, - parts: {}, + parts: { rendering: { radioStationIdFromPick } }, }); } diff --git a/src/layers/radio/navigation.js b/src/layers/radio/navigation.js index 6aa8ac485..7015cf6ab 100644 --- a/src/layers/radio/navigation.js +++ b/src/layers/radio/navigation.js @@ -152,11 +152,11 @@ export function createNavigation({ /** Radio may move the globe only while no tracked entity owns the follow camera. */ function radioCameraNavigationAllowed(viewer = layerState._viewer) { - return Boolean(viewer?.camera) && !isFollowing(viewer); + return Boolean(findCamera(viewer)) && !isFollowing(viewer); } function radioGlobeRecenterPlan(viewer = layerState._viewer) { - const pose = viewer?.camera ? findCamera(viewer)?.pose() : null; + const pose = findCamera(viewer)?.pose() ?? null; const canvas = viewer?.scene?.canvas; const width = canvas?.clientWidth || canvas?.width; const height = canvas?.clientHeight || canvas?.height; diff --git a/src/layers/radio/rendering.js b/src/layers/radio/rendering.js index bd82dba3d..9f8613ff9 100644 --- a/src/layers/radio/rendering.js +++ b/src/layers/radio/rendering.js @@ -12,6 +12,34 @@ import { DEFAULT_RADIO_FILTER, } from './policy.js'; +/** + * A station id from ordinary, selected, or Cesium cluster pick shapes. + * @param {object|null|undefined} picked A scene pick result. + * @returns {string|null} + */ +export function radioStationIdFromPick(picked) { + const pending = [picked?.id, picked?.primitive?.id]; + const seen = new Set(); + while (pending.length) { + const value = pending.shift(); + if (typeof value === 'string' || typeof value === 'number') { + const id = String(value); + if (id.startsWith(`${RADIO_PREFIX}selected:`)) + return id.slice(`${RADIO_PREFIX}selected:`.length); + if (id.startsWith(RADIO_PREFIX)) return id.slice(RADIO_PREFIX.length); + continue; + } + if (!value || typeof value !== 'object' || seen.has(value)) continue; + seen.add(value); + if (Array.isArray(value)) pending.push(...value); + else { + pending.push(value.id); + if (value.primitive) pending.push(value.primitive.id); + } + } + return null; +} + export function createRendering({ state: layerState, services, @@ -395,7 +423,37 @@ export function createRendering({ scheduleRadioOverlayPublish(); }); } + /** Show or hide the stations' entities. */ + function setStationsShown(shown) { + if (layerState._dataSource) layerState._dataSource.show = shown; + } + + /** Remove the selected station's entity, if there is one. */ + function removeSelectionEntity() { + if (layerState._selectedEntity && layerState._viewer) + layerState._viewer.entities.remove(layerState._selectedEntity); + layerState._selectedEntity = null; + } + + /** + * Entity visibility changes do not invalidate Cesium's existing cluster + * primitives. Toggle a public clustering input twice to mark the current + * cluster set dirty without changing its effective configuration. + */ + function reclusterStations() { + if (!layerState._dataSource?.clustering?.enabled) return; + const clustering = layerState._dataSource.clustering; + const clusterPoints = clustering.clusterPoints; + clustering.clusterPoints = !clusterPoints; + clustering.clusterPoints = clusterPoints; + layerState._viewer?.scene?.requestRender(); + } + return { + radioStationIdFromPick, + setStationsShown, + removeSelectionEntity, + reclusterStations, markerPosition, updateSelectionEntity, clusterPointCollection, diff --git a/src/layers/radio/selection.js b/src/layers/radio/selection.js index 2b2ba282a..3b9338a83 100644 --- a/src/layers/radio/selection.js +++ b/src/layers/radio/selection.js @@ -57,12 +57,7 @@ export function createSelection({ } if (changed && parts.interaction.radioPresentationAllowed()) { parts.rendering.updateRenderVisibility(); - if (filterChanged && layerState._dataSource?.clustering?.enabled) { - const clusterPoints = layerState._dataSource.clustering.clusterPoints; - layerState._dataSource.clustering.clusterPoints = !clusterPoints; - layerState._dataSource.clustering.clusterPoints = clusterPoints; - layerState._viewer?.scene?.requestRender(); - } + if (filterChanged) parts.rendering.reclusterStations(); parts.rendering.scheduleRadioOverlayPublish(); } parts.presentation.emitState(); @@ -275,15 +270,7 @@ export function createSelection({ if (clearsCancelledPresentation) parts.rendering.updateSelectionEntity(); if (changed) parts.clustering.resetRadioClusterOverlayIdentities(); parts.rendering.updateRenderVisibility(); - if (changed && layerState._dataSource?.clustering?.enabled) { - // Entity visibility changes do not invalidate Cesium's existing cluster - // primitives. Toggle a public clustering input twice to mark the current - // cluster set dirty without changing its effective configuration. - const clusterPoints = layerState._dataSource.clustering.clusterPoints; - layerState._dataSource.clustering.clusterPoints = !clusterPoints; - layerState._dataSource.clustering.clusterPoints = clusterPoints; - layerState._viewer?.scene?.requestRender(); - } + if (changed) parts.rendering.reclusterStations(); parts.rendering.scheduleRadioOverlayPublish(); parts.presentation.emitState(); return true;