mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +00:00
Recent Imagery: defer the hand-over to a waiting pick instead of skipping it
The previous change skipped the hand-over for good while a user pick was pending. When that pick then probed empty, failed with a terminal error, or lost its source, nothing previewed and the slot stayed blank, where main would have draped the next ranked day. During the arrow-key debounce the empty slot also handed the Esri lease back and took it again 250 ms later. The hand-over is now deferred: the pick keeps first claim on the slot while its probe can still settle, and the next ranked day takes over as soon as the pick turns out empty, errors or loses its source. Turning a source off also drops a followed pick of that source. The layer keeps the current basemap while a deferred pick waits, and Escape releases it. Six tests cover both answer orders, the source toggle, a terminal error, the debounce and the lease.
This commit is contained in:
1 parent
881473cdd2
commit
8eac8bd545
3 files changed
+188
-13
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;
|
||||
@@ -300,6 +302,15 @@ export function createRecentImageryLayer({
|
||||
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 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
|
||||
@@ -322,7 +333,10 @@ export function createRecentImageryLayer({
|
||||
changed = true;
|
||||
// A day the user picked meanwhile, still being probed or debounced,
|
||||
// takes the slot instead of the next ranked day.
|
||||
if (wasAuto && !_followKey && !_pending) autoPreview(preview.key);
|
||||
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.
|
||||
@@ -336,6 +350,13 @@ export function createRecentImageryLayer({
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
if (_handoverDeferred && !pickWaiting()) {
|
||||
const failedKey = _followKey || followed?.key || null;
|
||||
_handoverDeferred = false;
|
||||
_followKey = null;
|
||||
autoPreview(failedKey);
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
@@ -567,7 +588,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();
|
||||
}
|
||||
|
||||
@@ -609,6 +634,7 @@ export function createRecentImageryLayer({
|
||||
_catalogErrors = [];
|
||||
_catalogError = null;
|
||||
_auto = null;
|
||||
_handoverDeferred = false;
|
||||
}
|
||||
|
||||
function cancelSearch() {
|
||||
@@ -670,7 +696,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();
|
||||
@@ -696,7 +724,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);
|
||||
}
|
||||
@@ -807,6 +845,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;
|
||||
}
|
||||
@@ -1092,14 +1139,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;
|
||||
},
|
||||
@@ -1129,6 +1172,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) {
|
||||
@@ -1422,6 +1466,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])
|
||||
|
||||
Reference in new issue
Block a user