mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Draw the aircraft family, Wildlife Sightings and the Cockpit through the contract
The layers that still had one Cesium and one Navara implementation, or
drew on Cesium only, now draw through engine.movers, engine.lines and
engine.camera on both engines, and application code holds the engine
instead of guessing it from a viewer.
- Aircraft family: flights, military and local ADS-B share one display
(src/layers/aircraft/render/display.js). The Cesium and Navara
renderers are gone. Where they differed, the display follows Cesium:
- attach and visibility tracking, live disableDepthTestDistance
changes, the tracked glyph's distance scale, model ids that change,
local ADS-B markers hidden until shown and its UAT ring as a point;
- the trail head's hidden alpha is 0.45, the contract's
depthFailAlpha scaled by the head's 0.9.
The tracked glyph stays over the fleet, as on Navara. The movers
contract reports readiness per model and reads model axes as the
glTF's own on every engine. Cesium's follow takes any native target
through a proxy entity in the ENU frame and mirrors its readout fields.
- Wildlife Sightings draws badges and the density glow as sprite sets
and its privacy cells as line outlines (no fill yet). It takes clicks
from engine.input and its card anchors to the engine's canvas and
camera, so the layer is in both engines' catalogs again and a switch
keeps the session's layer set.
- Cockpit: cockpitHost takes the engine only. The ridden aircraft is the
engine follow's target, hidden through its sprite; only the Cesium
Viewer's stock double-click is still routed around.
- About forty camera, navigation, share-link, HUD, voice, detection and
layer-lifecycle callers take the engine. isGlobeEngine and
engineFromViewer calls outside src/globe fall from 51 to 14.
The coupling baseline drops accordingly: layer renderer lines from
5239/12331 to 4546/11106 (Cesium/Navara), `viewer` lines from 2424 to
2209, Cesium-importing files from 69 to 66.
This commit is contained in:
1 parent
48988015f1
commit
35e70ec280
145 files changed
+4716
-4212
No files matched your search
@@ -35,7 +35,6 @@ import {
|
||||
} from './cyberSonarControls.js';
|
||||
|
||||
import * as geo from '../geo/index.js';
|
||||
import { engineFromViewer } from '../globe/cesium/engineFromViewer.js';
|
||||
import { cesiumHeading, cesiumRoll } from '../cameraAngles.js';
|
||||
|
||||
import { aircraftTrackingTarget } from '../cockpitTracking.js';
|
||||
@@ -94,8 +93,7 @@ export class StyleManager extends ShellFacade {
|
||||
/**
|
||||
* @param {Cesium.Viewer} viewer - The CesiumJS viewer instance.
|
||||
* @param {object} [options] `engine`: the page's globe engine (the world
|
||||
* overlay host, camera navigation, HUD and share links run on it; defaults
|
||||
* to the one registered for the viewer).
|
||||
* overlay host, camera navigation, HUD and share links run on it).
|
||||
* @param {object} [options]
|
||||
* @param {boolean} [options.localePicker=true] - false removes the language
|
||||
* picker, for a host that does not initialize Core's locale.
|
||||
@@ -103,7 +101,7 @@ export class StyleManager extends ShellFacade {
|
||||
constructor(
|
||||
viewer,
|
||||
{
|
||||
engine = engineFromViewer(viewer),
|
||||
engine = null,
|
||||
mapStackController = null,
|
||||
placeSearch,
|
||||
services,
|
||||
@@ -635,6 +633,7 @@ export class StyleManager extends ShellFacade {
|
||||
|
||||
// Full-globe sun/moon ring on either engine, below the HUD/readout.
|
||||
this.celestialRing = new CelestialRing(viewer ?? engine, {
|
||||
engine,
|
||||
enabled: false,
|
||||
store: useCelestialRingStore(applicationPinia()),
|
||||
onAutoDisable: () =>
|
||||
@@ -716,7 +715,7 @@ export class StyleManager extends ShellFacade {
|
||||
|
||||
async _attachScene({
|
||||
viewer = null,
|
||||
engine = engineFromViewer(viewer),
|
||||
engine = null,
|
||||
mapStackController = null,
|
||||
services = {},
|
||||
engineSwitch = true,
|
||||
@@ -863,7 +862,7 @@ export class StyleManager extends ShellFacade {
|
||||
if (changed('cctvLayer')) this._initCctvPanel();
|
||||
if (changed('radioLayer', 'localAdsbLayer')) this._initRadioPanel();
|
||||
if (changed('streetLevelLayer')) this._initStreetLevelPanel();
|
||||
if (changed('wildlifeSightingsLayer')) this._initWildlifeSightingCard();
|
||||
this._initWildlifeSightingCard();
|
||||
if (
|
||||
changed(
|
||||
'radioLayer',
|
||||
@@ -1347,18 +1346,17 @@ export class StyleManager extends ShellFacade {
|
||||
return this._runExplicitNavigation('camera', () => focus(cameraId));
|
||||
}
|
||||
|
||||
/** Keep one compact card anchored to the selected wildlife sighting. */
|
||||
/** Keep one compact card anchored to the selected wildlife sighting. The
|
||||
* card follows the engine's canvas and camera, so each globe builds its own. */
|
||||
_initWildlifeSightingCard() {
|
||||
this._wildlifeSightingCard?.destroy();
|
||||
this._wildlifeSightingCard = null;
|
||||
const layer = this.services.wildlifeSightingsLayer;
|
||||
// The layer draws on Cesium only; another engine gets its stand-in and
|
||||
// no card (the card anchors to Cesium's canvas).
|
||||
if (typeof layer?.subscribeSelection !== 'function' || !this.viewer) return;
|
||||
if (typeof layer?.subscribeSelection !== 'function' || !this.engine) return;
|
||||
this._wildlifeSightingCard = createWildlifeSightingCard({
|
||||
layer,
|
||||
ui: this._ui,
|
||||
viewer: this.viewer,
|
||||
engine: this.engine,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
import * as geo from '../geo/index.js';
|
||||
import { isPickedWorldPosition } from '../data/scenePick.js';
|
||||
import { isGlobeEngine } from '../globe/contract.js';
|
||||
import { engineFromViewer } from '../globe/cesium/engineFromViewer.js';
|
||||
import { t } from '../i18n/index.js';
|
||||
|
||||
// The camera is the globe engine's, and so is the follow: the followed
|
||||
// entity is engine.camera.following().native (on Cesium also an entity the
|
||||
// app put on viewer.trackedEntity). The viewer, when there is one, is read
|
||||
// only for its clock, and for its tracked entity when the engine reports no
|
||||
// follow: callers pass an engine and that viewer, or a viewer whose engine
|
||||
// is registered (engineFromViewer).
|
||||
const engineOf = (target) => engineFromViewer(target);
|
||||
const trackerOf = (target, tracker) =>
|
||||
tracker ?? (target && !isGlobeEngine(target) ? target : null);
|
||||
// app put on viewer.trackedEntity). The viewer, when callers pass one, is
|
||||
// read only for its clock, and for its tracked entity when the engine
|
||||
// reports no follow.
|
||||
|
||||
// Cesium's EasingFunction.CUBIC_IN_OUT (tween.js Cubic.InOut).
|
||||
function cubicInOut(amount) {
|
||||
@@ -57,11 +51,9 @@ function normalizedHeading(heading) {
|
||||
|
||||
/**
|
||||
* Return the world position under the center of the canvas, when available.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | object} target The
|
||||
* globe engine, or a viewer registered for one.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | null} engine
|
||||
*/
|
||||
export function pickViewTarget(target) {
|
||||
const engine = engineOf(target);
|
||||
export function pickViewTarget(engine) {
|
||||
if (!engine) return null;
|
||||
const { width, height } = engine.host.size();
|
||||
if (!width || !height) return null;
|
||||
@@ -92,15 +84,12 @@ export function pickViewTarget(target) {
|
||||
|
||||
/**
|
||||
* Describe the camera as an orbit around the current viewport center.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | object} target The
|
||||
* globe engine, or a viewer registered for one.
|
||||
* @param {object} [tracker] The viewer whose tracked entity is the orbit
|
||||
* target (defaults to `target` when that is a viewer).
|
||||
* @param {import('../globe/contract.js').GlobeEngine | null} engine
|
||||
* @param {object | null} [viewer] The Cesium viewer whose tracked entity is
|
||||
* the orbit target.
|
||||
*/
|
||||
export function readCameraTargetFrame(target, tracker) {
|
||||
const engine = engineOf(target);
|
||||
export function readCameraTargetFrame(engine, viewer = null) {
|
||||
if (!engine) return null;
|
||||
const viewer = trackerOf(target, tracker);
|
||||
const entity = followedEntity(engine, viewer);
|
||||
const follow = engineFollow(engine, viewer);
|
||||
const center = entity
|
||||
@@ -137,15 +126,12 @@ export function readCameraTargetFrame(target, tracker) {
|
||||
|
||||
/**
|
||||
* Apply an orbit frame, then return the camera to the fixed-world frame.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | object} target The
|
||||
* globe engine, or a viewer registered for one.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | null} engine
|
||||
* @param {object} frame From {@link readCameraTargetFrame}.
|
||||
* @param {object} [tracker] As in readCameraTargetFrame.
|
||||
* @param {object | null} [viewer] As in readCameraTargetFrame.
|
||||
*/
|
||||
function setCameraTargetFrame(target, frame, tracker) {
|
||||
const engine = engineOf(target);
|
||||
function setCameraTargetFrame(engine, frame, viewer = null) {
|
||||
if (!engine || !frame?.target || !Number.isFinite(frame.range)) return false;
|
||||
const viewer = trackerOf(target, tracker);
|
||||
const { camera } = engine;
|
||||
// Inside an engine's own follow: the new frame is the follow's offset (a
|
||||
// camera command would end the follow; Cesium's tracked entity keeps its
|
||||
@@ -211,21 +197,21 @@ function frameIsTilted(frame) {
|
||||
}
|
||||
|
||||
/** Toggle between a straight-down map and a useful oblique map angle. */
|
||||
export function toggleCameraTilt(target, tracker) {
|
||||
const frame = readCameraTargetFrame(target, tracker);
|
||||
export function toggleCameraTilt(engine, viewer = null) {
|
||||
const frame = readCameraTargetFrame(engine, viewer);
|
||||
if (!frame) return false;
|
||||
const tilted = frameIsTilted(frame);
|
||||
const pitch = tilted ? STRAIGHT_DOWN_PITCH : OBLIQUE_PITCH;
|
||||
return setCameraTargetFrame(target, { ...frame, pitch }, tracker)
|
||||
return setCameraTargetFrame(engine, { ...frame, pitch }, viewer)
|
||||
? { tilted: !tilted, pitch }
|
||||
: false;
|
||||
}
|
||||
|
||||
/** Rotate around the viewport center until north is at the top. */
|
||||
export function resetCameraNorth(target, tracker) {
|
||||
const frame = readCameraTargetFrame(target, tracker);
|
||||
export function resetCameraNorth(engine, viewer = null) {
|
||||
const frame = readCameraTargetFrame(engine, viewer);
|
||||
if (!frame) return false;
|
||||
return setCameraTargetFrame(target, { ...frame, heading: 0 }, tracker);
|
||||
return setCameraTargetFrame(engine, { ...frame, heading: 0 }, viewer);
|
||||
}
|
||||
|
||||
function headingDegrees(engine) {
|
||||
@@ -234,17 +220,15 @@ function headingDegrees(engine) {
|
||||
|
||||
/**
|
||||
* Ease an orbit without handing off the entity that owns the follow camera.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | object} target The
|
||||
* globe engine, or a viewer registered for one.
|
||||
* @param {import('../globe/contract.js').GlobeEngine | null} engine
|
||||
* @param {{ now?: () => number, duration?: number, tracker?: object }} [options]
|
||||
* `tracker` as in readCameraTargetFrame.
|
||||
* `tracker`: the viewer, as in readCameraTargetFrame.
|
||||
*/
|
||||
export function createCameraOrientationAnimator(
|
||||
target,
|
||||
{ now = () => performance.now(), duration = 650, tracker } = {},
|
||||
engine,
|
||||
{ now = () => performance.now(), duration = 650, tracker = null } = {},
|
||||
) {
|
||||
const engine = engineOf(target);
|
||||
const viewer = trackerOf(target, tracker);
|
||||
const viewer = tracker;
|
||||
let remove = null;
|
||||
let pending = null;
|
||||
const cancel = () => {
|
||||
@@ -310,12 +294,11 @@ export function createCameraOrientationAnimator(
|
||||
* runNavigation: Function,
|
||||
* showToast?: Function,
|
||||
* animationMs?: number,
|
||||
* }} options `engine` defaults to the one registered for `viewer`; the viewer
|
||||
* is otherwise only read for its clock and tracked entity.
|
||||
* }} options The viewer is only read for its clock and tracked entity.
|
||||
*/
|
||||
export function bindCameraOrientationControls({
|
||||
viewer = null,
|
||||
engine = engineOf(viewer),
|
||||
engine = null,
|
||||
publish,
|
||||
runNavigation,
|
||||
showToast,
|
||||
|
||||
@@ -15,14 +15,13 @@ import { NavigationController } from './navigationController.js';
|
||||
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
|
||||
import * as geo from '../geo/index.js';
|
||||
import { createCesiumEngine } from '../globe/cesium/createCesiumEngine.js';
|
||||
import { registerViewerEngine } from '../globe/cesium/engineFromViewer.js';
|
||||
|
||||
// The controls run on the globe engine; these viewer doubles get the Cesium
|
||||
// engine registered for them, as the app's scene engine is. A Viewer's
|
||||
// canvas is its scene's.
|
||||
// The controls run on the globe engine; these viewer doubles carry the
|
||||
// Cesium engine built over them (`viewer.engine`), as the app's scene engine
|
||||
// is. A Viewer's canvas is its scene's.
|
||||
function withEngine(viewer) {
|
||||
viewer.canvas = viewer.scene.canvas;
|
||||
registerViewerEngine(viewer, createCesiumEngine(viewer));
|
||||
viewer.engine = createCesiumEngine(viewer);
|
||||
return viewer;
|
||||
}
|
||||
|
||||
@@ -178,7 +177,7 @@ test('a heading written into a real camera reads back as the same heading', () =
|
||||
);
|
||||
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
|
||||
|
||||
const frame = readCameraTargetFrame(viewer);
|
||||
const frame = readCameraTargetFrame(viewer.engine, viewer);
|
||||
assert.ok(frame, `no frame at ${headingDeg}/${pitchDeg}`);
|
||||
const readDeg = Cesium.Math.toDegrees(frame.heading);
|
||||
assert.ok(
|
||||
@@ -208,11 +207,11 @@ test('north-up really points a real camera north from every quadrant', () => {
|
||||
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
|
||||
|
||||
assert.equal(
|
||||
resetCameraNorth(viewer),
|
||||
resetCameraNorth(viewer.engine, viewer),
|
||||
true,
|
||||
`reset failed at ${headingDeg}`,
|
||||
);
|
||||
const after = readCameraTargetFrame(viewer);
|
||||
const after = readCameraTargetFrame(viewer.engine, viewer);
|
||||
assert.ok(after, `no frame after reset at ${headingDeg}`);
|
||||
const readDeg = Cesium.Math.toDegrees(after.heading);
|
||||
assert.ok(
|
||||
@@ -242,9 +241,9 @@ test('tilt moves a real camera between the two pitches and keeps target and rang
|
||||
);
|
||||
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
|
||||
|
||||
const first = toggleCameraTilt(viewer);
|
||||
const first = toggleCameraTilt(viewer.engine, viewer);
|
||||
assert.deepEqual(first, { tilted: true, pitch: OBLIQUE_PITCH });
|
||||
const tilted = readCameraTargetFrame(viewer);
|
||||
const tilted = readCameraTargetFrame(viewer.engine, viewer);
|
||||
assert.ok(Math.abs(tilted.pitch - OBLIQUE_PITCH) < 1e-6);
|
||||
assert.ok(Math.abs(tilted.range - 3000) < 1, `range ${tilted.range}`);
|
||||
assert.ok(
|
||||
@@ -276,9 +275,9 @@ test('tilt moves a real camera between the two pitches and keeps target and rang
|
||||
`camera points ${offBy.toFixed(2)} deg away from its target`,
|
||||
);
|
||||
|
||||
const second = toggleCameraTilt(viewer);
|
||||
const second = toggleCameraTilt(viewer.engine, viewer);
|
||||
assert.deepEqual(second, { tilted: false, pitch: STRAIGHT_DOWN_PITCH });
|
||||
const down = readCameraTargetFrame(viewer);
|
||||
const down = readCameraTargetFrame(viewer.engine, viewer);
|
||||
assert.ok(Math.abs(down.pitch - STRAIGHT_DOWN_PITCH) < 1e-6);
|
||||
assert.ok(Math.abs(down.range - 3000) < 1);
|
||||
});
|
||||
@@ -291,19 +290,19 @@ test('tilt alternates at globe range, not only at map range', () => {
|
||||
const { viewer } = createRealViewer(AUSTIN_GROUND);
|
||||
orbit(viewer, AUSTIN_GROUND, 0, STRAIGHT_DOWN_PITCH, range);
|
||||
|
||||
const first = toggleCameraTilt(viewer);
|
||||
const first = toggleCameraTilt(viewer.engine, viewer);
|
||||
assert.deepEqual(
|
||||
first,
|
||||
{ tilted: true, pitch: OBLIQUE_PITCH },
|
||||
`first click at ${range} m must tilt`,
|
||||
);
|
||||
const second = toggleCameraTilt(viewer);
|
||||
const second = toggleCameraTilt(viewer.engine, viewer);
|
||||
assert.deepEqual(
|
||||
second,
|
||||
{ tilted: false, pitch: STRAIGHT_DOWN_PITCH },
|
||||
`second click at ${range} m must level (camera pitch reads ${Cesium.Math.toDegrees(viewer.camera.pitch).toFixed(1)} deg)`,
|
||||
);
|
||||
const third = toggleCameraTilt(viewer);
|
||||
const third = toggleCameraTilt(viewer.engine, viewer);
|
||||
assert.deepEqual(
|
||||
third,
|
||||
{ tilted: true, pitch: OBLIQUE_PITCH },
|
||||
@@ -319,6 +318,7 @@ test('the button shows the state the next click will produce, at every range', (
|
||||
const bar = recorder();
|
||||
const controls = bindCameraOrientationControls({
|
||||
viewer,
|
||||
engine: viewer.engine,
|
||||
publish: bar.publish,
|
||||
runNavigation: (_noun, navigate) => navigate(),
|
||||
// No frame loop drives this fixture: apply each change at once.
|
||||
@@ -353,6 +353,7 @@ test('the needle follows a rotation too small for the camera-changed threshold',
|
||||
const bar = recorder();
|
||||
const controls = bindCameraOrientationControls({
|
||||
viewer,
|
||||
engine: viewer.engine,
|
||||
publish: bar.publish,
|
||||
runNavigation: (_noun, navigate) => navigate(),
|
||||
});
|
||||
@@ -383,6 +384,7 @@ test('north-up indicator follows real heading including the 360-degree seam', ()
|
||||
const bar = recorder();
|
||||
const controls = bindCameraOrientationControls({
|
||||
viewer,
|
||||
engine: viewer.engine,
|
||||
publish: bar.publish,
|
||||
runNavigation: (_noun, navigate) => navigate(),
|
||||
});
|
||||
@@ -409,6 +411,7 @@ test('a settled camera publishes no change, and teardown releases every signal',
|
||||
const moveEndBefore = viewer.camera.moveEnd.numberOfListeners;
|
||||
const controls = bindCameraOrientationControls({
|
||||
viewer,
|
||||
engine: viewer.engine,
|
||||
publish: bar.publish,
|
||||
runNavigation: (_noun, navigate) => navigate(),
|
||||
});
|
||||
@@ -451,9 +454,9 @@ test('a sky-facing camera yields no frame and both actions decline', () => {
|
||||
camera.pickEllipsoid = () => undefined;
|
||||
const viewer = withEngine({ camera, scene });
|
||||
|
||||
assert.equal(readCameraTargetFrame(viewer), null);
|
||||
assert.equal(toggleCameraTilt(viewer), false);
|
||||
assert.equal(resetCameraNorth(viewer), false);
|
||||
assert.equal(readCameraTargetFrame(viewer.engine, viewer), null);
|
||||
assert.equal(toggleCameraTilt(viewer.engine, viewer), false);
|
||||
assert.equal(resetCameraNorth(viewer.engine, viewer), false);
|
||||
});
|
||||
|
||||
test('center picking prefers terrain over the ellipsoid and falls through an invalid depth hit', () => {
|
||||
@@ -464,14 +467,14 @@ test('center picking prefers terrain over the ellipsoid and falls through an inv
|
||||
viewer.scene.globe.pick = () => terrain;
|
||||
viewer.camera.pickEllipsoid = () => sea;
|
||||
sameXYZ(
|
||||
pickViewTarget(viewer),
|
||||
pickViewTarget(viewer.engine),
|
||||
terrain,
|
||||
'the rendered ground wins over sea level',
|
||||
);
|
||||
|
||||
viewer.scene.globe.pick = () => null;
|
||||
sameXYZ(
|
||||
pickViewTarget(viewer),
|
||||
pickViewTarget(viewer.engine),
|
||||
sea,
|
||||
'the ellipsoid still answers when nothing is under the cursor',
|
||||
);
|
||||
@@ -479,7 +482,7 @@ test('center picking prefers terrain over the ellipsoid and falls through an inv
|
||||
|
||||
test('target frame identifies a straight-down camera in local ENU space', () => {
|
||||
const { viewer } = createViewer();
|
||||
const frame = readCameraTargetFrame(viewer);
|
||||
const frame = readCameraTargetFrame(viewer.engine, viewer);
|
||||
assert.ok(frame);
|
||||
assert.ok(Math.abs(frame.pitch - Cesium.Math.toRadians(-90)) < 0.001);
|
||||
assert.ok(frame.range > 999 && frame.range < 1_001);
|
||||
@@ -488,8 +491,8 @@ test('target frame identifies a straight-down camera in local ENU space', () =>
|
||||
|
||||
test('tilt preserves the picked target and range while choosing oblique pitch', () => {
|
||||
const { viewer, calls, target } = createViewer();
|
||||
const before = readCameraTargetFrame(viewer);
|
||||
const result = toggleCameraTilt(viewer);
|
||||
const before = readCameraTargetFrame(viewer.engine, viewer);
|
||||
const result = toggleCameraTilt(viewer.engine, viewer);
|
||||
const lookAt = calls.find((call) => call.type === 'lookAt');
|
||||
assert.deepEqual(result, { tilted: true, pitch: OBLIQUE_PITCH });
|
||||
sameXYZ(lookAt.target, target);
|
||||
@@ -501,8 +504,8 @@ test('tilt preserves the picked target and range while choosing oblique pitch',
|
||||
|
||||
test('north-up preserves target pitch and range', () => {
|
||||
const { viewer, calls } = createViewer();
|
||||
const before = readCameraTargetFrame(viewer);
|
||||
assert.equal(resetCameraNorth(viewer), true);
|
||||
const before = readCameraTargetFrame(viewer.engine, viewer);
|
||||
assert.equal(resetCameraNorth(viewer.engine, viewer), true);
|
||||
const lookAt = calls.find((call) => call.type === 'lookAt');
|
||||
assert.equal(lookAt.offset.heading, 0);
|
||||
assert.equal(lookAt.offset.pitch, before.pitch);
|
||||
@@ -516,6 +519,7 @@ test('bindings route both controls and release every listener on destroy', () =>
|
||||
const toasts = [];
|
||||
const controls = bindCameraOrientationControls({
|
||||
viewer,
|
||||
engine: viewer.engine,
|
||||
publish: bar.publish,
|
||||
runNavigation(noun, navigate) {
|
||||
navigations.push(noun);
|
||||
@@ -574,12 +578,13 @@ for (const [label, altitude, range] of [
|
||||
),
|
||||
);
|
||||
let time = 0;
|
||||
const animator = createCameraOrientationAnimator(viewer, {
|
||||
const animator = createCameraOrientationAnimator(viewer.engine, {
|
||||
tracker: viewer,
|
||||
now: () => time,
|
||||
duration: 1000,
|
||||
});
|
||||
for (const pitch of [STRAIGHT_DOWN_PITCH, OBLIQUE_PITCH]) {
|
||||
const frame = readCameraTargetFrame(viewer);
|
||||
const frame = readCameraTargetFrame(viewer.engine, viewer);
|
||||
animator.animate(frame, { heading: 0, pitch });
|
||||
for (const step of [0, 100, 500, 900, 1000]) {
|
||||
time = (pitch === STRAIGHT_DOWN_PITCH ? 0 : 1000) + step;
|
||||
@@ -599,7 +604,7 @@ for (const [label, altitude, range] of [
|
||||
1e-8,
|
||||
),
|
||||
);
|
||||
const actual = readCameraTargetFrame(viewer);
|
||||
const actual = readCameraTargetFrame(viewer.engine, viewer);
|
||||
const eased = Cesium.EasingFunction.CUBIC_IN_OUT(step / 1000);
|
||||
assert.ok(
|
||||
Math.abs(actual.pitch - Cesium.Math.lerp(frame.pitch, pitch, eased)) <
|
||||
@@ -612,15 +617,20 @@ for (const [label, altitude, range] of [
|
||||
target = Cesium.Cartesian3.fromDegrees(-96, 31, altitude);
|
||||
follow.update(viewer.clock.currentTime);
|
||||
assert.equal(viewer.trackedEntity, entity);
|
||||
assert.ok(Math.abs(readCameraTargetFrame(viewer).range - range) < 1e-5);
|
||||
assert.ok(
|
||||
Math.abs(readCameraTargetFrame(viewer.engine, viewer).range - range) <
|
||||
1e-5,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
test('orientation animation cancels on replacement and explicit cancellation', () => {
|
||||
const { viewer } = createRealViewer(Cesium.Cartesian3.fromDegrees(0, 0));
|
||||
orbit(viewer, Cesium.Cartesian3.fromDegrees(0, 0), 90, OBLIQUE_PITCH, 1000);
|
||||
const animator = createCameraOrientationAnimator(viewer);
|
||||
const frame = readCameraTargetFrame(viewer);
|
||||
const animator = createCameraOrientationAnimator(viewer.engine, {
|
||||
tracker: viewer,
|
||||
});
|
||||
const frame = readCameraTargetFrame(viewer.engine, viewer);
|
||||
animator.animate(frame, { heading: 0, pitch: STRAIGHT_DOWN_PITCH });
|
||||
animator.animate(frame, { heading: 0, pitch: OBLIQUE_PITCH });
|
||||
assert.equal(viewer.scene.preUpdate.numberOfListeners, 1);
|
||||
@@ -704,6 +714,7 @@ test('rapid tilt presses reverse direction and north-up keeps the requested tilt
|
||||
let controls;
|
||||
controls = bindCameraOrientationControls({
|
||||
viewer,
|
||||
engine: viewer.engine,
|
||||
publish: bar.publish,
|
||||
runNavigation: (_noun, navigate) => {
|
||||
controls.cancel();
|
||||
@@ -718,7 +729,7 @@ test('rapid tilt presses reverse direction and north-up keeps the requested tilt
|
||||
assert.equal(viewer.scene.preUpdate.numberOfListeners, 1);
|
||||
time = 650;
|
||||
viewer.scene.preUpdate.raiseEvent();
|
||||
const frame = readCameraTargetFrame(viewer);
|
||||
const frame = readCameraTargetFrame(viewer.engine, viewer);
|
||||
assert.ok(Math.abs(frame.pitch - STRAIGHT_DOWN_PITCH) < 1e-6);
|
||||
assert.ok(Math.abs(frame.heading) < 1e-6);
|
||||
controls.destroy();
|
||||
|
||||
@@ -33,7 +33,7 @@ export function update() {
|
||||
// Entry availability changes on a human timescale (tracking start/stop,
|
||||
// info arriving after a poll) — polling it every rendered frame ran
|
||||
// readAircraftInfo() + DOM pokes at display rate in plain map mode.
|
||||
// 250 ms keeps the chip imperceptibly fresh; trackedEntityChanged still
|
||||
// 250 ms keeps the chip imperceptibly fresh; the follow change still
|
||||
// fires syncEntry immediately on the events that matter. (perf item 9)
|
||||
const nowMs = performance.now();
|
||||
if (nowMs - (this._lastEntrySyncMs || 0) >= 250) {
|
||||
|
||||
@@ -74,11 +74,17 @@ import * as geo from '../geo/index.js';
|
||||
import { cockpitHost } from './cockpitHost.js';
|
||||
|
||||
export class CockpitViewController {
|
||||
/**
|
||||
* @param {import('../globe/contract.js').GlobeEngine} engine The scene's
|
||||
* globe engine: its camera, frames, input and follow (cockpitHost.js).
|
||||
* @param {object} options `viewer`: Cesium's Viewer on the Cesium engine,
|
||||
* whose stock double-click the Cockpit's goes ahead of.
|
||||
*/
|
||||
constructor(
|
||||
viewer,
|
||||
engine,
|
||||
{
|
||||
services,
|
||||
engine = null,
|
||||
viewer = null,
|
||||
onVisionChange = null,
|
||||
getInitialVisionMode = null,
|
||||
onCameraTakeover = null,
|
||||
@@ -87,11 +93,10 @@ export class CockpitViewController {
|
||||
onEntered = null,
|
||||
onExited = null,
|
||||
onRide = null,
|
||||
restoreTrackingFrame = null,
|
||||
publish = {},
|
||||
} = {},
|
||||
) {
|
||||
this.host = cockpitHost(viewer, engine);
|
||||
this.host = cockpitHost(engine, { viewer });
|
||||
this.services = services;
|
||||
this.destroyed = false;
|
||||
this.disposed = false;
|
||||
@@ -127,10 +132,6 @@ export class CockpitViewController {
|
||||
this.onEntered = onEntered;
|
||||
this.onExited = onExited;
|
||||
this.onRide = onRide;
|
||||
this.restoreTrackingFrame =
|
||||
typeof restoreTrackingFrame === 'function'
|
||||
? restoreTrackingFrame
|
||||
: () => false;
|
||||
this.isEntryAllowed =
|
||||
typeof isEntryAllowed === 'function' ? isEntryAllowed : () => true;
|
||||
this.isUtilityDisclosureOpen =
|
||||
|
||||
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import { CockpitViewController } from './cockpitController.js';
|
||||
import { COCKPIT_MIN_GROUND_CLEARANCE_M } from './cockpitPresentation.js';
|
||||
import * as geo from '../geo/index.js';
|
||||
import { createCockpitEngine } from '../testSupport/cockpitEngine.mjs';
|
||||
|
||||
function environment() {
|
||||
const original = { document: globalThis.document, window: globalThis.window };
|
||||
@@ -14,25 +15,18 @@ function environment() {
|
||||
const window = Object.assign(new EventTarget(), { clearTimeout, setTimeout });
|
||||
globalThis.document = document;
|
||||
globalThis.window = window;
|
||||
const callbacks = new Set();
|
||||
const event = {
|
||||
addEventListener(fn) {
|
||||
callbacks.add(fn);
|
||||
return () => callbacks.delete(fn);
|
||||
},
|
||||
};
|
||||
const viewer = {
|
||||
scene: {
|
||||
preUpdate: event,
|
||||
screenSpaceCameraController: { enableInputs: false },
|
||||
},
|
||||
trackedEntityChanged: event,
|
||||
entities: { contains: () => false },
|
||||
};
|
||||
const cockpit = createCockpitEngine();
|
||||
const { engine } = cockpit;
|
||||
// The Cockpit's frame and follow subscriptions.
|
||||
const subscriptions = () =>
|
||||
engine.frames.preUpdate.numberOfListeners +
|
||||
engine.camera.followChanged.numberOfListeners;
|
||||
return {
|
||||
viewer,
|
||||
callbacks,
|
||||
engine,
|
||||
cockpit,
|
||||
subscriptions,
|
||||
restore() {
|
||||
engine.destroy();
|
||||
Object.assign(globalThis, original);
|
||||
},
|
||||
};
|
||||
@@ -41,11 +35,20 @@ function environment() {
|
||||
test('Cockpit subscriptions are released once and retained actions cannot restart it', () => {
|
||||
const env = environment();
|
||||
try {
|
||||
const owner = new CockpitViewController(env.viewer, { services: {} });
|
||||
assert.equal(env.callbacks.size, 2);
|
||||
const before = env.subscriptions();
|
||||
const owner = new CockpitViewController(env.engine, { services: {} });
|
||||
assert.equal(env.subscriptions(), before + 2);
|
||||
let doubleClicks = 0;
|
||||
owner.onSceneDoubleClick = () => {
|
||||
doubleClicks++;
|
||||
};
|
||||
env.engine.fake.input('doubleClick', { position: { x: 1, y: 1 } });
|
||||
assert.equal(doubleClicks, 1);
|
||||
owner.dispose();
|
||||
owner.dispose();
|
||||
assert.equal(env.callbacks.size, 0);
|
||||
assert.equal(env.subscriptions(), before);
|
||||
env.engine.fake.input('doubleClick', { position: { x: 1, y: 1 } });
|
||||
assert.equal(doubleClicks, 1, 'the double-click route is released');
|
||||
assert.equal(owner.enter(), false);
|
||||
assert.equal(owner.navigateContext(1), false);
|
||||
assert.equal(owner.toggleTrackedTr3b(), false);
|
||||
@@ -60,18 +63,19 @@ test('disposing an active Cockpit releases the supplied render owner without ret
|
||||
const env = environment();
|
||||
try {
|
||||
const released = [];
|
||||
const owner = new CockpitViewController(env.viewer, {
|
||||
const owner = new CockpitViewController(env.engine, {
|
||||
services: { releaseContinuousRender: (reason) => released.push(reason) },
|
||||
});
|
||||
owner.active = true;
|
||||
const ridden = env.cockpit.aircraft();
|
||||
env.engine.input.setCameraInputs(false);
|
||||
ridden.show = false;
|
||||
Object.assign(owner, { active: true, trackedEntity: ridden });
|
||||
owner.dispose();
|
||||
owner.dispose();
|
||||
assert.deepEqual(released, ['cockpit']);
|
||||
assert.equal(
|
||||
env.viewer.scene.screenSpaceCameraController.enableInputs,
|
||||
true,
|
||||
);
|
||||
assert.equal(env.viewer.trackedEntity, undefined);
|
||||
assert.equal(env.engine.fake.cameraInputsEnabled, true);
|
||||
assert.equal(ridden.show, true, 'the ridden glyph is shown again');
|
||||
assert.equal(env.engine.camera.following(), null, 'and not followed');
|
||||
assert.equal(owner.active, false);
|
||||
} finally {
|
||||
env.restore();
|
||||
@@ -91,15 +95,17 @@ test('aircraft identity is read from the supplied layer instances', () => {
|
||||
layerId: 'military',
|
||||
callsign: 'MILITARY',
|
||||
};
|
||||
const owner = new CockpitViewController(env.viewer, {
|
||||
const owner = new CockpitViewController(env.engine, {
|
||||
services: {
|
||||
flightsLayer: { getTrackedInfo: () => civilian },
|
||||
militaryFlightsLayer: { getTrackedInfo: () => military },
|
||||
// A follow change syncs the entry and its TR-3B chip.
|
||||
isTr3b: () => false,
|
||||
},
|
||||
});
|
||||
env.viewer.trackedEntity = { gevTrackedId: 'military:def456' };
|
||||
env.cockpit.ride(env.cockpit.aircraft({ gevTrackedId: 'military:def456' }));
|
||||
assert.deepEqual(owner.readAircraftInfo(), military);
|
||||
env.viewer.trackedEntity = { gevTrackedId: 'flights:abc123' };
|
||||
env.cockpit.ride(env.cockpit.aircraft({ gevTrackedId: 'flights:abc123' }));
|
||||
assert.deepEqual(owner.readAircraftInfo(), civilian);
|
||||
owner.dispose();
|
||||
} finally {
|
||||
@@ -112,7 +118,7 @@ test('an obsolete regional briefing cannot publish after Cockpit disposal', asyn
|
||||
try {
|
||||
let finish;
|
||||
let signal;
|
||||
const owner = new CockpitViewController(env.viewer, {
|
||||
const owner = new CockpitViewController(env.engine, {
|
||||
services: {
|
||||
regionalDistanceM: () => Infinity,
|
||||
fetchRegionalBrief: (_lat, _lon, options) => {
|
||||
@@ -148,14 +154,15 @@ test('stopping Cockpit revokes camera actions before deferred disposal releases
|
||||
const env = environment();
|
||||
try {
|
||||
const released = [];
|
||||
const owner = new CockpitViewController(env.viewer, {
|
||||
const before = env.subscriptions();
|
||||
const owner = new CockpitViewController(env.engine, {
|
||||
services: {
|
||||
releaseContinuousRender: (reason) => released.push(reason),
|
||||
},
|
||||
});
|
||||
owner.active = true;
|
||||
owner.stop();
|
||||
assert.equal(env.callbacks.size, 0);
|
||||
assert.equal(env.subscriptions(), before);
|
||||
assert.equal(owner.update(), false);
|
||||
assert.equal(owner.navigateContext(1), false);
|
||||
assert.deepEqual(released, []);
|
||||
@@ -174,13 +181,12 @@ test('stopped Cockpit cannot rearm briefing rotation or request a fresh region',
|
||||
let next = 0;
|
||||
let fetches = 0;
|
||||
let paints = 0;
|
||||
env.viewer.scene.screenSpaceCameraController.enableInputs = true;
|
||||
window.setTimeout = (callback) => {
|
||||
frames.set(++next, callback);
|
||||
return next;
|
||||
};
|
||||
window.clearTimeout = (id) => frames.delete(id);
|
||||
const owner = new CockpitViewController(env.viewer, {
|
||||
const owner = new CockpitViewController(env.engine, {
|
||||
services: {
|
||||
regionalDistanceM: () => Infinity,
|
||||
fetchRegionalBrief: () => {
|
||||
@@ -223,7 +229,7 @@ test('the weather toggle flips from its own state, however fast it is pressed',
|
||||
requested.push(event.detail.enabled),
|
||||
);
|
||||
const published = [];
|
||||
const owner = new CockpitViewController(env.viewer, {
|
||||
const owner = new CockpitViewController(env.engine, {
|
||||
services: {},
|
||||
publish: { context: (view) => published.push(view.weather) },
|
||||
});
|
||||
@@ -261,23 +267,9 @@ test('the cockpit eye stays above the engine surface when the aircraft reads bel
|
||||
place.latitude,
|
||||
107,
|
||||
);
|
||||
const views = [];
|
||||
Object.assign(env.viewer, {
|
||||
clock: { currentTime: 0 },
|
||||
camera: {
|
||||
setView: ({ destination }) =>
|
||||
views.push(geo.cartographic.fromCartesian(destination).height),
|
||||
positionCartographic: { ...place, height: 130 },
|
||||
},
|
||||
entities: { contains: () => true },
|
||||
});
|
||||
env.viewer.scene.globe = { getHeight: () => SURFACE_M };
|
||||
const entity = {
|
||||
position: {
|
||||
getValue: (time, result) => geo.cartesian3.clone(aircraft, result),
|
||||
},
|
||||
};
|
||||
const owner = new CockpitViewController(env.viewer, {
|
||||
env.engine.fake.script('terrainHeight', SURFACE_M);
|
||||
const entity = env.cockpit.aircraft({ position: aircraft });
|
||||
const owner = new CockpitViewController(env.engine, {
|
||||
services: {
|
||||
cachedGroundFloor: () => undefined,
|
||||
GROUND_FLOOR_LIFT_M: 1.5,
|
||||
@@ -297,6 +289,12 @@ test('the cockpit eye stays above the engine surface when the aircraft reads bel
|
||||
updateHud() {},
|
||||
});
|
||||
owner.update();
|
||||
const views = env.engine.fake
|
||||
.callsOf('camera.setView')
|
||||
.map(
|
||||
({ args: [{ destination }] }) =>
|
||||
geo.cartographic.fromCartesian(destination).height,
|
||||
);
|
||||
assert.equal(views.length, 1);
|
||||
assert.ok(
|
||||
views[0] >= SURFACE_M + COCKPIT_MIN_GROUND_CLEARANCE_M - 1e-6,
|
||||
|
||||
@@ -40,12 +40,14 @@ export class CockpitCoordinator {
|
||||
operations,
|
||||
);
|
||||
this._cockpitDisplayPortal = null;
|
||||
// The Cockpit rides the engine's follow; a shell with no globe yet has
|
||||
// none.
|
||||
this.cockpitView =
|
||||
viewer || (engine?.frames?.preUpdate && engine?.camera?.followChanged)
|
||||
? this._createCockpitView(viewer, services)
|
||||
engine?.frames?.preUpdate && engine?.camera?.followChanged
|
||||
? this._createCockpitView(services)
|
||||
: null;
|
||||
}
|
||||
_createCockpitView(viewer, services) {
|
||||
_createCockpitView(services) {
|
||||
const {
|
||||
flightsLayer,
|
||||
militaryFlightsLayer,
|
||||
@@ -64,8 +66,9 @@ export class CockpitCoordinator {
|
||||
regionalDistanceM,
|
||||
weatherCodeLabel,
|
||||
} = services;
|
||||
return new CockpitViewController(viewer, {
|
||||
engine: this.engine,
|
||||
return new CockpitViewController(this.engine, {
|
||||
// Cesium's stock double-click goes after the Cockpit's.
|
||||
viewer: this.viewer,
|
||||
services: {
|
||||
flightsLayer,
|
||||
militaryFlightsLayer,
|
||||
@@ -107,18 +110,6 @@ export class CockpitCoordinator {
|
||||
onEntered: () => this.enterPanels(),
|
||||
onExited: () => this.exitPanels(),
|
||||
onRide: (layerId) => this._adoptRiddenLayer(layerId),
|
||||
restoreTrackingFrame: (entity) => {
|
||||
const [layerId, ...idParts] = String(entity?.gevTrackedId || '').split(
|
||||
':',
|
||||
);
|
||||
const trackedId = idParts.join(':');
|
||||
if (!trackedId) return false;
|
||||
if (layerId === 'flights')
|
||||
return flightsLayer.refocusTrackedById?.(trackedId) === true;
|
||||
if (layerId === 'military')
|
||||
return militaryFlightsLayer.refocusTrackedById?.(trackedId) === true;
|
||||
return false;
|
||||
},
|
||||
});
|
||||
}
|
||||
get _dataManager() {
|
||||
@@ -178,10 +169,10 @@ export class CockpitCoordinator {
|
||||
const active = Boolean(this.cockpitView?.active);
|
||||
const gateOpen = Boolean(this.cockpitView?.isEntryAllowed?.());
|
||||
// "Could Cockpit be ENTERED right now" — so it is false while already
|
||||
// inside, unconditionally. Cockpit takes the entity off
|
||||
// `viewer.trackedEntity` on entry and NEXT puts one back, which made this
|
||||
// flip true/false between calls while `active` stayed true; readers
|
||||
// (including the voice model) read that as a broken half-entered state.
|
||||
// inside, unconditionally. Cockpit releases the engine's follow on entry
|
||||
// and NEXT starts another, which made this flip true/false between
|
||||
// calls while `active` stayed true; readers (including the voice model)
|
||||
// read that as a broken half-entered state.
|
||||
const entryAllowed =
|
||||
!active && Boolean(gateOpen && info && this.cockpitView?.host.current());
|
||||
// Entry needs only the ridden aircraft's own layer: with one tracked,
|
||||
|
||||
@@ -11,6 +11,7 @@ import { createApp, defineComponent, h, nextTick } from 'vue';
|
||||
import { DataLayerManager } from '../data/manager.js';
|
||||
import { createDependencies } from '../layers/awareness/dependencies.js';
|
||||
import { CockpitCoordinator } from './cockpitCoordinator.js';
|
||||
import { createCockpitEngine } from '../testSupport/cockpitEngine.mjs';
|
||||
import { ContextControls } from './contextControls.js';
|
||||
import { _handleContextLayerChange } from './contextLayerChanges.js';
|
||||
import { useCockpitStore } from './stores/cockpit.js';
|
||||
@@ -60,29 +61,17 @@ function fixture(
|
||||
tracked?.layerId === layerId && dataManager.isEnabled(layerId)
|
||||
? tracked.info
|
||||
: null;
|
||||
const entityFor = (subject) => ({
|
||||
position: { getValue: () => null },
|
||||
show: true,
|
||||
gevTrackedId: subject ? `${subject.layerId}:${subject.info.icao24}` : '',
|
||||
});
|
||||
const entities = new Set();
|
||||
const entity = entityFor(tracked);
|
||||
entities.add(entity);
|
||||
const listeners = () => ({ addEventListener: () => () => {} });
|
||||
const viewer = {
|
||||
trackedEntity: tracked ? entity : undefined,
|
||||
clock: { currentTime: null },
|
||||
camera: { cancelFlight() {}, frustum: { fov: 1, aspectRatio: 1 } },
|
||||
entities: { contains: (candidate) => entities.has(candidate) },
|
||||
scene: {
|
||||
preUpdate: listeners(),
|
||||
screenSpaceCameraController: { enableInputs: true },
|
||||
},
|
||||
trackedEntityChanged: listeners(),
|
||||
};
|
||||
// The tracked aircraft is the engine follow's glyph, as its layer draws it.
|
||||
const globe = createCockpitEngine();
|
||||
const { engine } = globe;
|
||||
const aircraftFor = (subject) =>
|
||||
globe.aircraft({
|
||||
gevTrackedId: `${subject.layerId}:${subject.info.icao24}`,
|
||||
});
|
||||
if (tracked) globe.ride(aircraftFor(tracked));
|
||||
const context = { mode: contextMode, changing };
|
||||
const coordinator = new CockpitCoordinator({
|
||||
viewer,
|
||||
engine,
|
||||
services: {
|
||||
flightsLayer: { getTrackedInfo: trackedFrom('flights') },
|
||||
militaryFlightsLayer: { getTrackedInfo: trackedFrom('military') },
|
||||
@@ -119,6 +108,7 @@ function fixture(
|
||||
});
|
||||
t.after(() => {
|
||||
coordinator.stop();
|
||||
engine.destroy();
|
||||
app.unmount();
|
||||
document.body.classList.remove('cockpit-mode');
|
||||
});
|
||||
@@ -141,8 +131,7 @@ function fixture(
|
||||
/** Track another aircraft, as Contacts navigation does mid-session. */
|
||||
const retrack = (subject) => {
|
||||
tracked = subject;
|
||||
viewer.trackedEntity = entityFor(subject);
|
||||
entities.add(viewer.trackedEntity);
|
||||
return globe.ride(aircraftFor(subject));
|
||||
};
|
||||
const $ = (selector) => document.querySelector(selector);
|
||||
return { $, coordinator, cockpit, store, layers, disable, retrack, pinia };
|
||||
@@ -429,8 +418,10 @@ test('a ride handed to an aircraft on a layer Contacts turned on keeps that laye
|
||||
await settle();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
// NEXT hands the view to a military aircraft; Contacts turned its layer on.
|
||||
retrack({ layerId: 'military', info: MILITARY });
|
||||
assert.equal(cockpit._adoptTrackedEntity(performance.now()), true);
|
||||
// The Cockpit adopts it when the engine's follow changes to it.
|
||||
const military = retrack({ layerId: 'military', info: MILITARY });
|
||||
assert.equal(cockpit.trackedEntity, military);
|
||||
assert.equal(military.show, false, 'the new ride is not drawn either');
|
||||
assert.equal(cockpit.readSubjectLayerId(), 'military');
|
||||
await manager.setEnabled('ais-live-vessels', false, { origin: 'user' });
|
||||
await settle();
|
||||
|
||||
+13
-33
@@ -1,36 +1,15 @@
|
||||
// Camera and aircraft ownership used by the shared first-person controller.
|
||||
// Camera and aircraft ownership used by the shared first-person controller,
|
||||
// on the globe contract: the ridden aircraft is the engine follow's target,
|
||||
// the aircraft display's tracked glyph handle.
|
||||
import { routeViewerDoubleClick } from '../globe/cesium/doubleClick.js';
|
||||
|
||||
export function cockpitHost(viewer, engine) {
|
||||
if (viewer) {
|
||||
return {
|
||||
preUpdate: viewer.scene.preUpdate,
|
||||
followChanged: viewer.trackedEntityChanged,
|
||||
followed: () => viewer.trackedEntity,
|
||||
current: () =>
|
||||
viewer.trackedEntity?.position ? viewer.trackedEntity : null,
|
||||
contains: (entity) => viewer.entities.contains(entity),
|
||||
position: (entity, result) =>
|
||||
entity.position.getValue(viewer.clock.currentTime, result),
|
||||
release: () => {
|
||||
viewer.trackedEntity = undefined;
|
||||
},
|
||||
restore: (entity, refocus) => {
|
||||
viewer.trackedEntity = entity;
|
||||
refocus(entity);
|
||||
},
|
||||
camera: viewer.camera,
|
||||
cartographic: () => viewer.camera.positionCartographic,
|
||||
terrainHeight: (place) => viewer.scene.globe?.getHeight(place),
|
||||
surface: viewer.scene,
|
||||
inputs: (enabled) => {
|
||||
viewer.scene.screenSpaceCameraController.enableInputs = enabled;
|
||||
},
|
||||
canvasPosition: (world) =>
|
||||
viewer.scene.cartesianToCanvasCoordinates(world) ?? null,
|
||||
routeDoubleClick: (handle) => routeViewerDoubleClick(viewer, handle),
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @param {import('../globe/contract.js').GlobeEngine} engine
|
||||
* @param {{ viewer?: object|null }} [options] `viewer`: Cesium's Viewer when
|
||||
* the engine is Cesium. Its stock double-click would drop the follow, so
|
||||
* the Cockpit's goes first; Navara has none to route around.
|
||||
*/
|
||||
export function cockpitHost(engine, { viewer = null } = {}) {
|
||||
const aircraft = () => {
|
||||
const target = engine.camera.following()?.native;
|
||||
return target?.resumeAircraftFollow ? target : null;
|
||||
@@ -50,8 +29,9 @@ export function cockpitHost(viewer, engine) {
|
||||
surface: engine,
|
||||
inputs: (enabled) => engine.input.setCameraInputs(enabled),
|
||||
canvasPosition: (world) => engine.projector.worldToWindow(world) ?? null,
|
||||
// Navara has no stock double-click to route around.
|
||||
routeDoubleClick: (handle) =>
|
||||
engine.input.on('doubleClick', (event) => handle(event.position)),
|
||||
viewer
|
||||
? routeViewerDoubleClick(viewer, handle)
|
||||
: engine.input.on('doubleClick', (event) => handle(event.position)),
|
||||
};
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import assert from 'node:assert/strict';
|
||||
import { createPinia } from 'pinia';
|
||||
import { createApp, defineComponent, h, nextTick } from 'vue';
|
||||
import { CockpitViewController } from './cockpitController.js';
|
||||
import { createCockpitEngine } from '../testSupport/cockpitEngine.mjs';
|
||||
import { useCockpitStore } from './stores/cockpit.js';
|
||||
import CockpitView from './views/CockpitView.vue';
|
||||
import ContextView from './views/ContextView.vue';
|
||||
@@ -39,19 +40,10 @@ function fixture(t) {
|
||||
};
|
||||
}
|
||||
const converted = new Set();
|
||||
const listeners = () => ({ addEventListener: () => () => {} });
|
||||
const entity = { position: {}, show: true };
|
||||
const viewer = {
|
||||
trackedEntity: entity,
|
||||
camera: { cancelFlight() {} },
|
||||
entities: { contains: (candidate) => candidate === entity },
|
||||
scene: {
|
||||
preUpdate: listeners(),
|
||||
screenSpaceCameraController: { enableInputs: true },
|
||||
},
|
||||
trackedEntityChanged: listeners(),
|
||||
};
|
||||
const cockpit = new CockpitViewController(viewer, {
|
||||
const globe = createCockpitEngine();
|
||||
const { engine } = globe;
|
||||
const aircraft = globe.ride(globe.aircraft());
|
||||
const cockpit = new CockpitViewController(engine, {
|
||||
services: {
|
||||
flightsLayer: { getTrackedInfo: () => INFO, refreshTr3b() {} },
|
||||
militaryFlightsLayer: { getTrackedInfo: () => null },
|
||||
@@ -79,11 +71,12 @@ function fixture(t) {
|
||||
});
|
||||
t.after(() => {
|
||||
cockpit.stop();
|
||||
engine.destroy();
|
||||
app.unmount();
|
||||
document.body.classList.remove('cockpit-mode');
|
||||
});
|
||||
const $ = (selector) => document.querySelector(selector);
|
||||
return { $, cockpit, store, converted, hiddenFocus };
|
||||
return { $, cockpit, store, converted, hiddenFocus, globe, aircraft };
|
||||
}
|
||||
|
||||
const shown = ($) => ({
|
||||
@@ -135,7 +128,7 @@ test('a tracked aircraft shows the entry and a TR-3B chip that names its action'
|
||||
});
|
||||
|
||||
test('entering shows the HUD and focuses the exit once it renders; exiting returns focus to the entry', async (t) => {
|
||||
const { $, cockpit } = fixture(t);
|
||||
const { $, cockpit, globe, aircraft } = fixture(t);
|
||||
cockpit.syncEntry();
|
||||
await nextTick();
|
||||
const entry = $('#cockpit-entry');
|
||||
@@ -155,9 +148,17 @@ test('entering shows the HUD and focuses the exit once it renders; exiting retur
|
||||
const hud = $('#cockpit-hud');
|
||||
assert.equal(hud.classList.contains('signals-active'), true);
|
||||
assert.equal(document.activeElement?.id, 'map-view-switch');
|
||||
// First person: the ridden aircraft's glyph is not drawn, the engine's
|
||||
// follow and camera inputs are the Cockpit's.
|
||||
assert.equal(aircraft.show, false);
|
||||
assert.equal(globe.following(), null);
|
||||
assert.equal(globe.engine.fake.cameraInputsEnabled, false);
|
||||
|
||||
$('#map-view-switch').click();
|
||||
assert.equal(cockpit.active, false);
|
||||
assert.equal(aircraft.show, true);
|
||||
assert.equal(globe.following(), aircraft, 'the follow resumes');
|
||||
assert.equal(globe.engine.fake.cameraInputsEnabled, true);
|
||||
await nextTick();
|
||||
await Promise.resolve();
|
||||
assert.deepEqual(shown($), {
|
||||
|
||||
@@ -7,8 +7,9 @@ import {
|
||||
} from '../cockpitMath.js';
|
||||
|
||||
export function readAircraftInfo() {
|
||||
// In cockpit mode the controller takes the entity off `viewer.trackedEntity`
|
||||
// (see update()), so the cockpit's own handle is the tracked identity there.
|
||||
// In cockpit mode the controller releases the engine's follow of the
|
||||
// aircraft (see enter()), so the cockpit's own handle is the tracked
|
||||
// identity there.
|
||||
const trackedEntity = this.host.followed() || this.trackedEntity;
|
||||
return resolveTrackedAircraftInfo({
|
||||
civilian: this.services.flightsLayer.getTrackedInfo?.() || null,
|
||||
@@ -32,13 +33,11 @@ export function readSubjectLayerId() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The subject entry would take: a Cesium-tracked aircraft.
|
||||
* The subject entry would take: the aircraft the engine follows.
|
||||
* @returns {'aircraft'|null}
|
||||
*/
|
||||
export function resolveEntryKind() {
|
||||
return this.readAircraftInfo() && this.viewer.trackedEntity?.position
|
||||
? 'aircraft'
|
||||
: null;
|
||||
return this.readAircraftInfo() && this.host.current() ? 'aircraft' : null;
|
||||
}
|
||||
|
||||
export function dispatchCockpitModeChanged(active, info = null) {
|
||||
@@ -265,7 +264,7 @@ export function exit({ restoreTracking = true } = {}) {
|
||||
this.trackedEntityWasShown = true;
|
||||
this.dispatchCockpitModeChanged(false);
|
||||
if (restoreTracking && entity && this.host.contains(entity)) {
|
||||
this.host.restore(entity, this.restoreTrackingFrame);
|
||||
this.host.restore(entity);
|
||||
}
|
||||
this.syncEntry();
|
||||
// Back to whichever entry was used: the Contacts button or the readout's.
|
||||
|
||||
@@ -76,7 +76,7 @@ export class LayerBindings {
|
||||
routeWorldFocusRequest(
|
||||
event,
|
||||
(detail, fly) => this._runExplicitWorldFocus(detail, fly),
|
||||
(detail) => flyToWorldTarget(this.engine ?? this.viewer, detail),
|
||||
(detail) => flyToWorldTarget(this.engine, detail),
|
||||
);
|
||||
this._removeWorldRequestFocusListener = registerWorldFocusRequestListener(
|
||||
window,
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
import * as geo from '../geo/index.js';
|
||||
import { t } from '../i18n/index.js';
|
||||
import { createStateChannel } from '../app/stateChannel.js';
|
||||
import { engineFromViewer } from '../globe/cesium/engineFromViewer.js';
|
||||
import { LocationControls } from './location.js';
|
||||
|
||||
/**
|
||||
* Own destination selection, lookup, orbit and world-jump lifetime. The camera
|
||||
* is the globe `engine`'s, and a world jump stops its follow
|
||||
* (`engine.camera.following()`); `viewer` is optional and only clears a
|
||||
* Cesium tracked entity that no registered engine reports.
|
||||
* Cesium tracked entity the engine does not report.
|
||||
*/
|
||||
export class LocationNavigation {
|
||||
constructor({
|
||||
viewer = null,
|
||||
engine = engineFromViewer(viewer),
|
||||
engine = null,
|
||||
placeSearch,
|
||||
services,
|
||||
elements,
|
||||
@@ -469,7 +468,7 @@ export class LocationNavigation {
|
||||
}
|
||||
|
||||
/** Navigate on another globe (an engine switch). */
|
||||
attachScene({ viewer = null, engine = engineFromViewer(viewer) } = {}) {
|
||||
attachScene({ viewer = null, engine = null } = {}) {
|
||||
if (this._disposed) return;
|
||||
this.viewer = viewer;
|
||||
this.engine = engine;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { cancelCameraArrival } from '../data/cameraArrival.js';
|
||||
import { createStateChannel } from '../app/stateChannel.js';
|
||||
import { engineFromViewer } from '../globe/cesium/engineFromViewer.js';
|
||||
import {
|
||||
beginDeferredNavigation,
|
||||
reassertNavigationHandoff,
|
||||
@@ -15,7 +14,7 @@ import {
|
||||
export class NavigationController {
|
||||
constructor({
|
||||
viewer = null,
|
||||
engine = engineFromViewer(viewer),
|
||||
engine = null,
|
||||
tracking,
|
||||
settleSearch = () => {},
|
||||
interruptCameraMotion,
|
||||
@@ -289,7 +288,7 @@ export class NavigationController {
|
||||
});
|
||||
}
|
||||
this.viewer = viewer;
|
||||
this.engine = engine ?? engineFromViewer(viewer);
|
||||
this.engine = engine;
|
||||
}
|
||||
/** Subscribe to ownership changes without claiming the camera or exposing mutable state. */
|
||||
subscribeCameraHandoff(listener) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
export function createWildlifeSightingCard({
|
||||
layer,
|
||||
ui,
|
||||
viewer = null,
|
||||
engine = null,
|
||||
documentRef = globalThis.document,
|
||||
windowRef = globalThis.window,
|
||||
now = () => Date.now(),
|
||||
@@ -66,7 +66,7 @@ export function createWildlifeSightingCard({
|
||||
|
||||
function observeLayout(elements) {
|
||||
const next = new Set(
|
||||
[host.firstElementChild, viewer?.scene?.canvas, ...elements].filter(
|
||||
[host.firstElementChild, engine?.host.canvas, ...elements].filter(
|
||||
Boolean,
|
||||
),
|
||||
);
|
||||
@@ -97,12 +97,12 @@ export function createWildlifeSightingCard({
|
||||
|
||||
function position({ allowPan = false } = {}) {
|
||||
if (destroyed || !selected.value || !host.firstElementChild) return;
|
||||
const point = project(viewer, selected.value, layer);
|
||||
const point = project(engine, selected.value, layer);
|
||||
if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y)) {
|
||||
host.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
const safe = readWildlifeCardSafeArea({ documentRef, viewer, windowRef });
|
||||
const safe = readWildlifeCardSafeArea({ documentRef, engine, windowRef });
|
||||
observeLayout(safe.elements);
|
||||
host.style.width = `${Math.min(WILDLIFE_SELECTED_CARD_WIDTH, safe.bounds.width)}px`;
|
||||
host.style.maxHeight = `${safe.bounds.height}px`;
|
||||
@@ -137,7 +137,7 @@ export function createWildlifeSightingCard({
|
||||
const reduced =
|
||||
windowRef?.matchMedia?.('(prefers-reduced-motion: reduce)').matches ===
|
||||
true;
|
||||
pan(viewer, point, result.anchor, reduced);
|
||||
pan(engine, point, result.anchor, reduced);
|
||||
}
|
||||
host.style.left = `${result.left}px`;
|
||||
host.style.top = `${result.top}px`;
|
||||
@@ -211,7 +211,7 @@ export function createWildlifeSightingCard({
|
||||
const outside = (event) => {
|
||||
if (!selected.value || host.contains(event.target)) return;
|
||||
// The layer selects on pointer-up; its following click must keep the card open.
|
||||
const canvas = viewer?.scene?.canvas;
|
||||
const canvas = engine?.host.canvas;
|
||||
if (canvas && (event.target === canvas || canvas.contains?.(event.target)))
|
||||
return;
|
||||
layer.clearSightingSelection();
|
||||
@@ -231,19 +231,19 @@ export function createWildlifeSightingCard({
|
||||
if (!selected.value || removeFrame) return;
|
||||
// Installed only for camera motion; an idle card has zero per-frame work.
|
||||
removeFrame =
|
||||
viewer?.scene?.preRender?.addEventListener?.(() => position()) || null;
|
||||
engine?.frames.preRender.addEventListener(() => position()) || null;
|
||||
}
|
||||
listen(viewer?.camera?.moveStart, () => {
|
||||
listen(engine?.camera.moveStart, () => {
|
||||
moving = true;
|
||||
startFrameUpdates();
|
||||
});
|
||||
listen(viewer?.camera?.moveEnd, () => {
|
||||
listen(engine?.camera.moveEnd, () => {
|
||||
moving = false;
|
||||
removeFrame?.();
|
||||
removeFrame = null;
|
||||
position();
|
||||
});
|
||||
listen(viewer?.camera?.changed, () => {
|
||||
listen(engine?.camera.changed, () => {
|
||||
if (!moving) position();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import '../testSupport/registerDom.mjs';
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import { nextTick } from 'vue';
|
||||
import * as geo from '../geo/index.js';
|
||||
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { getLocale, setLocale, t } from '../i18n/index.js';
|
||||
import { LOCALES } from '../i18n/locale.js';
|
||||
@@ -12,6 +13,7 @@ import { createWildlifeSightingCard } from './wildlifeSightingCard.js';
|
||||
import {
|
||||
panWildlifeSighting,
|
||||
placeWildlifeSightingCard,
|
||||
projectWildlifeSighting,
|
||||
readWildlifeCardSafeArea,
|
||||
} from './wildlifeSightingPlacement.js';
|
||||
import { createUiRuntime } from './vueRuntime.js';
|
||||
@@ -47,19 +49,6 @@ const rect = (left, top, width, height) => ({
|
||||
right: left + width,
|
||||
bottom: top + height,
|
||||
});
|
||||
const events = () => {
|
||||
const listeners = new Set();
|
||||
return {
|
||||
addEventListener(fn) {
|
||||
listeners.add(fn);
|
||||
return () => listeners.delete(fn);
|
||||
},
|
||||
emit() {
|
||||
for (const fn of listeners) fn();
|
||||
},
|
||||
size: () => listeners.size,
|
||||
};
|
||||
};
|
||||
const settle = async () => {
|
||||
await nextTick();
|
||||
await Promise.resolve();
|
||||
@@ -92,13 +81,14 @@ function fixture(
|
||||
};
|
||||
const ui = createUiRuntime();
|
||||
const overlays = new Map();
|
||||
const moveStart = events();
|
||||
const moveEnd = events();
|
||||
const changed = events();
|
||||
const preRender = events();
|
||||
const viewer = {
|
||||
scene: { canvas, preRender, pick: () => picked },
|
||||
camera: { moveStart, moveEnd, changed },
|
||||
const engine = createFakeEngine({ width: 1200, height: 900, canvas });
|
||||
engine.fake.script('pick', () => picked ?? undefined);
|
||||
const raise = (name) => ({ emit: () => engine.fake.emit(name) });
|
||||
const moveStart = raise('camera.moveStart');
|
||||
const moveEnd = raise('camera.moveEnd');
|
||||
const preRender = {
|
||||
...raise('frames.preRender'),
|
||||
size: () => engine.frames.preRender.numberOfListeners,
|
||||
};
|
||||
const state = {
|
||||
enabled: true,
|
||||
@@ -109,11 +99,10 @@ function fixture(
|
||||
rowById: new Map([[initialRow.stableId, initialRow]]),
|
||||
positions: new Map([[initialRow.stableId, { x: 1, y: 2, z: 3 }]]),
|
||||
contextIds: new Set(),
|
||||
viewer,
|
||||
engine,
|
||||
};
|
||||
let picked = null;
|
||||
let hit = null;
|
||||
let onClick;
|
||||
let clears = 0;
|
||||
let staleListener;
|
||||
const subscriptions = new Set();
|
||||
@@ -123,18 +112,11 @@ function fixture(
|
||||
state,
|
||||
services: {
|
||||
now: () => NOW,
|
||||
cesium: { ScreenSpaceEventType: { LEFT_CLICK: 0 } },
|
||||
overlayHost: {
|
||||
setEntries: (id, entries) => overlays.set(id, entries),
|
||||
hitTest: (_x, _y, { sourceId }) =>
|
||||
hit?.sourceId === sourceId ? hit : null,
|
||||
},
|
||||
screenSpaceEventHandlerFactory: () => ({
|
||||
setInputAction(fn) {
|
||||
onClick = fn;
|
||||
},
|
||||
destroy() {},
|
||||
}),
|
||||
focus: { requestWorldFocus: (value) => flights.push(value) },
|
||||
},
|
||||
parts: {
|
||||
@@ -162,7 +144,7 @@ function fixture(
|
||||
const card = createWildlifeSightingCard({
|
||||
layer,
|
||||
ui,
|
||||
viewer,
|
||||
engine,
|
||||
documentRef: document,
|
||||
windowRef,
|
||||
now: () => NOW,
|
||||
@@ -170,7 +152,7 @@ function fixture(
|
||||
projections++;
|
||||
return currentPoint;
|
||||
},
|
||||
pan: (_viewer, from, to, reduced) => {
|
||||
pan: (_engine, from, to, reduced) => {
|
||||
pans.push({ from, to, reduced });
|
||||
currentPoint = to;
|
||||
return true;
|
||||
@@ -187,7 +169,7 @@ function fixture(
|
||||
selection,
|
||||
layer,
|
||||
card,
|
||||
viewer,
|
||||
engine,
|
||||
windowRef,
|
||||
overlays,
|
||||
flights,
|
||||
@@ -204,9 +186,14 @@ function fixture(
|
||||
staleListener: () => staleListener,
|
||||
clears: () => clears,
|
||||
async click(kind = 'dot', target = initialRow) {
|
||||
// An icon pick names the badge's mover set and instance as well.
|
||||
picked =
|
||||
kind === 'icon'
|
||||
? { primitive: { id: `wildlife:${target.stableId}` } }
|
||||
? {
|
||||
id: `wildlife:${target.stableId}`,
|
||||
owner: 'wildlife-sightings',
|
||||
instance: 0,
|
||||
}
|
||||
: { id: `wildlife:${target.stableId}` };
|
||||
hit =
|
||||
kind === 'ambient photo card'
|
||||
@@ -217,7 +204,7 @@ function fixture(
|
||||
}),
|
||||
}
|
||||
: null;
|
||||
onClick({ position: { x: 50, y: 50 } });
|
||||
engine.fake.input('click', { position: { x: 50, y: 50 } });
|
||||
await settle();
|
||||
},
|
||||
async publish(next) {
|
||||
@@ -459,7 +446,7 @@ test('a selected dot flies to its true position and its card pans clear of chrom
|
||||
);
|
||||
const safe = readWildlifeCardSafeArea({
|
||||
documentRef: document,
|
||||
viewer: f.viewer,
|
||||
engine: f.engine,
|
||||
windowRef: f.windowRef,
|
||||
});
|
||||
assert.equal(
|
||||
@@ -481,42 +468,68 @@ test('a selected dot flies to its true position and its card pans clear of chrom
|
||||
|
||||
test('the camera correction preserves altitude and orientation and honors reduced motion', () => {
|
||||
const flights = [];
|
||||
const camera = {
|
||||
positionWC: Cesium.Cartesian3.fromDegrees(0, 0, 250_000),
|
||||
positionCartographic: { height: 250_000 },
|
||||
const engine = createFakeEngine({
|
||||
canvas: { getBoundingClientRect: () => rect(0, 0, 1200, 900) },
|
||||
});
|
||||
engine.fake.setPose({
|
||||
position: geo.cartesian3.fromDegrees(0, 0, 250_000),
|
||||
heading: 0.2,
|
||||
pitch: -1.2,
|
||||
roll: 0.1,
|
||||
pickEllipsoid: (p) => Cesium.Cartesian3.fromDegrees(p.x / 100, p.y / 100),
|
||||
flyTo: (value) => flights.push(value),
|
||||
};
|
||||
const viewer = {
|
||||
camera,
|
||||
scene: {
|
||||
canvas: { getBoundingClientRect: () => rect(0, 0, 1200, 900) },
|
||||
globe: { ellipsoid: Cesium.Ellipsoid.WGS84 },
|
||||
},
|
||||
};
|
||||
});
|
||||
const pose = engine.camera.pose();
|
||||
engine.fake.script('pickEllipsoid', (p) =>
|
||||
geo.cartesian3.fromDegrees(p.x / 100, p.y / 100),
|
||||
);
|
||||
engine.camera.flyTo = (value) => flights.push(value);
|
||||
for (const reduced of [false, true]) {
|
||||
assert.equal(
|
||||
panWildlifeSighting(viewer, { x: 10, y: 10 }, { x: 30, y: 50 }, reduced),
|
||||
panWildlifeSighting(engine, { x: 10, y: 10 }, { x: 30, y: 50 }, reduced),
|
||||
true,
|
||||
);
|
||||
const flight = flights.at(-1);
|
||||
assert.ok(
|
||||
Math.abs(
|
||||
Cesium.Cartographic.fromCartesian(flight.destination).height - 250_000,
|
||||
geo.cartographic.fromCartesian(flight.destination).height - 250_000,
|
||||
) < 0.001,
|
||||
);
|
||||
assert.deepEqual(flight.orientation, {
|
||||
heading: pose.heading,
|
||||
pitch: pose.pitch,
|
||||
roll: pose.roll,
|
||||
});
|
||||
for (const [angle, value] of Object.entries({
|
||||
heading: 0.2,
|
||||
pitch: -1.2,
|
||||
roll: 0.1,
|
||||
});
|
||||
}))
|
||||
assert.ok(Math.abs(flight.orientation[angle] - value) < 1e-9, angle);
|
||||
assert.equal(flight.duration, reduced ? 0 : 0.22);
|
||||
}
|
||||
});
|
||||
|
||||
test('a sighting projects through the engine onto the page, and not from behind the globe', () => {
|
||||
const engine = createFakeEngine({
|
||||
canvas: { getBoundingClientRect: () => rect(30, 40, 1024, 768) },
|
||||
});
|
||||
engine.fake.setPose({ position: geo.cartesian3.fromDegrees(0, 0, 250_000) });
|
||||
const centre = projectWildlifeSighting(engine, row, null);
|
||||
assert.ok(Math.abs(centre.x - (30 + 512)) < 1e-6);
|
||||
assert.ok(Math.abs(centre.y - (40 + 384)) < 1e-6);
|
||||
const anchored = { x: 1, y: 2, z: 3 };
|
||||
engine.fake.script('worldToWindow', () => ({ x: 10, y: 20 }));
|
||||
engine.projector.horizonVisible = (position) => position === anchored;
|
||||
assert.deepEqual(
|
||||
projectWildlifeSighting(engine, row, {
|
||||
getSightingPosition: () => anchored,
|
||||
}),
|
||||
{ x: 40, y: 60 },
|
||||
'the layer anchor wins over the row coordinates',
|
||||
);
|
||||
assert.equal(projectWildlifeSighting(engine, row, null), null);
|
||||
assert.equal(projectWildlifeSighting(null, row, null), null);
|
||||
});
|
||||
|
||||
test('the browser click that follows a globe selection does not close the card it opened', async (context) => {
|
||||
const f = fixture(context);
|
||||
await f.click();
|
||||
@@ -526,8 +539,8 @@ test('the browser click that follows a globe selection does not close the card i
|
||||
f.cardElement(),
|
||||
'focus lands on the card, not as a ring on its close button',
|
||||
);
|
||||
// Cesium selects on pointer-up; the DOM click event lands on the canvas
|
||||
// afterwards and must not count as an outside click.
|
||||
// The engine reports the globe click on pointer-up; the DOM click event
|
||||
// lands on the canvas afterwards and must not count as an outside click.
|
||||
f.canvas.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
await settle();
|
||||
assert.ok(f.cardElement(), 'the card stays open');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from '../geo/index.js';
|
||||
import { WORLD_OVERLAY_OCCLUDER_SELECTORS } from '../overlays/worldOverlayChrome.js';
|
||||
|
||||
// DOM cards also avoid the HUD edges and responsive sheet containers.
|
||||
@@ -32,13 +32,13 @@ const rectAt = (left, top, width, height) => ({
|
||||
height,
|
||||
});
|
||||
|
||||
/** Read visible chrome rectangles inside the viewer's usable screen area. */
|
||||
/** Read visible chrome rectangles inside the globe canvas's usable area. */
|
||||
export function readWildlifeCardSafeArea({
|
||||
documentRef,
|
||||
viewer,
|
||||
engine,
|
||||
windowRef = globalThis.window,
|
||||
}) {
|
||||
const canvasRect = viewer?.scene?.canvas?.getBoundingClientRect?.();
|
||||
const canvasRect = engine?.host?.canvas?.getBoundingClientRect?.();
|
||||
const width =
|
||||
windowRef?.innerWidth || documentRef.documentElement.clientWidth;
|
||||
const height =
|
||||
@@ -208,67 +208,51 @@ export function placeWildlifeSightingCard(point, size, safeArea) {
|
||||
}
|
||||
|
||||
/** Project a front-side sighting into viewport coordinates. */
|
||||
export function projectWildlifeSighting(viewer, row, layer) {
|
||||
if (
|
||||
!viewer?.scene ||
|
||||
!Number.isFinite(row?.lat) ||
|
||||
!Number.isFinite(row?.lon)
|
||||
)
|
||||
export function projectWildlifeSighting(engine, row, layer) {
|
||||
if (!engine || !Number.isFinite(row?.lat) || !Number.isFinite(row?.lon))
|
||||
return null;
|
||||
const position =
|
||||
layer?.getSightingPosition?.(row.stableId) ||
|
||||
Cesium.Cartesian3.fromDegrees(row.lon, row.lat);
|
||||
const ellipsoid = viewer.scene.globe?.ellipsoid || Cesium.Ellipsoid.WGS84;
|
||||
if (
|
||||
viewer.camera?.positionWC &&
|
||||
new Cesium.EllipsoidalOccluder(
|
||||
ellipsoid,
|
||||
viewer.camera.positionWC,
|
||||
).isPointVisible(position) !== true
|
||||
)
|
||||
return null;
|
||||
const point = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
viewer.scene,
|
||||
position,
|
||||
);
|
||||
geo.cartesian3.fromDegrees(row.lon, row.lat);
|
||||
if (engine.projector.horizonVisible(position) !== true) return null;
|
||||
const point = engine.projector.worldToWindow(position);
|
||||
if (!point) return null;
|
||||
const rect = viewer.scene.canvas?.getBoundingClientRect?.();
|
||||
const rect = engine.host.canvas?.getBoundingClientRect?.();
|
||||
return { x: point.x + (rect?.left || 0), y: point.y + (rect?.top || 0) };
|
||||
}
|
||||
|
||||
/** Translate the camera by the smallest screen correction and preserve its
|
||||
* altitude/orientation. A card must never zoom merely to reveal its anchor. */
|
||||
export function panWildlifeSighting(viewer, from, to, reducedMotion = false) {
|
||||
const camera = viewer?.camera;
|
||||
if (!camera?.pickEllipsoid || !camera.flyTo) return false;
|
||||
const rect = viewer.scene.canvas.getBoundingClientRect();
|
||||
const local = (p) => new Cesium.Cartesian2(p.x - rect.left, p.y - rect.top);
|
||||
const ellipsoid = viewer.scene.globe?.ellipsoid || Cesium.Ellipsoid.WGS84;
|
||||
const start = camera.pickEllipsoid(local(from), ellipsoid);
|
||||
const finish = camera.pickEllipsoid(local(to), ellipsoid);
|
||||
if (!start || !finish || !camera.positionWC) return false;
|
||||
const delta = Cesium.Cartesian3.subtract(
|
||||
start,
|
||||
finish,
|
||||
new Cesium.Cartesian3(),
|
||||
export function panWildlifeSighting(engine, from, to, reducedMotion = false) {
|
||||
const camera = engine?.camera;
|
||||
if (!camera) return false;
|
||||
const rect = engine.host.canvas?.getBoundingClientRect?.();
|
||||
const local = (p) => ({
|
||||
x: p.x - (rect?.left || 0),
|
||||
y: p.y - (rect?.top || 0),
|
||||
});
|
||||
const start = camera.pickEllipsoid(local(from));
|
||||
const finish = camera.pickEllipsoid(local(to));
|
||||
if (!start || !finish) return false;
|
||||
const pose = camera.pose();
|
||||
const destination = geo.cartesian3.add(
|
||||
pose.position,
|
||||
geo.cartesian3.subtract(start, finish, geo.cartesian3.create()),
|
||||
geo.cartesian3.create(),
|
||||
);
|
||||
const destination = Cesium.Cartesian3.add(
|
||||
camera.positionWC,
|
||||
delta,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const cartographic = ellipsoid.cartesianToCartographic(destination);
|
||||
const cartographic = geo.cartographic.fromCartesian(destination);
|
||||
if (!cartographic) return false;
|
||||
cartographic.height = camera.positionCartographic.height;
|
||||
cartographic.height = pose.cartographic.height;
|
||||
camera.flyTo({
|
||||
destination: ellipsoid.cartographicToCartesian(cartographic),
|
||||
destination: geo.cartographic.toCartesian(cartographic),
|
||||
orientation: {
|
||||
heading: camera.heading,
|
||||
pitch: camera.pitch,
|
||||
roll: camera.roll,
|
||||
heading: pose.heading,
|
||||
pitch: pose.pitch,
|
||||
roll: pose.roll,
|
||||
},
|
||||
duration: reducedMotion ? 0 : 0.22,
|
||||
easingFunction: Cesium.EasingFunction.QUADRATIC_OUT,
|
||||
// The contract has no ease-out; linear keeps the correction prompt.
|
||||
easing: 'linear',
|
||||
});
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user