mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 11:42:21 +00:00
fix(recent-imagery): address dateline review (halves availability, voice guard, export, renderer fallback)
This commit is contained in:
1 parent
9a34d63f1d
commit
d60f2420f4
9 files changed
+209
-54
No files matched your search
@@ -148,8 +148,9 @@ export function createRecentImageryRenderer({
|
||||
}
|
||||
|
||||
function mount(slotId, { candidate, box, alpha, split }) {
|
||||
const rectangles = nonCrossingBoxes(box);
|
||||
const parts = rectangles.length ? rectangles : [box];
|
||||
// [] means "not a box": add no layer rather than drape the raw box.
|
||||
const parts = nonCrossingBoxes(box);
|
||||
if (!parts.length) return false;
|
||||
// Build every provider before adding any layer, so a throw on the second
|
||||
// half of a dateline box cannot leave the first layer untracked.
|
||||
const providers = parts.map((part) => createProvider(candidate, part));
|
||||
@@ -176,6 +177,7 @@ export function createRecentImageryRenderer({
|
||||
split,
|
||||
};
|
||||
applyLook(owned[slotId]);
|
||||
return true;
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -215,7 +217,7 @@ export function createRecentImageryRenderer({
|
||||
return true;
|
||||
}
|
||||
removeOwned(slotId);
|
||||
mount(slotId, { candidate, box, ...look });
|
||||
if (!mount(slotId, { candidate, box, ...look })) return false;
|
||||
requestRender('recent-imagery-show');
|
||||
return true;
|
||||
},
|
||||
|
||||
@@ -287,3 +287,13 @@ test('a dateline provider that fails on the second half adds no layer', () => {
|
||||
assert.equal(globe.layers.length, 0);
|
||||
assert.equal(renderer.ownedCount(), 0);
|
||||
});
|
||||
|
||||
test('a box that is not a box adds no layer and drapes nothing', () => {
|
||||
const { renderer, globe, renders } = fixture();
|
||||
for (const bad of [{ west: NaN, south: 0, east: 1, north: 1 }, { west: 0 }]) {
|
||||
assert.equal(renderer.showSlot('a', S30, bad), false);
|
||||
}
|
||||
assert.equal(globe.layers.length, 0);
|
||||
assert.equal(renderer.ownedCount(), 0);
|
||||
assert.deepEqual(renders, []);
|
||||
});
|
||||
@@ -3,17 +3,34 @@ import { gibsTemplate, nonCrossingBoxes, wvsSnapshotUrl } from './model.js';
|
||||
|
||||
/**
|
||||
* Worldview Snapshots rejects a BBOX with west > east, so a dateline box is
|
||||
* probed on its wider side. That is enough for the Data-Present answer, and
|
||||
* the thumbnail shows that side.
|
||||
* probed as its two non-crossing halves, wider first. Granules do not cross
|
||||
* +/-180, so a day has data when either half does.
|
||||
*/
|
||||
function requestBox(box) {
|
||||
if (!(box?.west > box?.east)) return box;
|
||||
function requestBoxes(box) {
|
||||
if (!(box?.west > box?.east)) return [box];
|
||||
const halves = nonCrossingBoxes(box);
|
||||
return halves.reduce(
|
||||
(wider, half) =>
|
||||
half.east - half.west > wider.east - wider.west ? half : wider,
|
||||
halves[0] ?? box,
|
||||
);
|
||||
if (!halves.length) return [box];
|
||||
return [...halves].sort((a, b) => b.east - b.west - (a.east - a.west));
|
||||
}
|
||||
|
||||
const isPresent = (response) => dataPresent(response) === 'true';
|
||||
|
||||
const dataPresent = (response) =>
|
||||
response?.ok
|
||||
? String(response.headers?.get?.('Data-Present') ?? '').toLowerCase()
|
||||
: '';
|
||||
|
||||
/**
|
||||
* One answer for a crossing box: the first half that has data (the wider side
|
||||
* wins a tie, so the thumbnail shows it); both confirmed empty is empty; any
|
||||
* other mix (a failed or unreadable half) is returned as that half's response
|
||||
* so the day is never called empty on partial evidence.
|
||||
*/
|
||||
function combineHalves(responses) {
|
||||
const present = responses.find(isPresent);
|
||||
if (present) return present;
|
||||
const unproven = responses.find((r) => dataPresent(r) !== 'false');
|
||||
return unproven ?? responses[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,18 +50,29 @@ export function createRecentImagerySource({
|
||||
searchHls: (query) => search({ ...query, fetchImpl }),
|
||||
async getThumbnail(candidate, box, { size = 256, signal } = {}) {
|
||||
signal?.throwIfAborted();
|
||||
const response = await fetchImpl(
|
||||
thumbnailUrl({
|
||||
product: candidate.product,
|
||||
day: candidate.day,
|
||||
box: requestBox(box),
|
||||
width: size,
|
||||
height: size,
|
||||
}),
|
||||
{ signal },
|
||||
const settled = await Promise.allSettled(
|
||||
requestBoxes(box).map((half) =>
|
||||
fetchImpl(
|
||||
thumbnailUrl({
|
||||
product: candidate.product,
|
||||
day: candidate.day,
|
||||
box: half,
|
||||
width: size,
|
||||
height: size,
|
||||
}),
|
||||
{ signal },
|
||||
),
|
||||
),
|
||||
);
|
||||
signal?.throwIfAborted();
|
||||
return response;
|
||||
const responses = settled
|
||||
.filter((result) => result.status === 'fulfilled')
|
||||
.map((result) => result.value);
|
||||
// A half that data proves present settles the day; otherwise a
|
||||
// rejected half is an error, never an empty day.
|
||||
if (responses.length < settled.length && !responses.some(isPresent))
|
||||
throw settled.find((result) => result.status === 'rejected').reason;
|
||||
return responses.length > 1 ? combineHalves(responses) : responses[0];
|
||||
},
|
||||
getTileTemplate: (product, day) => tileTemplate(product, day),
|
||||
};
|
||||
|
||||
@@ -41,7 +41,7 @@ test('cancelled thumbnail acquisition does not return stale responses or retry',
|
||||
assert.equal(calls, 1);
|
||||
});
|
||||
|
||||
test('a dateline thumbnail is requested for the wider side, never as a crossing BBOX', async () => {
|
||||
test('a dateline thumbnail is requested as two non-crossing halves, never as a crossing BBOX', async () => {
|
||||
const requested = [];
|
||||
const source = createRecentImagerySource({
|
||||
thumbnailUrl: ({ box }) => {
|
||||
@@ -57,23 +57,100 @@ test('a dateline thumbnail is requested for the wider side, never as a crossing
|
||||
east: -179,
|
||||
north: 1,
|
||||
});
|
||||
assert.deepEqual(requested.at(-1), {
|
||||
west: -180,
|
||||
south: 0,
|
||||
east: -179,
|
||||
north: 1,
|
||||
});
|
||||
assert.deepEqual(requested, [
|
||||
{ west: -180, south: 0, east: -179, north: 1 },
|
||||
{ west: 179.9, south: 0, east: 180, north: 1 },
|
||||
]);
|
||||
requested.length = 0;
|
||||
await source.getThumbnail(candidate, {
|
||||
west: 179,
|
||||
south: 0,
|
||||
east: -179.9,
|
||||
north: 1,
|
||||
});
|
||||
assert.deepEqual(requested.at(-1), {
|
||||
west: 179,
|
||||
south: 0,
|
||||
east: 180,
|
||||
north: 1,
|
||||
});
|
||||
assert.deepEqual(requested[0], { west: 179, south: 0, east: 180, north: 1 });
|
||||
assert.equal(requested.length, 2);
|
||||
assert.ok(requested.every((box) => box.west <= box.east));
|
||||
});
|
||||
|
||||
const NARROW_WEST = { west: 179.9, south: 0, east: -179, north: 1 };
|
||||
const dated = (present, body = 'image') =>
|
||||
new Response(body, { headers: { 'Data-Present': present } });
|
||||
function halvesSource(answers) {
|
||||
const requested = [];
|
||||
const source = createRecentImagerySource({
|
||||
thumbnailUrl: ({ box }) => `https://imagery.example/${box.west}/${box.east}`,
|
||||
fetchImpl: async (url) => {
|
||||
requested.push(url);
|
||||
const answer = answers[url.split('imagery.example/')[1]];
|
||||
if (answer instanceof Error) throw answer;
|
||||
return answer.clone ? answer : answer();
|
||||
},
|
||||
});
|
||||
return { source, requested };
|
||||
}
|
||||
const candidate = { product: 'S30', day: '2026-10-01' };
|
||||
|
||||
test('a crossing box probes both halves and is present when only the narrow half has data', async () => {
|
||||
const { source, requested } = halvesSource({
|
||||
'-180/-179': dated('false'),
|
||||
'179.9/180': dated('true', 'narrow'),
|
||||
});
|
||||
const response = await source.getThumbnail(candidate, NARROW_WEST);
|
||||
assert.equal(requested.length, 2);
|
||||
assert.equal(response.headers.get('Data-Present'), 'true');
|
||||
assert.equal(await response.text(), 'narrow');
|
||||
});
|
||||
|
||||
test('a crossing box with data only on the wider half is present and shows the wider side', async () => {
|
||||
const { source } = halvesSource({
|
||||
'-180/-179': dated('true', 'wide'),
|
||||
'179.9/180': dated('false'),
|
||||
});
|
||||
const response = await source.getThumbnail(candidate, NARROW_WEST);
|
||||
assert.equal(await response.text(), 'wide');
|
||||
});
|
||||
|
||||
test('a crossing box is empty only when both halves are confirmed empty', async () => {
|
||||
const { source } = halvesSource({
|
||||
'-180/-179': dated('false'),
|
||||
'179.9/180': dated('false'),
|
||||
});
|
||||
const response = await source.getThumbnail(candidate, NARROW_WEST);
|
||||
assert.equal(response.headers.get('Data-Present'), 'false');
|
||||
});
|
||||
|
||||
test('a crossing box is not called empty when the other half failed', async () => {
|
||||
const { source } = halvesSource({
|
||||
'-180/-179': dated('false'),
|
||||
'179.9/180': () => new Response('x', { status: 503 }),
|
||||
});
|
||||
const response = await source.getThumbnail(candidate, NARROW_WEST);
|
||||
assert.equal(response.ok, false);
|
||||
});
|
||||
|
||||
test('a crossing box with both halves present shows the wider half', async () => {
|
||||
const { source } = halvesSource({
|
||||
'-180/-179': dated('true', 'wide'),
|
||||
'179.9/180': dated('true', 'narrow'),
|
||||
});
|
||||
const response = await source.getThumbnail(candidate, NARROW_WEST);
|
||||
assert.equal(await response.text(), 'wide');
|
||||
});
|
||||
|
||||
test('a rejected half does not hide data on the other half, and never reads as empty', 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');
|
||||
const failing = halvesSource({
|
||||
'-180/-179': new Error('network'),
|
||||
'179.9/180': dated('false'),
|
||||
});
|
||||
await assert.rejects(
|
||||
failing.source.getThumbnail(candidate, NARROW_WEST),
|
||||
/network/,
|
||||
);
|
||||
});
|
||||
+10
-4
@@ -523,6 +523,10 @@ export function createRecentImageryPanel({
|
||||
|
||||
function exportsView() {
|
||||
const ab = snapshot.mode === 'ab';
|
||||
// Worldview Snapshots rejects a crossing BBOX: say so up front.
|
||||
const crossing = Boolean(
|
||||
snapshot.box && snapshot.box.west > snapshot.box.east,
|
||||
);
|
||||
return [
|
||||
{
|
||||
id: 'export',
|
||||
@@ -532,10 +536,12 @@ export function createRecentImageryPanel({
|
||||
label: ab
|
||||
? t('EXPORT {slot}', { slot: slotId.toUpperCase() })
|
||||
: t('EXPORT'),
|
||||
title: ab
|
||||
? t('Download {slot} as a PNG', { slot: slotId.toUpperCase() })
|
||||
: t('Download the image as a PNG'),
|
||||
disabled: !exportTarget(slotId) || exporting.has(slotId),
|
||||
title: crossing
|
||||
? t('Select one side of the dateline')
|
||||
: ab
|
||||
? t('Download {slot} as a PNG', { slot: slotId.toUpperCase() })
|
||||
: t('Download the image as a PNG'),
|
||||
disabled: crossing || !exportTarget(slotId) || exporting.has(slotId),
|
||||
reserved: slotId === 'b' ? !ab : undefined,
|
||||
onClick: () => void exportImage(slotId),
|
||||
})),
|
||||
|
||||
@@ -978,6 +978,10 @@ test('opacity drives both images; EXPORT downloads the pin or the preview and EX
|
||||
'Select one side of the dateline',
|
||||
'the drawn box is not a warning until an export is tried',
|
||||
);
|
||||
const crossingExport = f.byAction('export-a');
|
||||
assert.equal(crossingExport.disabled, true, 'EXPORT is off up front');
|
||||
assert.equal(crossingExport.title, 'Select one side of the dateline');
|
||||
// The exportImage guard stays as a backstop.
|
||||
assert.equal(await f.readout.exportImage('a'), false);
|
||||
assert.equal(
|
||||
f.byId('ri-notice-text').textContent,
|
||||
|
||||
@@ -17,7 +17,12 @@
|
||||
* @module voice/imageryActions
|
||||
*/
|
||||
|
||||
import { PRODUCTS, rankLatest } from '../layers/recentImagery/model.js';
|
||||
import {
|
||||
PRODUCTS,
|
||||
boxCentre,
|
||||
lonSpanDeg,
|
||||
rankLatest,
|
||||
} from '../layers/recentImagery/model.js';
|
||||
import {
|
||||
displacedLayerResult,
|
||||
watchExplicitLayerOff,
|
||||
@@ -203,19 +208,18 @@ export async function findImagery(
|
||||
`No area "${args.areaId}" on this page — call resolve_area again.`,
|
||||
);
|
||||
const [west, south, east, north] = record.bbox;
|
||||
if (west > east)
|
||||
return fail(
|
||||
'DATELINE',
|
||||
`${record.name} crosses the date line; the imagery box needs one side of it.`,
|
||||
);
|
||||
// 30 m pixels over a landmark-sized area show a handful of blobs: a small
|
||||
// area gets the layer's own 10 km box around its centre instead.
|
||||
// west > east is the short arc across the date line: measure and centre
|
||||
// it with the layer's own helpers, never (west + east) / 2.
|
||||
const small =
|
||||
(north - south) * 111 < 5 &&
|
||||
(east - west) * 111 * Math.cos((((north + south) / 2) * Math.PI) / 180) <
|
||||
lonSpanDeg(west, east) *
|
||||
111 *
|
||||
Math.cos((((north + south) / 2) * Math.PI) / 180) <
|
||||
5;
|
||||
box = small
|
||||
? { pin: { lon: (west + east) / 2, lat: (south + north) / 2 } }
|
||||
? { pin: boxCentre({ west, south, east, north }) }
|
||||
: { west, south, east, north };
|
||||
areaName = record.name;
|
||||
} else if (where === 'point') {
|
||||
|
||||
@@ -236,7 +236,7 @@ test('an area handle searches its bounding box; the view and pointer have their
|
||||
assert.equal(unknown.code, 'AREA_UNKNOWN');
|
||||
});
|
||||
|
||||
test('a mixed antimeridian area gets the deliberate imagery date-line refusal', async () => {
|
||||
test('a mixed antimeridian area is searched as its short-arc box', async () => {
|
||||
const square = (w, s, e, n) => [
|
||||
[w, s],
|
||||
[e, s],
|
||||
@@ -251,6 +251,7 @@ test('a mixed antimeridian area gets the deliberate imagery date-line refusal',
|
||||
[178, 1],
|
||||
[178, 0],
|
||||
];
|
||||
const layer = fakeLayer();
|
||||
const store = createAreaStore();
|
||||
const area = store.put({
|
||||
geometry: [[crossing], [square(-176, 0.2, -174, 0.8)]],
|
||||
@@ -258,11 +259,33 @@ test('a mixed antimeridian area gets the deliberate imagery date-line refusal',
|
||||
source: 'osm',
|
||||
});
|
||||
assert.deepEqual(area.bbox, [178, 0, -174, 1]);
|
||||
const result = await findImagery(deps(fakeLayer(), { area }).value, {
|
||||
const result = await findImagery(deps(layer, { area }).value, {
|
||||
areaId: area.areaId,
|
||||
});
|
||||
assert.equal(result.ok, false);
|
||||
assert.equal(result.code, 'DATELINE');
|
||||
assert.equal(result.ok, true, 'the guard is lifted');
|
||||
assert.deepEqual(layer.calls.find((c) => c[0] === 'setBox')[1], {
|
||||
west: 178,
|
||||
south: 0,
|
||||
east: -174,
|
||||
north: 1,
|
||||
});
|
||||
});
|
||||
|
||||
test('a small area across the date line is pinned at its short-arc centre', async () => {
|
||||
const layer = fakeLayer();
|
||||
await findImagery(
|
||||
deps(layer, {
|
||||
area: {
|
||||
areaId: 'd',
|
||||
name: 'Dateline Islet',
|
||||
bbox: [179.998, 0, -179.998, 0.01],
|
||||
},
|
||||
}).value,
|
||||
{ areaId: 'd' },
|
||||
);
|
||||
const [, lon, lat] = layer.calls.find((c) => c[0] === 'boxFromPinAt');
|
||||
assert.ok(Math.abs(Math.abs(lon) - 180) < 1e-9, `pin lon ${lon}, not 0`);
|
||||
assert.equal(lat, 0.005);
|
||||
});
|
||||
|
||||
test('a box the layer refuses is refused with its reason, and the layer is turned on first', async () => {
|
||||
|
||||
Reference in new issue
Block a user