mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 17:22:19 +00:00
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.
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
import { toLonLatH } from '../../geo/ellipsoid.js';
|
|
import { canvasOf, findCamera, findQuery } from '../../render/rendererOf.js';
|
|
import { viewAreaRadiusKm } from './viewArea.js';
|
|
|
|
/**
|
|
* The area a viewer is looking at, as `{ lat, lon, radiusKm }`: centered on
|
|
* the point in the middle of the screen (or below the camera when the middle
|
|
* shows sky), sized by the camera's height. Null for a view that wants every
|
|
* vessel.
|
|
*/
|
|
export function vesselViewArea(viewer) {
|
|
const pose = findCamera(viewer)?.pose();
|
|
const radiusKm = viewAreaRadiusKm(pose?.height);
|
|
if (radiusKm == null) return null;
|
|
let { lat, lon } = pose;
|
|
const canvas = canvasOf(viewer);
|
|
if (canvas?.clientWidth && canvas?.clientHeight) {
|
|
try {
|
|
const hit = findQuery(viewer)?.pickEllipsoid(
|
|
canvas.clientWidth / 2,
|
|
canvas.clientHeight / 2,
|
|
);
|
|
const center = hit ? toLonLatH(hit) : null;
|
|
if (center) ({ lat, lon } = center);
|
|
} catch {
|
|
/* the camera position stands in */
|
|
}
|
|
}
|
|
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null;
|
|
return { lat, lon, radiusKm };
|
|
}
|