mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Load the default renderer as the page starts, and follow through the camera port in tests
- The standalone page starts loading the default renderer as it starts (loadDefaultRenderer), so Cesium arrives beside the page's own setup, not after it; the scene takes a plugin or a promise of one. - Where a follow target's layer has no display position yet, the followed position is the target's own position at the frame port's scene time. - The globe engine's photoreal base that fails to come back is off again and the globe shown; a later switch tries again. The draped-imagery host asks the map engine whether the globe is shown where the renderer cannot say. The scene resizes the renderer with its container. - Cockpit and voice tests follow through the camera port (followEntity), not by setting the viewer's tracked entity; the fake frame port has a scene time.
This commit is contained in:
1 parent
6daf63d90c
commit
ae4fbb5053
21 files changed
+328
-87
No files matched your search
+19
-6
@@ -32,15 +32,28 @@ const shownGlobes = new WeakMap();
|
||||
|
||||
const credit = (text) => ({ text });
|
||||
|
||||
/** Turn a photoreal handle's base on or off, reporting a failure. */
|
||||
/**
|
||||
* Turn a photoreal handle's base on or off. Turning it on can fail (the
|
||||
* port answers route `none`, or rejects): the handle is then off again, so
|
||||
* a later switch tries again, and the globe is shown so the base is not
|
||||
* left blank. Only the latest switch of a handle settles it.
|
||||
*/
|
||||
function applyPhotoreal(handle, shown) {
|
||||
if (handle.shown === shown || released.has(handle)) return;
|
||||
handle.shown = shown;
|
||||
handle.globe
|
||||
.setPhotoreal(shown ? handle.spec : null)
|
||||
.catch((error) =>
|
||||
console.warn('[MapStack] photoreal switch failed', error),
|
||||
);
|
||||
const switchId = (handle.switches = (handle.switches ?? 0) + 1);
|
||||
const failed = (error) => {
|
||||
if (handle.switches !== switchId || released.has(handle)) return;
|
||||
console.warn('[MapStack] photoreal switch failed', error);
|
||||
if (!shown) return;
|
||||
handle.shown = false;
|
||||
handle.globe.setGlobeVisible(true);
|
||||
shownGlobes.set(handle.globe, true);
|
||||
};
|
||||
handle.globe.setPhotoreal(shown ? handle.spec : null).then((status) => {
|
||||
if (shown && status?.route === 'none')
|
||||
failed(status.error?.message ?? 'photoreal unavailable');
|
||||
}, failed);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -121,3 +121,34 @@ test('a renderer without photoreal reports none, with the reason it gave', async
|
||||
assert.equal(result.tileset, null);
|
||||
assert.equal(result.route, 'none');
|
||||
});
|
||||
|
||||
test('photoreal that fails to come back leaves the globe shown, and is tried again', async () => {
|
||||
const { host, renderer } = scene(['photoreal']);
|
||||
const loaded = await engine.loadPhotoreal(host, { googleApiKey: 'key' });
|
||||
const handle = loaded.tileset;
|
||||
engine.showTileset(handle, false);
|
||||
engine.setGlobeShown(host, false);
|
||||
// The port cannot draw photoreal any more.
|
||||
renderer.globe.setPhotoreal = async (spec) => ({
|
||||
route: 'none',
|
||||
error: { code: 'refused', message: 'refused' },
|
||||
spec,
|
||||
});
|
||||
const warn = console.warn;
|
||||
console.warn = () => {};
|
||||
try {
|
||||
engine.showTileset(handle, true);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
} finally {
|
||||
console.warn = warn;
|
||||
}
|
||||
assert.equal(engine.tilesetShown(handle), false, 'off again');
|
||||
assert.equal(engine.globeShown(host), true, 'the base is not blank');
|
||||
let tried = 0;
|
||||
renderer.globe.setPhotoreal = async () => {
|
||||
tried += 1;
|
||||
return { route: 'google' };
|
||||
};
|
||||
engine.showTileset(handle, true);
|
||||
assert.equal(tried, 1, 'a later switch tries again');
|
||||
});
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import { msg } from '../i18n/marker.js';
|
||||
import { findGlobe } from '../render/rendererOf.js';
|
||||
import { mapEngineFor } from './engine.js';
|
||||
|
||||
/** Guidance shown when the active map stack cannot host draped imagery. */
|
||||
export const NO_IMAGERY_HOST = msg(
|
||||
@@ -20,8 +21,8 @@ const NONE = Object.freeze({ collection: null, kind: 'none' });
|
||||
* imagery while the globe is shown, else the shown base tileset (the map
|
||||
* stack's `getImageryHostTileset()`), else none. `collection` names the host
|
||||
* (one value per host, so a change of host is a change of it). A renderer
|
||||
* that does not say whether its globe is shown (no `globeVisibility`) has it
|
||||
* shown whenever no base tileset is.
|
||||
* that does not say whether its globe is shown (no `globeVisibility`) is
|
||||
* answered by the scene's map engine, which shows and hides it.
|
||||
* @param {{ viewer?: object, tileset?: object }} scene
|
||||
* @returns {{ collection: object | null, kind: 'globe' | 'tileset' | 'none' }}
|
||||
*/
|
||||
@@ -29,7 +30,9 @@ export function resolveImageryHost({ viewer, tileset } = {}) {
|
||||
const globe = findGlobe(viewer);
|
||||
const shownTileset =
|
||||
tileset && tileset.isDestroyed?.() !== true ? tileset : null;
|
||||
const globeShown = globe?.isGlobeVisible?.() ?? (globe && !shownTileset);
|
||||
const globeShown =
|
||||
globe &&
|
||||
(globe.isGlobeVisible?.() ?? mapEngineFor(viewer).globeShown(viewer));
|
||||
if (globe && globeShown) return { collection: globe.imagery, kind: 'globe' };
|
||||
if (shownTileset) return { collection: shownTileset, kind: 'tileset' };
|
||||
return NONE;
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import { NO_IMAGERY_HOST, resolveImageryHost } from './imageryHost.js';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import { createStubRenderer } from '../render/stub/index.js';
|
||||
import { globeMapEngine } from './globeEngine.js';
|
||||
|
||||
/** A scene object bound to a stub renderer, its globe shown or hidden. */
|
||||
function scene({ globeShown, capabilities } = {}) {
|
||||
@@ -28,15 +29,18 @@ test('a hidden globe hands imagery to the shown base tileset', () => {
|
||||
assert.deepEqual(host, { collection: tileset, kind: 'tileset' });
|
||||
});
|
||||
|
||||
test('without globe visibility, the globe hosts unless a tileset is shown', () => {
|
||||
test('without globe visibility, the map engine says whether the globe is shown', () => {
|
||||
const { viewer, renderer } = scene({ capabilities: [] });
|
||||
assert.equal(renderer.globe.isGlobeVisible, undefined);
|
||||
const tileset = { id: 'tiles' };
|
||||
globeMapEngine.setGlobeShown(viewer, false);
|
||||
assert.deepEqual(resolveImageryHost({ viewer, tileset }), {
|
||||
collection: tileset,
|
||||
kind: 'tileset',
|
||||
});
|
||||
assert.deepEqual(resolveImageryHost({ viewer, tileset: null }), {
|
||||
// A globe stack shows the globe: a tileset kept from startup is not the host.
|
||||
globeMapEngine.setGlobeShown(viewer, true);
|
||||
assert.deepEqual(resolveImageryHost({ viewer, tileset }), {
|
||||
collection: renderer.globe.imagery,
|
||||
kind: 'globe',
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user