refactor(ui): navigation, orientation, share links and HUD use the globe engine

The application shell keeps the page's globe engine and hands it to the
navigation controller, location navigation (search, city and POI flights,
orbit, globe reset), the tilt and north-up controls, share-link save and
restore, share restoration's first-gesture listeners and the HUD. The
viewer is passed only where entity tracking still lives on it (phase 1c)
and to the HUD's basemap label context (voice); every such use is null-safe.

Share links and captured shots write heading and roll as Cesium's camera
reports them (src/cameraAngles.js): the contract's [0, 2π) pose maps an
exact 0 back to Cesium's 2π, except the roll of a vertical view, so
links stay byte-identical (heading=360, roll=360) on every engine.

Source-reading tests follow the moved code with the same checks.
This commit is contained in:
German Khokhlov committed 2026-10-15 19:47:51 +04:00
1 parent 16e63f4c50
commit ec38e6ef16
19 files changed
+594 -226

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
// Share links read the camera through the globe engine and write heading and
// roll the way Cesium's camera reports them (in (0, 2π]), so a link made on
// any engine reads as one made on Cesium.
import test from 'node:test';
import assert from 'node:assert/strict';
import * as geo from './geo/index.js';
import { createFakeEngine } from './globe/testing/fakeEngine.js';
import { ShareLinkManager } from './sharelink.js';
function linkFor(pose) {
globalThis.window = { location: { hash: '', href: 'http://localhost/' } };
const engine = createFakeEngine();
engine.fake.setPose(pose);
const manager = new ShareLinkManager(engine);
const params = new URLSearchParams(manager._buildHashParams().toString());
manager.destroy();
return Object.fromEntries(
['lat', 'lon', 'alt', 'heading', 'pitch', 'roll'].map((k) => [k, params.get(k)]),
);
}
const at = (heading, pitch, roll = 0) => ({
position: geo.cartesian3.fromDegrees(-73.9857, 40.7484, 1800),
heading: geo.math.toRadians(heading),
pitch: geo.math.toRadians(pitch),
roll: geo.math.toRadians(roll),
});
test('a level north-facing view writes heading and roll 360, as Cesium reports them', () => {
assert.deepEqual(linkFor(at(0, -30)), {
lat: '40.7484',
lon: '-73.9857',
alt: '1800',
heading: '360',
pitch: '-30',
roll: '360',
});
});
test('a straight-down view writes roll 0; other angles round as before', () => {
const down = linkFor(at(0, -90));
assert.equal(down.heading, '360');
assert.equal(down.roll, '0');
assert.equal(down.pitch, '-90');
const oblique = linkFor(at(45.4, -29.6, 2));
assert.deepEqual([oblique.heading, oblique.pitch, oblique.roll], ['45', '-30', '2']);
assert.equal(linkFor(at(359.7, -30)).heading, '360');
});
test('the camera changed event schedules a hash update and destroy unsubscribes', () => {
globalThis.window = { location: { hash: '', href: 'http://localhost/' } };
const engine = createFakeEngine();
const manager = new ShareLinkManager(engine);
assert.equal(engine.camera.changed.numberOfListeners, 1);
manager.destroy();
assert.equal(engine.camera.changed.numberOfListeners, 0);
});