mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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:
1 parent
abe9f97768
commit
b19fa56565
49 files changed
+269
-119
No files matched your search
@@ -17,7 +17,12 @@ import {
|
||||
TWO_PI,
|
||||
zeroToTwoPi,
|
||||
} from '../geo/index.js';
|
||||
import { findCamera, findFrame, findQuery } from '../render/rendererOf.js';
|
||||
import {
|
||||
canvasOf,
|
||||
findCamera,
|
||||
findFrame,
|
||||
findQuery,
|
||||
} from '../render/rendererOf.js';
|
||||
import { placeFollowEye } from './shareFollow.js';
|
||||
|
||||
function trackedTarget(viewer) {
|
||||
@@ -55,7 +60,7 @@ function cubicInOut(k) {
|
||||
/** Return the world position under the center of the canvas, when available. */
|
||||
export function pickViewTarget(viewer) {
|
||||
const query = findQuery(viewer);
|
||||
const canvas = viewer?.scene?.canvas;
|
||||
const canvas = canvasOf(viewer);
|
||||
if (!query || !canvas) return null;
|
||||
const width = canvas.clientWidth || canvas.width || 0;
|
||||
const height = canvas.clientHeight || canvas.height || 0;
|
||||
@@ -329,7 +334,7 @@ export function bindCameraOrientationControls({
|
||||
subscribe(findCamera(viewer)?.on('moveEnd', refreshTilt));
|
||||
if (viewer) removers.push(onFollowChanged(viewer, animator.cancel));
|
||||
for (const type of ['pointerdown', 'wheel']) {
|
||||
const canvas = viewer?.scene?.canvas;
|
||||
const canvas = canvasOf(viewer);
|
||||
canvas?.addEventListener?.(type, animator.cancel, { passive: true });
|
||||
removers.push(() => canvas?.removeEventListener?.(type, animator.cancel));
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import { inputFor as defaultInputFor } from '../input/dispatcher.js';
|
||||
import { validateBox } from '../layers/recentImagery/model.js';
|
||||
import { createImageryBoxPreview } from '../layers/recentImagery/rendering.js';
|
||||
import { msg } from '../i18n/index.js';
|
||||
import { canvasOf } from '../render/rendererOf.js';
|
||||
|
||||
/** The id this tool claims the pointer under. */
|
||||
export const IMAGERY_BOX_POINTER_OWNER = 'recent-imagery-box';
|
||||
@@ -39,7 +40,7 @@ export function initImageryBoxTool({
|
||||
pickWorld = pickWorldFromScreen,
|
||||
documentRef = globalThis.document,
|
||||
} = {}) {
|
||||
if (!viewer?.scene || typeof onBox !== 'function') return null;
|
||||
if (!viewer || typeof onBox !== 'function') return null;
|
||||
|
||||
let active = false;
|
||||
let destroyed = false;
|
||||
@@ -62,7 +63,7 @@ export function initImageryBoxTool({
|
||||
const setPreview = (visible) => preview.setVisible(visible);
|
||||
const worldAt = (position) => {
|
||||
if (!position) return null;
|
||||
const canvas = viewer.scene.canvas;
|
||||
const canvas = canvasOf(viewer);
|
||||
const w = canvas?.clientWidth || canvas?.width || 1;
|
||||
const h = canvas?.clientHeight || canvas?.height || 1;
|
||||
const point = pickWorld(viewer, position.x / w, position.y / h);
|
||||
|
||||
@@ -24,6 +24,26 @@ function defaultValueText(beforePercent, afterPercent) {
|
||||
return `A ${beforePercent} percent, B ${afterPercent} percent`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A globe port's split as `createImagerySplit` writes it (its `scene`): the
|
||||
* divider moves the globe's split through the port. Null when the globe
|
||||
* has no split.
|
||||
* @param {import('../render/contract/globe').GlobePort|null|undefined} globe
|
||||
* @returns {{splitPosition: number}|null}
|
||||
*/
|
||||
export function globeSplitTarget(globe) {
|
||||
const imagery = globe?.imagery;
|
||||
if (!imagery?.setSplit) return null;
|
||||
return {
|
||||
get splitPosition() {
|
||||
return imagery.getSplit();
|
||||
},
|
||||
set splitPosition(value) {
|
||||
imagery.setSplit(value);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Split divider for before/after imagery comparison.
|
||||
*
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
tn,
|
||||
translateKnown,
|
||||
} from '../i18n/index.js';
|
||||
import { createImagerySplit } from './imagerySplit.js';
|
||||
import { createImagerySplit, globeSplitTarget } from './imagerySplit.js';
|
||||
import RecentImageryReadout from './recentImagery/RecentImageryReadout.vue';
|
||||
import {
|
||||
PRODUCTS,
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
import { displayDay, displayMetres } from '../layers/recentImagery/display.js';
|
||||
import { formatQuantity } from './unitLabels.js';
|
||||
import { pointerOwnerName } from '../data/pointerOwnerNames.js';
|
||||
import { canvasOf, findGlobe } from '../render/rendererOf.js';
|
||||
|
||||
const PANEL_ID = 'recent-imagery-panel';
|
||||
const OVERVIEW_MIN_BOX_KM = 25;
|
||||
@@ -701,7 +702,7 @@ export function createRecentImageryPanel({
|
||||
}
|
||||
if (!live || split || destroyed) return;
|
||||
split = createSplit({
|
||||
scene: viewer?.scene,
|
||||
scene: globeSplitTarget(findGlobe(viewer)),
|
||||
initialValue: snapshot.split,
|
||||
id: 'recent-imagery-split-line',
|
||||
handleClass: 'recent-imagery-split-handle',
|
||||
@@ -722,7 +723,7 @@ export function createRecentImageryPanel({
|
||||
right: rightPercent,
|
||||
}),
|
||||
getViewportWidth: () =>
|
||||
Number(viewer?.scene?.canvas?.clientWidth) ||
|
||||
Number(canvasOf(viewer)?.clientWidth) ||
|
||||
Number(document.documentElement?.clientWidth) ||
|
||||
0,
|
||||
onChange: (value) => layer.setSplit(value),
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
settle,
|
||||
} from '../layers/recentImagery/testDoubles.mjs';
|
||||
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
|
||||
import { fakeGlobePort } from '../testSupport/fakeGlobePort.mjs';
|
||||
|
||||
const S18 = 'S30:2026-09-18';
|
||||
const L16 = 'L30:2026-09-16';
|
||||
@@ -130,7 +131,8 @@ function fixture({ fetchImpl, controller = fakeController() } = {}) {
|
||||
camera: {},
|
||||
scene: { canvas: { clientWidth: 1000 }, requestRender() {} },
|
||||
};
|
||||
bindFakeCesiumCamera(viewer);
|
||||
const globe = fakeGlobePort();
|
||||
bindFakeCesiumCamera(viewer, { globe });
|
||||
layer.init(viewer);
|
||||
layer.attachMapStackController(controller);
|
||||
let active = false;
|
||||
@@ -213,6 +215,7 @@ function fixture({ fetchImpl, controller = fakeController() } = {}) {
|
||||
...dom,
|
||||
layer,
|
||||
viewer,
|
||||
globe,
|
||||
renderer,
|
||||
thumbnails,
|
||||
catalog,
|
||||
@@ -879,6 +882,9 @@ test('the divider exists only while a swipe is live, labelled A / B or IMAGE / B
|
||||
assert.equal(f.splits.length, 1);
|
||||
assert.deepEqual(labels(), ['IMAGE', 'BASEMAP']);
|
||||
assert.equal(f.splits[0].options.id, 'recent-imagery-split-line');
|
||||
// The divider moves the globe's split, through the renderer's globe port.
|
||||
f.splits[0].options.scene.splitPosition = 0.3;
|
||||
assert.equal(f.globe.imagery.getSplit(), 0.3);
|
||||
assert.deepEqual(swapState(), [false, false, 'false', 'false']);
|
||||
assert.deepEqual(directions(), ['left', undefined]);
|
||||
// VS BASEMAP: SWAP puts the image right of the basemap, and back.
|
||||
|
||||
Reference in new issue
Block a user