From 154d3388e526f19d6f4ad22015b9129d51237df0 Mon Sep 17 00:00:00 2001 From: brandonabyrd Date: Fri, 13 Nov 2026 09:35:51 -0600 Subject: [PATCH] fix: refresh imagery halves after thumbnail probes --- changelog.d/1540-recent-imagery-dateline.md | 11 ++- docs/CURRENT-STATE.md | 2 +- .../recentImagery/dateline-halves.test.mjs | 12 ++- src/layers/recentImagery/index.js | 4 +- src/layers/recentImagery/index.test.mjs | 17 ++++ src/layers/recentImagery/source.js | 28 ++++-- src/layers/recentImagery/source.test.mjs | 85 +++++++++++++++++++ 7 files changed, 146 insertions(+), 13 deletions(-) diff --git a/changelog.d/1540-recent-imagery-dateline.md b/changelog.d/1540-recent-imagery-dateline.md index 4786ba34e7..6b5dfa6419 100644 --- a/changelog.d/1540-recent-imagery-dateline.md +++ b/changelog.d/1540-recent-imagery-dateline.md @@ -4,6 +4,11 @@ both sides. Availability probes both sides of ±180° (a day counts as present when either side has data, and sides confirmed empty are not draped). Each side has a deadline so a stalled probe cannot indefinitely block the day; - unknown or failed sides are not treated as empty. Voice accepts named areas - across the dateline, and EXPORT is disabled up front with the reason, since - Worldview Snapshots cannot draw a box that crosses ±180° (Byrd-IT, #1540). + unknown or failed sides are not treated as empty. A side that is not + confirmed present is draped only where the product has alpha: VIIRS is a + JPEG, so an unproven side would land on the map as a black rectangle, and + only a side Worldview confirmed present is draped for it; a PNG (HLS) + keeps the unproven side because alpha hides it. The day itself stays + present. Voice accepts named areas across the dateline, and EXPORT is + disabled up front with the reason, since Worldview Snapshots cannot draw a + box that crosses ±180° (Byrd-IT, #1540). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 5da48f0298..43beee2ae9 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -7277,7 +7277,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, a box across the dateline sent as one bounding box with west > east, which CMR reads as the short box, 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 and inside the Web-Mercator limit (`validateBox`). A drag whose corners are more than 180° of longitude apart is the short box across the dateline, returned with west > east; its width is the short arc, so only a short arc over the cap is refused as too large. Worldview Snapshots rejects a west > east BBOX, so EXPORT (`Select one side of the dateline`) and `get_recent_imagery` (`A snapshot cannot cross the dateline`) refuse a dateline box without requesting one, and its thumbnails and Data-Present probes ask Worldview about each side of ±180° separately (wider side first, 15 s deadline per side, the caller's cancellation kept): the day is present when either side has data and empty only when both sides are confirmed empty, a side that failed or timed out is never read as empty, and a side confirmed empty is not draped. 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. +- **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 and inside the Web-Mercator limit (`validateBox`). A drag whose corners are more than 180° of longitude apart is the short box across the dateline, returned with west > east; its width is the short arc, so only a short arc over the cap is refused as too large. Worldview Snapshots rejects a west > east BBOX, so EXPORT (`Select one side of the dateline`) and `get_recent_imagery` (`A snapshot cannot cross the dateline`) refuse a dateline box without requesting one, and its thumbnails and Data-Present probes ask Worldview about each side of ±180° separately (wider side first, 15 s deadline per side, the caller's cancellation kept): the day is present when either side has data and empty only when both sides are confirmed empty, a side that failed or timed out is never read as empty, and a side confirmed empty is not draped. A side that is not confirmed present is draped only for a product with alpha: VIIRS is a JPEG, so an unproven side would land on the map as a black rectangle and only a side Worldview confirmed present is draped for it, while a PNG (HLS) keeps the unproven side because alpha hides it. The day itself stays present. 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. - **Rendering.** `rendering.js` owns at most two slots (a dateline box drapes two GIBS layers in its slot, one each side of ±180) 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. diff --git a/src/layers/recentImagery/dateline-halves.test.mjs b/src/layers/recentImagery/dateline-halves.test.mjs index 37a6191d39..a430eda348 100644 --- a/src/layers/recentImagery/dateline-halves.test.mjs +++ b/src/layers/recentImagery/dateline-halves.test.mjs @@ -340,8 +340,8 @@ test('a half that fails or stalls after the other half proved data does not unse assert.equal(response.headers.get('Data-Present'), 'true'); assert.deepEqual( response.presentBoxes, - [EAST_HALF, WEST_HALF], - 'the unproven half is not called empty', + [WEST_HALF], + 'the stalled half is not draped: VIIRS is a JPEG without alpha', ); const failing = timedFetch({ @@ -666,9 +666,15 @@ test('a failed half is not mistaken for confirmed empty when the other is presen halfDeadlineMs: 20, }); const response = await source.getThumbnail(FIJI_CANDIDATE, FIJI_BOX); + assert.equal( + response.headers.get('Data-Present'), + 'true', + 'the day itself stays present', + ); assert.deepEqual( new Set(response.presentBoxes.map(bbox)), - new Set([bbox(EAST_HALF), bbox(WEST_HALF)]), + new Set([bbox(EAST_HALF)]), + 'the failed half is not draped: VIIRS is a JPEG without alpha', ); }); diff --git a/src/layers/recentImagery/index.js b/src/layers/recentImagery/index.js index 6520d81f85..ba29b3e95f 100644 --- a/src/layers/recentImagery/index.js +++ b/src/layers/recentImagery/index.js @@ -832,7 +832,9 @@ export function createRecentImageryLayer({ const drapesChanged = SLOT_IDS.some( (slotId) => (owned[slotId]?.key || null) !== shown[slotId], ); - if (drapesChanged && !pruned && !followed) syncRender(); + // The key can stay the same while a new probe changes its boxes. + // showSlot itself avoids rebuilding an unchanged drape. + if (!pruned && !followed) syncRender(); notify('thumbnail'); if (pruned || followed || drapesChanged) notify(); }); diff --git a/src/layers/recentImagery/index.test.mjs b/src/layers/recentImagery/index.test.mjs index 913d5a1a6a..0268e8e093 100644 --- a/src/layers/recentImagery/index.test.mjs +++ b/src/layers/recentImagery/index.test.mjs @@ -1410,3 +1410,20 @@ test('a box dragged across the dateline is searched, listed and draped as one bo assert.equal(f.drapes().a, `${S18}|none`, 'the crossing box is draped'); assert.equal(f.snap().boxSizeKm.width < 100, true, 'the short arc, not 360°'); }); + + +test('thumbnail availability changes refresh an already shown day', async () => { + const f = fixture(); + const priorGet = f.thumbnails.get; + let boxes = [BOX]; + f.thumbnails.get = (key) => ({ ...priorGet(key), availableBoxes: boxes }); + await f.ready(); + f.thumbnails.probeRequested(); + const slot = Object.keys(f.owned()).find((id) => f.owned()[id]); + assert.ok(slot, 'a day is already on the map'); + const key = f.owned()[slot].key; + boxes = [{ ...BOX, east: BOX.west + 1 }]; + f.thumbnails.probe(key, 'present'); + assert.deepEqual(f.owned()[slot].availableBoxes, boxes); + f.layer.destroy(); +}); diff --git a/src/layers/recentImagery/source.js b/src/layers/recentImagery/source.js index f9f304ef45..18f2cf3753 100644 --- a/src/layers/recentImagery/source.js +++ b/src/layers/recentImagery/source.js @@ -1,5 +1,10 @@ import { searchHls } from './catalog.js'; -import { gibsTemplate, nonCrossingBoxes, wvsSnapshotUrl } from './model.js'; +import { + PRODUCTS, + gibsTemplate, + nonCrossingBoxes, + wvsSnapshotUrl, +} from './model.js'; /** * A half's answer is only worth so much waiting: past this deadline the half @@ -23,6 +28,15 @@ function requestBoxes(box) { const isPresent = (response) => dataPresent(response) === 'true'; +/** + * A product without alpha (the VIIRS JPEG) cannot hide an empty half: it + * would drape as a black rectangle. Only a half Worldview confirmed present + * may be draped for it; a PNG (HLS) has alpha, so an unknown half is safe + * to keep and drape. + */ +const drapesOnlyProven = (candidate) => + PRODUCTS[candidate?.product]?.format === 'jpg'; + const dataPresent = (response) => response?.ok ? String(response.headers?.get?.('Data-Present') ?? '').toLowerCase() @@ -209,10 +223,14 @@ export function createRecentImagerySource({ return withPresentBoxes( combineHalves(responses), probes - .filter( - (probe, i) => - results[i].status === 'rejected' || - dataPresent(results[i].value) !== 'false', + .filter((probe, i) => + // A product without alpha may drape only a half Worldview + // confirmed present: an empty or unproven half would land on + // the map as a black rectangle. A PNG keeps an unproven half. + drapesOnlyProven(candidate) + ? isPresent(results[i].value) + : results[i].status === 'rejected' || + dataPresent(results[i].value) !== 'false', ) .map((entry) => nonCrossingBoxes(entry.half)[0]), ); diff --git a/src/layers/recentImagery/source.test.mjs b/src/layers/recentImagery/source.test.mjs index 1318286a61..0d488a1da6 100644 --- a/src/layers/recentImagery/source.test.mjs +++ b/src/layers/recentImagery/source.test.mjs @@ -190,3 +190,88 @@ test('a rejected half does not hide data on the other half, and never reads as e /Thumbnail request failed/, ); }); + +// PR #1540 review (P2): a half whose probe failed or hung must not be +// draped for a product without alpha. VIIRS is a JPEG, so an empty or +// unknown half would land on the map as a black rectangle. Only a half +// Worldview confirmed present (`Data-Present: true`) may be draped for it. +// PNG products (HLS) keep an unknown half: alpha hides it. +const JPEG_CANDIDATE = { product: 'VIIRS', day: '2026-10-01' }; +const WIDE_BOX = { west: -180, south: 0, east: -179, north: 1 }; +const NARROW_BOX = { west: 179.9, south: 0, east: 180, north: 1 }; + +test('a JPEG product drapes only the half Worldview confirmed present: a rejected half is not draped', async () => { + const { source } = halvesSource({ + '-180/-179': new Error('network'), + '179.9/180': dated('true', 'narrow'), + }); + const response = await source.getThumbnail(JPEG_CANDIDATE, NARROW_WEST); + assert.equal( + response.headers.get('Data-Present'), + 'true', + 'the day itself stays present', + ); + assert.deepEqual( + response.presentBoxes, + [NARROW_BOX], + 'the failed half is not draped', + ); +}); + +test('a JPEG product does not drape a half whose probe hung', async () => { + const requested = []; + const source = createRecentImagerySource({ + thumbnailUrl: ({ box }) => { + requested.push(box); + return `https://imagery.example/${box.west}/${box.east}`; + }, + halfDeadlineMs: 20, + fetchImpl: async (url) => { + const answer = { + '-180/-179': () => new Promise(() => {}), + '179.9/180': () => dated('true', 'narrow'), + }[url.split('imagery.example/')[1]]; + return answer(); + }, + }); + const response = await source.getThumbnail(JPEG_CANDIDATE, NARROW_WEST); + assert.equal(requested.length, 2, 'both halves were requested'); + assert.equal( + response.headers.get('Data-Present'), + 'true', + 'the day itself stays present', + ); + assert.deepEqual( + response.presentBoxes, + [NARROW_BOX], + 'the hung half is not draped', + ); +}); + +test('a JPEG product does not drape a half that answered with an unknown presence', async () => { + const { source } = halvesSource({ + '-180/-179': dated('unknown', 'maybe'), + '179.9/180': dated('true', 'narrow'), + }); + const response = await source.getThumbnail(JPEG_CANDIDATE, NARROW_WEST); + assert.equal(response.headers.get('Data-Present'), 'true'); + assert.deepEqual( + response.presentBoxes, + [NARROW_BOX], + 'an unproven half is not draped', + ); +}); + +test('a PNG product keeps an unknown or failed half: alpha hides it', async () => { + const { source } = halvesSource({ + '-180/-179': new Error('network'), + '179.9/180': dated('true', 'narrow'), + }); + const response = await source.getThumbnail(candidate, NARROW_WEST); + assert.equal(await response.text(), 'narrow'); + assert.deepEqual( + response.presentBoxes, + [WIDE_BOX, NARROW_BOX], + 'a PNG keeps the unproven half', + ); +});