mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 09:12:18 +00:00
Merge origin/main: street-level links, embed terrain waits, Swedish, and host-supplied weather frames on the renderer's ports
A weather frame source's regional tiles reach the renderer through the imagery layer's fetchTile, drawn and handed over as PNG bytes, a null tile one shared transparent tile; the camera-owner watch listens on the renderer's canvas.
This commit is contained in:
commit
c57e535275
110 files changed
+12262
-168
No files matched your search
+200
-18
@@ -14,7 +14,12 @@ import {
|
||||
keyAlternatives,
|
||||
summarizeCoverage,
|
||||
} from './uiState.js';
|
||||
import { canvasSize, groundUnderCamera, viewCentre } from './view.js';
|
||||
import {
|
||||
canvasSize,
|
||||
groundUnderCamera,
|
||||
metresBetween,
|
||||
viewCentre,
|
||||
} from './view.js';
|
||||
import { toLonLatH } from '../../geo/index.js';
|
||||
import { findCamera, findQuery } from '../../render/rendererOf.js';
|
||||
import { isPickedWorldPosition } from '../../data/scenePick.js';
|
||||
@@ -24,6 +29,7 @@ import {
|
||||
AIM_AT_GROUND_MESSAGE,
|
||||
keyStatusLabel,
|
||||
NEAREST_RADIUS_M,
|
||||
NEAREST_RADIUS_MAX_M,
|
||||
POSITION_PICK_ID,
|
||||
STREET_LEVEL_LAYER_ID,
|
||||
} from './policy.js';
|
||||
@@ -35,6 +41,11 @@ const KEY_STATUS_TIMEOUT_MS = 10_000;
|
||||
/** Re-measures of a ground not loaded yet (Google 3D), a second apart. */
|
||||
const GROUND_RETRY_LIMIT = 5;
|
||||
const GROUND_RETRY_MS = 1000;
|
||||
/**
|
||||
* An armed point stays the OPEN button's target while the view centre is
|
||||
* this close to it (m); a user who moved on opens what the view shows now.
|
||||
*/
|
||||
const ARMED_REACH_M = 1000;
|
||||
|
||||
/**
|
||||
* The Street Level layer over imagery providers (contract in registry.js).
|
||||
@@ -174,6 +185,12 @@ export function createStreetLevelLayer({
|
||||
const owner = state.providers.get(state.street.providerId);
|
||||
if (state.street.open && owner && !providerAvailable(owner))
|
||||
layer.closeViewer();
|
||||
// An armed lookup for a source whose map left dies too.
|
||||
const armedFor = state.street.armed?.providerIds?.map((id) =>
|
||||
state.providers.get(id),
|
||||
);
|
||||
if (armedFor?.some((entry) => entry && !providerAvailable(entry)))
|
||||
state.street.armed = null;
|
||||
for (const entry of state.providers.values()) {
|
||||
if (!entry.def.requiresMapStack) continue;
|
||||
if (state.enabled && entry.on && providerAvailable(entry))
|
||||
@@ -258,8 +275,11 @@ export function createStreetLevelLayer({
|
||||
if (providerAvailable(entry)) parts.credits.show(state.viewer, entry.def);
|
||||
}
|
||||
|
||||
/** Sources whose open photo a replacing request keeps up while it switches them off. */
|
||||
const heldViewers = new Map();
|
||||
|
||||
function deactivate(entry) {
|
||||
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);
|
||||
}
|
||||
@@ -272,6 +292,13 @@ export function createStreetLevelLayer({
|
||||
nearestLookup = null;
|
||||
}
|
||||
|
||||
/** Close the image and deselect its sequence on the map. */
|
||||
function closeViewer() {
|
||||
abortNearest();
|
||||
parts.viewerHost.close();
|
||||
parts.clearSequences();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ground under the screen centre: the drawn surface, else the ellipsoid;
|
||||
* null for sky, undefined when it cannot aim.
|
||||
@@ -298,8 +325,14 @@ export function createStreetLevelLayer({
|
||||
}
|
||||
|
||||
/** `frame: false` keeps the camera where it is (the user picked the spot). */
|
||||
function openImage(providerId, imageId, { frame = true } = {}) {
|
||||
function openImage(
|
||||
providerId,
|
||||
imageId,
|
||||
{ frame = true, signal = null } = {},
|
||||
) {
|
||||
if (signal?.aborted) return Promise.resolve(false);
|
||||
abortNearest();
|
||||
state.street.armed = null;
|
||||
const entry = state.providers.get(providerId);
|
||||
if (entry && !providerAvailable(entry)) {
|
||||
state.street.loading = false;
|
||||
@@ -307,7 +340,7 @@ export function createStreetLevelLayer({
|
||||
notify();
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
return parts.viewerHost.open(providerId, imageId, { frame });
|
||||
return parts.viewerHost.open(providerId, imageId, { frame, signal });
|
||||
}
|
||||
|
||||
function unavailableReason(entry) {
|
||||
@@ -353,6 +386,9 @@ export function createStreetLevelLayer({
|
||||
function switchProvider(entry, on) {
|
||||
if (entry.on === on) return;
|
||||
entry.on = on;
|
||||
// A lookup armed for this source dies with it.
|
||||
if (!on && state.street.armed?.providerIds?.includes(entry.def.id))
|
||||
state.street.armed = null;
|
||||
if (!state.enabled) return;
|
||||
if (on) activate(entry);
|
||||
else deactivate(entry);
|
||||
@@ -489,6 +525,33 @@ export function createStreetLevelLayer({
|
||||
},
|
||||
/** Registered providers, in chip order. */
|
||||
providerIds: defs.map((def) => def.id),
|
||||
/** The map stack a provider needs (`requiresMapStack`), or null for any. */
|
||||
requiredMapStack(providerId) {
|
||||
const def = defs.find((entry) => entry.id === providerId);
|
||||
return def?.requiresMapStack || null;
|
||||
},
|
||||
/**
|
||||
* A provider's name and key state on any map (the panel lists a provider
|
||||
* only on the map it needs). `configured` is null until its status call
|
||||
* answers; `keyRequired` covers a missing or refused key.
|
||||
*/
|
||||
providerStatus(providerId) {
|
||||
const entry = state.providers.get(providerId);
|
||||
if (!entry) return null;
|
||||
const stats = entry.instance.coverageStats();
|
||||
return {
|
||||
id: entry.def.id,
|
||||
name: entry.def.name,
|
||||
on: entry.on,
|
||||
configured: entry.status ? entry.status.configured === true : null,
|
||||
keyRequired: stats.keyRequired === true || stats.keyRejected === true,
|
||||
keyRejected: stats.keyRejected === true,
|
||||
groundClick: entry.def.groundClick === true,
|
||||
billed: entry.def.billedPerImage === true,
|
||||
available: providerAvailable(entry),
|
||||
error: stats.error || null,
|
||||
};
|
||||
},
|
||||
getSourceAvailability() {
|
||||
const available = defs.length > 0;
|
||||
return {
|
||||
@@ -646,19 +709,66 @@ export function createStreetLevelLayer({
|
||||
* Open the nearest image of the active providers (or `providerIds`) near
|
||||
* a point, else the view centre, or with `aim: 'screen-centre'` the ground
|
||||
* under the screen centre (sky: nothing). Providers without
|
||||
* `nearestImage` are skipped.
|
||||
* `nearestImage` are skipped. Options:
|
||||
* - `radiusM` widens the search where a provider can (a geocoded landmark
|
||||
* is rarely within 50 m of a street);
|
||||
* - `signal` retires the lookup: nothing opens after it fires;
|
||||
* - `armed: false` (the assistant's own request) ignores a link's armed
|
||||
* point and keeps it until a photo opens;
|
||||
* - `replace: true` keeps an open photo (and EXPAND) up while it looks and
|
||||
* closes it if nothing opens;
|
||||
* - `proceed()` is asked before a found photo loads or an empty lookup
|
||||
* reports; false retires the request and leaves the panel as it was.
|
||||
* Why nothing opened is in `street.nearestOutcome`: 'empty', 'sky' or
|
||||
* null (an error).
|
||||
*/
|
||||
async openNearest(
|
||||
point,
|
||||
{ providerIds = null, frame = true, aim = 'view' } = {},
|
||||
{
|
||||
providerIds = null,
|
||||
frame = true,
|
||||
aim = 'view',
|
||||
radiusM = null,
|
||||
signal: callerSignal = null,
|
||||
armed: useArmed = true,
|
||||
replace = false,
|
||||
proceed = null,
|
||||
} = {},
|
||||
) {
|
||||
if (callerSignal?.aborted) return false;
|
||||
state.street.nearestOutcome = null;
|
||||
// An OPEN press after a link armed a lookup opens what the link asked;
|
||||
// any other lookup is a new request and drops the armed one.
|
||||
const armed = useArmed ? state.street.armed : null;
|
||||
if (useArmed) state.street.armed = null;
|
||||
const closeReplaced = () => {
|
||||
if (replace && state.street.open) closeViewer();
|
||||
};
|
||||
if (!point && aim === 'screen-centre' && armed) {
|
||||
// OPEN promises the view centre: the link's spot only while the view
|
||||
// still shows it, or when the view cannot be picked.
|
||||
const centre = armed.point ? screenCentreGround() : null;
|
||||
if (!armed.point) radiusM ??= armed.radiusM;
|
||||
else if (
|
||||
centre === undefined ||
|
||||
(centre && metresBetween(centre, armed.point) <= ARMED_REACH_M)
|
||||
) {
|
||||
point = armed.point;
|
||||
radiusM ??= armed.radiusM;
|
||||
}
|
||||
}
|
||||
const radius = Number.isFinite(radiusM)
|
||||
? Math.min(NEAREST_RADIUS_MAX_M, Math.max(1, radiusM))
|
||||
: NEAREST_RADIUS_M;
|
||||
let view = point;
|
||||
if (!view && aim === 'screen-centre') {
|
||||
view = screenCentreGround();
|
||||
if (view === null) {
|
||||
abortNearest();
|
||||
closeReplaced();
|
||||
state.street.loading = false;
|
||||
state.street.error = AIM_AT_GROUND_MESSAGE;
|
||||
state.street.nearestOutcome = 'sky';
|
||||
notify();
|
||||
return false;
|
||||
}
|
||||
@@ -670,6 +780,19 @@ export function createStreetLevelLayer({
|
||||
const lookup = new AbortController();
|
||||
nearestLookup = lookup;
|
||||
const { signal } = lookup;
|
||||
const onCallerAbort = () => lookup.abort();
|
||||
callerSignal?.addEventListener('abort', onCallerAbort, { once: true });
|
||||
const retired = () => {
|
||||
callerSignal?.removeEventListener('abort', onCallerAbort);
|
||||
// A newer lookup owns the panel, its spinner and its error.
|
||||
if (nearestLookup !== lookup) return false;
|
||||
nearestLookup = null;
|
||||
if (state.street.loading) {
|
||||
state.street.loading = false;
|
||||
notify();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
state.street.loading = true;
|
||||
state.street.error = null;
|
||||
notify();
|
||||
@@ -684,49 +807,108 @@ export function createStreetLevelLayer({
|
||||
try {
|
||||
imageId = await entry.instance.nearestImage(
|
||||
{ lat: view.lat, lon: view.lon },
|
||||
{ signal },
|
||||
radius === NEAREST_RADIUS_M
|
||||
? { signal }
|
||||
: { signal, radiusM: radius },
|
||||
);
|
||||
} catch (error) {
|
||||
if (callerSignal?.aborted) return retired();
|
||||
// Overtaken: whatever replaced it owns the panel, errors included.
|
||||
if (signal.aborted) return false;
|
||||
if (signal.aborted) return retired();
|
||||
// One provider failing (no key, offline) must not hide the others.
|
||||
lastError = error;
|
||||
continue;
|
||||
}
|
||||
if (signal.aborted) return false;
|
||||
if (callerSignal?.aborted) return retired();
|
||||
if (signal.aborted) return retired();
|
||||
if (!state.enabled) break;
|
||||
// Switched off, or its map left, while it looked: try the next.
|
||||
if (!imageId || !entry.on || !providerAvailable(entry)) continue;
|
||||
if (proceed && proceed() !== true) return retired();
|
||||
nearestLookup = null;
|
||||
return openImage(entry.def.id, imageId, { frame });
|
||||
callerSignal?.removeEventListener('abort', onCallerAbort);
|
||||
// A sequence playing in the replaced photo would step past this one.
|
||||
if (replace && state.street.open) parts.viewerHost.stopPlayback();
|
||||
// The caller's signal still counts while the viewer mounts and loads.
|
||||
return openImage(entry.def.id, imageId, {
|
||||
frame,
|
||||
signal: callerSignal,
|
||||
});
|
||||
}
|
||||
if (nearestLookup === lookup) nearestLookup = null;
|
||||
callerSignal?.removeEventListener('abort', onCallerAbort);
|
||||
// Replaced while it looked: the panel is the newer lookup's.
|
||||
if (nearestLookup !== lookup) return false;
|
||||
// Given up by its caller: the panel stays as it was.
|
||||
if (proceed && proceed() !== true) return retired();
|
||||
nearestLookup = null;
|
||||
closeReplaced();
|
||||
// Switched off while it looked: nothing to open, nothing to report.
|
||||
const stillOn = entries.some(
|
||||
(entry) => entry.on && providerAvailable(entry),
|
||||
);
|
||||
// A provider's own refusal is English data that the panel translates;
|
||||
// the core's refusal is built here, for the panel only, in the language.
|
||||
if (state.enabled && stillOn && !lastError)
|
||||
state.street.nearestOutcome = 'empty';
|
||||
if (state.enabled && stillOn)
|
||||
state.street.error =
|
||||
lastError?.message ||
|
||||
(point
|
||||
? t('No street-level imagery within {radius} m of that point', {
|
||||
radius: NEAREST_RADIUS_M,
|
||||
radius,
|
||||
})
|
||||
: t(
|
||||
'No street-level imagery within {radius} m of the view centre',
|
||||
{ radius: NEAREST_RADIUS_M },
|
||||
{
|
||||
radius,
|
||||
},
|
||||
));
|
||||
state.street.loading = false;
|
||||
notify();
|
||||
return false;
|
||||
},
|
||||
/** Close the image and deselect its sequence on the map. */
|
||||
closeViewer() {
|
||||
abortNearest();
|
||||
parts.viewerHost.close();
|
||||
parts.clearSequences();
|
||||
closeViewer,
|
||||
/**
|
||||
* 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() {
|
||||
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;
|
||||
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);
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Arm a nearest lookup for the next OPEN press without running it (a link
|
||||
* to a source that bills every load). Any other lookup, open or close, the
|
||||
* source switched off or its map leaving clears it.
|
||||
*/
|
||||
armNearest(point, { providerIds = null, radiusM = null } = {}) {
|
||||
state.street.armed = {
|
||||
point:
|
||||
Number.isFinite(point?.lat) && Number.isFinite(point?.lon)
|
||||
? { lat: point.lat, lon: point.lon }
|
||||
: null,
|
||||
providerIds: Array.isArray(providerIds) ? [...providerIds] : null,
|
||||
radiusM: Number.isFinite(radiusM) ? radiusM : null,
|
||||
};
|
||||
notify();
|
||||
},
|
||||
setViewerRenderMode: (mode) => parts.viewerHost.setRenderMode(mode),
|
||||
resizeViewer: () => parts.viewerHost.resize(),
|
||||
|
||||
Reference in new issue
Block a user