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

+8 -3
View File
@@ -23,7 +23,12 @@ import {
import { entityRecord, readEntityRecord } from '../../data/entityRecords.js';
import { alprIconPosition, alprMarkers } from './markerState.js';
import { horizonFrom } from '../../geo/horizon.js';
import { cameraOf, findCredits, findQuery } from '../../render/rendererOf.js';
import {
cameraOf,
canvasOf,
findCredits,
findQuery,
} from '../../render/rendererOf.js';
/** A `#rrggbb` colour as `rgb(r,g,b)`, the form the readout card has always had. */
function cssRgb(hex) {
@@ -162,7 +167,7 @@ export function createAlprPresentation({ state, services, source }) {
* @returns {number|null} Count, or null without a scene to project into.
*/
function countOnScreen() {
const canvas = state.viewer?.scene?.canvas;
const canvas = canvasOf(state.viewer);
const width = canvas?.clientWidth || canvas?.width;
const height = canvas?.clientHeight || canvas?.height;
const query = findQuery(state.viewer);
@@ -266,7 +271,7 @@ export function createAlprPresentation({ state, services, source }) {
// that point instead; the camera-to-ground range keeps zoom-out queries capped.
function viewportBox(viewer) {
const query = findQuery(viewer);
const canvas = viewer?.scene?.canvas;
const canvas = canvasOf(viewer);
if (typeof query?.pickEllipsoid === 'function' && canvas) {
const width = canvas.clientWidth || canvas.width;
const height = canvas.clientHeight || canvas.height;
@@ -24,6 +24,9 @@ function overlay(screenAngle) {
});
const viewer = {
container,
get canvas() {
return this.scene?.canvas;
},
scene: { canvas: { clientWidth: 800, clientHeight: 600 } },
};
bindRenderer(viewer, { camera: camera.port });
+2 -2
View File
@@ -11,7 +11,7 @@ import {
import { bearingBetweenCoordinates } from '../../cockpitMath.js';
import { AWARENESS_PAGE_SIZE, CONTEXT_RIM_HEIGHT_M } from './policy.js';
import { formatAwarenessDirection } from './presentation.js';
import { drawOf, findCamera } from '../../render/rendererOf.js';
import { canvasOf, drawOf, findCamera } from '../../render/rendererOf.js';
import {
PI_OVER_TWO,
distance,
@@ -145,7 +145,7 @@ export function createRendering({
return;
}
const canvas = layerState.viewer.scene.canvas;
const canvas = canvasOf(layerState.viewer);
const width = canvas.clientWidth || canvas.width;
const height = canvas.clientHeight || canvas.height;
const sonar = isCyberSonarActive()
+2 -2
View File
@@ -1,6 +1,6 @@
import { fromDegrees } from '../../geo/ellipsoid.js';
import { distance, dot } from '../../geo/vector.js';
import { findCamera } from '../../render/rendererOf.js';
import { canvasOf, findCamera } from '../../render/rendererOf.js';
import { viewshedColors, cameraHue } from '../../data/cctvViewshed.js';
import { CCTV_OVERLAY_SOURCE_ID } from '../../data/cctvCards.js';
import { GIZMO_ID_PREFIX } from '../../data/cctvGizmo.js';
@@ -365,7 +365,7 @@ export function createLifecycle({
attachViewListeners();
// A resize or rotation changes what is on screen without moving the
// camera.
const canvas = layerState._viewer.scene?.canvas;
const canvas = canvasOf(layerState._viewer);
if (layerState._viewResizeCanvas !== canvas) {
// A re-init against a new viewer observes its canvas instead.
layerState._viewResizeObserver?.disconnect();
+3 -3
View File
@@ -23,7 +23,7 @@ import {
translateKnown,
} from '../../i18n/index.js';
import { formatQuantity } from '../../ui/unitLabels.js';
import { cameraOf } from '../../render/rendererOf.js';
import { cameraOf, canvasOf } from '../../render/rendererOf.js';
// "10-12 15:00 UTC" never breaks across lines: no-break spaces, and a word
// joiner after the hyphen (JetBrains Mono has no U+2011 non-breaking hyphen).
@@ -98,12 +98,12 @@ export function createCyclonesLayer({
rendering?.setSelection(id);
}
function installSelection() {
if (selectionOwner || !viewer?.scene?.canvas) return;
const canvas = canvasOf(viewer);
if (selectionOwner || !canvas) return;
const owner = {};
selectionOwner = owner;
// Snapshot before sibling bubble listeners can rebuild the overlay hit
// rectangles. A vessel selection does that synchronously in the same click.
const canvas = viewer.scene.canvas;
let capturedHit = null;
const overlayHit = (x, y) => {
const hit = hitTestOverlay(x, y);
+6
View File
@@ -114,6 +114,9 @@ test('map selection yields to pointer owners and owns only its enabled handler',
const canvas = new EventTarget();
canvas.getBoundingClientRect = () => ({ left: 100, top: 200 });
const viewer = {
get canvas() {
return this.scene?.canvas;
},
scene: {
canvas,
pick() {
@@ -308,6 +311,9 @@ test('a click on a storm card or lead-hour label selects that storm without pick
const canvas = new EventTarget();
canvas.getBoundingClientRect = () => ({ left: 0, top: 0 });
const viewer = {
get canvas() {
return this.scene?.canvas;
},
scene: {
canvas,
pick() {
+4 -3
View File
@@ -4,6 +4,7 @@ import {
FIRMS_AMBIENT_COHORT_LIMIT,
} from '../../data/firmsLabels.js';
import { MAX_AMBIENT_LABELS, LABEL_VIEW_MARGIN_PX } from './policy.js';
import { canvasOf } from '../../render/rendererOf.js';
export function createCards({
layerState,
@@ -29,7 +30,6 @@ export function createCards({
function rebuildAmbientLabels() {
if (!layerState._viewer) return;
const scene = layerState._viewer.scene;
const { query } = components.rendering.scenePorts();
const project = (position) => query?.project(position) ?? null;
const now = Date.now();
@@ -70,8 +70,9 @@ export function createCards({
}
}
const width = scene.canvas.clientWidth;
const height = scene.canvas.clientHeight;
const canvas = canvasOf(layerState._viewer);
const width = canvas.clientWidth;
const height = canvas.clientHeight;
let ambientCount = 0;
for (const candidate of layerState._labelCandidates) {
+3
View File
@@ -53,6 +53,9 @@ function harness(fires, heightM, { sceneFromViewer = false } = {}) {
heightM,
),
},
get canvas() {
return this.scene?.canvas;
},
scene: {
canvas: { clientWidth: 800, clientHeight: 600 },
preRender: new Cesium.Event(),
+7 -5
View File
@@ -7,6 +7,7 @@ import { fromDegrees } from '../../geo/index.js';
import { horizonFrom } from '../../geo/horizon.js';
import {
cameraOf,
canvasOf,
drawOf,
findFrame,
findQuery,
@@ -57,8 +58,8 @@ export function createNamedMarkers({ state, services, parts, overlayHost }) {
!same(pose.position, lastPose.position) ||
!same(pose.direction, lastPose.direction) ||
!same(pose.up, lastPose.up) ||
width !== viewer.scene.canvas.clientWidth ||
height !== viewer.scene.canvas.clientHeight
width !== canvasOf(viewer).clientWidth ||
height !== canvasOf(viewer).clientHeight
);
}
@@ -69,8 +70,9 @@ export function createNamedMarkers({ state, services, parts, overlayHost }) {
function refresh(pose = null) {
const viewer = state.viewer;
if (!state.enabled || !points) return;
width = viewer.scene.canvas.clientWidth;
height = viewer.scene.canvas.clientHeight;
const canvas = canvasOf(viewer);
width = canvas.clientWidth;
height = canvas.clientHeight;
pose ??= cameraOf(viewer).pose();
lastPose = {
position: { ...pose.position },
@@ -175,7 +177,7 @@ export function createNamedMarkers({ state, services, parts, overlayHost }) {
function sync(records) {
const viewer = state.viewer;
if (!viewer?.scene) return;
if (!viewer) return;
points ??= drawOf(viewer).points({ id: setId, horizonCull: true });
points.show = state.enabled;
const named = records
+6 -1
View File
@@ -156,7 +156,12 @@ test('mission hover throttles, clears on motion/hidden, and releases listeners',
removeEventListener: (_n, fn) => listeners.delete(fn),
};
const camera = fakeCameraPort();
const viewer = { scene: { canvas: { style: {} } } };
const viewer = {
get canvas() {
return this.scene?.canvas;
},
scene: { canvas: { style: {} } },
};
bindRenderer(viewer, { camera: camera.port });
const hover = createLaunchHover({
viewer,
+7 -6
View File
@@ -1,6 +1,6 @@
import { isPointerFree } from '../../data/inputOwnership.js';
import { inputFor } from '../../input/dispatcher.js';
import { findCamera, findFrame } from '../../render/rendererOf.js';
import { canvasOf, findCamera, findFrame } from '../../render/rendererOf.js';
const HOVER_PICK_INTERVAL_MS = 120;
@@ -25,8 +25,9 @@ export function createLaunchHover({
let pendingPosition = null;
let trailingTimer = null;
const clearCursor = () => {
if (ownsCursor && viewer.scene.canvas.style.cursor === 'pointer')
viewer.scene.canvas.style.cursor = '';
const canvas = canvasOf(viewer);
if (ownsCursor && canvas.style.cursor === 'pointer')
canvas.style.cursor = '';
ownsCursor = false;
};
const cancelTrailing = () => {
@@ -60,7 +61,7 @@ export function createLaunchHover({
const pick = (position, at) => {
lastPick = at;
if (launchAt(position)) {
viewer.scene.canvas.style.cursor = 'pointer';
canvasOf(viewer).style.cursor = 'pointer';
ownsCursor = true;
} else clearCursor();
};
@@ -215,8 +216,8 @@ export function createLifecycle({
parts.selection.stopMissionZoomAnchor();
parts.rendering.showMissions(false);
parts.orbitRendering.syncMissionOrbitPrimitiveVisibility();
if (layerState._viewer?.scene?.canvas)
layerState._viewer.scene.canvas.style.cursor = '';
const canvas = canvasOf(layerState._viewer);
if (canvas) canvas.style.cursor = '';
parts.launchPad.hideLaunchPadZone();
parts.overlays.hideReplayVehicleOverlay();
layerState._selectedLaunchId = null;
+2 -2
View File
@@ -1,6 +1,6 @@
import { WGS84 } from '../../geo/ellipsoid.js';
import { dot, magnitude, normalize, toDegrees } from '../../geo/vector.js';
import { findQuery } from '../../render/rendererOf.js';
import { canvasOf, findQuery } from '../../render/rendererOf.js';
import { t, msg } from '../../i18n/index.js';
import {
createCyberSonarSampler,
@@ -489,7 +489,7 @@ export function createOverlays({ state: layerState, services, parts, source }) {
hideReplayVehicleOverlay();
return null;
}
const canvas = layerState._viewer.scene.canvas;
const canvas = canvasOf(layerState._viewer);
if (
windowPosition.x < -80 ||
windowPosition.y < -100 ||
+6 -1
View File
@@ -122,7 +122,12 @@ test('the scene chrome renders the overlay in the globe container', async (t) =>
test('the replay overlay sits where the query port projects the vehicle, facing along its path', async () => {
const { bindRenderer } = await import('../../render/rendererOf.js');
const viewer = { scene: { canvas: { clientWidth: 800, clientHeight: 600 } } };
const viewer = {
get canvas() {
return this.scene?.canvas;
},
scene: { canvas: { clientWidth: 800, clientHeight: 600 } },
};
const projected = [];
let behindEye = false;
// The path runs along x; the port puts x metres at x pixels, y = 300.
+3 -3
View File
@@ -12,7 +12,7 @@ import {
vec,
} from '../../geo/vector.js';
import { MISSION_GLOBE_VIEW_RANGE_M, MISSION_FOCUS_RANGE_M } from './policy.js';
import { cameraOf, findCamera } from '../../render/rendererOf.js';
import { cameraOf, canvasOf, findCamera } from '../../render/rendererOf.js';
export function createSelection({
state: layerState,
@@ -23,7 +23,7 @@ export function createSelection({
const { getKeyholeGeometry } = services.geometry;
function focusFullGlobe(viewer, duration = 2.4) {
const canvas = viewer?.scene?.canvas;
const canvas = canvasOf(viewer);
const height = canvas?.clientHeight || canvas?.height;
const width = canvas?.clientWidth || canvas?.width;
if (!(width > 0) || !(height > 0)) return;
@@ -121,7 +121,7 @@ export function createSelection({
const launchPosition = fromDegrees(launch.lon, launch.lat);
let range = 18000000;
if (orbitPositions?.length > 1) {
const canvas = layerState._viewer.scene.canvas;
const canvas = canvasOf(layerState._viewer);
const fovy = camera.pose().fovy || toRadians(60);
const aspect = Math.max(
0.1,
+2 -2
View File
@@ -6,7 +6,7 @@ import {
GLOBAL_RADIO_ALTITUDE_M,
RADIO_GLOBE_RECENTER_MAX_HEIGHT_M,
} from './policy.js';
import { cameraOf, findCamera } from '../../render/rendererOf.js';
import { cameraOf, canvasOf, findCamera } from '../../render/rendererOf.js';
export function createNavigation({
state: layerState,
@@ -157,7 +157,7 @@ export function createNavigation({
function radioGlobeRecenterPlan(viewer = layerState._viewer) {
const pose = findCamera(viewer)?.pose() ?? null;
const canvas = viewer?.scene?.canvas;
const canvas = canvasOf(viewer);
const width = canvas?.clientWidth || canvas?.width;
const height = canvas?.clientHeight || canvas?.height;
// The eye at the earth's centre has no geodetic position.
+3
View File
@@ -100,6 +100,9 @@ export function boxToolFakes() {
const sources = [];
const viewer = {
renders: 0,
get canvas() {
return this.scene.canvas;
},
scene: {
canvas: { clientWidth: 1000, clientHeight: 500 },
screenSpaceCameraController: { enableInputs: true },
+2 -2
View File
@@ -3,7 +3,7 @@ import { horizonFrom } from '../../geo/horizon.js';
import { densifyRhumb } from '../../geo/rhumb.js';
import { distance, toRadians } from '../../geo/vector.js';
import { cssColor } from '../../render/color.js';
import { cameraOf, drawOf } from '../../render/rendererOf.js';
import { cameraOf, canvasOf, drawOf } from '../../render/rendererOf.js';
import {
clampLabel,
createCableOverlayEntry,
@@ -418,7 +418,7 @@ export function createRendering({ state }) {
const pose = cameraOf(viewer).pose();
const cameraPos = pose?.position;
if (!cameraPos) return false;
const canvasHeight = viewer.scene?.canvas?.clientHeight || 1080;
const canvasHeight = canvasOf(viewer)?.clientHeight || 1080;
// The field of view along the canvas's longer side.
const fov =
pose.aspectRatio > 1
+4 -1
View File
@@ -80,7 +80,7 @@ test('superseding a stalled pass aborts promptly without clearing newer loading'
// and the near plane, and window positions from the scene itself.
const ANGLE = 35 * Math.PI / 180;
function portView(scene) {
const viewer = { scene };
const viewer = { scene, canvas: scene.canvas };
const position = { x: 0, y: 0, z: 450 };
const direction = { x: 0, y: Math.cos(ANGLE), z: -Math.sin(ANGLE) };
bindRenderer(viewer, {
@@ -213,6 +213,9 @@ function flowFixture(source) {
_roadMode: 'osm',
_parseRoads: (data) => data.roads,
_viewer: {
get canvas() {
return this.scene?.canvas;
},
scene: {
globe: {
show: true,
+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.
+2 -3
View File
@@ -2,7 +2,7 @@ import { requestWithDeadline } from '../../sources/requestDeadline.js';
import { resolveRoadMode, ROAD_SOURCE_LABELS } from './roadModes.js';
import { phaseTiming } from '../../sources/phaseTiming.js';
import { RoadRequestError, roadRequestError } from './source.js';
import { loadedSurfaceHeight } from './surface.js';
import { viewerRoadSurface } from './surface.js';
import {
isUnavailableCapability,
sourceResponseError,
@@ -273,8 +273,7 @@ export function createIngestion({
let estimated = services.ground?.cachedGroundFloor?.(centerLat, centerLon);
// A miss is the local mesh still loading.
if (!Number.isFinite(estimated))
estimated = loadedSurfaceHeight(
layerState._viewer?.scene,
estimated = viewerRoadSurface(layerState._viewer).loadedHeight(
{ lon: centerLon, lat: centerLat },
[layerState._pointCollection],
);
+13 -2
View File
@@ -32,7 +32,12 @@ function setup(t) {
state._enabled = true;
state._liveMode = true;
state._pointCollection = new C.PointPrimitiveCollection();
state._viewer = { scene: {} };
state._viewer = {
scene: {},
get canvas() {
return this.scene?.canvas;
},
};
const parts = {
rendering: {
removeHeatLines() {},
@@ -735,6 +740,9 @@ test('selection asks the query port for depth and screen positions, and the came
segmentDist: [11],
});
const viewer = {
get canvas() {
return this.scene?.canvas;
},
scene: {
canvas: { clientWidth: 1000, clientHeight: 800 },
globe: { show: true, tilesLoaded: true, getHeight: () => 0 },
@@ -813,6 +821,9 @@ test('selection asks the query port for depth and screen positions, and the came
test('height easing stops visible waypoints at the camera near plane', () => {
const viewer = {
get canvas() {
return this.scene?.canvas;
},
scene: {
canvas: { clientWidth: 1000, clientHeight: 800 },
camera: {},
@@ -879,7 +890,7 @@ test('height easing through the Cesium ports stops at the near plane of a looked
const centre = C.Cartesian3.fromDegrees(0, 0, 0);
// A transformed camera: lookAt leaves the camera in the target's frame.
scene.camera.lookAt(centre, new C.HeadingPitchRange(0, -0.5, 600));
const viewer = { scene, camera: scene.camera };
const viewer = { scene, camera: scene.camera, canvas: scene.canvas };
const eyeDepth = (p) =>
-C.Matrix4.multiplyByPoint(scene.camera.viewMatrix, p, new C.Cartesian3())
.z;
+5 -5
View File
@@ -4,7 +4,7 @@ import {
equalsEpsilon,
lerpInto,
} from '../../geo/vector.js';
import { findCamera, findQuery } from '../../render/rendererOf.js';
import { canvasOf, findCamera, findQuery } from '../../render/rendererOf.js';
import { MAX_DOTS, roadDotBudget } from './policy.js';
export const DOT_CHANGE_BUDGET = 768;
@@ -207,15 +207,15 @@ export function createRetention({ state, parts }) {
*/
function frameView() {
const viewer = state._viewer;
const scene = viewer?.scene;
if (!scene?.canvas?.clientHeight) return null;
const canvas = canvasOf(viewer);
if (!canvas?.clientHeight) return null;
const query = findQuery(viewer);
if (!query) return null;
return {
query,
pose: findCamera(viewer)?.pose() ?? null,
width: scene.canvas.clientWidth,
height: scene.canvas.clientHeight,
width: canvas.clientWidth,
height: canvas.clientHeight,
};
}
function easeHeights(dt) {
+16
View File
@@ -80,6 +80,22 @@ export function trafficSurfaceReady(scene) {
return currentRenderedFrame(scene)?.ready === true;
}
/**
* The surface reads here over the scene `viewer` draws, for code that holds
* the viewer: the scene is read once, as this is called.
* @param {object|undefined} viewer
*/
export function viewerRoadSurface(viewer) {
const scene = viewer?.scene;
return {
drawnReady: () => drawnSurfaceReady(scene),
ready: () => trafficSurfaceReady(scene),
prepare: (roads, ...rest) => prepareRoadSurfaces(roads, scene, ...rest),
loadedHeight: (location, exclude) =>
loadedSurfaceHeight(scene, location, exclude),
};
}
/** Preserve bends and insert height samples at most 150 m apart, splitting long roads. */
export function roadSurfaceChunks(coordinates) {
const chunks = [];
+2 -2
View File
@@ -1,6 +1,6 @@
import { createReticleFootprint } from './footprint.js';
import { toLonLatH } from '../../geo/ellipsoid.js';
import { findCamera, findQuery } from '../../render/rendererOf.js';
import { canvasOf, findCamera, findQuery } from '../../render/rendererOf.js';
import {
deriveFetchCenter,
clampBoundsAroundCenter,
@@ -27,7 +27,7 @@ export function createViewport({ state: layerState, services, parts, source }) {
/** The canvas size in CSS pixels, as the layer has always read it. */
function canvasSize() {
const canvas = layerState._viewer.scene.canvas;
const canvas = canvasOf(layerState._viewer);
return {
width: canvas.clientWidth || canvas.width,
height: canvas.clientHeight || canvas.height,
+2 -2
View File
@@ -1,5 +1,5 @@
import { toLonLatH } from '../../geo/ellipsoid.js';
import { findCamera, findQuery } from '../../render/rendererOf.js';
import { canvasOf, findCamera, findQuery } from '../../render/rendererOf.js';
import { viewAreaRadiusKm } from './viewArea.js';
/**
@@ -13,7 +13,7 @@ export function vesselViewArea(viewer) {
const radiusKm = viewAreaRadiusKm(pose?.height);
if (radiusKm == null) return null;
let { lat, lon } = pose;
const canvas = viewer?.scene?.canvas;
const canvas = canvasOf(viewer);
if (canvas?.clientWidth && canvas?.clientHeight) {
try {
const hit = findQuery(viewer)?.pickEllipsoid(
+3
View File
@@ -7,6 +7,9 @@ import { vesselViewArea } from './cameraArea.js';
/** A viewer whose camera and query ports answer as given. */
function viewerWith({ height, lon = 4, lat = 52, hit, size = [1600, 900] }) {
const viewer = {
get canvas() {
return this.scene?.canvas;
},
scene: { canvas: { clientWidth: size[0], clientHeight: size[1] } },
};
const picks = [];
+2 -1
View File
@@ -10,6 +10,7 @@ import { fromDegrees } from '../../geo/ellipsoid.js';
import { horizonFrom, liftedForHorizon } from '../../geo/horizon.js';
import { distance } from '../../geo/vector.js';
import {
canvasOf,
drawOf,
findCamera,
findFrame,
@@ -552,7 +553,7 @@ export function createRendering({
*/
function publishVesselOverlayEntries(entries) {
const canvas = state.viewer?.scene?.canvas || state.viewer?.canvas;
const canvas = canvasOf(state.viewer);
const width = Number(canvas?.clientWidth) || 0;
const height = Number(canvas?.clientHeight) || 0;
const ambientLimit = vesselOverlayCohortLimit(
+7 -2
View File
@@ -11,7 +11,12 @@ import {
import { formatUtcDayMonth, t, msg } from '../../i18n/index.js';
import { formatScaleLabel } from '../../ui/unitLabels.js';
import { toLonLatH } from '../../geo/ellipsoid.js';
import { cameraOf, findCamera, findQuery } from '../../render/rendererOf.js';
import {
cameraOf,
canvasOf,
findCamera,
findQuery,
} from '../../render/rendererOf.js';
/**
* A stored (English) failure in the language. HTTP failures from source.js
@@ -580,7 +585,7 @@ export function createWeatherLayer({
const shownProblem = problem ? presentWeatherProblem(problem) : null;
const shownHost = hostStatus ? t(hostStatus) : null;
const b = manifest?.bounds;
const canvas = viewer?.scene?.canvas;
const canvas = canvasOf(viewer);
const point =
canvas &&
findQuery(viewer)?.pickEllipsoid(
+2 -2
View File
@@ -7,7 +7,7 @@ import {
} from './presentation.js';
import { inspectWindAtCenter, WIND_UNITS } from './inspection.js';
import { createWindInspectionMarker } from './inspectionMarker.js';
import { findQuery } from '../../render/rendererOf.js';
import { canvasOf, findQuery } from '../../render/rendererOf.js';
import { t, msg, translateKnown } from '../../i18n/index.js';
import { unitLabel } from '../../ui/unitLabels.js';
@@ -81,7 +81,7 @@ export function createWindLayer({
};
const sample = (position) => {
const view = viewer
? { query: findQuery(viewer), canvas: viewer.scene?.canvas }
? { query: findQuery(viewer), canvas: canvasOf(viewer) }
: {};
reading = inspectWindAtCenter(manifest, view, {
position,
+3
View File
@@ -317,6 +317,9 @@ test('sample stays fixed across model, field and unit changes; dismissal and dis
let center = fromDegrees(0, 0);
const viewer = {
container,
get canvas() {
return this.scene?.canvas;
},
scene: {
canvas: { clientWidth: 800, clientHeight: 600, getBoundingClientRect: () => ({ left: 0, top: 0 }) },
},
+2 -2
View File
@@ -1,6 +1,6 @@
import { useWindInspectionStore } from '../../ui/stores/windInspection.js';
import { applicationPinia } from '../../ui/vueRuntime.js';
import { findFrame, findQuery } from '../../render/rendererOf.js';
import { canvasOf, findFrame, findQuery } from '../../render/rendererOf.js';
/**
* One passive marker for the captured location; it never samples on camera
@@ -33,7 +33,7 @@ export function createWindInspectionMarker({
return {
show(position) {
clear();
const canvas = viewer?.scene?.canvas;
const canvas = canvasOf(viewer);
const query = viewer ? findQuery(viewer) : null;
const frame = viewer ? findFrame(viewer) : null;
if (!position || !container?.ownerDocument || !canvas || !query || !frame)
@@ -26,6 +26,9 @@ function fixture(t) {
const projected = [];
const requests = [];
const viewer = {
get canvas() {
return this.scene?.canvas;
},
scene: {
canvas: {
clientWidth: 800,