Files
gods-eye-view/src/layers/vessels/cameraArea.js
T
Sameh Khamis 1c840cb66f Read the vessel view area and evidence through the camera and query ports
The area the vessel feed asks for comes from the camera port's pose and
the query port's ellipsoid pick at the middle of the screen, converted
with geo/ellipsoid, rather than from the Cesium camera; the development
evidence snapshot projects through the query port. Both answer as the
Cesium calls did. The rendering module, still on the Cesium allow-list,
loads the camera factory so a viewer of a caller's own still has both
ports. cameraArea and evidence leave the Cesium allow-list.
2026-11-06 23:02:09 -08:00

32 lines
1.1 KiB
JavaScript

import { toLonLatH } from '../../geo/ellipsoid.js';
import { 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 = viewer?.scene?.canvas;
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 };
}