mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
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.
This commit is contained in:
1 parent
0a81c2e197
commit
1c840cb66f
6 files changed
+104
-22
No files matched your search
@@ -1639,10 +1639,12 @@
|
||||
"modules": [
|
||||
"src/data/headingDegrees.js",
|
||||
"src/layers/vessels/cards.js",
|
||||
"src/geo/index.js",
|
||||
"src/layers/vessels/evidence.js",
|
||||
"src/layers/vessels/index.js",
|
||||
"src/layers/vessels/ingestion.js",
|
||||
"src/layers/vessels/cameraArea.js",
|
||||
"src/geo/ellipsoid.js",
|
||||
"src/layers/vessels/viewArea.js",
|
||||
"src/layers/vessels/lifecycle.js",
|
||||
"src/layers/vessels/policy.js",
|
||||
@@ -1687,6 +1689,17 @@
|
||||
"src/styles/styleStages.js",
|
||||
"src/input/dispatcher.js",
|
||||
"src/render/cesium/drawHit.js",
|
||||
"src/render/cesium/camera.js",
|
||||
"src/render/camera/events.js",
|
||||
"src/geo/celestial.js",
|
||||
"src/geo/quaternion.js",
|
||||
"src/geo/frames.js",
|
||||
"src/render/cesium/query.js",
|
||||
"src/render/cesium/credits.js",
|
||||
"src/queries/heights.js",
|
||||
"src/render/creditMarkup.js",
|
||||
"src/render/cesium/draw.js",
|
||||
"src/render/cesium/frame.js",
|
||||
"src/render/cesium/follow.js",
|
||||
"src/render/cesium/cameraInput.js",
|
||||
"src/render/cesium/common.js",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { toLonLatH } from '../../geo/ellipsoid.js';
|
||||
import { findCamera, findQuery } from '../../render/rendererOf.js';
|
||||
import { viewAreaRadiusKm } from './viewArea.js';
|
||||
|
||||
/**
|
||||
@@ -8,26 +9,23 @@ import { viewAreaRadiusKm } from './viewArea.js';
|
||||
* vessel.
|
||||
*/
|
||||
export function vesselViewArea(viewer) {
|
||||
const camera = viewer?.camera;
|
||||
const scene = viewer?.scene;
|
||||
const height = camera?.positionCartographic?.height;
|
||||
const radiusKm = viewAreaRadiusKm(height);
|
||||
const pose = findCamera(viewer)?.pose();
|
||||
const radiusKm = viewAreaRadiusKm(pose?.height);
|
||||
if (radiusKm == null) return null;
|
||||
let center = camera.positionCartographic;
|
||||
const canvas = scene?.canvas;
|
||||
let { lat, lon } = pose;
|
||||
const canvas = viewer?.scene?.canvas;
|
||||
if (canvas?.clientWidth && canvas?.clientHeight) {
|
||||
try {
|
||||
const hit = camera.pickEllipsoid(
|
||||
new Cesium.Cartesian2(canvas.clientWidth / 2, canvas.clientHeight / 2),
|
||||
scene.globe?.ellipsoid,
|
||||
const hit = findQuery(viewer)?.pickEllipsoid(
|
||||
canvas.clientWidth / 2,
|
||||
canvas.clientHeight / 2,
|
||||
);
|
||||
if (hit) center = Cesium.Cartographic.fromCartesian(hit);
|
||||
const center = hit ? toLonLatH(hit) : null;
|
||||
if (center) ({ lat, lon } = center);
|
||||
} catch {
|
||||
/* the camera position stands in */
|
||||
}
|
||||
}
|
||||
const lat = Cesium.Math.toDegrees(center.latitude);
|
||||
const lon = Cesium.Math.toDegrees(center.longitude);
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null;
|
||||
return { lat, lon, radiusKm };
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { bindRenderer } from '../../render/rendererOf.js';
|
||||
import { vesselViewArea } from './cameraArea.js';
|
||||
|
||||
/** A viewer whose camera and query ports answer as given. */
|
||||
function viewerWith({ height, lon = 4, lat = 52, hit, size = [1600, 900] }) {
|
||||
const viewer = {
|
||||
scene: { canvas: { clientWidth: size[0], clientHeight: size[1] } },
|
||||
};
|
||||
const picks = [];
|
||||
const unbind = bindRenderer(viewer, {
|
||||
camera: { pose: () => ({ lon, lat, height }) },
|
||||
query: {
|
||||
pickEllipsoid(x, y) {
|
||||
picks.push([x, y]);
|
||||
if (hit instanceof Error) throw hit;
|
||||
return hit ?? null;
|
||||
},
|
||||
},
|
||||
});
|
||||
return { viewer, picks, unbind };
|
||||
}
|
||||
|
||||
test('the view area centres on the ground in the middle of the screen', () => {
|
||||
const { viewer, picks, unbind } = viewerWith({
|
||||
height: 120000,
|
||||
hit: fromDegrees(3.5, 51.25),
|
||||
});
|
||||
const area = vesselViewArea(viewer);
|
||||
unbind();
|
||||
assert.deepEqual(picks, [[800, 450]]);
|
||||
assert.ok(Math.abs(area.lon - 3.5) < 1e-9);
|
||||
assert.ok(Math.abs(area.lat - 51.25) < 1e-9);
|
||||
assert.ok(Math.abs(area.radiusKm - 120) < 1e-9);
|
||||
});
|
||||
|
||||
test('sky in the middle, a failed pick or no canvas leave the camera position', () => {
|
||||
for (const options of [
|
||||
{ hit: null },
|
||||
{ hit: new Error('no globe') },
|
||||
{ hit: fromDegrees(0, 0), size: [0, 0] },
|
||||
]) {
|
||||
const { viewer, unbind } = viewerWith({ height: 5000, ...options });
|
||||
const area = vesselViewArea(viewer);
|
||||
unbind();
|
||||
assert.deepEqual(area, { lat: 52, lon: 4, radiusKm: 10 });
|
||||
}
|
||||
});
|
||||
|
||||
test('a wide view, an unknown height or no camera asks for every vessel', () => {
|
||||
for (const height of [500000, NaN]) {
|
||||
const { viewer, unbind } = viewerWith({ height });
|
||||
const area = vesselViewArea(viewer);
|
||||
unbind();
|
||||
assert.equal(area, null);
|
||||
}
|
||||
assert.equal(vesselViewArea(null), null);
|
||||
assert.equal(vesselViewArea({ scene: {} }), null);
|
||||
});
|
||||
|
||||
test('a camera with no position asks for every vessel', () => {
|
||||
const { viewer, unbind } = viewerWith({
|
||||
height: 5000,
|
||||
lon: NaN,
|
||||
lat: NaN,
|
||||
size: [0, 0],
|
||||
});
|
||||
const area = vesselViewArea(viewer);
|
||||
unbind();
|
||||
assert.equal(area, null);
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { findQuery } from '../../render/rendererOf.js';
|
||||
import { FOCUS_EVIDENCE_DEV } from './policy.js';
|
||||
|
||||
export function createEvidence({
|
||||
@@ -38,16 +38,12 @@ export function createEvidence({
|
||||
|
||||
function _focusEvidenceVesselSnapshot() {
|
||||
if (!FOCUS_EVIDENCE_DEV || !state.viewer) return [];
|
||||
const query = findQuery(state.viewer);
|
||||
return state.records.all.map((record) => {
|
||||
const visual = components.rendering.getVisual(record);
|
||||
const row = state.icons?.row(visual.iconId) ?? -1;
|
||||
const position = row >= 0 ? visual.position : null;
|
||||
const screen = position
|
||||
? Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
state.viewer.scene,
|
||||
position,
|
||||
)
|
||||
: null;
|
||||
const screen = position ? query?.project(position) : null;
|
||||
return {
|
||||
id: record.mmsi,
|
||||
show: row >= 0 && visual.visible === true,
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import * as Cesium from 'cesium';
|
||||
// The Cesium camera factory, which loads the query factory: given a viewer
|
||||
// of a caller's own, with no renderer bound, the view area and evidence
|
||||
// reads still find a camera and a query port.
|
||||
import '../../render/cesium/camera.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
import {
|
||||
vesselTypeCss,
|
||||
|
||||
@@ -129,8 +129,6 @@
|
||||
"src/layers/transit/lifecycle.js",
|
||||
"src/layers/transit/rendering.js",
|
||||
"src/layers/transit/testing.js",
|
||||
"src/layers/vessels/cameraArea.js",
|
||||
"src/layers/vessels/evidence.js",
|
||||
"src/layers/vessels/rendering.js",
|
||||
"src/layers/vessels/tracking.js",
|
||||
"src/layers/weather/index.js",
|
||||
|
||||
Reference in new issue
Block a user