mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 11:42:21 +00:00
fix: refresh imagery halves after thumbnail probes
This commit is contained in:
1 parent
fb3f921ac7
commit
154d3388e5
7 files changed
+146
-13
No files matched your search
@@ -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',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
@@ -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]),
|
||||
);
|
||||
|
||||
@@ -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',
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user