diff --git a/changelog.d/1702-cctv-nearest-same-camera.md b/changelog.d/1702-cctv-nearest-same-camera.md index 63833e6ca6..660f59c589 100644 --- a/changelog.d/1702-cctv-nearest-same-camera.md +++ b/changelog.d/1702-cctv-nearest-same-camera.md @@ -1,4 +1,5 @@ - Keep the CCTV camera picked with NEAREST, from the camera list or by a scene when it is the camera the view just moved to. The pick did not stick: NEAREST's own flight, or the next pan, switched to another camera, so the - panel showed a camera nobody had picked (gekh, #1702). + panel showed a camera nobody had picked. Choosing the camera the list already + shows now counts as a pick too (gekh, #1702). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 51dd971fe0..96484b78b8 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -2000,6 +2000,18 @@ The view pass reruns while the camera moves, paced by its own cost. The camera picker lists the cameras in view, active camera first, and closes with the count of cameras outside the view. +Turning CCTV on opens on the camera nearest the view. Until someone picks a +camera, each settled move, such as a shared view's flight landing, moves it to +the camera then nearest the view. Automatic selection ends at the first pick: +NEAREST, PREV or NEXT, a camera chosen in the picker, a click on a camera, a +click on empty ground that deselects, an auto-hop step, or a call to +`selectCamera`, `focusNearest`, `focusNearestToPoint` or +`setParams({ selectedCameraId })`, which voice and scenes use. Picking the +camera that is already active counts. While the camera is the automatic one, +the picker shows it from a hidden first option, so choosing that camera from +the list is a change and ends automatic selection; closing the list without a +choice keeps it. + Traffic owns its rendered-surface observer only while enabled, removes it on disable/destroy, and rebuilds no cached heights on frames where the surface identity is unchanged. Its dots and heat-lines are two renderer draw sets, it animates on the frame port's preRender, and it follows the camera through the camera port at its own 5% threshold rather than the shared `percentageChanged` ledger. The surface identity is the globe port's `surfaceVersion()` and tile readiness its `isSettled('surface')`, so the layer no longer reaches Cesium. Heat-lines are always asked for draped: where the Cesium renderer cannot drape (no depth textures) its draw port draws them (and every other draped line) over the surface, in their colour where the surface hides them and hidden past the horizon, recolouring a line in place when only its colour changes, rather than the layer dropping them. Traffic and bikeshare expose factories through `./layers/traffic` and diff --git a/src/data/cctvExplicitPickEndsOpening.test.mjs b/src/data/cctvExplicitPickEndsOpening.test.mjs index cfe6498880..fdb207e4c9 100644 --- a/src/data/cctvExplicitPickEndsOpening.test.mjs +++ b/src/data/cctvExplicitPickEndsOpening.test.mjs @@ -11,6 +11,7 @@ import cctvLayer, { _setCctvOverlayHostForTest, reopenNearestCamera, } from './cctv.js'; +import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs'; const BASE = { headingDeg: 41, @@ -39,19 +40,9 @@ function record(id, lat, lon) { } function viewerAt(lat, lon) { - return { - entities: new Cesium.EntityCollection(), + const viewer = { isDestroyed: () => false, - trackedEntity: null, - camera: { - positionWC: Cesium.Cartesian3.fromDegrees(lon, lat, 300), - positionCartographic: Cesium.Cartographic.fromDegrees(lon, lat, 300), - heading: 0.4, - pitch: -0.7, - roll: 0, - transform: Cesium.Matrix4.clone(Cesium.Matrix4.IDENTITY), - flyToBoundingSphere() {}, - }, + eye: { lat, lon, height: 300 }, scene: { canvas: { clientWidth: 1200, clientHeight: 800 }, cartesianToCanvasCoordinates: () => undefined, @@ -59,14 +50,20 @@ function viewerAt(lat, lon) { requestRender() {}, }, }; + // The layer reads the eye and flies through the renderer's camera port. + viewer.draw = bindFakeDraw(viewer, { + camera: { + pose: () => ({ ...viewer.eye }), + on: () => () => {}, + followed: null, + flyToBounds() {}, + }, + }).draw; + return viewer; } function moveViewer(viewer, lat, lon) { - viewer.camera.positionCartographic = Cesium.Cartographic.fromDegrees( - lon, - lat, - 300, - ); + viewer.eye = { lat, lon, height: 300 }; } function withReopenedLayer(fn) { @@ -98,6 +95,7 @@ function withReopenedLayer(fn) { moveViewer(viewer, 51.5131, -0.1291); assert.equal(reopenNearestCamera(), true); assert.equal(cctvLayer.getUIState().activeCameraId, 'b-cambridge'); + assert.equal(cctvLayer.getUIState().activeCameraProvisional, true); fn(viewer); } finally { globalThis.document = originalDocument; @@ -114,11 +112,16 @@ for (const [name, pick] of [ 'setParams({ selectedCameraId })', () => cctvLayer.setParams({ selectedCameraId: 'b-cambridge' }), ], + [ + 'focusNearestToPoint', + () => cctvLayer.focusNearestToPoint(51.513, -0.129, { focus: false }), + ], ]) { test(`an explicit ${name} pick of the re-opened camera ends the opening pick`, () => { withReopenedLayer((viewer) => { pick(); assert.equal(cctvLayer.getUIState().activeCameraId, 'b-cambridge'); + assert.equal(cctvLayer.getUIState().activeCameraProvisional, false); // A later settled move (a pan, or the landing of the pick's own flight) // leaves the explicit choice alone. moveViewer(viewer, 51.5081, -0.1281); diff --git a/src/layers/cctv/navigation.js b/src/layers/cctv/navigation.js index 6b2ba96aaf..7f99142839 100644 --- a/src/layers/cctv/navigation.js +++ b/src/layers/cctv/navigation.js @@ -73,9 +73,8 @@ export function createNavigation({ return false; const nearest = nearestCameraIdToViewer(); if (!nearest || nearest === layerState._activeCameraId) return false; - parts.selection.setActiveCamera(nearest); - // setActiveCamera ends the opening pick; this is still that pick. - layerState._openingCameraProvisional = true; + // Still the opening pick: its notification tells the picker so. + parts.selection.setActiveCamera(nearest, { opening: true }); return true; } diff --git a/src/layers/cctv/presentation.js b/src/layers/cctv/presentation.js index f23c007334..cc398ea5f1 100644 --- a/src/layers/cctv/presentation.js +++ b/src/layers/cctv/presentation.js @@ -286,6 +286,10 @@ export function createPresentation({ hoverId: layerState._hoverCardId, }, activeCameraId: activeId, + // The camera CCTV opened on, following the view until someone picks one. + activeCameraProvisional: Boolean( + activeId && layerState._openingCameraProvisional, + ), activeCameraReselection: layerState._activeCameraReselection, activeCamera: active ? getPublicCameraState(active, activeId) : null, cameraIndex: cameraIndex(), diff --git a/src/layers/cctv/selection.js b/src/layers/cctv/selection.js index 7ec4e90166..7e147834a3 100644 --- a/src/layers/cctv/selection.js +++ b/src/layers/cctv/selection.js @@ -49,10 +49,13 @@ export function createSelection({ * Sets the active camera by ID, initializes its projection runtime, refreshes * its frame, and updates styles. * @param {string} cameraId - ID of the camera to activate. + * @param {Object} [options] + * @param {boolean} [options.opening=false] - The opening camera following + * the view, not someone's pick: settled moves may still replace it. * @returns {'activated'|'unchanged'|'not-found'} Discriminated activation result. */ - function setActiveCamera(cameraId) { + function setActiveCamera(cameraId, { opening = false } = {}) { if (!cameraId || !layerState._recordById.has(cameraId)) return CCTV_ACTIVATION_RESULT.NOT_FOUND; const record = layerState._recordById.get(cameraId); @@ -71,19 +74,22 @@ export function createSelection({ ) ) { // Picking the camera a settled move re-opened is still a choice: later - // settled moves must leave it alone. - layerState._openingCameraProvisional = false; + // settled moves must leave it alone, and the picker learns it. + const endsOpening = layerState._openingCameraProvisional && !opening; + if (endsOpening) layerState._openingCameraProvisional = false; // Browser-only feeds have a separate player; a reselect retries it // without re-running activation or touching the projection geometry. if (parts.model.isBrowserOverlayCamera(record.camera)) { layerState._activeCameraReselection += 1; parts.presentation.notifyListeners(); + } else if (endsOpening) { + parts.presentation.notifyListeners(); } return CCTV_ACTIVATION_RESULT.UNCHANGED; } layerState._activeCameraId = cameraId; layerState._autoHopSuspended = false; - layerState._openingCameraProvisional = false; + layerState._openingCameraProvisional = opening; // A real activation creates projection work — wake the self-stopping loop. parts.projection.startProjectionLoop(); if (previousActiveRecord && previousActiveRecord !== record) { diff --git a/src/layers/cctv/selection.test.mjs b/src/layers/cctv/selection.test.mjs index 92ee536706..96be823b0a 100644 --- a/src/layers/cctv/selection.test.mjs +++ b/src/layers/cctv/selection.test.mjs @@ -52,3 +52,16 @@ test('same-camera selection notifies browser-overlay feeds so playback can retry assert.equal(fixture.state._activeCameraReselection, 1); assert.equal(fixture.notifications(), 1); }); + +test('same-camera selection ends the opening pick and tells the panel once', () => { + const fixture = makeSelection('tripcheck-odot'); + fixture.state._openingCameraProvisional = true; + + assert.equal( + fixture.selection.setActiveCamera('same-camera'), + CCTV_ACTIVATION_RESULT.UNCHANGED, + ); + assert.equal(fixture.state._openingCameraProvisional, false); + assert.equal(fixture.state._activeCameraReselection, 0); + assert.equal(fixture.notifications(), 1); +}); diff --git a/src/ui/cctv/CctvPicker.vue b/src/ui/cctv/CctvPicker.vue index a4b1a077cb..efe611e50b 100644 --- a/src/ui/cctv/CctvPicker.vue +++ b/src/ui/cctv/CctvPicker.vue @@ -5,7 +5,9 @@ import { useCctvStore } from '../stores/cctv.js'; // The camera picker: the cameras in view and a closing note for those the // view leaves out. It renders only when CctvControls publishes a picker, -// which re-applies the active camera, as on every layer notification. +// which re-applies the active camera, as on every layer notification. The +// opening camera, which follows the view until someone picks one, shows in a +// hidden first option: choosing that camera from the list is a change. const { picker } = storeToRefs(useCctvStore()); // The selection, applied once the options are in place. @@ -21,6 +23,13 @@ const vPick = { mounted: pick, updated: pick };