Keep the radio layer's data source in its rendering part, and take the radio lifecycle off the Cesium list

The radio lifecycle no longer makes, shows, hides or removes the stations'
Cesium data source or the selected station's entity itself: the rendering
part does, through installDataSource, setStationsShown,
removeSelectionEntity and removeDataSource, in the same order as before.
The camera factory import moves to the rendering part too, which stays on
the list. The lifecycle no longer imports Cesium or drives the viewer, so
it leaves the allow-list.
This commit is contained in:
Sameh Khamis committed 2026-11-07 04:35:50 -08:00
1 parent 436b110547
commit 35021d9f10
5 files changed
+135 -21

No files matched your search

+6 -20
View File
@@ -1,7 +1,3 @@
import * as Cesium from 'cesium';
// The Cesium camera factory: given a viewer of a caller's own, with no
// renderer bound, the layer's flights and camera reads find a camera port.
import '../../render/cesium/camera.js';
import {
RADIO_OVERLAY_SOURCE_ID,
DEFAULT_RADIO_VOLUME,
@@ -18,18 +14,14 @@ export function createLifecycle({
const { clearOverlaySource, setOverlaySourceVisible } = services.overlays;
const methods = {
/** Initialize the Cesium data source and the single audio element. */
/** Initialize the stations' rendering and the single audio element. */
init(viewer) {
layerState._sessionGeneration += 1;
layerState._viewer = viewer;
parts.clustering.resetRadioClusterOverlayIdentities();
parts.playback.installAudio();
if (!layerState._dataSource) {
layerState._dataSource = new Cesium.CustomDataSource('Radio stations');
viewer.dataSources.add(layerState._dataSource);
parts.rendering.installClusterStyling();
}
layerState._dataSource.show = false;
parts.rendering.installDataSource(viewer);
parts.rendering.setStationsShown(false);
clearOverlaySource(RADIO_OVERLAY_SOURCE_ID);
setOverlaySourceVisible(RADIO_OVERLAY_SOURCE_ID, false);
},
@@ -58,10 +50,8 @@ export function createLifecycle({
layerState._cancelledTuningPresentationStation = null;
layerState._tuningUnavailableStationId = null;
parts.playback.stopRadioPlayback({ origin: 'layer-disable' });
if (layerState._dataSource) layerState._dataSource.show = false;
if (layerState._selectedEntity && layerState._viewer)
layerState._viewer.entities.remove(layerState._selectedEntity);
layerState._selectedEntity = null;
parts.rendering.setStationsShown(false);
parts.rendering.removeSelectionEntity();
if (layerState._overlayPublishTimer)
clearTimeout(layerState._overlayPublishTimer);
layerState._overlayPublishTimer = null;
@@ -86,11 +76,7 @@ export function createLifecycle({
if (layerState._audio) layerState._audio.volume = DEFAULT_RADIO_VOLUME;
layerState._audio = null;
layerState._userVolume = DEFAULT_RADIO_VOLUME;
layerState._removeClusterListener?.();
layerState._removeClusterListener = null;
if (layerState._dataSource && layerState._viewer)
layerState._viewer.dataSources.remove(layerState._dataSource, true);
layerState._dataSource = null;
parts.rendering.removeDataSource();
clearOverlaySource(RADIO_OVERLAY_SOURCE_ID);
layerState._stations = [];
layerState._acceptedCatalogSnapshot = EMPTY_ACCEPTED_CATALOG_SNAPSHOT;
+103
View File
@@ -0,0 +1,103 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { createLifecycle } from './lifecycle.js';
import { createRendering } from './rendering.js';
import { createState } from './state.js';
const overlays = () => ({
clearOverlaySource() {},
setOverlaySourceVisible() {},
setOverlayEntries() {},
});
/** A viewer whose data sources and entities record what was done to them. */
function recordingViewer() {
const calls = [];
return {
calls,
dataSources: {
add: (source) => calls.push(['add', source]),
remove: (source, destroy) => calls.push(['remove', source, destroy]),
},
entities: { remove: (entity) => calls.push(['removeEntity', entity]) },
scene: { requestRender() {} },
};
}
test('the stations data source is added once, clustered, and removed with its listener', () => {
const services = {
ground: { cachedGroundFloor: () => null },
overlays: overlays(),
render: { governorRequestRender() {} },
};
const state = createState({ services });
const rendering = createRendering({ state, services, parts: {} });
const viewer = recordingViewer();
state._viewer = viewer;
rendering.installDataSource(viewer);
const source = state._dataSource;
assert.ok(source, 'a data source is made');
assert.equal(source.name, 'Radio stations');
assert.equal(source.clustering.enabled, true);
assert.equal(typeof state._removeClusterListener, 'function');
rendering.installDataSource(viewer);
assert.deepEqual(viewer.calls, [['add', source]], 'added once');
rendering.setStationsShown(false);
assert.equal(source.show, false);
rendering.removeDataSource();
assert.deepEqual(viewer.calls.at(-1), ['remove', source, true]);
assert.equal(state._dataSource, null);
assert.equal(state._removeClusterListener, null);
assert.equal(source.clustering.clusterEvent.numberOfListeners, 0);
});
test('the lifecycle leaves the Cesium data source and entities to the rendering part', () => {
const services = { overlays: overlays() };
const state = createState({ services });
const done = [];
const record =
(name) =>
(...args) =>
done.push([name, ...args]);
const parts = {
clustering: {
resetRadioClusterOverlayIdentities() {},
emptyRadioOverlayDiagnostics: () => ({}),
},
playback: { installAudio() {}, stopRadioPlayback() {} },
rendering: {
installDataSource: record('installDataSource'),
setStationsShown: record('setStationsShown'),
removeSelectionEntity: record('removeSelectionEntity'),
removeDataSource: record('removeDataSource'),
},
interaction: {
syncRadioLifecyclePresentation() {},
removeInteraction() {},
},
presentation: { emitState() {} },
navigation: { invalidateRadioCameraNavigation() {} },
tuning: { endRadioTuning() {} },
volume: { cancelRadioVolumeTransition() {} },
};
const { methods } = createLifecycle({ state, services, parts });
const viewer = recordingViewer();
methods.init(viewer);
assert.deepEqual(done, [
['installDataSource', viewer],
['setStationsShown', false],
]);
done.length = 0;
methods.destroy();
assert.deepEqual(done, [
['setStationsShown', false],
['removeSelectionEntity'],
['removeDataSource'],
]);
assert.deepEqual(viewer.calls, [], 'the lifecycle drives no viewer itself');
assert.equal(state._viewer, null);
});
+25
View File
@@ -1,4 +1,7 @@
import * as Cesium from 'cesium';
// The Cesium camera factory: given a viewer of a caller's own, with no
// renderer bound, the layer's flights and camera reads find a camera port.
import '../../render/cesium/camera.js';
import { clusterPointCollection as clusterPointsOf } from '../../render/cesium/internals.js';
import { horizonOccluder } from '../../data/iconOrientation.js';
import {
@@ -423,6 +426,26 @@ export function createRendering({
scheduleRadioOverlayPublish();
});
}
/**
* Add the stations' data source to the viewer, once, with its clustering.
* @param {object} viewer
*/
function installDataSource(viewer) {
if (layerState._dataSource) return;
layerState._dataSource = new Cesium.CustomDataSource('Radio stations');
viewer.dataSources.add(layerState._dataSource);
installClusterStyling();
}
/** Stop styling clusters and take the data source off the viewer. */
function removeDataSource() {
layerState._removeClusterListener?.();
layerState._removeClusterListener = null;
if (layerState._dataSource && layerState._viewer)
layerState._viewer.dataSources.remove(layerState._dataSource, true);
layerState._dataSource = null;
}
/** Show or hide the stations' entities. */
function setStationsShown(shown) {
if (layerState._dataSource) layerState._dataSource.show = shown;
@@ -451,6 +474,8 @@ export function createRendering({
return {
radioStationIdFromPick,
installDataSource,
removeDataSource,
setStationsShown,
removeSelectionEntity,
reclusterStations,
-1
View File
@@ -62,7 +62,6 @@
"src/layers/military/state.js",
"src/layers/military/testing.js",
"src/layers/military/tracking.js",
"src/layers/radio/lifecycle.js",
"src/layers/radio/rendering.js",
"src/layers/recentImagery/rendering.js",
"src/layers/satellites/rendering.js",