From b65a7aaed8e16c29108bfece126806b3cca92ccd Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 13 Nov 2026 18:47:30 +0400 Subject: [PATCH 1/4] Keep an explicit CCTV pick of the camera a move re-opened Until someone picks a camera, a settled move re-opens CCTV on the camera nearest the view and keeps the opening pick provisional. setActiveCamera ends that opening pick, but for a camera that is already active and activated it returns UNCHANGED before clearing the flag. So pressing NEAREST on the camera a move had just re-opened (or selecting it from the list, or through setParams) left the pick provisional, and the landing of NEAREST's own flight, or the next pan, switched to another camera. Clear the provisional flag on the UNCHANGED path too. reopenNearestCamera only activates a different camera, so it is unaffected, and the same-camera re-select still skips the activation work. --- src/data/cctvExplicitPickEndsOpening.test.mjs | 129 ++++++++++++++++++ src/layers/cctv/selection.js | 3 + 2 files changed, 132 insertions(+) create mode 100644 src/data/cctvExplicitPickEndsOpening.test.mjs diff --git a/src/data/cctvExplicitPickEndsOpening.test.mjs b/src/data/cctvExplicitPickEndsOpening.test.mjs new file mode 100644 index 0000000000..cfe6498880 --- /dev/null +++ b/src/data/cctvExplicitPickEndsOpening.test.mjs @@ -0,0 +1,129 @@ +// An explicit pick of the camera that a settled move just re-opened must end +// the opening pick. That pick goes through setActiveCamera's UNCHANGED path +// (same camera, already activated); if that path keeps the provisional flag, +// the next settled move (a pan, or the landing of NEAREST's own flight) +// switches the camera away from the one the user chose. +import assert from 'node:assert/strict'; +import test from 'node:test'; +import * as Cesium from 'cesium'; +import cctvLayer, { + _setCctvCoverageStateForTest, + _setCctvOverlayHostForTest, + reopenNearestCamera, +} from './cctv.js'; + +const BASE = { + headingDeg: 41, + pitchDeg: -5, + fovDeg: 56, + rangeM: 210, + mountHeightM: 100, + groundElevationM: 0, + city: 'London', +}; + +function record(id, lat, lon) { + return { + camera: { ...BASE, id, name: `Camera ${id}`, lat, lon }, + coverageEntities: [], + projection: null, + activationDone: true, + groundResolved: {}, + groundSamples: {}, + groundPrior: 0, + frustumGeometry: null, + frustumPositions: null, + probeClampRangeM: null, + position: Cesium.Cartesian3.fromDegrees(lon, lat, 100), + }; +} + +function viewerAt(lat, lon) { + return { + entities: new Cesium.EntityCollection(), + 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() {}, + }, + scene: { + canvas: { clientWidth: 1200, clientHeight: 800 }, + cartesianToCanvasCoordinates: () => undefined, + primitives: { add: (p) => p, remove: () => true }, + requestRender() {}, + }, + }; +} + +function moveViewer(viewer, lat, lon) { + viewer.camera.positionCartographic = Cesium.Cartographic.fromDegrees( + lon, + lat, + 300, + ); +} + +function withReopenedLayer(fn) { + _setCctvOverlayHostForTest({ + setEntries() {}, + setVisible() {}, + clearSource() {}, + }); + // Activation builds the projection canvas and frame image. + const originalDocument = globalThis.document; + const originalImage = globalThis.Image; + globalThis.document = { createElement: () => ({ getContext: () => null }) }; + globalThis.Image = class {}; + try { + const trafalgar = record('a-trafalgar', 51.508, -0.128); + const cambridge = record('b-cambridge', 51.513, -0.129); + // enable() assigned the opening camera without activating it. + trafalgar.activationDone = false; + const viewer = viewerAt(51.5081, -0.1281); + _setCctvCoverageStateForTest({ + viewer, + records: [trafalgar, cambridge], + activeCameraId: 'a-trafalgar', + enabled: true, + openingCameraProvisional: true, + }); + // A settled move next to Cambridge Circus re-opens there, still as the + // opening pick. + moveViewer(viewer, 51.5131, -0.1291); + assert.equal(reopenNearestCamera(), true); + assert.equal(cctvLayer.getUIState().activeCameraId, 'b-cambridge'); + fn(viewer); + } finally { + globalThis.document = originalDocument; + globalThis.Image = originalImage; + _setCctvOverlayHostForTest(); + _setCctvCoverageStateForTest({ enabled: false }); + } +} + +for (const [name, pick] of [ + ['NEAREST (focusNearest)', () => cctvLayer.focusNearest({ focus: false })], + ['selectCamera', () => cctvLayer.selectCamera('b-cambridge')], + [ + 'setParams({ selectedCameraId })', + () => cctvLayer.setParams({ selectedCameraId: 'b-cambridge' }), + ], +]) { + test(`an explicit ${name} pick of the re-opened camera ends the opening pick`, () => { + withReopenedLayer((viewer) => { + pick(); + assert.equal(cctvLayer.getUIState().activeCameraId, 'b-cambridge'); + // 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); + assert.equal(reopenNearestCamera(), false); + assert.equal(cctvLayer.getUIState().activeCameraId, 'b-cambridge'); + }); + }); +} diff --git a/src/layers/cctv/selection.js b/src/layers/cctv/selection.js index 834b2f583c..1a5c1c1613 100644 --- a/src/layers/cctv/selection.js +++ b/src/layers/cctv/selection.js @@ -79,6 +79,9 @@ export function createSelection({ record, ) ) { + // Picking the camera a settled move re-opened is still a choice: later + // settled moves must leave it alone. + 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)) { From 707a6a664a97e0f61304d13775747b7796171042 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 13 Nov 2026 18:52:37 +0400 Subject: [PATCH 2/4] Changelog fragment for #1702 --- changelog.d/1702-cctv-nearest-same-camera.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog.d/1702-cctv-nearest-same-camera.md diff --git a/changelog.d/1702-cctv-nearest-same-camera.md b/changelog.d/1702-cctv-nearest-same-camera.md new file mode 100644 index 0000000000..63833e6ca6 --- /dev/null +++ b/changelog.d/1702-cctv-nearest-same-camera.md @@ -0,0 +1,4 @@ +- 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). From a6eecee1570f9d31468d3485096c3a7c14ffea91 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 20 Nov 2026 01:10:42 +0400 Subject: [PATCH 3/4] Let the camera picker pick the opening CCTV camera The picker preselected the active camera, and a native select fires no change for the option it already shows. So while CCTV was still following the view, choosing the camera the picker showed did nothing, and the next pan switched to another camera. The layer now reports whether the active camera is the opening one (activeCameraProvisional). While it is, the picker shows that camera from a hidden, disabled first option, so choosing it from the list is a change and ends automatic selection; closing the list keeps it. A same-camera pick that ends the opening pick notifies listeners so the picker drops the hidden option, and reopenNearestCamera passes { opening: true } so its own notification already carries the opening state. docs/CURRENT-STATE.md now says when automatic selection ends. Tests cover the hidden option, confirming and dismissing the picker before a pan, the notification, and focusNearestToPoint, which is now on main. --- changelog.d/1702-cctv-nearest-same-camera.md | 3 +- docs/CURRENT-STATE.md | 12 + src/data/cctvExplicitPickEndsOpening.test.mjs | 37 ++-- src/layers/cctv/navigation.js | 5 +- src/layers/cctv/presentation.js | 4 + src/layers/cctv/selection.js | 14 +- src/layers/cctv/selection.test.mjs | 13 ++ src/ui/cctv/CctvPicker.vue | 11 +- src/ui/cctvPicker.test.mjs | 24 ++ src/ui/cctvPickerOpening.test.mjs | 205 ++++++++++++++++++ src/ui/cctvPresentation.js | 12 +- src/ui/stores/cctv.js | 5 +- 12 files changed, 315 insertions(+), 30 deletions(-) create mode 100644 src/ui/cctvPickerOpening.test.mjs 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 };