Merge main into byrdit/recent-imagery-dateline

This commit is contained in:
German Khokhlov committed 2026-11-20 17:38:13 +04:00
commit 8fd0a35f6a
391 files changed
+32429 -1796

No files matched your search

+78 -17
View File
@@ -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;
}
@@ -562,7 +597,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();
}
@@ -604,6 +643,7 @@ export function createRecentImageryLayer({
_catalogErrors = [];
_catalogError = null;
_auto = null;
_handoverDeferred = false;
}
function cancelSearch() {
@@ -665,7 +705,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();
@@ -682,7 +724,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 };
@@ -691,7 +733,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);
}
@@ -802,6 +854,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;
}
@@ -1036,6 +1097,7 @@ export function createRecentImageryLayer({
if (list[next].key === _focusKey) return;
_focusKey = list[next].key;
schedulePreviewFromFocus();
resumeHandover();
requestThumbnails();
notify();
},
@@ -1074,6 +1136,7 @@ export function createRecentImageryLayer({
if (!drapable(candidate)) {
clearPending();
_followKey = availability(candidate) === 'empty' ? null : candidate.key;
if (resumeHandover()) requestThumbnails();
notify();
return false;
}
@@ -1087,14 +1150,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;
},
@@ -1124,6 +1183,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) {
@@ -1417,6 +1477,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])