Read the camera verbs' and voice actions' canvas from the renderer

The camera verbs size their keyhole fit by the renderer's canvas and listen
on it for the user's input, and the voice actions size their view samples
by it, rather than reaching through `viewer.scene`; a viewer with no
renderer bound answers with its own canvas, the same element. The test
fakes give their viewers a canvas, and a fake camera binding's renderer
reports the fake viewer's.
This commit is contained in:
Sameh Khamis committed 2026-11-07 16:12:43 -08:00
1 parent 20fdfd492e
commit b47aa5f3de
14 files changed
+46 -9

No files matched your search

+1
View File
@@ -16,6 +16,7 @@ after(() => {
function viewerFixture() {
return {
clock: { onTick: { addEventListener: () => () => {} } },
canvas: { addEventListener() {}, removeEventListener() {} },
scene: { canvas: { addEventListener() {}, removeEventListener() {} } },
camera: { moveEnd: { addEventListener() {} } },
};
+1
View File
@@ -14,6 +14,7 @@ import { DataLayerManager } from '../data/manager.js';
const viewerFixture = () => ({
clock: { onTick: { addEventListener: () => () => {} } },
camera: { moveEnd: { addEventListener() {} } },
canvas: { addEventListener() {}, removeEventListener() {} },
scene: { canvas: { addEventListener() {}, removeEventListener() {} } },
});
const request = (ws, id, name, args = {}) =>
+12 -5
View File
@@ -21,7 +21,12 @@ import {
toRadians,
} from '../geo/index.js';
import { sphereFromPoints } from '../geo/sphere.js';
import { cameraOf, findCamera, findQuery } from '../render/rendererOf.js';
import {
cameraOf,
findCamera,
findQuery,
rendererOf,
} from '../render/rendererOf.js';
import { CITY_POIS } from '../cityPois.js';
import { greatCircleKm } from '../geoDistance.js';
import {
@@ -3965,13 +3970,16 @@ function selectedEntityContext(dataManager) {
return summarizeContextRecord(record, { includeProperties: true });
}
/** The canvas the renderer draws in (the viewer's own when none is bound). */
const canvasOf = (viewer) => rendererOf(viewer)?.canvas ?? viewer.canvas;
function visibleEntityContexts(
viewer,
dataManager,
{ layerId = null, limit = 5, target = null } = {},
) {
const nearbyRecords = [];
const canvas = viewer.scene.canvas;
const canvas = canvasOf(viewer);
const width = canvas.clientWidth || canvas.width || 0;
const height = canvas.clientHeight || canvas.height || 0;
const centerX = width / 2;
@@ -4322,7 +4330,7 @@ function cameraViewSignature(camera) {
function getViewTargetCartesian(viewer) {
const query = findQuery(viewer);
if (!query) return null;
const canvas = viewer.scene.canvas;
const canvas = canvasOf(viewer);
const width = canvas.clientWidth || canvas.width || 0;
const height = canvas.clientHeight || canvas.height || 0;
const x = width / 2;
@@ -4356,8 +4364,7 @@ function getViewTargetCartesian(viewer) {
}
function sampleViewportCartographics(viewer) {
const scene = viewer.scene;
const canvas = scene.canvas;
const canvas = canvasOf(viewer);
const width = canvas.clientWidth || canvas.width || 0;
const height = canvas.clientHeight || canvas.height || 0;
if (!width || !height) return [];
+2
View File
@@ -1306,6 +1306,7 @@ test('generic same-response Radio visibility disable supersedes delayed Select',
});
const viewer = {
clock: { onTick: { addEventListener: () => () => {} } },
canvas: { addEventListener() {}, removeEventListener() {} },
scene: { canvas: { addEventListener() {}, removeEventListener() {} } },
camera: { moveEnd: { addEventListener() {} } },
};
@@ -1558,6 +1559,7 @@ test('Pause and Stop preserve independent dedicated and generic Radio ON across
});
const viewer = {
clock: { onTick: { addEventListener: () => () => {} } },
canvas: { addEventListener() {}, removeEventListener() {} },
scene: { canvas: { addEventListener() {}, removeEventListener() {} } },
camera: { moveEnd: { addEventListener() {} } },
};
+1
View File
@@ -497,6 +497,7 @@ async function directActions(
const runner = createGevActionRunner({
viewer: {
clock: { onTick: { addEventListener: () => () => {} } },
canvas: { addEventListener() {}, removeEventListener() {} },
scene: { canvas: { addEventListener() {}, removeEventListener() {} } },
camera: { moveEnd: { addEventListener() {} } },
},
+1
View File
@@ -54,6 +54,7 @@ export function harness({
const enabled = new Set(on);
const viewer = {
clock: { onTick: { addEventListener: () => () => {} } },
canvas: { addEventListener() {}, removeEventListener() {} },
scene: { canvas: { addEventListener() {}, removeEventListener() {} } },
camera: {
moveEnd: { addEventListener() {} },