diff --git a/src/layers/launches/ingestion.test.mjs b/src/layers/launches/ingestion.test.mjs index bee7d99ce..f24082dcb 100644 --- a/src/layers/launches/ingestion.test.mjs +++ b/src/layers/launches/ingestion.test.mjs @@ -112,6 +112,17 @@ async function fixture({ legacySource = false } = {}) { destroyLaunchPadZonePrimitive: noop, }, rendering: { + // As the rendering part owns the entities' data source. + attach(target) { + state._dataSource = new Cesium.CustomDataSource('rocket-launches'); + state._dataSource.show = false; + target.dataSources.add(state._dataSource); + }, + detach(target) { + if (state._dataSource) + target.dataSources.remove(state._dataSource, true); + state._dataSource = null; + }, updateMissionFrame: noop, addLaunchEntity(record) { state._dataSource.entities.add({ diff --git a/src/layers/launches/lifecycle.js b/src/layers/launches/lifecycle.js index 449be72ee..2787d17de 100644 --- a/src/layers/launches/lifecycle.js +++ b/src/layers/launches/lifecycle.js @@ -1,4 +1,3 @@ -import * as Cesium from 'cesium'; import { isPointerFree } from '../../data/inputOwnership.js'; import { inputFor } from '../../input/dispatcher.js'; @@ -91,11 +90,15 @@ export function createLaunchHover({ const at = now(); const wait = HOVER_PICK_INTERVAL_MS - (at - lastPick); if (wait > 0) { - // Cesium reuses the movement object, so keep a copy of the position. - pendingPosition = Cesium.Cartesian2.clone( - movement.endPosition, - pendingPosition ?? undefined, - ); + // The input source may reuse the movement object, so keep a copy of + // the position. + const end = movement.endPosition; + if (end == null) pendingPosition = undefined; + else { + pendingPosition ??= { x: 0, y: 0 }; + pendingPosition.x = end.x; + pendingPosition.y = end.y; + } if (trailingTimer === null) trailingTimer = setTimer(trailing, wait); return; } @@ -127,9 +130,7 @@ export function createLifecycle({ layerState._enabled = false; parts.panel.createMissionPanel(); parts.overlays.createReplayVehicleOverlay(); - layerState._dataSource = new Cesium.CustomDataSource('rocket-launches'); - layerState._dataSource.show = false; - viewer.dataSources.add(layerState._dataSource); + parts.rendering.attach(viewer); layerState._count = 0; layerState._lastUpdate = null; layerState._stale = false; @@ -256,9 +257,7 @@ export function createLifecycle({ layerState._replayTracks.clear(); parts.panel.clearMissionPanel(); layerState._viewer = null; - if (layerState._dataSource) - viewer.dataSources.remove(layerState._dataSource, true); - layerState._dataSource = null; + parts.rendering.detach(viewer); layerState._count = 0; layerState._orbitMatches = 0; layerState._lastUpdate = null; diff --git a/src/layers/launches/rendering.js b/src/layers/launches/rendering.js index 2aa1dc627..9a6d10f63 100644 --- a/src/layers/launches/rendering.js +++ b/src/layers/launches/rendering.js @@ -37,6 +37,24 @@ export function createRendering({ if (current !== next) graphic.show = next; } + /** + * The layer's entities, hidden until enabled. They stay entities: the + * replay vehicle and the live payload move every frame, the selected site + * is the viewer's selected entity, and the orbits draw with their own + * materials. + */ + function attach(viewer) { + layerState._dataSource = new Cesium.CustomDataSource('rocket-launches'); + layerState._dataSource.show = false; + viewer.dataSources.add(layerState._dataSource); + } + + function detach(viewer) { + if (layerState._dataSource) + viewer.dataSources.remove(layerState._dataSource, true); + layerState._dataSource = null; + } + /** Make a launch's site marker the viewer's selected entity, or none. */ function selectLaunchEntity(launchId) { const viewer = layerState._viewer; @@ -626,6 +644,8 @@ export function createRendering({ } } return { + attach, + detach, setGraphicVisibility, selectLaunchEntity, isolateMission, diff --git a/src/render/cesiumAllowList.json b/src/render/cesiumAllowList.json index e466120d6..0ec7db454 100644 --- a/src/render/cesiumAllowList.json +++ b/src/render/cesiumAllowList.json @@ -75,7 +75,6 @@ "src/layers/installations/namedMarkers.js", "src/layers/installations/rendering.js", "src/layers/launches/launchPad.js", - "src/layers/launches/lifecycle.js", "src/layers/launches/orbitRendering.js", "src/layers/launches/overlays.js", "src/layers/launches/rendering.js",