mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
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.
This commit is contained in:
1 parent
a8f41d30fc
commit
045267c841
7 files changed
+76
-52
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 } },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user