mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
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.
This commit is contained in:
1 parent
81d8e3a4a7
commit
1f1d08f34e
5 files changed
+40
-38
No files matched your search
@@ -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).
|
||||
|
||||
@@ -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) => ({
|
||||
|
||||
+35
-1
@@ -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;
|
||||
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in new issue
Block a user