fix(ui): north-up and tilt keep an engine's own follow (Navara)

Inside a Navara follow the orientation controls frame the follow's target
and retarget its viewFrom instead of moving the camera, and the release
cancels only a running flight (a cancel is a camera command, which ends
the follow). Cesium's trackedEntity path is unchanged. Updated test:
cameraOrientationControls.test.mjs (orientation navigation starts a
flight before expecting its cancel; no flight, no cancel).
This commit is contained in:
German Khokhlov committed 2026-10-17 03:48:12 +04:00
1 parent dcfb1219d5
commit 2da7b6d0d9
3 files changed
+85 -2

No files matched your search

+50
View File
@@ -13,6 +13,7 @@ import {
} from './cameraOrientationControls.js';
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';
@@ -651,6 +652,10 @@ test('orientation navigation preserves follow and selection; new navigation canc
cancelFlight();
};
let cockpit = false;
engine.camera.flyTo({
destination: geo.cartesian3.fromDegrees(30, 40, 5000),
duration: 1,
});
const navigation = new NavigationController({
viewer,
engine,
@@ -675,6 +680,15 @@ test('orientation navigation preserves follow and selection; new navigation canc
'cancel-flight',
]);
calls.length = 0;
// No running flight: a cancel would be a camera command, ending an engine's
// own follow, so the orientation leaves the camera alone.
navigation.runOrientation('camera', () => 'animated');
assert.deepEqual(calls, [
'cancel-orientation',
'interrupt-motion',
'stop-orbit',
]);
calls.length = 0;
navigation._stampNavigation({ cancelPendingSelection: false });
assert.deepEqual(calls, ['cancel-orientation', 'clear-location']);
calls.length = 0;
@@ -761,3 +775,39 @@ test('the controls run on a globe engine alone', (t) => {
assert.equal(engine.frames.preUpdate.numberOfListeners, 0);
assert.equal(engine.camera.moveEnd.numberOfListeners, 0);
});
test("north-up and tilt inside an engine's own follow keep following (Navara)", () => {
const engine = createFakeEngine();
const target = Cesium.Cartesian3.fromDegrees(-73.78, 40.64, 3000);
const handle = engine.camera.follow({
position: () => target,
// 2 km south-east of the target, 1 km up: heading about 315°.
viewFrom: { x: 1400, y: -1400, z: 1000 },
});
engine.fake.frame();
const before = readCameraTargetFrame(engine);
assert.ok(before, 'a frame around the followed target');
sameXYZ(before.target, target, 'the frame centres the follow target');
assert.equal(resetCameraNorth(engine), true);
engine.fake.frame();
assert.equal(engine.camera.following(), handle, 'north-up keeps the follow');
const north = readCameraTargetFrame(engine);
const headingDeg = Cesium.Math.toDegrees(north.heading);
assert.ok(
Math.min(headingDeg, 360 - headingDeg) < 0.01,
`north-up left the follow at ${headingDeg.toFixed(2)} deg`,
);
assert.ok(Math.abs(north.range - before.range) < 1, 'same range');
assert.ok(Math.abs(north.pitch - before.pitch) < 1e-6, 'same pitch');
const tilt = toggleCameraTilt(engine);
assert.ok(tilt, 'tilt applied');
engine.fake.frame();
assert.equal(engine.camera.following(), handle, 'tilt keeps the follow');
const tilted = readCameraTargetFrame(engine);
assert.ok(
Math.abs(tilted.pitch - tilt.pitch) < 1e-6,
'the follow took the tilted pitch',
);
handle.stop();
engine.destroy();
});