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

+4 -3
View File
@@ -1,5 +1,6 @@
import { VESSEL_OVERLAY_SOURCE_ID } from '../../data/vesselLabels.js';
import { msg, t } from '../../i18n/index.js';
import { findCamera } from '../../render/rendererOf.js';
import { AIS_FIRST_CONNECT_GRACE_MS, AIS_HEALTHY_STATUSES } from './policy.js';
export function createLifecycle({
@@ -190,9 +191,9 @@ export function createLifecycle({
);
// Vessels are asked for by view, so ask again when the view moves away.
removeViewListener();
const moveEnd = activeViewer?.camera?.moveEnd;
if (typeof moveEnd?.addEventListener === 'function')
state.feed.removeViewListener = moveEnd.addEventListener(() => {
const camera = findCamera(activeViewer);
if (camera)
state.feed.removeViewListener = camera.on('moveEnd', () => {
components.ingestion.refreshIfMoved(activeViewer);
});
return components.ingestion.loadLivePositions(activeViewer);
+6 -13
View File
@@ -1,17 +1,10 @@
import { msg } from '../../i18n/index.js';
import { NO_IMAGERY_HOST } from '../../maps/imageryHost.js';
/** Resolve the visible surface that can own weather imagery without scene mutation. */
export function resolveImageryHost({ viewer, tileset }) {
if (viewer?.scene?.globe?.show === true)
return { collection: viewer.imageryLayers, kind: 'globe' };
if (tileset?.imageryLayers)
return { collection: tileset.imageryLayers, kind: 'tileset' };
return { collection: null, kind: 'none' };
}
export const NO_IMAGERY_HOST = msg(
'Hidden by this map source · choose a globe map',
);
/**
* Resolve the visible surface that can own weather imagery without scene
* mutation: the map stack's imagery host (`src/maps/imageryHost.js`).
*/
export { NO_IMAGERY_HOST, resolveImageryHost } from '../../maps/imageryHost.js';
/** Report imagery suspension without changing or detaching the resolved host. */
export function imageryHostStatus(host) {
+17 -21
View File
@@ -5,6 +5,8 @@ import {
imageryHostStatus,
NO_IMAGERY_HOST,
} from './imageryHost.js';
import { bindRenderer } from '../../render/rendererOf.js';
import { createStubRenderer } from '../../render/stub/index.js';
test('only a missing host suspends weather; 3D Tiles has no height gate', () => {
assert.equal(imageryHostStatus({ kind: 'tileset' }), null);
@@ -12,28 +14,22 @@ test('only a missing host suspends weather; 3D Tiles has no height gate', () =>
assert.equal(imageryHostStatus({ kind: 'none' }), NO_IMAGERY_HOST);
});
test('visible globe takes precedence over a tileset', () => {
const viewer = { imageryLayers: {}, scene: { globe: { show: true } } };
assert.deepEqual(
resolveImageryHost({ viewer, tileset: { imageryLayers: {} } }),
{ collection: viewer.imageryLayers, kind: 'globe' },
);
});
test('hidden globe uses the supplied tileset imagery collection', () => {
const tileset = { imageryLayers: {} };
const viewer = { scene: { globe: { show: false } } };
test('weather drapes on the map stack imagery host', () => {
const renderer = createStubRenderer();
const viewer = {};
bindRenderer(viewer, renderer);
const tileset = { id: 'tiles' };
assert.deepEqual(resolveImageryHost({ viewer, tileset }), {
collection: tileset.imageryLayers,
collection: renderer.globe.imagery,
kind: 'globe',
});
renderer.globe.setGlobeVisible(false);
assert.deepEqual(resolveImageryHost({ viewer, tileset }), {
collection: tileset,
kind: 'tileset',
});
});
test('hidden globe without an imagery-capable tileset has no host', () => {
for (const tileset of [null, {}])
assert.deepEqual(
resolveImageryHost({
viewer: { scene: { globe: { show: false } } },
tileset,
}),
{ collection: null, kind: 'none' },
);
assert.deepEqual(resolveImageryHost({ viewer, tileset: null }), {
collection: null,
kind: 'none',
});
});