From 1f1d08f34e87d092a1f77437416f110c3fafa57a Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 7 Nov 2026 18:09:37 -0800 Subject: [PATCH] Move the click's ground pick into the input dispatcher and weather's default host into its shell rendering pickGroundPosition reads Cesium's depth and ellipsoid picks, so it moves unchanged from scenePick into the listed input dispatcher, its only caller. Weather rendering's default imagery host comes from the listed shell rendering's globeImageryHost instead of reading the viewer's imagery layers. --- src/data/scenePick.js | 34 ------------------- src/data/scenePick.test.mjs | 2 +- src/input/dispatcher.js | 36 ++++++++++++++++++++- src/layers/streetLevel/groundClick.test.mjs | 3 +- src/layers/weather/rendering.js | 3 +- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/data/scenePick.js b/src/data/scenePick.js index 52bab7a21..e9f175509 100644 --- a/src/data/scenePick.js +++ b/src/data/scenePick.js @@ -48,40 +48,6 @@ export function isPickedWorldPosition(position) { return magnitude >= MIN_PICK_MAGNITUDE_M && magnitude <= MAX_PICK_MAGNITUDE_M; } -/** - * The world position under a screen point: the rendered surface where the - * depth buffer has it, else the ellipsoid; null over the sky. - * - * @param {object} viewer A Cesium viewer. - * @param {{x: number, y: number}} screenPosition - * @returns {{x: number, y: number, z: number}|null} A Cartesian3. - */ -export function pickGroundPosition(viewer, screenPosition) { - const scene = viewer?.scene; - let position = null; - if ( - scene?.pickPositionSupported && - typeof scene.pickPosition === 'function' - ) { - try { - position = scene.pickPosition(screenPosition); - } catch { - position = null; - } - } - if ( - !isPickedWorldPosition(position) && - typeof viewer?.camera?.pickEllipsoid === 'function' - ) { - try { - position = viewer.camera.pickEllipsoid(screenPosition); - } catch { - position = null; - } - } - return isPickedWorldPosition(position) ? position : null; -} - /** * Whether a `scene.pick()` result is the map itself: nothing, or 3D tile * content (which has no id). diff --git a/src/data/scenePick.test.mjs b/src/data/scenePick.test.mjs index 630ce4003..2340e4242 100644 --- a/src/data/scenePick.test.mjs +++ b/src/data/scenePick.test.mjs @@ -163,7 +163,7 @@ test('the guard rejects each way Cesium mishandles a degenerate pick', () => { }); test('the ground under a click: the rendered surface, else the ellipsoid, never the sky', async () => { - const { pickGroundPosition } = await import('./scenePick.js'); + const { pickGroundPosition } = await import('../input/dispatcher.js'); const ground = { x: 6378137, y: 0, z: 0 }; const sky = { x: 500, y: 0, z: 0 }; const viewer = (picked, ellipsoid) => ({ diff --git a/src/input/dispatcher.js b/src/input/dispatcher.js index e833a1311..34b706354 100644 --- a/src/input/dispatcher.js +++ b/src/input/dispatcher.js @@ -44,7 +44,7 @@ import { pickContact, resolvePickId, } from '../data/pickRegistry.js'; -import { isSurfacePick, pickGroundPosition } from '../data/scenePick.js'; +import { isPickedWorldPosition, isSurfacePick } from '../data/scenePick.js'; import { sensorPickPosition } from './sensorPick.js'; // A tool takes the pointer with a lease before it subscribes with one. @@ -56,6 +56,40 @@ export { releasePointer, } from '../data/inputOwnership.js'; +/** + * The world position under a screen point: the rendered surface where the + * depth buffer has it, else the ellipsoid; null over the sky. + * + * @param {object} viewer A Cesium viewer. + * @param {{x: number, y: number}} screenPosition + * @returns {{x: number, y: number, z: number}|null} A Cartesian3. + */ +export function pickGroundPosition(viewer, screenPosition) { + const scene = viewer?.scene; + let position = null; + if ( + scene?.pickPositionSupported && + typeof scene.pickPosition === 'function' + ) { + try { + position = scene.pickPosition(screenPosition); + } catch { + position = null; + } + } + if ( + !isPickedWorldPosition(position) && + typeof viewer?.camera?.pickEllipsoid === 'function' + ) { + try { + position = viewer.camera.pickEllipsoid(screenPosition); + } catch { + position = null; + } + } + return isPickedWorldPosition(position) ? position : null; +} + /** The handler event types the scene's input port binds, for test doubles. */ export const HANDLER_EVENT_TYPES = Cesium.ScreenSpaceEventType; diff --git a/src/layers/streetLevel/groundClick.test.mjs b/src/layers/streetLevel/groundClick.test.mjs index e6d14b268..8d36bc8df 100644 --- a/src/layers/streetLevel/groundClick.test.mjs +++ b/src/layers/streetLevel/groundClick.test.mjs @@ -3,6 +3,7 @@ import test from 'node:test'; import * as Cesium from 'cesium'; import { createGroundClick, groundClickHeightOk } from './groundClick.js'; import * as scenePick from '../../data/scenePick.js'; +import { pickGroundPosition } from '../../input/dispatcher.js'; import { bindFakeCesiumCamera } from '../../testSupport/fakeCameraPort.mjs'; import { streetPorts } from '../../testSupport/streetLevelFakes.mjs'; @@ -70,7 +71,7 @@ function harness({ const click = (pick) => openAtGround({ surface: scenePick.isSurfacePick(pick), - ground: () => scenePick.pickGroundPosition(state.viewer, { x: 1, y: 1 }), + ground: () => pickGroundPosition(state.viewer, { x: 1, y: 1 }), }); return { opened, click }; } diff --git a/src/layers/weather/rendering.js b/src/layers/weather/rendering.js index 9e5252f7b..97379c77e 100644 --- a/src/layers/weather/rendering.js +++ b/src/layers/weather/rendering.js @@ -1,6 +1,7 @@ import { weatherTileUrl } from './source.js'; import { WEATHER_IMAGERY_Z } from './imageryOrder.js'; import { imageryHostStatus } from './imageryHost.js'; +import { globeImageryHost } from './shellRendering.js'; import { drawMosaicTile } from './rasterTiles.js'; import { weatherDisplay } from './display.js'; import { msg } from '../../i18n/index.js'; @@ -600,7 +601,7 @@ export function createWeatherRendering({ frameOf = findFrame, toBitmap = (canvas) => globalThis.createImageBitmap(canvas, { premultiplyAlpha: 'none' }), - getHost = () => ({ collection: viewer.imageryLayers, kind: 'globe' }), + getHost = () => globeImageryHost(viewer), onChange = () => {}, timeoutMs = 25_000, now = () => performance.now(),