mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Move geo import, voice capture, visual settings, scope mask and recent imagery onto the renderer ports
Geo import asks the frame port for renders, the camera port for moveEnd and the globe port's progress for the terrain queue running dry; its data sources are added, removed and shown by the listed geoImportPins module. Voice capture waits on the frame port's postRender. Visual settings toggle the infrared fog through the globe sky port, and the anime style dims the Milky Way through a sky getter it is given. The scope mask reads the camera height and listens on the frame and camera ports. Recent imagery picks the view centre, reads the view rectangle and the field of view through the query and camera ports. Installations claim camera sensitivity from their rendering module. The application shell loads the unbound globe factory.
This commit is contained in:
1 parent
b19fa56565
commit
81d8e3a4a7
20 files changed
+308
-119
No files matched your search
@@ -1,9 +1,5 @@
|
||||
import { cameraOf } from '../../render/rendererOf.js';
|
||||
import { CAMERA_CHANGED_THRESHOLD, LAYER_ID } from './policy.js';
|
||||
import {
|
||||
claimCameraSensitivity,
|
||||
releaseCameraSensitivity,
|
||||
} from '../../data/cameraSensitivity.js';
|
||||
|
||||
export function createLifecycle({
|
||||
state: layerState,
|
||||
@@ -52,11 +48,7 @@ export function createLifecycle({
|
||||
});
|
||||
parts.namedMarkers?.enable();
|
||||
parts.namedMarkers?.sync(layerState.records || []);
|
||||
claimCameraSensitivity(
|
||||
layerState.viewer.camera,
|
||||
LAYER_ID,
|
||||
CAMERA_CHANGED_THRESHOLD,
|
||||
);
|
||||
parts.rendering.claimCameraChanges?.();
|
||||
registerPickOwner(LAYER_ID, (id) => layerState.recordById.has(id));
|
||||
layerState.dataSource.show = true;
|
||||
// DataLayerManager invokes update() immediately after enable(), which owns
|
||||
@@ -67,7 +59,7 @@ export function createLifecycle({
|
||||
layerState.enabled = false;
|
||||
services.credits?.hideOsmCredit?.(layerState.viewer, LAYER_ID);
|
||||
parts.namedMarkers?.hide();
|
||||
releaseCameraSensitivity(layerState.viewer?.camera, LAYER_ID);
|
||||
parts.rendering.releaseCameraChanges?.();
|
||||
layerState.contextAnchor = null;
|
||||
layerState.contextPosition = null;
|
||||
layerState.coverage = { kind: 'viewport' };
|
||||
|
||||
@@ -4,7 +4,16 @@ import * as Cesium from 'cesium';
|
||||
// factory its other parts reach the renderer through.
|
||||
import '../../render/cesium/camera.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
import { LAYER_ID, MAX_RENDERED, COLOR_BY_CLASS } from './policy.js';
|
||||
import {
|
||||
CAMERA_CHANGED_THRESHOLD,
|
||||
LAYER_ID,
|
||||
MAX_RENDERED,
|
||||
COLOR_BY_CLASS,
|
||||
} from './policy.js';
|
||||
import {
|
||||
claimCameraSensitivity,
|
||||
releaseCameraSensitivity,
|
||||
} from '../../data/cameraSensitivity.js';
|
||||
import { entityRecord } from '../../data/entityRecords.js';
|
||||
import { installationMarkers } from './markerState.js';
|
||||
|
||||
@@ -382,9 +391,26 @@ export function createRendering({
|
||||
renderRecords();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* While the layer is on, the Cesium camera reports changes at the layer's
|
||||
* threshold to its own `changed` listeners too (the camera port measures
|
||||
* each listener's threshold itself).
|
||||
*/
|
||||
function claimCameraChanges() {
|
||||
claimCameraSensitivity(
|
||||
layerState.viewer.camera,
|
||||
LAYER_ID,
|
||||
CAMERA_CHANGED_THRESHOLD,
|
||||
);
|
||||
}
|
||||
function releaseCameraChanges() {
|
||||
releaseCameraSensitivity(layerState.viewer?.camera, LAYER_ID);
|
||||
}
|
||||
return {
|
||||
attach,
|
||||
detach,
|
||||
claimCameraChanges,
|
||||
releaseCameraChanges,
|
||||
installationSurfaceHeightM,
|
||||
clearSelectionFill,
|
||||
syncSelectionFill,
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
PRODUCTS,
|
||||
boxCentre,
|
||||
boxFromPin,
|
||||
boxFromRectangle,
|
||||
boxFromDegrees,
|
||||
boxSideKm,
|
||||
dequantizeBox,
|
||||
fitViewHeightM,
|
||||
@@ -33,8 +33,14 @@ import {
|
||||
viewTooLargeMessage,
|
||||
} from './model.js';
|
||||
import { msg, t } from '../../i18n/index.js';
|
||||
import { fromDegrees, toLonLatH } from '../../geo/ellipsoid.js';
|
||||
import { READOUT_WORDS, displayDay, displayMetres } from './display.js';
|
||||
import { findCamera, findGlobe } from '../../render/rendererOf.js';
|
||||
import {
|
||||
canvasOf,
|
||||
findCamera,
|
||||
findGlobe,
|
||||
findQuery,
|
||||
} from '../../render/rendererOf.js';
|
||||
|
||||
/**
|
||||
* Quiet time after the last arrow key before the focused day previews, so a
|
||||
@@ -67,10 +73,6 @@ const clampUnit = (value, fallback) => {
|
||||
const boxSignature = (box) =>
|
||||
box ? BOX_EDGES.map((edge) => Number(box[edge]).toFixed(6)).join(',') : '';
|
||||
const sourceOf = (product) => PRODUCTS[product]?.source || null;
|
||||
const toDegrees = (radians) => (radians * 180) / Math.PI;
|
||||
const toRadians = (degrees) => (degrees * Math.PI) / 180;
|
||||
const ellipsoidOf = (viewer) =>
|
||||
viewer?.scene?.ellipsoid || viewer?.scene?.globe?.ellipsoid || null;
|
||||
|
||||
/**
|
||||
* The ground under the canvas centre, in degrees; null when the centre is
|
||||
@@ -79,20 +81,14 @@ const ellipsoidOf = (viewer) =>
|
||||
* @returns {{ lon: number, lat: number } | null}
|
||||
*/
|
||||
function viewCentre(viewer) {
|
||||
const ellipsoid = ellipsoidOf(viewer);
|
||||
const canvas = viewer?.scene?.canvas;
|
||||
const query = findQuery(viewer);
|
||||
const canvas = canvasOf(viewer);
|
||||
const width = Number(canvas?.clientWidth);
|
||||
const height = Number(canvas?.clientHeight);
|
||||
if (!ellipsoid?.cartesianToCartographic || !(width > 0) || !(height > 0))
|
||||
return null;
|
||||
const hit = viewer.camera?.pickEllipsoid?.(
|
||||
{ x: width / 2, y: height / 2 },
|
||||
ellipsoid,
|
||||
);
|
||||
const ground = hit ? ellipsoid.cartesianToCartographic(hit) : null;
|
||||
return ground
|
||||
? { lon: toDegrees(ground.longitude), lat: toDegrees(ground.latitude) }
|
||||
: null;
|
||||
if (!query || !(width > 0) || !(height > 0)) return null;
|
||||
const hit = query.pickEllipsoid(width / 2, height / 2);
|
||||
const ground = hit ? toLonLatH(hit) : null;
|
||||
return ground ? { lon: ground.lon, lat: ground.lat } : null;
|
||||
}
|
||||
const modeFrom = (value) =>
|
||||
MODES.includes(value)
|
||||
@@ -963,10 +959,10 @@ export function createRecentImageryLayer({
|
||||
* @returns {boolean}
|
||||
*/
|
||||
useCurrentView(viewer = _viewer) {
|
||||
const rectangle = viewer?.camera?.computeViewRectangle?.();
|
||||
const rectangle = findCamera(viewer)?.viewRectangle();
|
||||
if (!rectangle)
|
||||
return refuseBox('Point the camera at the ground to use the view');
|
||||
const box = boxFromRectangle(rectangle);
|
||||
const box = boxFromDegrees(rectangle);
|
||||
if (validateBox(box).reason === 'too-large') {
|
||||
const { width, height } = boxSideKm(box);
|
||||
return refuseBox(
|
||||
@@ -985,29 +981,20 @@ export function createRecentImageryLayer({
|
||||
*/
|
||||
zoomToFit() {
|
||||
const target = _boxError ? _refusalTarget : null;
|
||||
const camera = _viewer?.camera;
|
||||
const ellipsoid = ellipsoidOf(_viewer);
|
||||
// No camera port: a viewer of the caller's own whose renderer did not
|
||||
// bring the camera factory (GEV's own imagery renderer does).
|
||||
const port = findCamera(_viewer);
|
||||
if (!target || !port || !ellipsoid?.cartographicToCartesian) return null;
|
||||
const canvas = _viewer.scene?.canvas;
|
||||
if (!target || !port) return null;
|
||||
const canvas = canvasOf(_viewer);
|
||||
const height = fitViewHeightM({
|
||||
width: canvas?.clientWidth,
|
||||
height: canvas?.clientHeight,
|
||||
fovy: camera?.frustum?.fovy,
|
||||
fovy: port.pose().fovy,
|
||||
});
|
||||
port.flyTo(fromDegrees(target.lon, target.lat, height), {
|
||||
orientation: { heading: 0, pitch: -Math.PI / 2, roll: 0 },
|
||||
durationS: ZOOM_FIT_SECONDS,
|
||||
});
|
||||
port.flyTo(
|
||||
ellipsoid.cartographicToCartesian({
|
||||
longitude: toRadians(target.lon),
|
||||
latitude: toRadians(target.lat),
|
||||
height,
|
||||
}),
|
||||
{
|
||||
orientation: { heading: 0, pitch: -Math.PI / 2, roll: 0 },
|
||||
durationS: ZOOM_FIT_SECONDS,
|
||||
},
|
||||
);
|
||||
return height;
|
||||
},
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
settle,
|
||||
} from './testDoubles.mjs';
|
||||
import { bindFakeCesiumCamera } from '../../testSupport/fakeCameraPort.mjs';
|
||||
import { fakeSceneQuery } from '../../testSupport/fakeCesiumScene.mjs';
|
||||
|
||||
const NOW = new Date('2026-09-21T15:00:00Z');
|
||||
const LINK_BOX = {
|
||||
@@ -116,6 +117,7 @@ function fixture({
|
||||
controller = fakeController(),
|
||||
viirs = true,
|
||||
globeOf,
|
||||
ports = () => ({}),
|
||||
} = {}) {
|
||||
const renderer = fakeRenderer();
|
||||
const thumbnails = fakeThumbnails();
|
||||
@@ -138,7 +140,7 @@ function fixture({
|
||||
});
|
||||
if (viirs) layer.setSources({ viirs: true });
|
||||
const viewer = { camera: {} };
|
||||
bindFakeCesiumCamera(viewer);
|
||||
bindFakeCesiumCamera(viewer, ports(viewer));
|
||||
const reasons = [];
|
||||
layer.subscribe((snapshot, reason) => reasons.push(reason));
|
||||
layer.init(viewer);
|
||||
@@ -996,7 +998,8 @@ test('USE VIEW takes the camera rectangle and refuses a view over the cap instea
|
||||
});
|
||||
|
||||
test('ZOOM IN: an oversized box or view flies top-down to its centre at the height whose view is 400 km wide', () => {
|
||||
const f = fixture();
|
||||
// The renderer's query port picks the ellipsoid through the camera's own.
|
||||
const f = fixture({ ports: (viewer) => ({ query: fakeSceneQuery(viewer) }) });
|
||||
const flights = [];
|
||||
const landing = (i) =>
|
||||
Cesium.Ellipsoid.WGS84.cartesianToCartographic(flights[i].destination);
|
||||
@@ -1007,21 +1010,25 @@ test('ZOOM IN: an oversized box or view flies top-down to its centre at the heig
|
||||
const expected = 400_000 / (2 * Math.tan(Math.PI / 6));
|
||||
let centreHit = null;
|
||||
Object.assign(f.viewer, {
|
||||
scene: {
|
||||
canvas: { clientWidth: 1000, clientHeight: 500 },
|
||||
ellipsoid: {
|
||||
cartographicToCartesian: (c) =>
|
||||
Cesium.Ellipsoid.WGS84.cartographicToCartesian(c),
|
||||
cartesianToCartographic: (c) => c && { ...c },
|
||||
},
|
||||
},
|
||||
canvas: { clientWidth: 1000, clientHeight: 500 },
|
||||
});
|
||||
Object.assign(f.viewer.camera, {
|
||||
frustum: { fovy },
|
||||
flyTo: (options) => flights.push(options),
|
||||
pickEllipsoid: (position) => {
|
||||
assert.deepEqual(position, { x: 500, y: 250 }, 'the canvas centre');
|
||||
return centreHit;
|
||||
assert.deepEqual(
|
||||
[position.x, position.y],
|
||||
[500, 250],
|
||||
'the canvas centre',
|
||||
);
|
||||
return (
|
||||
centreHit &&
|
||||
Cesium.Cartesian3.fromRadians(
|
||||
centreHit.longitude,
|
||||
centreHit.latitude,
|
||||
centreHit.height,
|
||||
)
|
||||
);
|
||||
},
|
||||
});
|
||||
f.layer.enable();
|
||||
|
||||
@@ -237,6 +237,11 @@ function mapBox(box, fn) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Degrees box from a degrees rectangle (the camera port's `viewRectangle`). */
|
||||
export function boxFromDegrees(rectangle) {
|
||||
return mapBox(rectangle, (degrees) => degrees);
|
||||
}
|
||||
|
||||
/** Degrees box from a radians rectangle (Cesium `Rectangle` shape). */
|
||||
export function boxFromRectangle(rectangle) {
|
||||
return mapBox(rectangle, (radians) => (Number(radians) * 180) / Math.PI);
|
||||
|
||||
Reference in new issue
Block a user