Follow, credits, embed views and FPS through the engine on Navara

Five places still read the Cesium viewer and so did nothing, or the wrong
thing, on Navara. Each now goes through the globe contract, and Cesium
behaves as before.

- The Navara ground floor stands aside while the camera inputs are
  suspended, not only while they are switched off. The cockpit suspends
  them, so its eye 12 m up no longer jumps to the floor's 30 m between
  updates. A follow's own suspension keeps the floor on, as before.
- Follow state comes from engine.camera.following() and followChanged
  instead of viewer.trackedEntity. Enabling CCTV during a follow no longer
  flies away and ends it, a new follow stamps navigation, Director cards
  wait while a subject is followed, and an explicit navigation stops the
  follow on both engines.
- Navara registers every data credit, as Cesium does. The allowlist left
  out the layers that moved to Navara later (CCTV agencies, street-level
  imagery, GIBS, routing, bike feeds and others).
- Annotation links and embed mode attach on every engine; their camera
  flights use engine.camera.flyTo. Only Cesium adds the timer that keeps
  an inline panel drawing.
- The FPS readout counts engine.frames.postRender, so it shows on Navara.

Each fix has a test that fails without it.
This commit is contained in:
German Khokhlov committed 2026-11-08 17:05:27 +04:00
1 parent e1095ee553
commit 18f69c2699
23 files changed
+144 -158

No files matched your search

+15 -11
View File
@@ -144,10 +144,10 @@ const delay = (ms, signal) =>
});
/** Fly the camera to a view's camera and resolve when the flight ends. */
function flyTo(viewer, camera) {
function flyTo(engine, camera) {
announceNavigationAuthority('embed-view');
return new Promise((resolve) => {
viewer.camera.flyTo({
engine.camera.flyTo({
destination: geo.cartesian3.fromDegrees(
camera.lon,
camera.lat,
@@ -173,7 +173,7 @@ function flyTo(viewer, camera) {
*/
export async function applyView(
view,
{ viewer, dataManager, run, signal, retryMs = FOLLOW_RETRY_MS },
{ engine, dataManager, run, signal, retryMs = FOLLOW_RETRY_MS },
) {
const steps = [];
const act = async (name, args) => {
@@ -208,7 +208,7 @@ export async function applyView(
if (view.annotations.length)
await act('annotate_map', { annotations: [...view.annotations] });
if (!view.follow) {
steps.push({ step: 'camera', ok: await flyTo(viewer, view.camera) });
steps.push({ step: 'camera', ok: await flyTo(engine, view.camera) });
return steps;
}
// A followed entity owns the camera, and a camera flight would end the
@@ -227,7 +227,7 @@ export async function applyView(
};
let followed = await follow();
if (!followed) {
steps.push({ step: 'camera', ok: await flyTo(viewer, view.camera) });
steps.push({ step: 'camera', ok: await flyTo(engine, view.camera) });
for (let attempt = 1; attempt < FOLLOW_ATTEMPTS && !followed; attempt++) {
if (signal?.aborted) break;
await delay(retryMs, signal);
@@ -242,11 +242,14 @@ export async function applyView(
/**
* Install embed mode when the page asks for it, and draw any annotations the
* opening link carries. Returns a function that removes the message handler.
* opening link carries. `keepRendering({ windowRef })`, when the engine needs
* it, keeps an inline panel drawing (keepPanelRendering). Returns a function
* that removes the message handler.
*/
export function installViews({
shell,
viewer,
engine,
keepRendering = null,
dataManager,
run,
signal,
@@ -265,9 +268,10 @@ export function installViews({
windowRef.document.body.classList.add('ui-embed');
shell.setCleanView?.(true);
const stopRendering = isEmbeddedInline()
? keepPanelRendering(viewer, { windowRef })
: () => {};
const stopRendering =
isEmbeddedInline() && keepRendering
? keepRendering({ windowRef })
: () => {};
// A framing page talks to the app across frames; an inline panel shares
// the page with it and talks through the page's own window.
const peer = isEmbeddedInline() ? windowRef : windowRef.parent;
@@ -304,7 +308,7 @@ export function installViews({
}
queue = queue.then(async () => {
if (signal?.aborted) return;
const steps = await applyView(view, { viewer, dataManager, run, signal });
const steps = await applyView(view, { engine, dataManager, run, signal });
post(
{
type: EMBED_APPLIED_MESSAGE,
+11 -11
View File
@@ -10,7 +10,7 @@ import {
import { LayerLifecycle } from '../data/lifecycle.js';
import { createView } from '../view/index.js';
const fakeViewer = () => {
const fakeEngine = () => {
const flights = [];
return {
flights,
@@ -48,7 +48,7 @@ test('embed mode is opt-in by query parameter', () => {
});
test('a view is applied through the app actions in order', async () => {
const viewer = fakeViewer();
const engine = fakeEngine();
const { calls, run } = recorder();
const view = createView({
camera: { lat: 25, lon: 121, altitude_m: 300000, pitch_deg: -40 },
@@ -58,7 +58,7 @@ test('a view is applied through the app actions in order', async () => {
annotations: [{ type: 'pin', target: 'Taipei 101' }],
});
const steps = await applyView(view, {
viewer,
engine,
dataManager: fakeLayers(new Set(['earthquakes'])),
run,
});
@@ -78,7 +78,7 @@ test('a view is applied through the app actions in order', async () => {
['annotate_map', null, null],
],
);
assert.equal(viewer.flights.length, 1);
assert.equal(engine.flights.length, 1);
assert.ok(steps.every((step) => step.ok));
assert.ok(steps.some((step) => step.step === 'camera'));
});
@@ -93,7 +93,7 @@ test('a followed entity is retried until its layer has it', async () => {
follow: { kind: 'aircraft', id: 'abc123' },
});
const steps = await applyView(view, {
viewer: fakeViewer(),
engine: fakeEngine(),
dataManager: fakeLayers(new Set()),
run,
retryMs: 1,
@@ -125,7 +125,7 @@ test('an embedded page takes views only from its parent and answers it', async (
const { calls, run } = recorder();
const remove = installViews({
shell,
viewer: fakeViewer(),
engine: fakeEngine(),
dataManager: fakeLayers(new Set()),
run,
location: { search: '?embed=1', hash: '' },
@@ -204,7 +204,7 @@ test('an app loaded inline into a panel page talks through its own window', asyn
assert.equal(isEmbedded({ search: '' }), true);
const remove = installViews({
shell: { initialRestorePromise: Promise.resolve() },
viewer: fakeViewer(),
engine: fakeEngine(),
dataManager: fakeLayers(new Set()),
run: recorder().run,
location: { search: '', hash: '' },
@@ -288,7 +288,7 @@ test('annotations in a link are drawn after it restores, embedded or not', async
);
installViews({
shell: { initialRestorePromise: Promise.resolve() },
viewer: fakeViewer(),
engine: fakeEngine(),
dataManager: fakeLayers(new Set()),
run,
location: { search: '', hash: `#v=2&lat=1&lon=2&an=${an}` },
@@ -368,17 +368,17 @@ test('a panel reports a render error in full and stops drawing', () => {
});
test('a followed aircraft owns the camera, and cockpit view is entered after it', async () => {
const viewer = fakeViewer();
const engine = fakeEngine();
const { calls, run } = recorder();
const steps = await applyView(
createView({
camera: { lat: 32.7, lon: -117.2 },
follow: { kind: 'military_aircraft', id: 'AE1234', cockpit: true },
}),
{ viewer, dataManager: fakeLayers(new Set()), run, retryMs: 0 },
{ engine, dataManager: fakeLayers(new Set()), run, retryMs: 0 },
);
// Following worked at once, so no camera flight ended it.
assert.equal(viewer.flights.length, 0);
assert.equal(engine.flights.length, 0);
assert.deepEqual(calls.slice(-2), [
['track_entity', { query: 'ae1234', layerId: 'military' }],
['control_cockpit', { action: 'enter', targetLayer: 'military' }],
+2 -34
View File
@@ -5,7 +5,7 @@ import { t } from '../i18n/index.js';
// loads the Navara globe the same way, so the Cesium-mode bundle carries
// none of it.
import { DATA_CREDITS, registerDataCredits } from '../data/dataCredits.js';
import { registerDataCredits } from '../data/dataCredits.js';
import { createLayerAvailability } from './layers/renderers.js';
import { createNavaraAnnotationRenderer } from '../annotations/navaraAnnotationRenderer.js';
@@ -29,35 +29,6 @@ export function navaraModeNotice(availability) {
});
}
/** Static attribution for the shell and the layers available on Navara. */
const NAVARA_CREDIT_KEYS = new Set([
'inaturalist',
'photon-geocoder',
'openstreetmap',
'reearth-terrain',
'opensky',
'adsblol',
'adsbdb',
'aisstream',
'celestrak',
'launch-library-2',
'usgs',
'eccc-aqhi',
'wfigs',
's2-ghostmaps',
'telegeography',
'wind-gfs',
'ecmwf-ifs',
'weather-noaa',
'weather-lightning',
'weather-cyclones',
'dams',
'firms',
'gbfs',
'overture-military-names',
'radio-browser',
]);
/**
* The scene on the experimental Navara engine: no viewer and no Cesium
* objects. Navara builds the map sources from the controller's descriptions
@@ -109,10 +80,7 @@ export async function createNavaraScene({
signal.throwIfAborted();
// After the map's own credits, so Google's copyright lines come first in
// Navara's attribution card.
registerDataCredits(
engine,
(credits ?? DATA_CREDITS).filter(({ key }) => NAVARA_CREDIT_KEYS.has(key)),
);
registerDataCredits(engine, credits);
return {
viewer: null,
engine,
+4 -23
View File
@@ -174,30 +174,11 @@ test('the Navara scene tears down the controller, then the globe', async (t) =>
assert.equal(view.__GOOGLE_MAPS_API_KEY__, undefined);
});
test('Navara keeps attribution for every available W1/W2 source and excludes unavailable data', async (t) => {
const keys = [
'opensky',
'adsblol',
'adsbdb',
'aisstream',
'celestrak',
'launch-library-2',
'usgs',
'eccc-aqhi',
'wfigs',
'firms',
'gbfs',
'overture-military-names',
'radio-browser',
'photon-geocoder',
'openstreetmap',
'reearth-terrain',
];
test('Navara registers the attribution of every data source, as Cesium does', async (t) => {
// Every layer draws on Navara, so none of their credits may be dropped.
const keys = ['opensky', 'nasa-gibs', 'nyc-dot-cctv', 'mapillary', 'gdelt'];
const run = await startScene({
credits: [...keys, 'nasa-gibs'].map((key) => ({
key,
html: `Credit ${key}`,
})),
credits: keys.map((key) => ({ key, html: `Credit ${key}` })),
});
t.after(run.teardown);
assert.deepEqual(
+14 -19
View File
@@ -13,7 +13,7 @@ import {
currentSceneOf,
detachPartsOnTeardown,
} from './sceneParts.js';
import { installViews, isEmbeddedInline } from './embed.js';
import { installViews, isEmbeddedInline, keepPanelRendering } from './embed.js';
import {
installScopeMask,
destroyScopeMask,
@@ -310,20 +310,8 @@ function cesiumToolBackend({ engine, tileset }) {
viewer.useDefaultRenderLoop = !hidden;
cockpitCloudEffects?.setSuspended?.(hidden);
},
attachViews(
{ styleManager, dataManager, voiceCommands },
{ signal, defer },
) {
defer(
installViews({
shell: styleManager,
viewer,
dataManager,
run: (name, args) => voiceCommands.runner(name, args, { signal }),
signal,
}),
);
},
// An inline panel the host reports hidden stops Cesium's render loop.
keepRendering: (options) => keepPanelRendering(viewer, options),
};
}
@@ -336,7 +324,7 @@ function cesiumToolBackend({ engine, tileset }) {
* this engine), `recentImagery(layer)` the panel's globe,
* `attach(context, attachment)` adds
* the engine's own tools, `suspend(hidden, controls)` its hidden-tab
* handling and `attachViews(context, attachment)` its embedded views. The
* handling and `keepRendering` what keeps an inline panel drawing. The
* shared tools keep their session state across engines. Returns the
* annotation board (null without one) and voice commands.
*/
@@ -460,9 +448,16 @@ async function attachEngineTools(
signal,
defer,
});
backend.attachViews?.(
{ styleManager, dataManager, voiceCommands },
{ signal, defer },
// Annotation links and embed mode, on every engine.
defer(
installViews({
shell: styleManager,
engine,
keepRendering: backend.keepRendering ?? null,
dataManager,
run: (name, args) => voiceCommands.runner(name, args, { signal }),
signal,
}),
);
return { annotations, voiceCommands, startupChrome: backend.startupChrome };
}
+23
View File
@@ -17,9 +17,17 @@ test('without a viewer the tools run the governor on the engine, show the notice
window: globalThis.window,
document: globalThis.document,
localStorage: globalThis.localStorage,
location: globalThis.location,
};
const listeners = new Map();
globalThis.window = {};
// A link that carries an annotation, drawn once the view restores.
const linked = encodeURIComponent(
JSON.stringify([{ type: 'pin', target: 'Austin' }]),
);
globalThis.location = { search: '', hash: `#v=2&lat=1&lon=2&an=${linked}` };
let restored;
const initialRestorePromise = new Promise((resolve) => (restored = resolve));
globalThis.localStorage = {
getItem: () => null,
setItem() {},
@@ -54,11 +62,14 @@ test('without a viewer the tools run the governor on the engine, show the notice
// The voice pointer listens on the engine's canvas.
const canvas = new EventTarget();
const engine = createFakeEngine({ kind: 'navara', canvas });
// Navara's extension without its view: no annotation board.
engine.extensions = { navara: { alignDaylightToRestoredView() {} } };
const notices = [];
const chrome = [];
const cleanups = [];
let flushed = 0;
const styleManager = {
initialRestorePromise,
_showGlobalStatusNotice: (label, options) =>
notices.push({ label, options }),
};
@@ -102,6 +113,18 @@ test('without a viewer the tools run the governor on the engine, show the notice
defer: (dispose) => cleanups.push(dispose),
});
assert.ok(tools.sceneDirector);
const ran = [];
tools.voiceCommands.runner = async (name, args) => {
ran.push([name, args]);
return { ok: true };
};
restored();
await new Promise((resolve) => setTimeout(resolve, 0));
assert.deepEqual(
ran,
[['annotate_map', { annotations: [{ type: 'pin', target: 'Austin' }] }]],
"the link's annotations are drawn on this engine too",
);
assert.equal(tools.annotations, null);
assert.ok(tools.voiceCommands, 'voice runs on the engine');
assert.equal(window.__gevVoiceCommands, tools.voiceCommands);