Follow, drape and read the camera through the ports, not the viewer

- What the camera follows is the camera port's target only: no layer
  tracks an entity of its own any more, so followed.js stops reading and
  writing viewer.trackedEntity and the viewer's clock.
- Draped imagery's host is the globe port's imagery while the globe is
  shown (isGlobeVisible, or no shown base tileset where a renderer cannot
  say), else the shown base tileset; weather uses the same resolver.
- The World Packet reads the eye from the camera port's pose, and vessels
  ask again for the view on the camera port's moveEnd.
- The stub's canvas takes event listeners, and in a page is a real canvas
  filling the container it is given; createStubRendererPlugin makes it a
  renderer plugin.

The viewer access record is now empty.
This commit is contained in:
Sameh Khamis committed 2026-11-10 17:18:10 -08:00
1 parent ebbe006924
commit a72d4c3b1f
11 files changed
+230 -213

No files matched your search

+19 -11
View File
@@ -1,28 +1,36 @@
/**
* Where draped imagery can go on the current map stack. A globe stack drapes
* on `viewer.imageryLayers`; a 3D-tiles stack hides the globe, and Cesium
* 1.138 drapes imagery onto the tileset's own `imageryLayers` instead. When
* neither exists there is nowhere to drape and the caller says so.
* on the globe port's imagery; a 3D-tiles stack hides the globe, and the
* renderer drapes that imagery onto the shown base tileset instead. When
* neither is drawn there is nowhere to drape and the caller says so.
*/
import { msg } from '../i18n/marker.js';
import { findGlobe } from '../render/rendererOf.js';
/** Guidance shown when the active map stack cannot host draped imagery. */
export const NO_IMAGERY_HOST = msg(
'Hidden by this map source · choose a globe map',
);
const NONE = Object.freeze({ collection: null, kind: 'none' });
/**
* Resolve the imagery layer collection for the active map stack.
* Resolve the imagery host for the active map stack: the globe port's
* 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.
* @param {{ viewer?: object, tileset?: object }} scene
* @returns {{ collection: object | null, kind: 'globe' | 'tileset' | 'none' }}
*/
export function resolveImageryHost({ viewer, tileset } = {}) {
if (viewer?.scene?.globe?.show === true && viewer.imageryLayers) {
return { collection: viewer.imageryLayers, kind: 'globe' };
}
if (tileset?.imageryLayers && !tileset.isDestroyed?.()) {
return { collection: tileset.imageryLayers, kind: 'tileset' };
}
return { collection: null, kind: 'none' };
const globe = findGlobe(viewer);
const shownTileset =
tileset && tileset.isDestroyed?.() !== true ? tileset : null;
const globeShown = globe?.isGlobeVisible?.() ?? (globe && !shownTileset);
if (globe && globeShown) return { collection: globe.imagery, kind: 'globe' };
if (shownTileset) return { collection: shownTileset, kind: 'tileset' };
return NONE;
}
+41 -24
View File
@@ -1,39 +1,56 @@
import test from 'node:test';
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';
test('a shown globe hosts imagery on the viewer collection', () => {
const imageryLayers = { id: 'globe' };
const host = resolveImageryHost({
viewer: { scene: { globe: { show: true } }, imageryLayers },
tileset: { imageryLayers: { id: 'tiles' } },
});
assert.deepEqual(host, { collection: imageryLayers, kind: 'globe' });
/** A scene object bound to a stub renderer, its globe shown or hidden. */
function scene({ globeShown, capabilities } = {}) {
const renderer = createStubRenderer(
capabilities ? { capabilities } : undefined,
);
if (globeShown !== undefined) renderer.globe.setGlobeVisible(globeShown);
const viewer = {};
bindRenderer(viewer, renderer);
return { viewer, renderer };
}
test('a shown globe hosts imagery on the globe port', () => {
const { viewer, renderer } = scene({ globeShown: true });
const host = resolveImageryHost({ viewer, tileset: { id: 'tiles' } });
assert.deepEqual(host, { collection: renderer.globe.imagery, kind: 'globe' });
});
test('a hidden globe hands imagery to the tileset collection', () => {
const imageryLayers = { id: 'tiles' };
const host = resolveImageryHost({
viewer: { scene: { globe: { show: false } }, imageryLayers: {} },
tileset: { imageryLayers, isDestroyed: () => false },
test('a hidden globe hands imagery to the shown base tileset', () => {
const { viewer } = scene({ globeShown: false });
const tileset = { id: 'tiles', isDestroyed: () => false };
const host = resolveImageryHost({ viewer, tileset });
assert.deepEqual(host, { collection: tileset, kind: 'tileset' });
});
test('without globe visibility, the globe hosts unless a tileset is shown', () => {
const { viewer, renderer } = scene({ capabilities: [] });
assert.equal(renderer.globe.isGlobeVisible, undefined);
const tileset = { id: 'tiles' };
assert.deepEqual(resolveImageryHost({ viewer, tileset }), {
collection: tileset,
kind: 'tileset',
});
assert.deepEqual(resolveImageryHost({ viewer, tileset: null }), {
collection: renderer.globe.imagery,
kind: 'globe',
});
assert.deepEqual(host, { collection: imageryLayers, kind: 'tileset' });
});
test('no globe and no tileset means nowhere to drape', () => {
assert.deepEqual(
resolveImageryHost({
viewer: { scene: { globe: { show: false } }, imageryLayers: {} },
tileset: null,
}),
{ collection: null, kind: 'none' },
);
const { viewer } = scene({ globeShown: false });
assert.deepEqual(resolveImageryHost({ viewer, tileset: null }), {
collection: null,
kind: 'none',
});
assert.deepEqual(resolveImageryHost({}), { collection: null, kind: 'none' });
assert.deepEqual(
resolveImageryHost({
viewer: { scene: { globe: { show: false } } },
tileset: { imageryLayers: {}, isDestroyed: () => true },
}),
resolveImageryHost({ viewer, tileset: { isDestroyed: () => true } }),
{ collection: null, kind: 'none' },
);
assert.match(NO_IMAGERY_HOST, /globe map/);