From def87c4dc01f3bddf05de61c6c22ad8f951faf46 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 13 Nov 2026 18:45:37 +0400 Subject: [PATCH 1/5] Recent Imagery: drape the next ranked day when the automatic day is empty When the automatic day probes empty, pruneEmpty() hands it over to the next ranked day and follows that day until its probe answers. The thumbnail subscriber previews a followed day only while it is focused, but focus did not move with the hand-over: autoPreview() sets focus only when there is none, and reconcileFocus() moves focus off a hidden card to the nearest card, not to the next ranked day. With empty days shown, focus stayed on the empty day; with them hidden, it could land on an older neighbour. Either way the successor probed present and never reached the map. autoPreview() now takes the empty automatic day, and focus still on it moves to the successor. Focus the user moved elsewhere stays put. Two layer tests cover both cases; both fail without the change. --- docs/CURRENT-STATE.md | 2 +- src/layers/recentImagery/index.js | 15 +++++++++----- src/layers/recentImagery/index.test.mjs | 27 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 6073b5c842..1bf949836b 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -7274,7 +7274,7 @@ pins and share links already supply complete boxes. - The layer sits in the Data Layers panel's Cameras group beside Cameras (CCTV); Mapped ALPR Cameras moved to the Infrastructure group to make room. - DATA ▸ **Recent Imagery** (`recent-imagery`, `src/layers/recentImagery/`) lists the last 30 UTC days of imagery for a selected box and drapes the days you pick: HLS S30 (Sentinel-2) and L30 (Landsat 8/9) at 30 m, and the VIIRS NOAA-21 daily overview at 250 m. Keyless and browser-direct: NASA CMR for which days have HLS granules in the box (`catalog.js`, both collections concurrently, paged with `CMR-Search-After` up to 2,000 records each, `truncated` against CMR `hits`), GIBS WMTS for tiles, Worldview Snapshots for thumbnails and exports. Worldview's `Data-Present` header is the only availability signal: GIBS answers an empty tile with HTTP 200, and the JPEG overview would drape black, so a day confirmed empty never drapes. - **Box.** SELECT BOX (`src/ui/imageryBoxTool.js`) claims the pointer like Draw, borrows the stock click actions and freezes the camera only mid-drag; USE VIEW takes the camera rectangle; `boxFromPinAt` grows a 10 km box. Boxes must be ≤ 1,000 km a side, on one side of the dateline and inside the Web-Mercator limit (`validateBox`). A refusal (`boxError`, including the tool's own via `reportBoxRefusal`) stays at the top of the panel until a box succeeds; a view over the cap is refused with its size, never shrunk. An oversized box or view (`Box is … km wide · limit 1,000 km`, `View is … wide · …`) sets the hint to `Zoom in or draw a smaller box` and enables ZOOM IN: `zoomToFit()` flies top-down (1.2 s) to the refused box's centre, or the ground under the canvas centre for a view, at the height whose view is about 400 km wide for the canvas aspect and the camera's vertical FOV (`fitViewHeightM`, clamped 5–400 km), and returns that height. -- **Modes, pins and the preview.** The mode is explicit: `image` (one pinned day, slot `a`), `basemap` (that day on the left of a swipe, the basemap on the right: slot `a` splits LEFT and there is no second layer) and `ab` (day `a` left, day `b` right). `setAssignment(slot, key | null)` / `toggleAssignment(slot, key)` pin and unpin; a day is in one slot at most (pinning it in the other slot moves it) and an empty day cannot be pinned. `setMode()` keeps both pins; `b` only drapes in `ab`. While the mode's first empty slot exists the focused day previews in it: a click at once, arrow keys after 250 ms of quiet (`FOCUS_DEBOUNCE_MS`, one timer, last day wins); an unprobed day is followed and previews when its probe says present, an empty or unknown day never drapes and the previous preview stays. A pin change drops the preview until focus moves again, and unpinning takes that layer off at once. `rankLatest` picks START HERE coverage first (a present HLS day whose footprints cover the box, or have none, beats a newer sliver), then newest with all granules ≤ 20% known cloud, then newest; slivers only as `partial`; else the newest non-empty VIIRS day; it is focused and previewed after each search when nothing is pinned. Escape clears the preview (`clearPreview()`), then cancels the box tool, then blurs — with SELECT BOX armed too, through the tool's `onEscape` interceptor wired in `createApplicationTools`. Pins, mode, box and split changes made in the panel are published with `adoptLayerParams`, never while a share link is being applied. +- **Modes, pins and the preview.** The mode is explicit: `image` (one pinned day, slot `a`), `basemap` (that day on the left of a swipe, the basemap on the right: slot `a` splits LEFT and there is no second layer) and `ab` (day `a` left, day `b` right). `setAssignment(slot, key | null)` / `toggleAssignment(slot, key)` pin and unpin; a day is in one slot at most (pinning it in the other slot moves it) and an empty day cannot be pinned. `setMode()` keeps both pins; `b` only drapes in `ab`. While the mode's first empty slot exists the focused day previews in it: a click at once, arrow keys after 250 ms of quiet (`FOCUS_DEBOUNCE_MS`, one timer, last day wins); an unprobed day is followed and previews when its probe says present, an empty or unknown day never drapes and the previous preview stays. A pin change drops the preview until focus moves again, and unpinning takes that layer off at once. `rankLatest` picks START HERE coverage first (a present HLS day whose footprints cover the box, or have none, beats a newer sliver), then newest with all granules ≤ 20% known cloud, then newest; slivers only as `partial`; else the newest non-empty VIIRS day; it is focused and previewed after each search when nothing is pinned. When that day probes empty the next ranked day takes over, and focus still on the empty day moves with it, so the successor drapes once its probe says present. Escape clears the preview (`clearPreview()`), then cancels the box tool, then blurs — with SELECT BOX armed too, through the tool's `onEscape` interceptor wired in `createApplicationTools`. Pins, mode, box and split changes made in the panel are published with `adoptLayerParams`, never while a share link is being applied. - **Rendering.** `rendering.js` owns at most two GIBS layers on the host `src/maps/imageryHost.js` resolves: `viewer.imageryLayers` while the globe shows, the photoreal tileset's `imageryLayers` while it is hidden, or none (the panel says so). Layers are rebuilt on a new host, never re-parented. `MapSourceController.subscribe()` fires after every settled stack switch (silent switches and fallbacks included) and the layer rebinds on it. Tile requests pass a six-slot semaphore of our own (Cesium's global limits are untouched). Under `requestRenderMode` a deferred tile needs a later frame, but a deferral must never request one itself or a stalled tile keeps the scene rendering every frame: a request that finds the semaphore full asks for nothing (the settling request asks for one frame), and a tile Cesium itself deferred goes through one coalesced 250 ms retry. Thumbnails: three fetches at once, sixteen decoded images, least-recently-used where a `get` read is never a use; eviction keeps the probe result. The strip's visible window is probed around the focused card; the pinned and previewed days are probed wherever they sit, at the focused card's priority, so a pin restored or assigned off-screen still drapes. - **Esri surface and the swipe.** While any image is on the map (a preview included) the layer holds the map lease (`acquireImageryComparison`, owner `recent-imagery`, `esri-if-photoreal`): on Google 3D the map switches to Esri, because 30 m pixels over 3D buildings do not read, and Cesium's split only works on the globe. The lease is handed back, and Google 3D restored unless the operator changed maps meanwhile, when the last image leaves the map or the layer is disabled; the notice line says so while it holds. While a day is shown the imagery keeps Esri: a manual switch that lands on Google 3D is answered at once with a new lease under the same policy (`keepEsri`), the notice reads `Imagery stays on Esri · CLEAR to use Google 3D`, and the divider never suspends because of a map switch. It re-leases once per switch generation and only for a manual one (`MapSourceController#getSwitchOrigin()` is `manual` for an outside `setStack`, `automatic` for the controller's own fallback or recovery), never for the lease's own switch and never while releasing, so CLEAR and disable still return to Google 3D; a lease another owner holds stays refused. When Esri fails and the controller falls back to Google 3D on its own, the layer lets the lease go without restoring anything, both days drape on the tileset without a swipe and the guidance reads `Esri map unavailable · no swipe`; only the next manual switch to Google 3D takes Esri again, so a failing Esri map is never retried in a loop. Switching between globe stacks (Esri, OSM, Bing) only rebinds. On a tileset host both images drape without a swipe. The split control (`createImagerySplit`, labels A / B, or IMAGE / BASEMAP) exists only while a swipe is live, recentres on every new comparison (not while scrubbing the second day), except once for a split restored from a link. There is no keyboard shortcut (Space is the app's push-to-talk): SWAP (`#ri-swap`, in the controls row, its slot reserved and the button disabled while no swipe is live) trades the two sides, A to the right and B to the left, or the image to the right of the basemap, and a second click restores; the hint reads `Drag the divider · SWAP trades sides`. The swap is not in the share link, and every new comparison starts unswapped. One opacity applies to both drapes. Another owner holding the lease is reported and the images still drape. - **Panel.** `#recent-imagery-panel` is rail markup in the Context view (`src/ui/views/ContextView.vue`) beside `#weather-panel`, registered in `PanelLayoutController`, `PanelChrome` and the share panel state (`ui` token `i`), hidden while the layer is off and opened on first appearance unless a stored or shared collapse choice exists (`dataset.collapsedPreference`). `LayerPanel.attachRecentImagery(factory)` mounts the readout (`createRecentImageryPanel` in `src/ui/recentImagery.js`) into its `data-rail-scroller` body, as the weather readout is mounted. The body is a fixed stack in which no block changes height and no control moves in any state: `#ri-actions` (SELECT BOX · USE VIEW · CLEAR, rail-card actions), `#ri-notice` (one line: `#ri-notice-text` with the refusal, error, CLEAR notice or the Esri note, and `#ri-zoom-in` in a fixed slot at its right end, reserved unless an oversized box or view can be fitted), `#ri-strip` (day cards newest first: thumbnail, date, sensor, cloud, START HERE, PREVIEW, and a SHOW chip or A and B chips; ← → Home End move, S / A / B pin, Enter previews), `#ri-hint` (one line: the next step), `#ri-selection` (`#ri-mode` IMAGE · VS BASEMAP · A / B, then `#ri-slot-a` and `#ri-slot-b` with `#ri-unpin-a` / `#ri-unpin-b` kept in place when empty), `#ri-controls` (`#ri-opacity`, EXPORT / EXPORT A and EXPORT B) and `#ri-details`, a collapsed rail card holding the focused day's acquisition, coverage and granules, catalog notes, the empty-days toggle and the imagery credit. Absent controls are reserved (invisible), never removed. Every render preserves the body's `scrollTop`; opening DETAILS then scrolls its card into view once. diff --git a/src/layers/recentImagery/index.js b/src/layers/recentImagery/index.js index 5ab8e05ccb..b4552a18b2 100644 --- a/src/layers/recentImagery/index.js +++ b/src/layers/recentImagery/index.js @@ -285,12 +285,17 @@ export function createRecentImageryLayer({ const rank = (list) => rankLatest(list.map(withAvailability), { truncated: _truncated }); - /** Focus the START HERE day and preview it when the mode's slot is empty. */ - function autoPreview() { + /** + * Focus the START HERE day and preview it when the mode's slot is empty. + * @param {string | null} [emptyKey] The empty automatic day handed over; + * focus still on it moves too, since a followed day previews only while + * it is focused. + */ + function autoPreview(emptyKey = null) { const ranked = rank(sourcedCandidates()); if (!ranked.candidate) return; const key = ranked.candidate.key; - if (!_focusKey) _focusKey = key; + if (!_focusKey || _focusKey === emptyKey) _focusKey = key; if (!previewSlot() || activeSlotOf(key)) return; _auto = { key, reason: ranked.reason, certain: ranked.certain }; if (drapable(candidateFor(key))) _previewKey = key; @@ -317,7 +322,7 @@ export function createRecentImageryLayer({ _previewKey = null; _auto = null; changed = true; - if (wasAuto) autoPreview(); + if (wasAuto) autoPreview(preview.key); } // A followed day that turns out empty is dropped; an automatic one hands // over to the next ranked day. @@ -327,7 +332,7 @@ export function createRecentImageryLayer({ _followKey = null; if (wasAuto) { _auto = null; - autoPreview(); + autoPreview(followed.key); } changed = true; } diff --git a/src/layers/recentImagery/index.test.mjs b/src/layers/recentImagery/index.test.mjs index 90dbf3a528..2a0a3d2b17 100644 --- a/src/layers/recentImagery/index.test.mjs +++ b/src/layers/recentImagery/index.test.mjs @@ -1128,6 +1128,33 @@ test('an automatic overview that probes empty hands over to the next ranked day' assert.deepEqual(f.drapes(), { a: `${V15}|none`, b: null }); }); +test('with empty days shown, focus leaves an empty automatic overview with the hand-over and its successor drapes', async () => { + const f = fixture(); + f.layer.setSources({ hls: false }); + f.layer.setShowUnavailable(true); + await f.ready(); + assert.equal(f.diag().following, V21, 'today is followed'); + f.thumbnails.probe(V21, 'empty'); + assert.equal(f.diag().following, V15, 'yesterday takes over'); + assert.equal(f.snap().focus.key, V15, 'focus goes with it'); + f.thumbnails.probe(V15, 'present'); + assert.equal(f.snap().preview.key, V15); + assert.equal(f.snap().preview.pending, null); + assert.deepEqual(f.drapes(), { a: `${V15}|none`, b: null }); +}); + +test('focus on an empty automatic day moves to the next ranked day, not the nearest card, and it drapes once present', async () => { + const f = fixture(); + await f.ready([CANDIDATES[0], CANDIDATES[1], CANDIDATES[3]]); + assert.equal(f.snap().preview.key, S18); + f.thumbnails.probe(S18, 'empty'); + assert.equal(f.diag().following, V21, 'the newest overview takes over'); + assert.equal(f.snap().focus.key, V21, 'not the older neighbour V15'); + f.thumbnails.probe(V21, 'present'); + assert.equal(f.snap().preview.key, V21); + assert.deepEqual(f.drapes(), { a: `${V21}|none`, b: null }); +}); + test('a pinned day still being probed drapes once the probe says present', async () => { const f = fixture(); f.layer.setParams({ ...LINK_BOX, a: V21, mode: 0 }); From b863f41fb5f16bcb5fc684379baa80d29f879f34 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 13 Nov 2026 18:52:33 +0400 Subject: [PATCH 2/5] Changelog fragment for #1701 --- changelog.d/1701-recent-imagery-auto-successor.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog.d/1701-recent-imagery-auto-successor.md diff --git a/changelog.d/1701-recent-imagery-auto-successor.md b/changelog.d/1701-recent-imagery-auto-successor.md new file mode 100644 index 0000000000..6dd2644f1f --- /dev/null +++ b/changelog.d/1701-recent-imagery-auto-successor.md @@ -0,0 +1,4 @@ +- Recent Imagery: when the automatic day probes empty, the next ranked day now + drapes once its probe says present. Focus stayed on the empty day, or moved + to the nearest card rather than the next ranked day, so the successor never + reached the map (gekh, #1701). From 35f69e84dfc4d8530d0c5dabbc566a0b8137ee71 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 20 Nov 2026 00:33:01 +0400 Subject: [PATCH 3/5] Recent Imagery: keep a picked day when the automatic preview probes empty A card click on an unprobed day follows that day while the automatic preview stays on the map. If the automatic day then probed empty, the hand-over to the next ranked day overwrote that follow, so neither the picked day nor the successor draped when their probes came back present. The hand-over now leaves the slot to a day the user picked that is still being probed or waiting out the arrow-key debounce. Also covers the off-screen successor with empty days shown: once the visible days probe empty, the successor's probe is queued (the re-request that came with the merge from main) and the day drapes when present. --- .../1701-recent-imagery-auto-successor.md | 3 +- docs/CURRENT-STATE.md | 2 +- src/layers/recentImagery/index.js | 4 +- src/layers/recentImagery/index.test.mjs | 50 +++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/changelog.d/1701-recent-imagery-auto-successor.md b/changelog.d/1701-recent-imagery-auto-successor.md index 6dd2644f1f..6bb49a0313 100644 --- a/changelog.d/1701-recent-imagery-auto-successor.md +++ b/changelog.d/1701-recent-imagery-auto-successor.md @@ -1,4 +1,5 @@ - Recent Imagery: when the automatic day probes empty, the next ranked day now drapes once its probe says present. Focus stayed on the empty day, or moved to the nearest card rather than the next ranked day, so the successor never - reached the map (gekh, #1701). + reached the map. A day picked while the automatic one was still being probed + is no longer replaced by that hand-over (gekh, #1701). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 3bdc54c3e9..5348967dd1 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -8540,7 +8540,7 @@ pins and share links already supply complete boxes. - The layer sits in the Data Layers panel's Cameras group beside Cameras (CCTV); Mapped ALPR Cameras moved to the Infrastructure group to make room. - DATA ▸ **Recent Imagery** (`recent-imagery`, `src/layers/recentImagery/`) lists the last 30 UTC days of imagery for a selected box and drapes the days you pick: HLS S30 (Sentinel-2) and L30 (Landsat 8/9) at 30 m, and the VIIRS NOAA-21 daily overview at 250 m. Keyless and browser-direct: NASA CMR for which days have HLS granules in the box (`catalog.js`, both collections concurrently, paged with `CMR-Search-After` up to 2,000 records each, `truncated` against CMR `hits`), GIBS WMTS for tiles, Worldview Snapshots for thumbnails and exports. Worldview's `Data-Present` header is the only availability signal: GIBS answers an empty tile with HTTP 200, and the JPEG overview would drape black, so a day confirmed empty never drapes. - **Box.** SELECT BOX (`src/ui/imageryBoxTool.js`) claims the pointer like Draw, borrows the stock click actions and freezes the camera only mid-drag; USE VIEW takes the camera rectangle; `boxFromPinAt` grows a 10 km box. Boxes must be ≤ 1,000 km a side, on one side of the dateline and inside the Web-Mercator limit (`validateBox`). A refusal (`boxError`, including the tool's own via `reportBoxRefusal`) stays at the top of the panel until a box succeeds; a view over the cap is refused with its size, never shrunk. An oversized box or view (`Box is … km wide · limit 1,000 km`, `View is … wide · …`) sets the hint to `Zoom in or draw a smaller box` and enables ZOOM IN: `zoomToFit()` flies top-down (1.2 s) to the refused box's centre, or the ground under the canvas centre for a view, at the height whose view is about 400 km wide for the canvas aspect and the camera's vertical FOV (`fitViewHeightM`, clamped 5–400 km), and returns that height. -- **Modes, pins and the preview.** The mode is explicit: `image` (one pinned day, slot `a`), `basemap` (that day on the left of a swipe, the basemap on the right: slot `a` splits LEFT and there is no second layer) and `ab` (day `a` left, day `b` right). `setAssignment(slot, key | null)` / `toggleAssignment(slot, key)` pin and unpin; a day is in one slot at most (pinning it in the other slot moves it) and an empty day cannot be pinned. `setMode()` keeps both pins; `b` only drapes in `ab`. While the mode's first empty slot exists the focused day previews in it: a click at once, arrow keys after 250 ms of quiet (`FOCUS_DEBOUNCE_MS`, one timer, last day wins); an unprobed day is followed and previews when its probe says present, an empty or unknown day never drapes and the previous preview stays. A pin change drops the preview until focus moves again, and unpinning takes that layer off at once. `rankLatest` picks START HERE coverage first (a present HLS day whose footprints cover the box, or have none, beats a newer sliver), then newest with all granules ≤ 20% known cloud, then newest; slivers only as `partial`; else the newest non-empty VIIRS day; it is focused and previewed after each search when nothing is pinned. When that day probes empty the next ranked day takes over, and focus still on the empty day moves with it, so the successor drapes once its probe says present. Escape clears the preview (`clearPreview()`), then cancels the box tool, then blurs — with SELECT BOX armed too, through the tool's `onEscape` interceptor wired in `createApplicationTools`. Pins, mode, box and split changes made in the panel are published with `adoptLayerParams`, never while a share link is being applied. +- **Modes, pins and the preview.** The mode is explicit: `image` (one pinned day, slot `a`), `basemap` (that day on the left of a swipe, the basemap on the right: slot `a` splits LEFT and there is no second layer) and `ab` (day `a` left, day `b` right). `setAssignment(slot, key | null)` / `toggleAssignment(slot, key)` pin and unpin; a day is in one slot at most (pinning it in the other slot moves it) and an empty day cannot be pinned. `setMode()` keeps both pins; `b` only drapes in `ab`. While the mode's first empty slot exists the focused day previews in it: a click at once, arrow keys after 250 ms of quiet (`FOCUS_DEBOUNCE_MS`, one timer, last day wins); an unprobed day is followed and previews when its probe says present, an empty or unknown day never drapes and the previous preview stays. A pin change drops the preview until focus moves again, and unpinning takes that layer off at once. `rankLatest` picks START HERE coverage first (a present HLS day whose footprints cover the box, or have none, beats a newer sliver), then newest with all granules ≤ 20% known cloud, then newest; slivers only as `partial`; else the newest non-empty VIIRS day; it is focused and previewed after each search when nothing is pinned. When that day probes empty the next ranked day takes over, and focus still on the empty day moves with it, so the successor drapes once its probe says present; a day the user picked meanwhile, still being probed or debounced, keeps the slot instead. Escape clears the preview (`clearPreview()`), then cancels the box tool, then blurs — with SELECT BOX armed too, through the tool's `onEscape` interceptor wired in `createApplicationTools`. Pins, mode, box and split changes made in the panel are published with `adoptLayerParams`, never while a share link is being applied. - **Rendering.** `rendering.js` owns at most two GIBS layers on the host `src/maps/imageryHost.js` resolves: the globe port's imagery while the globe shows, the shown photoreal tileset while it is hidden, or none (the panel says so). Layers are rebuilt on a new host, never re-parented. `MapSourceController.subscribe()` fires after every settled stack switch (silent switches and fallbacks included) and the layer rebinds on it. Tile requests pass a six-slot semaphore of our own (Cesium's global limits are untouched). Under `requestRenderMode` a deferred tile needs a later frame, but a deferral must never request one itself or a stalled tile keeps the scene rendering every frame: a request that finds the semaphore full asks for nothing (the settling request asks for one frame), and a tile Cesium itself deferred goes through one coalesced 250 ms retry. Thumbnails: three fetches at once, sixteen decoded images, least-recently-used where a `get` read is never a use; eviction keeps the probe result. The strip's visible window is probed around the focused card; the pinned and previewed days are probed wherever they sit, at the focused card's priority, so a pin restored or assigned off-screen still drapes. A thumbnail request pass over a non-empty strip ends with `retain()`, which cancels queued and in-flight work for days it no longer wants (focus, visible range, pins, sources, the empty-day filter, a share link); a cancelled day already probed present keeps its status. When an automatic day probes empty, its successor is requested again, since scrolling may have cancelled that probe. - **Esri surface and the swipe.** While any image is on the map (a preview included) the layer holds the map lease (`acquireImageryComparison`, owner `recent-imagery`, `esri-if-photoreal`): on Google 3D the map switches to Esri, because 30 m pixels over 3D buildings do not read, and Cesium's split only works on the globe. The lease is handed back, and Google 3D restored unless the operator changed maps meanwhile, when the last image leaves the map or the layer is disabled; the notice line says so while it holds. While a day is shown the imagery keeps Esri: a manual switch that lands on Google 3D is answered at once with a new lease under the same policy (`keepEsri`), the notice reads `Imagery stays on Esri · CLEAR to use Google 3D`, and the divider never suspends because of a map switch. It re-leases once per switch generation and only for a manual one (`MapSourceController#getSwitchOrigin()` is `manual` for an outside `setStack`, `automatic` for the controller's own fallback or recovery), never for the lease's own switch and never while releasing, so CLEAR and disable still return to Google 3D; a lease another owner holds stays refused. When Esri fails and the controller falls back to Google 3D on its own, the layer lets the lease go without restoring anything, both days drape on the tileset without a swipe and the guidance reads `Esri map unavailable · no swipe`; only the next manual switch to Google 3D takes Esri again, so a failing Esri map is never retried in a loop. Switching between globe stacks (Esri, OSM, Bing) only rebinds. On a tileset host both images drape without a swipe. The split control (`createImagerySplit`, labels A / B, or IMAGE / BASEMAP) exists only while a swipe is live, recentres on every new comparison (not while scrubbing the second day), except once for a split restored from a link. There is no keyboard shortcut (Space is the app's push-to-talk): SWAP (`#ri-swap`, in the controls row, its slot reserved and the button disabled while no swipe is live) trades the two sides, A to the right and B to the left, or the image to the right of the basemap, and a second click restores; the hint reads `Drag the divider · SWAP trades sides`. The swap is not in the share link, and every new comparison starts unswapped. One opacity applies to both drapes. Another owner holding the lease is reported and the images still drape. - **Panel.** `#recent-imagery-panel` is rail markup in the Context view (`src/ui/views/ContextView.vue`) beside `#weather-panel`, registered in `PanelLayoutController`, `PanelChrome` and the share panel state (`ui` token `i`), hidden while the layer is off and opened on first appearance unless a stored or shared collapse choice exists (`dataset.collapsedPreference`). `LayerPanel.attachRecentImagery(factory)` mounts the readout (`createRecentImageryPanel` in `src/ui/recentImagery.js`) into its `data-rail-scroller` body, as the weather readout is mounted. The body is a fixed stack in which no block changes height and no control moves in any state: `#ri-actions` (SELECT BOX · USE VIEW · CLEAR, rail-card actions), `#ri-notice` (one line: `#ri-notice-text` with the refusal, error, CLEAR notice or the Esri note, and `#ri-zoom-in` in a fixed slot at its right end, reserved unless an oversized box or view can be fitted), `#ri-strip` (day cards newest first: thumbnail, date, sensor, cloud, START HERE, PREVIEW, and a SHOW chip or A and B chips; ← → Home End move, S / A / B pin, Enter previews), `#ri-hint` (one line: the next step), `#ri-selection` (`#ri-mode` IMAGE · VS BASEMAP · A / B, then `#ri-slot-a` and `#ri-slot-b` with `#ri-unpin-a` / `#ri-unpin-b` kept in place when empty), `#ri-controls` (`#ri-opacity`, EXPORT / EXPORT A and EXPORT B) and `#ri-details`, a collapsed rail card holding the focused day's acquisition, coverage and granules, catalog notes, the empty-days toggle and the imagery credit. Absent controls are reserved (invisible), never removed. Every render preserves the body's `scrollTop`; opening DETAILS then scrolls its card into view once. diff --git a/src/layers/recentImagery/index.js b/src/layers/recentImagery/index.js index abfdabd88e..1b4af80a1a 100644 --- a/src/layers/recentImagery/index.js +++ b/src/layers/recentImagery/index.js @@ -320,7 +320,9 @@ export function createRecentImageryLayer({ _previewKey = null; _auto = null; changed = true; - if (wasAuto) autoPreview(preview.key); + // A day the user picked meanwhile, still being probed or debounced, + // takes the slot instead of the next ranked day. + if (wasAuto && !_followKey && !_pending) autoPreview(preview.key); } // A followed day that turns out empty is dropped; an automatic one hands // over to the next ranked day. diff --git a/src/layers/recentImagery/index.test.mjs b/src/layers/recentImagery/index.test.mjs index 58cb608814..4b61f7c34a 100644 --- a/src/layers/recentImagery/index.test.mjs +++ b/src/layers/recentImagery/index.test.mjs @@ -1266,6 +1266,56 @@ test('empty auto VIIRS re-requests a cancelled successor', async () => { assert.deepEqual(f.drapes(), { a: `${next}|none`, b: null }); }); +test('with empty days shown, an off-screen successor is probed once the visible days return empty', async () => { + const f = fixture(); + const days = dailyViirs(); + f.layer.setSources({ hls: false }); + f.layer.setShowUnavailable(true); + f.layer.setVisibleRange(0, 5); + await f.ready(days); + const offscreen = days.findIndex( + ({ key }) => !f.thumbnails.requested.includes(key), + ); + assert.ok(offscreen > 5, 'the first unrequested day is off-screen'); + for (const { key } of days.slice(0, offscreen)) { + assert.equal(f.diag().following, key); + f.thumbnails.probe(key, 'empty'); + } + const successor = days[offscreen].key; + assert.equal(f.diag().following, successor); + assert.equal(f.snap().focus.key, successor); + assert.deepEqual(f.thumbnails.requests.at(-1), [successor, 0]); + assert.ok(f.thumbnails.retained.at(-1).includes(successor)); + f.thumbnails.probe(successor, 'present'); + assert.equal(f.snap().preview.key, successor); + assert.deepEqual(f.drapes(), { a: `${successor}|none`, b: null }); +}); + +test('a pick still being probed or debounced survives a late empty result for the automatic preview', async () => { + const f = fixture(); + await f.ready([CANDIDATES[0], CANDIDATES[1], CANDIDATES[3]]); + assert.equal(f.snap().preview.key, S18); + assert.equal(f.layer.preview(V15), false); + assert.equal(f.diag().following, V15); + f.thumbnails.probe(S18, 'empty'); + assert.equal(f.diag().following, V15, 'the pick is kept'); + assert.equal(f.snap().focus.key, V15); + f.thumbnails.probe(V21, 'present'); + f.thumbnails.probe(V15, 'present'); + assert.equal(f.snap().preview.key, V15); + assert.deepEqual(f.drapes(), { a: `${V15}|none`, b: null }); + // An arrow-key pick waiting out the debounce is kept too. + const g = fixture(); + await g.ready(); + g.thumbnails.setStatus(V15, 'present'); + g.layer.focus(3); + assert.equal(g.diag().pending, V15); + g.thumbnails.probe(S18, 'empty'); + assert.equal(g.owned().a, null, 'no other day drapes meanwhile'); + g.timers.flush(); + assert.equal(g.snap().preview.key, V15); +}); + test('restored pins outside the visible strip window are probed and swipe once present', async () => { const f = fixture(); const days = dailyViirs(); From 8eac8bd545bbe143c2910f24f0fdc16319ba8fa7 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 20 Nov 2026 11:57:55 +0400 Subject: [PATCH 4/5] Recent Imagery: defer the hand-over to a waiting pick instead of skipping it The previous change skipped the hand-over for good while a user pick was pending. When that pick then probed empty, failed with a terminal error, or lost its source, nothing previewed and the slot stayed blank, where main would have draped the next ranked day. During the arrow-key debounce the empty slot also handed the Esri lease back and took it again 250 ms later. The hand-over is now deferred: the pick keeps first claim on the slot while its probe can still settle, and the next ranked day takes over as soon as the pick turns out empty, errors or loses its source. Turning a source off also drops a followed pick of that source. The layer keeps the current basemap while a deferred pick waits, and Escape releases it. Six tests cover both answer orders, the source toggle, a terminal error, the debounce and the lease. --- docs/CURRENT-STATE.md | 2 +- src/layers/recentImagery/index.js | 69 ++++++++++--- src/layers/recentImagery/index.test.mjs | 130 ++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 13 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 521417f35f..31ee9e2542 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -8608,7 +8608,7 @@ pins and share links already supply complete boxes. - The layer sits in the Data Layers panel's Cameras group beside Cameras (CCTV); Mapped ALPR Cameras moved to the Infrastructure group to make room. - DATA ▸ **Recent Imagery** (`recent-imagery`, `src/layers/recentImagery/`) lists the last 30 UTC days of imagery for a selected box and drapes the days you pick: HLS S30 (Sentinel-2) and L30 (Landsat 8/9) at 30 m, and the VIIRS NOAA-21 daily overview at 250 m. Keyless and browser-direct: NASA CMR for which days have HLS granules in the box (`catalog.js`, both collections concurrently, paged with `CMR-Search-After` up to 2,000 records each, `truncated` against CMR `hits`), GIBS WMTS for tiles, Worldview Snapshots for thumbnails and exports. Worldview's `Data-Present` header is the only availability signal: GIBS answers an empty tile with HTTP 200, and the JPEG overview would drape black, so a day confirmed empty never drapes. - **Box.** SELECT BOX (`src/ui/imageryBoxTool.js`) claims the pointer like Draw, borrows the stock click actions and freezes the camera only mid-drag; USE VIEW takes the camera rectangle; `boxFromPinAt` grows a 10 km box. Boxes must be ≤ 1,000 km a side, on one side of the dateline and inside the Web-Mercator limit (`validateBox`). A refusal (`boxError`, including the tool's own via `reportBoxRefusal`) stays at the top of the panel until a box succeeds; a view over the cap is refused with its size, never shrunk. An oversized box or view (`Box is … km wide · limit 1,000 km`, `View is … wide · …`) sets the hint to `Zoom in or draw a smaller box` and enables ZOOM IN: `zoomToFit()` flies top-down (1.2 s) to the refused box's centre, or the ground under the canvas centre for a view, at the height whose view is about 400 km wide for the canvas aspect and the camera's vertical FOV (`fitViewHeightM`, clamped 5–400 km), and returns that height. -- **Modes, pins and the preview.** The mode is explicit: `image` (one pinned day, slot `a`), `basemap` (that day on the left of a swipe, the basemap on the right: slot `a` splits LEFT and there is no second layer) and `ab` (day `a` left, day `b` right). `setAssignment(slot, key | null)` / `toggleAssignment(slot, key)` pin and unpin; a day is in one slot at most (pinning it in the other slot moves it) and an empty day cannot be pinned. `setMode()` keeps both pins; `b` only drapes in `ab`. While the mode's first empty slot exists the focused day previews in it: a click at once, arrow keys after 250 ms of quiet (`FOCUS_DEBOUNCE_MS`, one timer, last day wins); an unprobed day is followed and previews when its probe says present, an empty or unknown day never drapes and the previous preview stays. A pin change drops the preview until focus moves again, and unpinning takes that layer off at once. `rankLatest` picks START HERE coverage first (a present HLS day whose footprints cover the box, or have none, beats a newer sliver), then newest with all granules ≤ 20% known cloud, then newest; slivers only as `partial`; else the newest non-empty VIIRS day; it is focused and previewed after each search when nothing is pinned. When that day probes empty the next ranked day takes over, and focus still on the empty day moves with it, so the successor drapes once its probe says present; a day the user picked meanwhile, still being probed or debounced, keeps the slot instead. Escape clears the preview (`clearPreview()`), then cancels the box tool, then blurs — with SELECT BOX armed too, through the tool's `onEscape` interceptor wired in `createApplicationTools`. Pins, mode, box and split changes made in the panel are published with `adoptLayerParams`, never while a share link is being applied. +- **Modes, pins and the preview.** The mode is explicit: `image` (one pinned day, slot `a`), `basemap` (that day on the left of a swipe, the basemap on the right: slot `a` splits LEFT and there is no second layer) and `ab` (day `a` left, day `b` right). `setAssignment(slot, key | null)` / `toggleAssignment(slot, key)` pin and unpin; a day is in one slot at most (pinning it in the other slot moves it) and an empty day cannot be pinned. `setMode()` keeps both pins; `b` only drapes in `ab`. While the mode's first empty slot exists the focused day previews in it: a click at once, arrow keys after 250 ms of quiet (`FOCUS_DEBOUNCE_MS`, one timer, last day wins); an unprobed day is followed and previews when its probe says present, an empty or unknown day never drapes and the previous preview stays. A pin change drops the preview until focus moves again, and unpinning takes that layer off at once. `rankLatest` picks START HERE coverage first (a present HLS day whose footprints cover the box, or have none, beats a newer sliver), then newest with all granules ≤ 20% known cloud, then newest; slivers only as `partial`; else the newest non-empty VIIRS day; it is focused and previewed after each search when nothing is pinned. When that day probes empty the next ranked day takes over, and focus still on the empty day moves with it, so the successor drapes once its probe says present; a day the user picked meanwhile, still being probed or debounced, keeps the slot instead (and the Esri lease while it waits), and if that pick probes empty, fails or loses its source the hand-over goes ahead. Escape clears the preview (`clearPreview()`), then cancels the box tool, then blurs — with SELECT BOX armed too, through the tool's `onEscape` interceptor wired in `createApplicationTools`. Pins, mode, box and split changes made in the panel are published with `adoptLayerParams`, never while a share link is being applied. - **Rendering.** `rendering.js` owns at most two GIBS layers on the host `src/maps/imageryHost.js` resolves: the globe port's imagery while the globe shows, the shown photoreal tileset while it is hidden, or none (the panel says so). Layers are rebuilt on a new host, never re-parented. `MapSourceController.subscribe()` fires after every settled stack switch (silent switches and fallbacks included) and the layer rebinds on it. Tile requests pass a six-slot semaphore of our own (Cesium's global limits are untouched). Under `requestRenderMode` a deferred tile needs a later frame, but a deferral must never request one itself or a stalled tile keeps the scene rendering every frame: a request that finds the semaphore full asks for nothing (the settling request asks for one frame), and a tile Cesium itself deferred goes through one coalesced 250 ms retry. Thumbnails: three fetches at once, sixteen decoded images, least-recently-used where a `get` read is never a use; eviction keeps the probe result. The strip's visible window is probed around the focused card; the pinned and previewed days are probed wherever they sit, at the focused card's priority, so a pin restored or assigned off-screen still drapes. A thumbnail request pass over a non-empty strip ends with `retain()`, which cancels queued and in-flight work for days it no longer wants (focus, visible range, pins, sources, the empty-day filter, a share link); a cancelled day already probed present keeps its status. When an automatic day probes empty, its successor is requested again, since scrolling may have cancelled that probe. - **Esri surface and the swipe.** While any image is on the map (a preview included) the layer holds the map lease (`acquireImageryComparison`, owner `recent-imagery`, `esri-if-photoreal`): on Google 3D the map switches to Esri, because 30 m pixels over 3D buildings do not read, and Cesium's split only works on the globe. The lease is handed back, and Google 3D restored unless the operator changed maps meanwhile, when the last image leaves the map or the layer is disabled; the notice line says so while it holds. While a day is shown the imagery keeps Esri: a manual switch that lands on Google 3D is answered at once with a new lease under the same policy (`keepEsri`), the notice reads `Imagery stays on Esri · CLEAR to use Google 3D`, and the divider never suspends because of a map switch. It re-leases once per switch generation and only for a manual one (`MapSourceController#getSwitchOrigin()` is `manual` for an outside `setStack`, `automatic` for the controller's own fallback or recovery), never for the lease's own switch and never while releasing, so CLEAR and disable still return to Google 3D; a lease another owner holds stays refused. When Esri fails and the controller falls back to Google 3D on its own, the layer lets the lease go without restoring anything, both days drape on the tileset without a swipe and the guidance reads `Esri map unavailable · no swipe`; only the next manual switch to Google 3D takes Esri again, so a failing Esri map is never retried in a loop. Switching between globe stacks (Esri, OSM, Bing) only rebinds. On a tileset host both images drape without a swipe. The split control (`createImagerySplit`, labels A / B, or IMAGE / BASEMAP) exists only while a swipe is live, recentres on every new comparison (not while scrubbing the second day), except once for a split restored from a link. There is no keyboard shortcut (Space is the app's push-to-talk): SWAP (`#ri-swap`, in the controls row, its slot reserved and the button disabled while no swipe is live) trades the two sides, A to the right and B to the left, or the image to the right of the basemap, and a second click restores; the hint reads `Drag the divider · SWAP trades sides`. The swap is not in the share link, and every new comparison starts unswapped. One opacity applies to both drapes. Another owner holding the lease is reported and the images still drape. - **Panel.** `#recent-imagery-panel` is rail markup in the Context view (`src/ui/views/ContextView.vue`) beside `#weather-panel`, registered in `PanelLayoutController`, `PanelChrome` and the share panel state (`ui` token `i`), hidden while the layer is off and opened on first appearance unless a stored or shared collapse choice exists (`dataset.collapsedPreference`). `LayerPanel.attachRecentImagery(factory)` mounts the readout (`createRecentImageryPanel` in `src/ui/recentImagery.js`) into its `data-rail-scroller` body, as the weather readout is mounted. The body is a fixed stack in which no block changes height and no control moves in any state: `#ri-actions` (SELECT BOX · USE VIEW · CLEAR, rail-card actions), `#ri-notice` (one line: `#ri-notice-text` with the refusal, error, CLEAR notice or the Esri note, and `#ri-zoom-in` in a fixed slot at its right end, reserved unless an oversized box or view can be fitted), `#ri-strip` (day cards newest first: thumbnail, date, sensor, cloud, START HERE, PREVIEW, and a SHOW chip or A and B chips; ← → Home End move, S / A / B pin, Enter previews), `#ri-hint` (one line: the next step), `#ri-selection` (`#ri-mode` IMAGE · VS BASEMAP · A / B, then `#ri-slot-a` and `#ri-slot-b` with `#ri-unpin-a` / `#ri-unpin-b` kept in place when empty), `#ri-controls` (`#ri-opacity`, EXPORT / EXPORT A and EXPORT B) and `#ri-details`, a collapsed rail card holding the focused day's acquisition, coverage and granules, catalog notes, the empty-days toggle and the imagery credit. Absent controls are reserved (invisible), never removed. Every render preserves the body's `scrollTop`; opening DETAILS then scrolls its card into view once. diff --git a/src/layers/recentImagery/index.js b/src/layers/recentImagery/index.js index 1b4af80a1a..6b01fb74e1 100644 --- a/src/layers/recentImagery/index.js +++ b/src/layers/recentImagery/index.js @@ -147,6 +147,8 @@ export function createRecentImageryLayer({ let _pendingTimer = null; /** A focused day still being probed: it previews once present. */ let _followKey = null; + /** The automatic day was empty and a user pick has first claim on its slot. */ + let _handoverDeferred = false; let _auto = null; let _notice = null; let _split = DEFAULT_SPLIT; @@ -300,6 +302,15 @@ export function createRecentImageryLayer({ else _followKey = key; } + /** A debounced or followed pick can still take the slot until its probe settles. */ + function pickWaiting() { + if (_pending) return true; + const followed = candidateFor(_followKey); + if (!followed) return false; + const status = thumbnails.get(followed.key)?.status; + return status !== 'empty' && status !== 'error'; + } + /** * A day whose probe came back empty leaves the map: JPEG products have no * alpha and would drape black "no data" tiles. A pinned day is unpinned and @@ -322,7 +333,10 @@ export function createRecentImageryLayer({ changed = true; // A day the user picked meanwhile, still being probed or debounced, // takes the slot instead of the next ranked day. - if (wasAuto && !_followKey && !_pending) autoPreview(preview.key); + if (wasAuto) { + if (pickWaiting()) _handoverDeferred = true; + else autoPreview(preview.key); + } } // A followed day that turns out empty is dropped; an automatic one hands // over to the next ranked day. @@ -336,6 +350,13 @@ export function createRecentImageryLayer({ } changed = true; } + if (_handoverDeferred && !pickWaiting()) { + const failedKey = _followKey || followed?.key || null; + _handoverDeferred = false; + _followKey = null; + autoPreview(failedKey); + changed = true; + } return changed; } @@ -567,7 +588,11 @@ export function createRecentImageryLayer({ } if (!comparison) return; if (shown.a || shown.b) acquireComparison(); - else if (_lease || _comparisonReady || _comparisonError) + // Keep the current basemap while the user's pick has first claim on the slot. + else if ( + !_handoverDeferred && + (_lease || _comparisonReady || _comparisonError) + ) releaseComparison(); } @@ -609,6 +634,7 @@ export function createRecentImageryLayer({ _catalogErrors = []; _catalogError = null; _auto = null; + _handoverDeferred = false; } function cancelSearch() { @@ -670,7 +696,9 @@ export function createRecentImageryLayer({ function applyPreview(key) { clearPending(); _followKey = null; - if (key === _previewKey) return false; + const changed = key !== _previewKey || _handoverDeferred; + _handoverDeferred = false; + if (!changed) return false; if (_auto?.key !== key) _auto = null; _previewKey = key; if (_enabled) syncRender(); @@ -696,7 +724,17 @@ export function createRecentImageryLayer({ const pending = _pending; _pending = null; if (_destroyed || !pending) return; - if (pending.key && !drapable(candidateFor(pending.key))) return; + if (pending.key && !drapable(candidateFor(pending.key))) { + if (_handoverDeferred) { + // Its empty card may already be hidden. Let focus follow the hand-over. + _focusKey = pending.key; + _followKey = pending.key; + syncRender(); + requestThumbnails(); + notify(); + } + return; + } if (applyPreview(pending.key)) notify(); }, FOCUS_DEBOUNCE_MS); } @@ -807,6 +845,15 @@ export function createRecentImageryLayer({ const pending = candidateFor(_pending?.key); if (!_sources[id] && pending && sourceOf(pending.product) === id) clearPending(); + // A followed pick goes too. An automatic day keeps its follow. + const followed = candidateFor(_followKey); + if ( + !_sources[id] && + followed && + sourceOf(followed.product) === id && + _auto?.key !== followed.key + ) + _followKey = null; } return changed; } @@ -1092,14 +1139,10 @@ export function createRecentImageryLayer({ * @returns {boolean} Whether a preview was showing or on its way. */ clearPreview() { - const had = Boolean(_pending || _followKey || plan().preview); - clearPending(); - _followKey = null; - if (_previewKey) { - _previewKey = null; - _auto = null; - if (_enabled) syncRender(); - } + const had = Boolean( + _pending || _followKey || _handoverDeferred || plan().preview, + ); + applyPreview(null); if (had) notify(); return had; }, @@ -1129,6 +1172,7 @@ export function createRecentImageryLayer({ // The preview belonged to the old pins; the next focus move brings it back. clearPending(); _followKey = null; + _handoverDeferred = false; _previewKey = null; _auto = null; if (_enabled) { @@ -1422,6 +1466,7 @@ export function createRecentImageryLayer({ if ('a' in params || 'b' in params) { clearPending(); _followKey = null; + _handoverDeferred = false; for (const slotId of SLOT_IDS) { if (slotId in params) _assigned[slotId] = parseCandidateKey(params[slotId]) diff --git a/src/layers/recentImagery/index.test.mjs b/src/layers/recentImagery/index.test.mjs index 4b61f7c34a..b7a42f71a8 100644 --- a/src/layers/recentImagery/index.test.mjs +++ b/src/layers/recentImagery/index.test.mjs @@ -1563,3 +1563,133 @@ test('a voice search cancelled mid-flight says so instead of looking empty', asy assert.equal(f.snap().searching, false); assert.equal(f.snap().notice, 'Search cancelled'); }); + +test('a pick that probes empty after the automatic day lets the next ranked day drape', async () => { + for (const order of [ + [S18, V15], + [V15, S18], + ]) { + const f = fixture(); + await f.ready(); + f.thumbnails.probe(L16, 'present'); + assert.equal(f.snap().preview.key, S18); + f.layer.preview(V15); + assert.equal(f.diag().following, V15); + for (const key of order) f.thumbnails.probe(key, 'empty'); + assert.equal(f.snap().preview.key, L16, `order ${order.join(' then ')}`); + assert.equal(f.owned().a?.key, L16, `order ${order.join(' then ')}`); + } + // A catalog day can also probe empty during the arrow-key debounce. + const f = fixture(); + await f.ready(); + f.thumbnails.probe(V21, 'present'); + f.layer.focus(2); + assert.equal(f.diag().pending, L16); + f.thumbnails.probe(S18, 'empty'); + f.thumbnails.probe(L16, 'empty'); + assert.equal(f.owned().a, null); + f.timers.flush(); + assert.equal(f.owned().a?.key, V21); + assert.equal(f.snap().focus.key, V21); +}); + +test('a deferred hand-over goes ahead once the pick fails or its source turns off', async () => { + const f = fixture(); + await f.ready(); + f.thumbnails.probe(L16, 'present'); + f.layer.preview(V15); + f.thumbnails.probe(S18, 'empty'); + assert.equal(f.owned().a, null, 'the pick keeps the slot while it is probed'); + f.thumbnails.probe(V15, 'error'); + assert.equal(f.diag().following, null); + assert.equal(f.owned().a?.key, L16); + assert.equal(f.snap().focus.key, L16, 'focus leaves the failed pick'); + const g = fixture(); + await g.ready(); + g.thumbnails.probe(L16, 'present'); + g.layer.preview(V15); + g.thumbnails.probe(S18, 'empty'); + g.layer.setSources({ viirs: false }); + assert.equal(g.diag().following, null); + assert.equal(g.owned().a?.key, L16); +}); + +test('turning off the source of a followed pick does not block the hand-over', async () => { + const f = fixture(); + await f.ready(); + f.thumbnails.probe(L16, 'present'); + f.layer.preview(V15); + assert.equal(f.diag().following, V15); + f.layer.setSources({ viirs: false }); + f.thumbnails.probe(S18, 'empty'); + assert.notEqual( + f.diag().following, + V15, + 'a pick whose source is off is no longer followed', + ); + assert.equal(f.owned().a?.key, L16); +}); + +// The fake loader's 'error' status stands for the real loader's terminal error (never re-fetched). +test('a pick whose probe failed does not block the hand-over', async () => { + const f = fixture(); + await f.ready(); + f.thumbnails.probe(L16, 'present'); + f.layer.preview(V15); + f.thumbnails.probe(V15, 'error'); + f.thumbnails.probe(S18, 'empty'); + assert.equal(f.owned().a?.key, L16); +}); + +test('an arrow-key pick waiting out the debounce keeps Esri through an empty automatic result', async () => { + const controller = leasingController(); + const f = fixture({ controller }); + await f.ready(); + await settleTimes(); + assert.equal(controller.getActiveId(), 'esri-imagery'); + f.thumbnails.probe(L16, 'present'); + f.thumbnails.probe(V15, 'present'); + const before = controller.calls.length; + f.layer.focus(3); + f.thumbnails.probe(S18, 'empty'); + await settleTimes(8); + assert.equal(f.owned().a, null, 'no other day drapes meanwhile'); + assert.equal( + controller.getActiveId(), + 'esri-imagery', + 'Esri held during the debounce', + ); + f.timers.flush(); + await settleTimes(8); + assert.equal(f.owned().a?.key, V15); + assert.deepEqual(controller.calls.slice(before), [], 'no stack switches'); +}); + +test('Escape ends a deferred hand-over, and a followed pick keeps Esri through it', async () => { + const escapeController = leasingController(); + const f = fixture({ controller: escapeController }); + await f.ready(); + await settleTimes(); + f.thumbnails.probe(L16, 'present'); + f.layer.preview(V15); + f.thumbnails.probe(S18, 'empty'); + f.layer.clearPreview(); + await settleTimes(8); + assert.equal(escapeController.getActiveId(), 'photoreal'); + f.thumbnails.probe(V21, 'present'); + assert.equal(f.owned().a, null, 'nothing drapes after Escape'); + const controller = leasingController(); + const g = fixture({ controller }); + await g.ready(); + await settleTimes(); + g.thumbnails.probe(L16, 'present'); + const before = controller.calls.length; + g.layer.preview(V15); + g.thumbnails.probe(S18, 'empty'); + await settleTimes(8); + assert.equal(controller.getActiveId(), 'esri-imagery'); + g.thumbnails.probe(V15, 'empty'); + await settleTimes(8); + assert.equal(g.owned().a?.key, L16); + assert.deepEqual(controller.calls.slice(before), [], 'no stack switches'); +}); From 06dccdb00fa389074ff2c13cf1a0da41e4108cb5 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 20 Nov 2026 12:35:22 +0400 Subject: [PATCH 5/5] Recent Imagery: hand a deferred slot over when the pick gives way to an empty card While a user pick kept first claim on the slot of an empty automatic day, a click or an arrow key onto a card already confirmed empty dropped that pick but left the hand-over waiting for the next probe result. Until then the map stayed blank and the Esri lease stayed held, where main showed the next ranked day. focus() and preview() now hand the slot over at once when no pick is left. An arrow key onto an empty card no longer follows that day, as a click already did, so focus stays on the card the user chose. --- docs/CURRENT-STATE.md | 2 +- src/layers/recentImagery/index.js | 11 ++++++++++- src/layers/recentImagery/index.test.mjs | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 31ee9e2542..30c32c2562 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -8608,7 +8608,7 @@ pins and share links already supply complete boxes. - The layer sits in the Data Layers panel's Cameras group beside Cameras (CCTV); Mapped ALPR Cameras moved to the Infrastructure group to make room. - DATA ▸ **Recent Imagery** (`recent-imagery`, `src/layers/recentImagery/`) lists the last 30 UTC days of imagery for a selected box and drapes the days you pick: HLS S30 (Sentinel-2) and L30 (Landsat 8/9) at 30 m, and the VIIRS NOAA-21 daily overview at 250 m. Keyless and browser-direct: NASA CMR for which days have HLS granules in the box (`catalog.js`, both collections concurrently, paged with `CMR-Search-After` up to 2,000 records each, `truncated` against CMR `hits`), GIBS WMTS for tiles, Worldview Snapshots for thumbnails and exports. Worldview's `Data-Present` header is the only availability signal: GIBS answers an empty tile with HTTP 200, and the JPEG overview would drape black, so a day confirmed empty never drapes. - **Box.** SELECT BOX (`src/ui/imageryBoxTool.js`) claims the pointer like Draw, borrows the stock click actions and freezes the camera only mid-drag; USE VIEW takes the camera rectangle; `boxFromPinAt` grows a 10 km box. Boxes must be ≤ 1,000 km a side, on one side of the dateline and inside the Web-Mercator limit (`validateBox`). A refusal (`boxError`, including the tool's own via `reportBoxRefusal`) stays at the top of the panel until a box succeeds; a view over the cap is refused with its size, never shrunk. An oversized box or view (`Box is … km wide · limit 1,000 km`, `View is … wide · …`) sets the hint to `Zoom in or draw a smaller box` and enables ZOOM IN: `zoomToFit()` flies top-down (1.2 s) to the refused box's centre, or the ground under the canvas centre for a view, at the height whose view is about 400 km wide for the canvas aspect and the camera's vertical FOV (`fitViewHeightM`, clamped 5–400 km), and returns that height. -- **Modes, pins and the preview.** The mode is explicit: `image` (one pinned day, slot `a`), `basemap` (that day on the left of a swipe, the basemap on the right: slot `a` splits LEFT and there is no second layer) and `ab` (day `a` left, day `b` right). `setAssignment(slot, key | null)` / `toggleAssignment(slot, key)` pin and unpin; a day is in one slot at most (pinning it in the other slot moves it) and an empty day cannot be pinned. `setMode()` keeps both pins; `b` only drapes in `ab`. While the mode's first empty slot exists the focused day previews in it: a click at once, arrow keys after 250 ms of quiet (`FOCUS_DEBOUNCE_MS`, one timer, last day wins); an unprobed day is followed and previews when its probe says present, an empty or unknown day never drapes and the previous preview stays. A pin change drops the preview until focus moves again, and unpinning takes that layer off at once. `rankLatest` picks START HERE coverage first (a present HLS day whose footprints cover the box, or have none, beats a newer sliver), then newest with all granules ≤ 20% known cloud, then newest; slivers only as `partial`; else the newest non-empty VIIRS day; it is focused and previewed after each search when nothing is pinned. When that day probes empty the next ranked day takes over, and focus still on the empty day moves with it, so the successor drapes once its probe says present; a day the user picked meanwhile, still being probed or debounced, keeps the slot instead (and the Esri lease while it waits), and if that pick probes empty, fails or loses its source the hand-over goes ahead. Escape clears the preview (`clearPreview()`), then cancels the box tool, then blurs — with SELECT BOX armed too, through the tool's `onEscape` interceptor wired in `createApplicationTools`. Pins, mode, box and split changes made in the panel are published with `adoptLayerParams`, never while a share link is being applied. +- **Modes, pins and the preview.** The mode is explicit: `image` (one pinned day, slot `a`), `basemap` (that day on the left of a swipe, the basemap on the right: slot `a` splits LEFT and there is no second layer) and `ab` (day `a` left, day `b` right). `setAssignment(slot, key | null)` / `toggleAssignment(slot, key)` pin and unpin; a day is in one slot at most (pinning it in the other slot moves it) and an empty day cannot be pinned. `setMode()` keeps both pins; `b` only drapes in `ab`. While the mode's first empty slot exists the focused day previews in it: a click at once, arrow keys after 250 ms of quiet (`FOCUS_DEBOUNCE_MS`, one timer, last day wins); an unprobed day is followed and previews when its probe says present, an empty or unknown day never drapes and the previous preview stays. A pin change drops the preview until focus moves again, and unpinning takes that layer off at once. `rankLatest` picks START HERE coverage first (a present HLS day whose footprints cover the box, or have none, beats a newer sliver), then newest with all granules ≤ 20% known cloud, then newest; slivers only as `partial`; else the newest non-empty VIIRS day; it is focused and previewed after each search when nothing is pinned. When that day probes empty the next ranked day takes over, and focus still on the empty day moves with it, so the successor drapes once its probe says present; a day the user picked meanwhile, still being probed or debounced, keeps the slot instead (and the Esri lease while it waits), and if that pick probes empty, fails, loses its source or gives way to an empty card the hand-over goes ahead. Escape clears the preview (`clearPreview()`), then cancels the box tool, then blurs — with SELECT BOX armed too, through the tool's `onEscape` interceptor wired in `createApplicationTools`. Pins, mode, box and split changes made in the panel are published with `adoptLayerParams`, never while a share link is being applied. - **Rendering.** `rendering.js` owns at most two GIBS layers on the host `src/maps/imageryHost.js` resolves: the globe port's imagery while the globe shows, the shown photoreal tileset while it is hidden, or none (the panel says so). Layers are rebuilt on a new host, never re-parented. `MapSourceController.subscribe()` fires after every settled stack switch (silent switches and fallbacks included) and the layer rebinds on it. Tile requests pass a six-slot semaphore of our own (Cesium's global limits are untouched). Under `requestRenderMode` a deferred tile needs a later frame, but a deferral must never request one itself or a stalled tile keeps the scene rendering every frame: a request that finds the semaphore full asks for nothing (the settling request asks for one frame), and a tile Cesium itself deferred goes through one coalesced 250 ms retry. Thumbnails: three fetches at once, sixteen decoded images, least-recently-used where a `get` read is never a use; eviction keeps the probe result. The strip's visible window is probed around the focused card; the pinned and previewed days are probed wherever they sit, at the focused card's priority, so a pin restored or assigned off-screen still drapes. A thumbnail request pass over a non-empty strip ends with `retain()`, which cancels queued and in-flight work for days it no longer wants (focus, visible range, pins, sources, the empty-day filter, a share link); a cancelled day already probed present keeps its status. When an automatic day probes empty, its successor is requested again, since scrolling may have cancelled that probe. - **Esri surface and the swipe.** While any image is on the map (a preview included) the layer holds the map lease (`acquireImageryComparison`, owner `recent-imagery`, `esri-if-photoreal`): on Google 3D the map switches to Esri, because 30 m pixels over 3D buildings do not read, and Cesium's split only works on the globe. The lease is handed back, and Google 3D restored unless the operator changed maps meanwhile, when the last image leaves the map or the layer is disabled; the notice line says so while it holds. While a day is shown the imagery keeps Esri: a manual switch that lands on Google 3D is answered at once with a new lease under the same policy (`keepEsri`), the notice reads `Imagery stays on Esri · CLEAR to use Google 3D`, and the divider never suspends because of a map switch. It re-leases once per switch generation and only for a manual one (`MapSourceController#getSwitchOrigin()` is `manual` for an outside `setStack`, `automatic` for the controller's own fallback or recovery), never for the lease's own switch and never while releasing, so CLEAR and disable still return to Google 3D; a lease another owner holds stays refused. When Esri fails and the controller falls back to Google 3D on its own, the layer lets the lease go without restoring anything, both days drape on the tileset without a swipe and the guidance reads `Esri map unavailable · no swipe`; only the next manual switch to Google 3D takes Esri again, so a failing Esri map is never retried in a loop. Switching between globe stacks (Esri, OSM, Bing) only rebinds. On a tileset host both images drape without a swipe. The split control (`createImagerySplit`, labels A / B, or IMAGE / BASEMAP) exists only while a swipe is live, recentres on every new comparison (not while scrubbing the second day), except once for a split restored from a link. There is no keyboard shortcut (Space is the app's push-to-talk): SWAP (`#ri-swap`, in the controls row, its slot reserved and the button disabled while no swipe is live) trades the two sides, A to the right and B to the left, or the image to the right of the basemap, and a second click restores; the hint reads `Drag the divider · SWAP trades sides`. The swap is not in the share link, and every new comparison starts unswapped. One opacity applies to both drapes. Another owner holding the lease is reported and the images still drape. - **Panel.** `#recent-imagery-panel` is rail markup in the Context view (`src/ui/views/ContextView.vue`) beside `#weather-panel`, registered in `PanelLayoutController`, `PanelChrome` and the share panel state (`ui` token `i`), hidden while the layer is off and opened on first appearance unless a stored or shared collapse choice exists (`dataset.collapsedPreference`). `LayerPanel.attachRecentImagery(factory)` mounts the readout (`createRecentImageryPanel` in `src/ui/recentImagery.js`) into its `data-rail-scroller` body, as the weather readout is mounted. The body is a fixed stack in which no block changes height and no control moves in any state: `#ri-actions` (SELECT BOX · USE VIEW · CLEAR, rail-card actions), `#ri-notice` (one line: `#ri-notice-text` with the refusal, error, CLEAR notice or the Esri note, and `#ri-zoom-in` in a fixed slot at its right end, reserved unless an oversized box or view can be fitted), `#ri-strip` (day cards newest first: thumbnail, date, sensor, cloud, START HERE, PREVIEW, and a SHOW chip or A and B chips; ← → Home End move, S / A / B pin, Enter previews), `#ri-hint` (one line: the next step), `#ri-selection` (`#ri-mode` IMAGE · VS BASEMAP · A / B, then `#ri-slot-a` and `#ri-slot-b` with `#ri-unpin-a` / `#ri-unpin-b` kept in place when empty), `#ri-controls` (`#ri-opacity`, EXPORT / EXPORT A and EXPORT B) and `#ri-details`, a collapsed rail card holding the focused day's acquisition, coverage and granules, catalog notes, the empty-days toggle and the imagery credit. Absent controls are reserved (invisible), never removed. Every render preserves the body's `scrollTop`; opening DETAILS then scrolls its card into view once. diff --git a/src/layers/recentImagery/index.js b/src/layers/recentImagery/index.js index 6b01fb74e1..5fff3e29ac 100644 --- a/src/layers/recentImagery/index.js +++ b/src/layers/recentImagery/index.js @@ -311,6 +311,13 @@ export function createRecentImageryLayer({ return status !== 'empty' && status !== 'error'; } + /** A pick dropped for an empty day hands a deferred slot over now. */ + function resumeHandover() { + if (!_handoverDeferred || pickWaiting()) return false; + syncRender(); + return true; + } + /** * A day whose probe came back empty leaves the map: JPEG products have no * alpha and would drape black "no data" tiles. A pinned day is unpinned and @@ -715,7 +722,7 @@ export function createRecentImageryLayer({ const key = activeSlotOf(candidate.key) ? null : candidate.key; if (key === _previewKey) return; if (key && !drapable(candidate)) { - _followKey = key; + if (availability(candidate) !== 'empty') _followKey = key; return; } _pending = { key }; @@ -1088,6 +1095,7 @@ export function createRecentImageryLayer({ if (list[next].key === _focusKey) return; _focusKey = list[next].key; schedulePreviewFromFocus(); + resumeHandover(); requestThumbnails(); notify(); }, @@ -1126,6 +1134,7 @@ export function createRecentImageryLayer({ if (!drapable(candidate)) { clearPending(); _followKey = availability(candidate) === 'empty' ? null : candidate.key; + if (resumeHandover()) requestThumbnails(); notify(); return false; } diff --git a/src/layers/recentImagery/index.test.mjs b/src/layers/recentImagery/index.test.mjs index b7a42f71a8..922783ec0d 100644 --- a/src/layers/recentImagery/index.test.mjs +++ b/src/layers/recentImagery/index.test.mjs @@ -1641,6 +1641,28 @@ test('a pick whose probe failed does not block the hand-over', async () => { assert.equal(f.owned().a?.key, L16); }); +test('a pick dropped for an empty card lets a deferred hand-over go ahead at once', async () => { + const f = fixture(); + await f.ready(); + f.layer.setShowUnavailable(true); + f.thumbnails.probe(V21, 'empty'); + f.layer.preview(V15); + f.thumbnails.probe(S18, 'empty'); + assert.equal(f.owned().a, null, 'the pick keeps the slot while it is probed'); + assert.equal(f.layer.preview(V21), false); + assert.equal(f.owned().a?.key, L16, 'a click on an empty card'); + const g = fixture(); + await g.ready(); + g.layer.setShowUnavailable(true); + g.thumbnails.probe(V21, 'empty'); + g.layer.preview(V15); + g.thumbnails.probe(S18, 'empty'); + g.layer.focus(0); + assert.equal(g.owned().a?.key, L16, 'an arrow key onto an empty card'); + assert.equal(g.snap().focus.key, V21, 'focus stays where the user put it'); + assert.equal(g.diag().following, null, 'an empty day is not followed'); +}); + test('an arrow-key pick waiting out the debounce keeps Esri through an empty automatic result', async () => { const controller = leasingController(); const f = fixture({ controller });