Read the canvas from the renderer in the layers, voice and tools

Files off the Cesium list sized themselves by, listened on and set the
cursor of `viewer.scene.canvas`. They now read `canvasOf(viewer)` from
src/render/rendererOf.js: the bound renderer's canvas, else the viewer's
own, the same element. Recent Imagery's divider moves the split through the
globe port (`globeSplitTarget`, moved from the flood event into
src/ui/imagerySplit.js), and traffic flow passes the viewer to the listed
surface module (`viewerRoadSurface`) instead of reaching for its scene.

The test fakes give their viewers a canvas, and the fake renderers report
it, as the Cesium renderer reports the viewer's.
This commit is contained in:
Sameh Khamis committed 2026-11-07 18:10:39 -08:00
1 parent abe9f97768
commit b19fa56565
49 files changed
+269 -119

No files matched your search

+19 -20
View File
@@ -1,13 +1,13 @@
import { roadIdentity } from './retention.js';
import { fromDegrees, toCartographicRadians } from '../../geo/ellipsoid.js';
import { copyInto, distance, distanceSquared } from '../../geo/vector.js';
import { findCamera, findFrame, findQuery } from '../../render/rendererOf.js';
import {
drawnSurfaceReady,
prepareRoadSurfaces,
roadHeightStations,
trafficSurfaceReady,
} from './surface.js';
canvasOf,
findCamera,
findFrame,
findQuery,
} from '../../render/rendererOf.js';
import { roadHeightStations, viewerRoadSurface } from './surface.js';
import { matchFlowToRoads } from '../../data/flowMatch.js';
import {
DOT_HEIGHT_OFFSET,
@@ -260,7 +260,8 @@ export function createFlow({ state: layerState, services, parts, source }) {
// Separate whole-graph preparation from tile completion and publication.
await nextTask();
if (!current()) return false;
const scene = layerState._viewer.scene;
const surface = viewerRoadSurface(layerState._viewer);
const canvas = canvasOf(layerState._viewer);
// The enable-time estimate can predate the first local mesh (especially
// after an intercontinental jump). Once previews have measured roads, use
// that local evidence to select the detail view at its real elevation.
@@ -283,11 +284,11 @@ export function createFlow({ state: layerState, services, parts, source }) {
// its camera port says where the eye is.
const query = findQuery(layerState._viewer);
let depthHeight;
if (query && scene.canvas?.clientWidth) {
if (query && canvas?.clientWidth) {
try {
const hit = query.pickPosition(
scene.canvas.clientWidth / 2,
scene.canvas.clientHeight * 0.6,
canvas.clientWidth / 2,
canvas.clientHeight * 0.6,
);
const height = hit && toCartographicRadians(hit)?.height;
if (Number.isFinite(height) && Math.abs(height) <= 9000)
@@ -344,7 +345,7 @@ export function createFlow({ state: layerState, services, parts, source }) {
)
return false;
// Spend surface work on roads crossing the canvas, with a small pan margin.
if (!scene.canvas?.clientWidth) return true;
if (!canvas?.clientWidth) return true;
let minX = Infinity,
minY = Infinity,
maxX = -Infinity,
@@ -357,7 +358,7 @@ export function createFlow({ state: layerState, services, parts, source }) {
minY = Math.min(minY, screen.y);
maxY = Math.max(maxY, screen.y);
}
road.coverageBand = maxY < scene.canvas.clientHeight / 2 ? 1 : 0;
road.coverageBand = maxY < canvas.clientHeight / 2 ? 1 : 0;
if (clamped.coverage && camera) {
road.baseDensityWeight ??= road.densityWeight || 1;
road.densityWeight =
@@ -368,9 +369,9 @@ export function createFlow({ state: layerState, services, parts, source }) {
if (!query) return true;
return (
maxX >= -100 &&
minX <= scene.canvas.clientWidth + 100 &&
minX <= canvas.clientWidth + 100 &&
maxY >= -100 &&
minY <= scene.canvas.clientHeight + 100
minY <= canvas.clientHeight + 100
);
});
const budgets = parts.model.allocateRoadDotBudgets(
@@ -475,9 +476,8 @@ export function createFlow({ state: layerState, services, parts, source }) {
// The first bounded surface slice needs its own task, not the prefix's tail.
await nextTask();
if (!current()) return false;
let prepared = await prepareRoadSurfaces(
let prepared = await viewerRoadSurface(layerState._viewer).prepare(
unresolved,
layerState._viewer.scene,
services.ground,
[layerState._pointCollection],
signal,
@@ -497,9 +497,8 @@ export function createFlow({ state: layerState, services, parts, source }) {
) {
await new Promise((resolve) => setTimeout(resolve, 100));
if (!current()) return false;
prepared = await prepareRoadSurfaces(
prepared = await viewerRoadSurface(layerState._viewer).prepare(
prepared.pending,
layerState._viewer.scene,
services.ground,
[layerState._pointCollection],
signal,
@@ -517,7 +516,7 @@ export function createFlow({ state: layerState, services, parts, source }) {
!preview &&
!label.includes('refined') &&
frame &&
(!trafficSurfaceReady(scene) ||
(!surface.ready() ||
prepared.pending.length ||
ready.some((road) => road.surfaceSettled === false))
) {
@@ -533,7 +532,7 @@ export function createFlow({ state: layerState, services, parts, source }) {
stop();
return;
}
if (!drawnSurfaceReady(scene)) return;
if (!surface.drawnReady()) return;
stop();
// Revalidate only local samples taken at a coarser rendered LOD. This
// background upgrade never holds road acquisition or first paint.