mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 11:42:21 +00:00
fix(recent-imagery): keep a slot's halves in place when its probe changes them
- A probe that narrows or widens a dateline slot keeps the layer of the half that stays; a new half is inserted right above it, so in A/B without a split one day stays on top on both sides of ±180. - A VIIRS dateline box drapes nothing without per-half evidence, so a replacement source without presentBoxes cannot drape an empty black side. - The loader keeps the halves confirmed empty; DETAILS says partial for a confirmed-empty side and unknown for a side that did not answer. - mount adds parts without a rollback; unused Cesium test fakes are gone.
This commit is contained in:
1 parent
5555aba82c
commit
e71ed72272
9 files changed
+164
-77
No files matched your search
@@ -41,13 +41,16 @@ const boxKey = (box) =>
|
||||
const partsKey = (parts) => parts.map(boxKey).sort().join(';');
|
||||
|
||||
/**
|
||||
* Without per-half evidence every part drapes. With evidence, only the parts
|
||||
* it lists drape (the source's drapesOnlyProven decides which those are).
|
||||
* Evidence for another box lists none of them.
|
||||
* Without per-half evidence a dateline JPEG waits for the probe because
|
||||
* an empty side would draw black. Other boxes drape all their parts.
|
||||
* With evidence, only the listed parts of this box drape.
|
||||
*/
|
||||
function drapedParts(box, availableBoxes) {
|
||||
function drapedParts(candidate, box, availableBoxes) {
|
||||
const parts = nonCrossingBoxes(box);
|
||||
if (!Array.isArray(availableBoxes)) return parts;
|
||||
if (!Array.isArray(availableBoxes))
|
||||
return parts.length > 1 && PRODUCTS[candidate.product]?.format === 'jpg'
|
||||
? []
|
||||
: parts;
|
||||
const listed = new Set(availableBoxes.filter(Boolean).map(boxKey));
|
||||
return parts.filter((part) => listed.has(boxKey(part)));
|
||||
}
|
||||
@@ -138,16 +141,10 @@ export function createRecentImageryRenderer({
|
||||
|
||||
function mount(slotId, { candidate, parts, alpha, split }) {
|
||||
if (!parts.length) return false;
|
||||
const layers = [];
|
||||
try {
|
||||
for (const part of parts)
|
||||
layers.push(host.globe.imagery.add(specFor(candidate, part)));
|
||||
} catch (error) {
|
||||
for (const layer of layers) layer.remove();
|
||||
throw error;
|
||||
}
|
||||
owned[slotId] = {
|
||||
layers,
|
||||
layers: parts.map((part) =>
|
||||
host.globe.imagery.add(specFor(candidate, part)),
|
||||
),
|
||||
globe: host.globe,
|
||||
candidate,
|
||||
parts,
|
||||
@@ -160,8 +157,9 @@ export function createRecentImageryRenderer({
|
||||
|
||||
return {
|
||||
/**
|
||||
* Drape the available parts of a candidate into a slot. The same parts of
|
||||
* the same day on the same port only need their look updated.
|
||||
* Drape the available parts of a candidate into a slot. On the same day
|
||||
* and port, keep each surviving layer, add a new part right above it and
|
||||
* remove dropped parts.
|
||||
* @param {'a'|'b'} slotId
|
||||
* @param {object} candidate
|
||||
* @param {object} box Degrees box.
|
||||
@@ -181,14 +179,41 @@ export function createRecentImageryRenderer({
|
||||
}
|
||||
const current = owned[slotId];
|
||||
const look = { alpha: clampAlpha(alpha), split: splitDirection };
|
||||
const parts = drapedParts(box, availableBoxes);
|
||||
const parts = drapedParts(candidate, box, availableBoxes);
|
||||
if (
|
||||
current &&
|
||||
current.globe === host.globe &&
|
||||
current.candidate.key === candidate.key &&
|
||||
partsKey(current.parts) === partsKey(parts)
|
||||
parts.length
|
||||
) {
|
||||
if (current.alpha !== look.alpha || current.split !== look.split) {
|
||||
if (partsKey(current.parts) !== partsKey(parts)) {
|
||||
const previous = new Map(
|
||||
current.parts.map((part, i) => [boxKey(part), current.layers[i]]),
|
||||
);
|
||||
// A new half goes right above the slot's surviving half, so both
|
||||
// halves keep the same place against the other slot.
|
||||
const survivor = parts
|
||||
.map((part) => previous.get(boxKey(part)))
|
||||
.find(Boolean);
|
||||
const at = survivor
|
||||
? host.globe.imagery.list().indexOf(survivor) + 1
|
||||
: undefined;
|
||||
const layers = parts.map((part) => {
|
||||
const key = boxKey(part);
|
||||
const layer = previous.get(key);
|
||||
previous.delete(key);
|
||||
return (
|
||||
layer ?? host.globe.imagery.add(specFor(candidate, part), at)
|
||||
);
|
||||
});
|
||||
for (const layer of previous.values()) layer.remove();
|
||||
Object.assign(current, { layers, parts, ...look });
|
||||
applyLook(current);
|
||||
requestRender('recent-imagery-show');
|
||||
} else if (
|
||||
current.alpha !== look.alpha ||
|
||||
current.split !== look.split
|
||||
) {
|
||||
Object.assign(current, look);
|
||||
applyLook(current);
|
||||
requestRender('recent-imagery-look');
|
||||
|
||||
@@ -330,7 +330,7 @@ test('the renderer drapes only the halves the probe allows, and rebind keeps the
|
||||
next.layers.map((layer) => layer.spec.rectangle),
|
||||
[east, west, east],
|
||||
);
|
||||
renderer.showSlot('a', VIIRS, FIJI_BOX);
|
||||
renderer.showSlot('a', VIIRS, FIJI_BOX, { availableBoxes: [west, east] });
|
||||
assert.equal(next.layers.length, 4);
|
||||
renderer.destroy();
|
||||
assert.equal(next.layers.length, 0);
|
||||
@@ -347,18 +347,67 @@ test('no allowed half, or halves of another box, drapes nothing', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('without per-half evidence a VIIRS dateline box drapes nothing, a plain VIIRS box and an HLS dateline box still drape', () => {
|
||||
const { renderer, globe } = fixture();
|
||||
assert.equal(renderer.showSlot('a', VIIRS, FIJI_BOX), false);
|
||||
assert.equal(globe.layers.length, 0);
|
||||
assert.equal(renderer.showSlot('a', VIIRS, BOX), true);
|
||||
assert.equal(globe.layers.length, 1);
|
||||
assert.equal(renderer.showSlot('b', S30, FIJI_BOX), true);
|
||||
assert.equal(globe.layers.length, 3);
|
||||
renderer.destroy();
|
||||
});
|
||||
|
||||
test('evidence going from none to empty removes the drape', () => {
|
||||
const { renderer, globe } = fixture();
|
||||
renderer.showSlot('a', VIIRS, FIJI_BOX);
|
||||
renderer.showSlot('a', S30, FIJI_BOX);
|
||||
assert.equal(globe.layers.length, 2);
|
||||
assert.equal(
|
||||
renderer.showSlot('a', VIIRS, FIJI_BOX, { availableBoxes: [] }),
|
||||
renderer.showSlot('a', S30, FIJI_BOX, { availableBoxes: [] }),
|
||||
false,
|
||||
);
|
||||
assert.equal(globe.layers.length, 0);
|
||||
renderer.destroy();
|
||||
});
|
||||
|
||||
test('a probe that narrows or widens a dateline drape keeps the layer of the unchanged half', () => {
|
||||
const renderer = createRecentImageryRenderer();
|
||||
const globe = fakeGlobePort();
|
||||
renderer.rebind({ collection: {}, kind: 'globe', globe });
|
||||
const [west, east] = nonCrossingBoxes(FIJI_BOX);
|
||||
const keyOf = (box) => [box.west, box.south, box.east, box.north].join(',');
|
||||
const layerFor = (box) =>
|
||||
globe.layers.find((layer) => keyOf(layer.spec.rectangle) === keyOf(box));
|
||||
|
||||
// An HLS day drapes both halves before its probe answers.
|
||||
renderer.showSlot('a', S30, FIJI_BOX, { alpha: 0.4, splitDirection: 'left' });
|
||||
const kept = layerFor(west);
|
||||
assert.ok(kept);
|
||||
const added = globe.added.length;
|
||||
|
||||
// The probe confirms the east half empty: only the east layer goes.
|
||||
renderer.showSlot('a', S30, FIJI_BOX, {
|
||||
alpha: 0.4,
|
||||
splitDirection: 'left',
|
||||
availableBoxes: [west],
|
||||
});
|
||||
assert.equal(kept.removed, false, 'the west layer survives the narrowing');
|
||||
assert.equal(globe.added.length, added, 'narrowing adds no layer');
|
||||
assert.equal(layerFor(east), undefined);
|
||||
|
||||
// A later probe admits east again: only the east layer is added.
|
||||
renderer.showSlot('a', S30, FIJI_BOX, {
|
||||
alpha: 0.4,
|
||||
splitDirection: 'left',
|
||||
availableBoxes: [west, east],
|
||||
});
|
||||
assert.equal(kept.removed, false, 'the west layer survives the widening');
|
||||
assert.equal(globe.added.length, added + 1);
|
||||
assert.equal(kept.alpha, 0.4);
|
||||
assert.equal(kept.split, 'left');
|
||||
renderer.destroy();
|
||||
});
|
||||
|
||||
test('the drag preview draws a wrapped fill and outline across the dateline', async () => {
|
||||
const draw = fakeDrawPort();
|
||||
let box = { west: 179, south: 0, east: 179, north: 0 };
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createRecentImageryRenderer } from './rendering.js';
|
||||
import { nonCrossingBoxes } from './model.js';
|
||||
import { FIJI_BOX } from './testDoubles.mjs';
|
||||
import { fakeGlobePort } from '../../testSupport/fakeGlobePort.mjs';
|
||||
|
||||
const A = { key: 'S30:2026-09-18', product: 'S30', day: '2026-09-18' };
|
||||
const B = { key: 'L30:2026-09-16', product: 'L30', day: '2026-09-16' };
|
||||
|
||||
test('slot order survives widening', () => {
|
||||
const renderer = createRecentImageryRenderer();
|
||||
const globe = fakeGlobePort();
|
||||
renderer.rebind({ collection: {}, kind: 'globe', globe });
|
||||
const [west, east] = nonCrossingBoxes(FIJI_BOX);
|
||||
const k = (b) => [b.west, b.south, b.east, b.north].join(',');
|
||||
const look = { alpha: 1, splitDirection: 'none' };
|
||||
renderer.showSlot('a', A, FIJI_BOX, { ...look, availableBoxes: [west] });
|
||||
renderer.showSlot('b', B, FIJI_BOX, {
|
||||
...look,
|
||||
availableBoxes: [west, east],
|
||||
});
|
||||
renderer.showSlot('a', A, FIJI_BOX, {
|
||||
...look,
|
||||
availableBoxes: [west, east],
|
||||
});
|
||||
const topOn = (box) => {
|
||||
const on = globe.layers.filter((l) => k(l.spec.rectangle) === k(box));
|
||||
return on.at(-1).spec.url.includes('S30') ? 'A' : 'B';
|
||||
};
|
||||
assert.equal(
|
||||
topOn(west),
|
||||
topOn(east),
|
||||
`west top ${topOn(west)}, east top ${topOn(east)}`,
|
||||
);
|
||||
renderer.destroy();
|
||||
});
|
||||
@@ -127,8 +127,8 @@ function withHalves(response, { presentBoxes, emptyBoxes }) {
|
||||
* Thumbnail responses must expose Data-Present: true for image admission, or
|
||||
* false for confirmed empty coverage, including injected getThumbnail sources.
|
||||
* getThumbnail also sets presentBoxes and emptyBoxes (see withHalves).
|
||||
* Without per-half evidence the renderer drapes every side of a dateline
|
||||
* box, so an empty side of a VIIRS JPEG then draws black.
|
||||
* Without per-half evidence the renderer drapes every side of an HLS
|
||||
* dateline box and no side of a VIIRS one.
|
||||
*/
|
||||
export function createRecentImagerySource({
|
||||
fetchImpl = (...args) => globalThis.fetch(...args),
|
||||
|
||||
@@ -23,48 +23,6 @@ export const FIJI_BOX = Object.freeze({
|
||||
north: -17,
|
||||
});
|
||||
|
||||
/** A provider whose tile requests stay pending until the test settles them. */
|
||||
class UrlTemplateImageryProvider {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
this.calls = [];
|
||||
this.pending = [];
|
||||
}
|
||||
requestImage(x, y, level) {
|
||||
this.calls.push([x, y, level]);
|
||||
return new Promise((resolve) => this.pending.push(resolve));
|
||||
}
|
||||
}
|
||||
|
||||
export function fakeCesium(requestImage) {
|
||||
class Provider extends UrlTemplateImageryProvider {}
|
||||
if (requestImage) Provider.prototype.requestImage = requestImage;
|
||||
return {
|
||||
UrlTemplateImageryProvider: Provider,
|
||||
WebMercatorTilingScheme: class {},
|
||||
Rectangle: {
|
||||
fromDegrees: (west, south, east, north) => ({ west, south, east, north }),
|
||||
},
|
||||
SplitDirection: { LEFT: -1, NONE: 0, RIGHT: 1 },
|
||||
};
|
||||
}
|
||||
|
||||
export function fakeCollection() {
|
||||
const layers = [];
|
||||
return {
|
||||
layers,
|
||||
addImageryProvider(provider) {
|
||||
const layer = { provider, alpha: 1, splitDirection: 0 };
|
||||
layers.push(layer);
|
||||
return layer;
|
||||
},
|
||||
remove(layer, destroy) {
|
||||
layers.splice(layers.indexOf(layer), 1);
|
||||
layer.destroyed = destroy;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
/** Timers that fire only when the test says so. */
|
||||
|
||||
@@ -16,6 +16,7 @@ const EMPTY = Object.freeze({
|
||||
objectUrl: null,
|
||||
acquisitionTime: null,
|
||||
availableBoxes: null,
|
||||
emptyBoxes: null,
|
||||
loading: false,
|
||||
});
|
||||
|
||||
@@ -157,6 +158,7 @@ export function createThumbnailLoader({
|
||||
entry.status = status;
|
||||
entry.acquisitionTime = acquisitionTime;
|
||||
entry.availableBoxes = availableBoxes;
|
||||
entry.emptyBoxes = emptyBoxes;
|
||||
}
|
||||
entry.objectUrl = objectUrl;
|
||||
touch(entry);
|
||||
@@ -221,6 +223,7 @@ export function createThumbnailLoader({
|
||||
objectUrl: null,
|
||||
acquisitionTime: null,
|
||||
availableBoxes: null,
|
||||
emptyBoxes: null,
|
||||
loading: false,
|
||||
controller: null,
|
||||
touched: 0,
|
||||
@@ -297,7 +300,7 @@ export function createThumbnailLoader({
|
||||
/**
|
||||
* Read a day's state. A read is not a use: it never changes residency.
|
||||
* @param {string} key Candidate key.
|
||||
* @returns {{ status: 'unknown'|'present'|'empty'|'error', objectUrl: string | null, acquisitionTime: string | null, availableBoxes: Array<object> | null, loading: boolean }}
|
||||
* @returns {{ status: 'unknown'|'present'|'empty'|'error', objectUrl: string | null, acquisitionTime: string | null, availableBoxes: Array<object> | null, emptyBoxes: Array<object> | null, loading: boolean }}
|
||||
*/
|
||||
get(key) {
|
||||
const entry = entries.get(key);
|
||||
@@ -307,6 +310,7 @@ export function createThumbnailLoader({
|
||||
objectUrl: entry.objectUrl,
|
||||
acquisitionTime: entry.acquisitionTime,
|
||||
availableBoxes: entry.availableBoxes,
|
||||
emptyBoxes: entry.emptyBoxes,
|
||||
loading: entry.loading,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -65,6 +65,7 @@ test('Data-Present decides the day: present with an object URL and sensing time,
|
||||
objectUrl: 'blob:1',
|
||||
acquisitionTime: '2026-09-18T17:12:00Z',
|
||||
availableBoxes: [BOX],
|
||||
emptyBoxes: [],
|
||||
loading: false,
|
||||
});
|
||||
assert.equal(loader.get('L30:2026-09-16').status, 'empty');
|
||||
|
||||
@@ -136,14 +136,16 @@ function coverageText(coverage) {
|
||||
return t('unknown');
|
||||
}
|
||||
|
||||
/** A present day covers the box only in part when its probe omits a side. */
|
||||
/** A confirmed-empty side means partial coverage. An unanswered side leaves coverage unknown. */
|
||||
function shownCoverage(candidate, box) {
|
||||
const drapes = candidate.thumbnail?.availableBoxes;
|
||||
return candidate.thumbnail?.status === 'present' &&
|
||||
Array.isArray(drapes) &&
|
||||
drapes.length < nonCrossingBoxes(box).length
|
||||
? 'partial'
|
||||
: candidate.coverage;
|
||||
const { status, availableBoxes, emptyBoxes } = candidate.thumbnail ?? {};
|
||||
if (
|
||||
status !== 'present' ||
|
||||
!Array.isArray(availableBoxes) ||
|
||||
availableBoxes.length >= nonCrossingBoxes(box).length
|
||||
)
|
||||
return candidate.coverage;
|
||||
return emptyBoxes?.length ? 'partial' : 'unknown';
|
||||
}
|
||||
|
||||
function cloudText(candidate) {
|
||||
|
||||
@@ -1066,7 +1066,7 @@ test('DETAILS is a collapsed rail card holding every note, and the empty-days to
|
||||
assert.equal(article.dataset.open, 'false');
|
||||
});
|
||||
|
||||
test('DETAILS shows partial coverage when a present dateline day drapes one half', async () => {
|
||||
test('DETAILS shows partial coverage for a dateline day with one side empty, unknown when a side did not answer', async () => {
|
||||
const f = fixture();
|
||||
f.layer.enable();
|
||||
f.layer.setBox(FIJI_BOX);
|
||||
@@ -1074,10 +1074,21 @@ test('DETAILS shows partial coverage when a present dateline day drapes one half
|
||||
await settle();
|
||||
assert.match(f.byId('ri-details').textContent, /Coverage full/);
|
||||
const get = f.thumbnails.get;
|
||||
const [west] = nonCrossingBoxes(FIJI_BOX);
|
||||
f.thumbnails.get = (key) => ({ ...get(key), availableBoxes: [west] });
|
||||
const [west, east] = nonCrossingBoxes(FIJI_BOX);
|
||||
f.thumbnails.get = (key) => ({
|
||||
...get(key),
|
||||
availableBoxes: [west],
|
||||
emptyBoxes: [east],
|
||||
});
|
||||
f.thumbnails.probe(f.snap().focus.key, 'present');
|
||||
assert.match(f.byId('ri-details').textContent, /Coverage partial/);
|
||||
f.thumbnails.get = (key) => ({
|
||||
...get(key),
|
||||
availableBoxes: [west],
|
||||
emptyBoxes: [],
|
||||
});
|
||||
f.thumbnails.probe(f.snap().focus.key, 'present');
|
||||
assert.match(f.byId('ri-details').textContent, /Coverage unknown/);
|
||||
});
|
||||
|
||||
test('the body scroll position survives renders even when DOM mutations reset it', async () => {
|
||||
|
||||
Reference in new issue
Block a user