mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Street Level: a replacement keeps its own state, and a posted view stands down
- Releasing a held viewer frees the old source's adapter without resetting the panel, so a replacement's error, outcome and armed OPEN survive; a cross-source replacement drops the old photo's details and marker. - The action holds the open photo only for its own switch-off: a source switched by hand during the load stops it and reports cancelled. - A posted view waiting on terrain watches the camera and stands down after a navigation or a globe press; a flat or straight-down camera asks no terrain. - An arming link opens the panel without persisting the layout, and a posted view's street-level step runs as programmatic. - An off-globe street_level point throws TypeError. - zh-Hant uses the file's wording for the new strings; README and CURRENT-STATE count 35 tools.
This commit is contained in:
1 parent
45a33b54df
commit
4fd36c44e0
14 files changed
+391
-84
No files matched your search
@@ -266,11 +266,11 @@ export function createStreetLevelLayer({
|
||||
if (providerAvailable(entry)) parts.credits.show(state.viewer, entry.def);
|
||||
}
|
||||
|
||||
/** Requests replacing the open photo that switch its source keep it up. */
|
||||
let viewerHolds = 0;
|
||||
/** Sources whose open photo a replacing request keeps up while it switches them off. */
|
||||
const heldViewers = new Map();
|
||||
|
||||
function deactivate(entry) {
|
||||
if (!viewerHolds) parts.viewerHost.unmount(entry.def.id);
|
||||
if (!heldViewers.has(entry.def.id)) parts.viewerHost.unmount(entry.def.id);
|
||||
entry.instance.deactivate();
|
||||
parts.credits.hide(state.viewer, entry.def);
|
||||
}
|
||||
@@ -854,19 +854,29 @@ export function createStreetLevelLayer({
|
||||
},
|
||||
closeViewer,
|
||||
/**
|
||||
* Keep the open photo up while a request that replaces it switches the
|
||||
* source, so EXPAND stays. Release closes it if its source is still off.
|
||||
* Keep the open photo up while a request that replaces it switches its
|
||||
* source off, so EXPAND stays; only that source's own switch-off is held,
|
||||
* a source switched by hand meanwhile still stops a load. Release frees
|
||||
* the old viewer.
|
||||
*/
|
||||
holdViewer() {
|
||||
viewerHolds += 1;
|
||||
const id = state.street.open ? state.street.providerId : null;
|
||||
if (!id) return () => {};
|
||||
heldViewers.set(id, (heldViewers.get(id) || 0) + 1);
|
||||
let held = true;
|
||||
return () => {
|
||||
if (!held) return;
|
||||
held = false;
|
||||
viewerHolds -= 1;
|
||||
if (viewerHolds) return;
|
||||
for (const entry of state.providers.values())
|
||||
if (!entry.on) parts.viewerHost.unmount(entry.def.id);
|
||||
const left = heldViewers.get(id) - 1;
|
||||
if (left > 0) return void heldViewers.set(id, left);
|
||||
heldViewers.delete(id);
|
||||
if (state.providers.get(id)?.on !== false) return;
|
||||
// Its photo still up (the request gave up) closes with its source;
|
||||
// otherwise the request replaced or closed it, and the panel keeps
|
||||
// what that request left (an error, an armed OPEN).
|
||||
if (state.street.open && state.street.providerId === id)
|
||||
parts.viewerHost.unmount(id);
|
||||
else parts.viewerHost.release(id);
|
||||
};
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -76,8 +76,8 @@ export const SEQUENCE_IMAGE_FIELDS =
|
||||
|
||||
/**
|
||||
* Images asked for in a nearest-image search: the API cuts at the limit
|
||||
* before any order, so this is its most, and the distance sort and the
|
||||
* imagery filter choose among all of the spot's photos.
|
||||
* before any order, so this is its most; the distance sort and the imagery
|
||||
* filter choose among the photos this one request returns.
|
||||
*/
|
||||
export const NEAREST_LIMIT = 100;
|
||||
/**
|
||||
|
||||
@@ -73,6 +73,19 @@ export function createViewerHost({ state, parts }) {
|
||||
active.unsubscribe();
|
||||
active.adapter.unmount();
|
||||
active = null;
|
||||
// The photo being replaced belonged to that source: none of its details
|
||||
// (id, place, author, link) describe the one loading now.
|
||||
const { open, loading, error, providerId, providerName, providerLabel } =
|
||||
state.street;
|
||||
Object.assign(state.street, freshStreet(), {
|
||||
open,
|
||||
loading,
|
||||
error,
|
||||
providerId,
|
||||
providerName,
|
||||
providerLabel,
|
||||
});
|
||||
parts.marker.clear();
|
||||
}
|
||||
const adapter = entry.instance.viewer;
|
||||
const promise = (async () => {
|
||||
@@ -202,5 +215,27 @@ export function createViewerHost({ state, parts }) {
|
||||
active = null;
|
||||
}
|
||||
|
||||
return { attach, open, close, resize, setRenderMode, stopPlayback, unmount };
|
||||
/**
|
||||
* Destroy `providerId`'s viewer and leave the panel's state alone: what a
|
||||
* request leaves behind once it replaced or closed that source's photo.
|
||||
*/
|
||||
function release(providerId) {
|
||||
if (active?.id !== providerId && mounting?.id !== providerId) return;
|
||||
const pending = mounting;
|
||||
mounting = null;
|
||||
active?.unsubscribe();
|
||||
(active?.adapter ?? pending?.adapter)?.unmount();
|
||||
active = null;
|
||||
}
|
||||
|
||||
return {
|
||||
attach,
|
||||
open,
|
||||
close,
|
||||
resize,
|
||||
setRenderMode,
|
||||
stopPlayback,
|
||||
unmount,
|
||||
release,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user