mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
Merge branch 'main' into codex/fix-annotation-height-culling
This commit is contained in:
4 files changed
+313
-18
No files matched your search
@@ -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;
|
||||
@@ -283,18 +285,39 @@ 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;
|
||||
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 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
|
||||
@@ -315,7 +338,12 @@ export function createRecentImageryLayer({
|
||||
_previewKey = null;
|
||||
_auto = null;
|
||||
changed = true;
|
||||
if (wasAuto) autoPreview();
|
||||
// A day the user picked meanwhile, still being probed or debounced,
|
||||
// takes the slot instead of the next ranked day.
|
||||
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.
|
||||
@@ -325,10 +353,17 @@ export function createRecentImageryLayer({
|
||||
_followKey = null;
|
||||
if (wasAuto) {
|
||||
_auto = null;
|
||||
autoPreview();
|
||||
autoPreview(followed.key);
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
if (_handoverDeferred && !pickWaiting()) {
|
||||
const failedKey = _followKey || followed?.key || null;
|
||||
_handoverDeferred = false;
|
||||
_followKey = null;
|
||||
autoPreview(failedKey);
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
@@ -560,7 +595,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();
|
||||
}
|
||||
|
||||
@@ -602,6 +641,7 @@ export function createRecentImageryLayer({
|
||||
_catalogErrors = [];
|
||||
_catalogError = null;
|
||||
_auto = null;
|
||||
_handoverDeferred = false;
|
||||
}
|
||||
|
||||
function cancelSearch() {
|
||||
@@ -663,7 +703,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();
|
||||
@@ -680,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 };
|
||||
@@ -689,7 +731,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);
|
||||
}
|
||||
@@ -800,6 +852,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;
|
||||
}
|
||||
@@ -1034,6 +1095,7 @@ export function createRecentImageryLayer({
|
||||
if (list[next].key === _focusKey) return;
|
||||
_focusKey = list[next].key;
|
||||
schedulePreviewFromFocus();
|
||||
resumeHandover();
|
||||
requestThumbnails();
|
||||
notify();
|
||||
},
|
||||
@@ -1072,6 +1134,7 @@ export function createRecentImageryLayer({
|
||||
if (!drapable(candidate)) {
|
||||
clearPending();
|
||||
_followKey = availability(candidate) === 'empty' ? null : candidate.key;
|
||||
if (resumeHandover()) requestThumbnails();
|
||||
notify();
|
||||
return false;
|
||||
}
|
||||
@@ -1085,14 +1148,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;
|
||||
},
|
||||
@@ -1122,6 +1181,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) {
|
||||
@@ -1415,6 +1475,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])
|
||||
|
||||
@@ -1176,6 +1176,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 });
|
||||
@@ -1239,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();
|
||||
@@ -1486,3 +1563,155 @@ 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('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 });
|
||||
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');
|
||||
});
|
||||
Reference in new issue
Block a user