Give a viewer of its own a frame port, and use it for the active fires layer

findFrame and frameOf find the bound renderer's frame port or, for a
caller's viewer with no renderer bound, one the Cesium adapter's factory
builds over it, as findQuery and findDraw do. Unlike the renderer's own,
it leaves the viewer's loop as its owner set it up: it listens to the
scene's phases, asks for frames, holds by asking again after each one
drawn, and maps suspend, the target rate and scene time onto the viewer.
Its preUpdate says whether the tick draws by the same test the renderer's
frame port makes, now shared by both.

The active fires layer's cards and LOD watcher take their query and frame
ports from findQuery and findFrame, in place of the layer's own copy of
projection, occlusion and preRender over the viewer's scene.
This commit is contained in:
Sameh Khamis committed 2026-11-06 22:25:07 -08:00
1 parent 784561a6ae
commit 4ed51930c2
12 files changed
+604 -132

No files matched your search

+14 -2
View File
@@ -70,10 +70,22 @@ function harness(fires, heightM, { sceneFromViewer = false } = {}) {
};
const ports = bindFakeCesiumScene(viewer);
const { draw } = ports;
// A renderer with no query or frame: the layer reads the viewer's scene.
// A renderer with no query or frame: the Cesium adapter builds them over
// the viewer's scene, as it does for a viewer with no renderer.
if (sceneFromViewer) {
ports.unbind();
bindRenderer(viewer, { draw, camera: ports.camera });
Object.assign(viewer.scene, {
preUpdate: new Cesium.Event(),
postRender: new Cesium.Event(),
requestRender() {},
forceRender() {},
pick: () => undefined,
drillPick: () => [],
camera: viewer.camera,
});
viewer.camera.pickEllipsoid = () => undefined;
viewer.clock = { currentTime: Cesium.JulianDate.now() };
}
const input = fakeInput(viewer);
const layer = createFirmsHeatmapLayer({
@@ -168,7 +180,7 @@ test('close in, detections replace the cells', async () => {
}
});
test("with no query or frame port, the layer still follows the camera through the viewer's scene", async () => {
test("with no query or frame port, the layer still follows the camera through ports built over the viewer's scene", async () => {
const h = harness([raw(30.5, -98.2, 1500)], 12_000_000, {
sceneFromViewer: true,
});
+9 -42
View File
@@ -1,13 +1,12 @@
import * as Cesium from 'cesium';
// Still Cesium for its icons, so this layer loads the unbound camera and
// draw factories its other parts reach the renderer through; see also
// scenePorts below.
// Still Cesium for its icons, so this layer loads the unbound camera
// factory, which loads the draw, frame and query factories its other parts
// reach the renderer through.
import '../../render/cesium/camera.js';
import { fromDegrees } from '../../geo/ellipsoid.js';
import { rendererOf } from '../../render/rendererOf.js';
import { findFrame, findQuery } from '../../render/rendererOf.js';
import { FIRMS_OVERLAY_SOURCE_ID } from '../../data/firmsLabels.js';
import { LOD_LEVELS, CONTEXT_TOP_N, GLOW_SPRITE_PX } from './policy.js';
import { horizonOccluder } from '../../data/iconOrientation.js';
import { createIconSet, ICON_CULL_LIFT } from '../../data/iconSet.js';
import { writeHoldSegment } from '../../data/iconSegment.js';
import { IconSetPrimitive } from '../../data/iconSetPrimitive.js';
@@ -371,47 +370,15 @@ export function createRendering({
}
/**
* The renderer's query and frame ports the cards and the LOD watcher use.
* A viewer with no renderer bound has neither yet;
* for one, this part (Cesium already, for its icons) answers the members
* the layer uses over the viewer's scene, as the layer did before.
* The renderer's query and frame ports the cards and the LOD watcher use:
* the bound renderer's, or for a viewer with no
* renderer bound, those the Cesium adapter builds over it (`findQuery`,
* `findFrame`; the camera factory loaded above loads theirs).
* @returns {{query: object|null, frame: object|null}}
*/
function scenePorts() {
const viewer = layerState._viewer;
const bound = rendererOf(viewer);
if (bound?.query && bound?.frame)
return { query: bound.query, frame: bound.frame };
const scene = viewer?.scene;
if (!scene)
return { query: bound?.query ?? null, frame: bound?.frame ?? null };
const eye = () =>
viewer.camera?.positionWC ? viewer.camera : scene.camera;
const query = bound?.query ?? {
project(position) {
const screen = Cesium.SceneTransforms.worldToWindowCoordinates(
scene,
Cesium.Cartesian3.clone(position),
);
return screen ? { x: screen.x, y: screen.y } : null;
},
isOccluded(position) {
const camera = eye();
if (!camera?.positionWC) return false;
return !horizonOccluder(camera).isPointVisible(
Cesium.Cartesian3.clone(position),
);
},
};
const frame = bound?.frame ?? {
on(phase, listener) {
const event = scene[phase];
return event?.addEventListener
? event.addEventListener(listener)
: () => {};
},
};
return { query, frame };
return { query: findQuery(viewer), frame: findFrame(viewer) };
}
return {