mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Move shared follow offsets and Draw onto the globe contract
Share links read the current follow handle and displayed position through engine.camera and restore their ENU offset with follow's swingTo option. Cesium retains its first-frame wait, displayed-position cache, 60-degree frame limit and range interpolation. Navara and the fake engine apply the same swing. Cancellation, camera handoff and destruction release it; an externally tracked Cesium entity keeps its existing handle. Draw uses one surface with engine input, geodesic lines and point movers. An exclusive pointer claim suppresses ambient subscriptions and deferred picks across ownership changes. Cesium owns suspension and exact restoration of its stock select and track actions. Camera gestures remain enabled. Detaching releases the sketch and preview and retains shape and colour. The separate Navara surface and Cesium data-source preview are removed. Cesium remains the reference for clicked heights, line width and dash, vertex size and outline, keyboard handling and completed annotations. One deliberate visual fix is that the occluded rubber band uses the selected colour instead of retaining the initial amber: it now identifies the same sketch as its visible segment. Navara adopts Cesium's geodesic preview edges. Finished annotation drapes are unchanged. External Cesium import files fall from 7 to 5, viewer lines from 1005 to 953, and engine-name lines from 39 to 37. No coupling metric grows. The full unit suite, import directions, package boundaries, formatting and coupling checks pass. Checked in the browser, keyless: the contract suite passes on Navara and on Cesium apart from the camera-events check that also fails intermittently before; qa-navara-draw passes; qa-draw-tool passes apart from its hidden-line pixel check, which fails the same way before this change. Its destroy check now expects no preview data source, since the preview has none.
This commit is contained in:
1 parent
910d693b94
commit
dacfd33f10
31 files changed
+1071
-785
No files matched your search
@@ -284,7 +284,7 @@ export class StyleManager extends ShellFacade {
|
||||
initialShareCode,
|
||||
});
|
||||
this.shareLinkManager.setFollowSubjectProvider(({ nowMs }) =>
|
||||
readShareFollowSubject({ viewer: this.viewer, nowMs }),
|
||||
readShareFollowSubject({ engine: this._scene?.engine, nowMs }),
|
||||
);
|
||||
this.shareLinkManager.setPanelStateProvider(() =>
|
||||
this._buildSharePanelState(),
|
||||
@@ -451,7 +451,7 @@ export class StyleManager extends ShellFacade {
|
||||
const services = this.services;
|
||||
const layerSession = this._layerSession;
|
||||
this._shareRestoration = new ShareRestoration({
|
||||
viewer,
|
||||
engine,
|
||||
canvas: engine?.host.canvas ?? viewer?.canvas,
|
||||
handoffLayers: layerSession?.handoffLayers,
|
||||
navigation: this._navigation,
|
||||
@@ -461,8 +461,8 @@ export class StyleManager extends ShellFacade {
|
||||
this._showGlobalStatusNotice(message, options),
|
||||
feedback: this._feedback,
|
||||
updateFeedback: () => this._updateGlobalLoadingFeedback(),
|
||||
applyFollowOffset: (entity, offset) =>
|
||||
applyShareFollowOffset(viewer, entity, offset),
|
||||
applyFollowOffset: (handle, offset) =>
|
||||
applyShareFollowOffset(engine, handle, offset),
|
||||
});
|
||||
|
||||
this._visualSettings = new VisualSettings({
|
||||
|
||||
+27
-158
@@ -1,190 +1,59 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { trackedDisplayPositionForCamera } from '../data/trackedCamera.js';
|
||||
import * as geo from '../geo/index.js';
|
||||
import { enuOffset } from '../globe/follow.js';
|
||||
import {
|
||||
SHARE_VIEW_ENTITY_KINDS,
|
||||
followOffsetFromEnu,
|
||||
followOffsetToEnu,
|
||||
} from '../share/follow.js';
|
||||
|
||||
/**
|
||||
* The bridge between the camera following an entity and a share link's thing
|
||||
* view: what the camera follows now, in the share format's terms, and the
|
||||
* stored follow offset applied to an entity the camera has started to follow.
|
||||
*/
|
||||
|
||||
const KIND_BY_LAYER = new Map(
|
||||
SHARE_VIEW_ENTITY_KINDS.map((entry) => [entry.layerId, entry.kind]),
|
||||
);
|
||||
const MAX_FRAMES = 120;
|
||||
|
||||
/** `position`'s local east/north/up offset from `origin`, in metres. */
|
||||
function enuOffset(origin, position) {
|
||||
const frame = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
|
||||
const local = Cesium.Matrix4.multiplyByPoint(
|
||||
Cesium.Matrix4.inverseTransformation(frame, new Cesium.Matrix4()),
|
||||
position,
|
||||
new Cesium.Cartesian3(),
|
||||
/** The followed subject, camera offset and displayed fix in share format. */
|
||||
export function readShareFollowSubject({ engine, nowMs = Date.now() }) {
|
||||
const handle = engine?.camera.following();
|
||||
const trackedId = String(
|
||||
handle?.label?.id || handle?.native?.gevTrackedId || '',
|
||||
);
|
||||
return { east: local.x, north: local.y, up: local.z };
|
||||
}
|
||||
|
||||
/**
|
||||
* The entity the camera follows as `{ kind, id, offset, lastKnown }`, with
|
||||
* the camera's offset from it and its displayed position as of `nowMs`; null
|
||||
* when the camera follows nothing a share link can name. A selected vessel is
|
||||
* not followed (the camera stays where the user puts it), so a link made then
|
||||
* keeps its own camera.
|
||||
*/
|
||||
export function readShareFollowSubject({ viewer, nowMs = Date.now() }) {
|
||||
const cameraPosition = viewer?.camera?.positionWC;
|
||||
if (!cameraPosition) return null;
|
||||
const tracked = viewer.trackedEntity;
|
||||
const trackedId = String(tracked?.gevTrackedId || '');
|
||||
const separator = trackedId.indexOf(':');
|
||||
if (separator <= 0) return null;
|
||||
const kind = KIND_BY_LAYER.get(trackedId.slice(0, separator));
|
||||
const id = trackedId.slice(separator + 1);
|
||||
const target = kind
|
||||
? trackedDisplayPositionForCamera(
|
||||
tracked,
|
||||
viewer.clock.currentTime,
|
||||
new Cesium.Cartesian3(),
|
||||
)
|
||||
: null;
|
||||
const target = kind ? (handle.label?.position?.() ?? handle.target()) : null;
|
||||
if (!kind || !id || !target) return null;
|
||||
const offset = followOffsetFromEnu(enuOffset(target, cameraPosition));
|
||||
const fix = Cesium.Cartographic.fromCartesian(target);
|
||||
const local = enuOffset(target, engine.camera.pose().position);
|
||||
const offset = followOffsetFromEnu({
|
||||
east: local.x,
|
||||
north: local.y,
|
||||
up: local.z,
|
||||
});
|
||||
const fix = geo.cartographic.fromCartesian(target);
|
||||
if (!offset || !fix) return null;
|
||||
return {
|
||||
kind,
|
||||
id,
|
||||
offset,
|
||||
lastKnown: {
|
||||
lat: Cesium.Math.toDegrees(fix.latitude),
|
||||
lon: Cesium.Math.toDegrees(fix.longitude),
|
||||
lat: geo.math.toDegrees(fix.latitude),
|
||||
lon: geo.math.toDegrees(fix.longitude),
|
||||
alt: fix.height,
|
||||
observedAtMs: nowMs,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Largest turn, in radians, the camera makes around the entity per frame. */
|
||||
const MAX_TURN_PER_FRAME = Math.PI / 3;
|
||||
|
||||
/**
|
||||
* Put the camera at a shared follow offset from `entity` once following it
|
||||
* has framed the camera. Cesium keeps the offset afterwards, as it keeps one
|
||||
* the user orbits to. The camera swings round the entity at most 60° a frame:
|
||||
* the follow's own guard treats a jump to the far side as the camera crossing
|
||||
* through the entity and puts it back. Returns a disposer.
|
||||
*/
|
||||
export function applyShareFollowOffset(viewer, entity, offset) {
|
||||
if (!viewer?.scene?.preUpdate || !entity || !(offset?.range > 0))
|
||||
/** Swing the current follow to a shared ENU offset; return its cancellation. */
|
||||
export function applyShareFollowOffset(engine, handle, offset) {
|
||||
if (!handle || engine?.camera.following() !== handle || !(offset?.range > 0))
|
||||
return () => {};
|
||||
const local = followOffsetToEnu(offset);
|
||||
let frames = 0;
|
||||
let remove = null;
|
||||
const stop = () => {
|
||||
remove?.();
|
||||
remove = null;
|
||||
handle.retarget({ swingTo: { x: local.east, y: local.north, z: local.up } });
|
||||
let stopped = false;
|
||||
return () => {
|
||||
if (stopped) return;
|
||||
stopped = true;
|
||||
if (engine.camera.following() === handle)
|
||||
handle.retarget({ swingTo: null });
|
||||
};
|
||||
remove = viewer.scene.preUpdate.addEventListener(() => {
|
||||
if (viewer.isDestroyed?.() || viewer.trackedEntity !== entity) {
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
frames += 1;
|
||||
const camera = viewer.camera;
|
||||
// Let the follow frame the camera first (its first frame), then move it.
|
||||
const framed =
|
||||
frames > 1 &&
|
||||
!Cesium.Matrix4.equals(camera.transform, Cesium.Matrix4.IDENTITY);
|
||||
const target = framed
|
||||
? trackedDisplayPositionForCamera(
|
||||
entity,
|
||||
viewer.clock.currentTime,
|
||||
new Cesium.Cartesian3(),
|
||||
)
|
||||
: null;
|
||||
if (!target) {
|
||||
if (frames >= MAX_FRAMES) stop();
|
||||
return;
|
||||
}
|
||||
// The offset is east/north/up at the entity; the follow's own frame may
|
||||
// differ, so place the camera in world space and re-express it there.
|
||||
const world = Cesium.Matrix4.multiplyByPoint(
|
||||
Cesium.Transforms.eastNorthUpToFixedFrame(target),
|
||||
new Cesium.Cartesian3(local.east, local.north, local.up),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const goal = Cesium.Matrix4.multiplyByPoint(
|
||||
Cesium.Matrix4.inverseTransformation(
|
||||
camera.transform,
|
||||
new Cesium.Matrix4(),
|
||||
),
|
||||
world,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const from = Cesium.Cartesian3.clone(
|
||||
camera.position,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
const angle =
|
||||
Cesium.Cartesian3.magnitude(from) > 0
|
||||
? Cesium.Cartesian3.angleBetween(from, goal)
|
||||
: 0;
|
||||
const done = !(angle > MAX_TURN_PER_FRAME);
|
||||
const next = done ? goal : turnToward(from, goal, MAX_TURN_PER_FRAME);
|
||||
camera.lookAtTransform(camera.transform, next);
|
||||
viewer.scene.requestRender?.();
|
||||
if (done) stop();
|
||||
});
|
||||
return stop;
|
||||
}
|
||||
|
||||
/**
|
||||
* `from` turned `step` radians toward `to`, with its length moved the same
|
||||
* fraction of the way: one frame of the swing round the entity.
|
||||
*/
|
||||
function turnToward(from, to, step) {
|
||||
const angle = Cesium.Cartesian3.angleBetween(from, to);
|
||||
const unitFrom = Cesium.Cartesian3.normalize(from, new Cesium.Cartesian3());
|
||||
// The direction perpendicular to `from` in the plane toward `to` (or any
|
||||
// perpendicular when they are opposite).
|
||||
let toward = Cesium.Cartesian3.subtract(
|
||||
Cesium.Cartesian3.normalize(to, new Cesium.Cartesian3()),
|
||||
Cesium.Cartesian3.multiplyByScalar(
|
||||
unitFrom,
|
||||
Math.cos(angle),
|
||||
new Cesium.Cartesian3(),
|
||||
),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
if (Cesium.Cartesian3.magnitude(toward) < 1e-9)
|
||||
toward = Cesium.Cartesian3.cross(
|
||||
unitFrom,
|
||||
Math.abs(unitFrom.z) < 0.9
|
||||
? Cesium.Cartesian3.UNIT_Z
|
||||
: Cesium.Cartesian3.UNIT_X,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
Cesium.Cartesian3.normalize(toward, toward);
|
||||
const length =
|
||||
Cesium.Cartesian3.magnitude(from) +
|
||||
(Cesium.Cartesian3.magnitude(to) - Cesium.Cartesian3.magnitude(from)) *
|
||||
(step / angle);
|
||||
const direction = Cesium.Cartesian3.add(
|
||||
Cesium.Cartesian3.multiplyByScalar(
|
||||
unitFrom,
|
||||
Math.cos(step),
|
||||
new Cesium.Cartesian3(),
|
||||
),
|
||||
Cesium.Cartesian3.multiplyByScalar(
|
||||
toward,
|
||||
Math.sin(step),
|
||||
new Cesium.Cartesian3(),
|
||||
),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
return Cesium.Cartesian3.multiplyByScalar(direction, length, direction);
|
||||
}
|
||||
+133
-101
@@ -1,3 +1,6 @@
|
||||
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
|
||||
import { createCesiumMoversEngine } from '../testSupport/cesiumMoversEngine.mjs';
|
||||
import { enuOffset } from '../globe/follow.js';
|
||||
import { viewerEngine } from '../testSupport/viewerEngine.mjs';
|
||||
// Short share links: `/share/<code>` opens through the start-up restore
|
||||
// pipeline, the address then follows the live view, and the share button
|
||||
@@ -127,7 +130,8 @@ function openPage(t, href, { managerOptions = {}, tracking = null } = {}) {
|
||||
const clock = installManualTimers(t);
|
||||
const viewer = fakeViewer();
|
||||
const restores = [];
|
||||
const manager = new ShareLinkManager(viewerEngine(viewer), {
|
||||
const engine = viewerEngine(viewer);
|
||||
const manager = new ShareLinkManager(engine, {
|
||||
onRestore: async (state) => restores.push(state),
|
||||
isNavigationCurrent: () => true,
|
||||
...managerOptions,
|
||||
@@ -135,7 +139,8 @@ function openPage(t, href, { managerOptions = {}, tracking = null } = {}) {
|
||||
const notices = [];
|
||||
let generation = 0;
|
||||
const owner = new ShareRestoration({
|
||||
viewer,
|
||||
engine,
|
||||
canvas: viewer.canvas,
|
||||
navigation: {
|
||||
_beginDeferredNavigation: () => ++generation,
|
||||
_reassertNavigationHandoff: () => true,
|
||||
@@ -147,7 +152,7 @@ function openPage(t, href, { managerOptions = {}, tracking = null } = {}) {
|
||||
feedback: {},
|
||||
updateFeedback() {},
|
||||
applyFollowOffset: (entity, offset) =>
|
||||
applyShareFollowOffset(viewer, entity, offset),
|
||||
applyShareFollowOffset(engine, entity, offset),
|
||||
});
|
||||
// Notices are checked by message; their start-up-cover timing is not.
|
||||
owner._presentAfterStartupCover = (message) => notices.push(message);
|
||||
@@ -161,7 +166,16 @@ function openPage(t, href, { managerOptions = {}, tracking = null } = {}) {
|
||||
};
|
||||
owner.start();
|
||||
t.after(() => owner.destroy());
|
||||
return { ...page, ...clock, viewer, manager, owner, restores, notices };
|
||||
return {
|
||||
...page,
|
||||
...clock,
|
||||
viewer,
|
||||
engine,
|
||||
manager,
|
||||
owner,
|
||||
restores,
|
||||
notices,
|
||||
};
|
||||
}
|
||||
|
||||
/** Run the delayed start-up restore and let it settle. */
|
||||
@@ -246,7 +260,11 @@ test('a thing view turns its layer on, follows by id and frames the shared offse
|
||||
const page = openPage(t, `http://localhost/share/${aircraftCode()}`, {
|
||||
tracking: (owner) => {
|
||||
// What the coordinator does when the aircraft is in the feed.
|
||||
owner.viewer.trackedEntity = entity;
|
||||
owner.engine.camera.follow({
|
||||
native: entity,
|
||||
position: entity.gevDisplayPosition,
|
||||
viewFrom: { x: 0, y: -4800, z: 3300 },
|
||||
});
|
||||
owner._handleShareTrackingRestoreStatus({
|
||||
layerId: 'flights',
|
||||
targetId: 'a1b2c3',
|
||||
@@ -256,29 +274,6 @@ test('a thing view turns its layer on, follows by id and frames the shared offse
|
||||
},
|
||||
});
|
||||
const target = Cesium.Cartesian3.fromDegrees(FIX.lon, FIX.lat, FIX.alt);
|
||||
const listeners = [];
|
||||
const looks = [];
|
||||
Object.assign(page.viewer, {
|
||||
clock: { currentTime: Cesium.JulianDate.now() },
|
||||
scene: {
|
||||
preUpdate: {
|
||||
addEventListener(fn) {
|
||||
listeners.push(fn);
|
||||
return () => listeners.splice(listeners.indexOf(fn), 1);
|
||||
},
|
||||
},
|
||||
},
|
||||
isDestroyed: () => false,
|
||||
});
|
||||
Object.assign(page.viewer.camera, {
|
||||
transform: Cesium.Transforms.eastNorthUpToFixedFrame(target),
|
||||
// The app's own follow framing: south of the aircraft and above it.
|
||||
position: new Cesium.Cartesian3(0, -4800, 3300),
|
||||
lookAtTransform(transform, offset) {
|
||||
looks.push(offset);
|
||||
this.position = Cesium.Cartesian3.clone(offset);
|
||||
},
|
||||
});
|
||||
entity = {
|
||||
gevTrackedId: 'flights:a1b2c3',
|
||||
gevDisplayPosition: () => target,
|
||||
@@ -304,16 +299,12 @@ test('a thing view turns its layer on, follows by id and frames the shared offse
|
||||
);
|
||||
// Once followed, the camera takes the shared offset after the follow's
|
||||
// own first frame.
|
||||
assert.equal(listeners.length, 1);
|
||||
listeners[0]();
|
||||
assert.equal(looks.length, 0);
|
||||
listeners[0]?.();
|
||||
assert.equal(looks.length, 1);
|
||||
for (let i = 0; i < 10; i++) page.engine.fake.frame();
|
||||
const local = enuOffset(target, page.engine.camera.pose().position);
|
||||
const expected = followOffsetToEnu(OFFSET);
|
||||
assert.ok(Math.abs(looks[0].x - expected.east) < 1);
|
||||
assert.ok(Math.abs(looks[0].y - expected.north) < 1);
|
||||
assert.ok(Math.abs(looks[0].z - expected.up) < 1);
|
||||
assert.equal(listeners.length, 0, 'the offset is applied once');
|
||||
assert.ok(Math.abs(local.x - expected.east) < 1);
|
||||
assert.ok(Math.abs(local.y - expected.north) < 1);
|
||||
assert.ok(Math.abs(local.z - expected.up) < 1);
|
||||
assert.deepEqual(page.notices, []);
|
||||
});
|
||||
|
||||
@@ -477,7 +468,17 @@ test('the followed entity is read in the share format, and its offset round-trip
|
||||
gevDisplayPosition: () => target,
|
||||
},
|
||||
};
|
||||
const subject = readShareFollowSubject({ viewer, nowMs: NOW_MS });
|
||||
const engine = {
|
||||
camera: {
|
||||
pose: () => ({ position: cameraPosition }),
|
||||
following: () =>
|
||||
viewer.trackedEntity && {
|
||||
native: viewer.trackedEntity,
|
||||
target: () => target,
|
||||
},
|
||||
},
|
||||
};
|
||||
const subject = readShareFollowSubject({ engine, nowMs: NOW_MS });
|
||||
assert.equal(subject.kind, 'military_aircraft');
|
||||
assert.equal(subject.id, 'ae1234');
|
||||
assert.deepEqual(subject.offset, offset);
|
||||
@@ -485,74 +486,80 @@ test('the followed entity is read in the share format, and its offset round-trip
|
||||
assert.ok(Math.abs(subject.lastKnown.alt - FIX.alt) < 1e-3);
|
||||
// A followed entity the share format has no kind for is not a thing view.
|
||||
viewer.trackedEntity.gevTrackedId = 'local-adsb:abc';
|
||||
assert.equal(readShareFollowSubject({ viewer }), null);
|
||||
assert.equal(readShareFollowSubject({ engine }), null);
|
||||
// Nor is a camera that follows nothing (a selected vessel is not followed).
|
||||
viewer.trackedEntity = undefined;
|
||||
assert.equal(readShareFollowSubject({ viewer }), null);
|
||||
assert.equal(readShareFollowSubject({ engine }), null);
|
||||
});
|
||||
|
||||
test('a shared offset on the far side swings round, never jumping through the entity', () => {
|
||||
const target = Cesium.Cartesian3.fromDegrees(FIX.lon, FIX.lat, FIX.alt);
|
||||
const listeners = [];
|
||||
const looks = [];
|
||||
const entity = { gevDisplayPosition: () => target };
|
||||
const viewer = {
|
||||
clock: { currentTime: Cesium.JulianDate.now() },
|
||||
scene: {
|
||||
preUpdate: {
|
||||
addEventListener(fn) {
|
||||
listeners.push(fn);
|
||||
return () => listeners.splice(listeners.indexOf(fn), 1);
|
||||
},
|
||||
},
|
||||
},
|
||||
trackedEntity: entity,
|
||||
camera: {
|
||||
transform: Cesium.Transforms.eastNorthUpToFixedFrame(target),
|
||||
position: new Cesium.Cartesian3(0, -4800, 3300),
|
||||
lookAtTransform(transform, offset) {
|
||||
looks.push(Cesium.Cartesian3.clone(offset));
|
||||
this.position = Cesium.Cartesian3.clone(offset);
|
||||
},
|
||||
},
|
||||
};
|
||||
// Looking south at the nose: the opposite side of the app's framing.
|
||||
const offset = { range: 5800, heading: 180, pitch: -35 };
|
||||
applyShareFollowOffset(viewer, entity, offset);
|
||||
let previous = viewer.camera.position;
|
||||
for (let frame = 0; frame < 10 && listeners.length; frame += 1) {
|
||||
listeners[0]();
|
||||
const now = viewer.camera.position;
|
||||
// The follow's guard treats a turn of 90° or more as a crossing.
|
||||
assert.ok(Cesium.Cartesian3.angleBetween(previous, now) < Math.PI / 2);
|
||||
previous = now;
|
||||
}
|
||||
assert.equal(listeners.length, 0, 'it arrives');
|
||||
assert.ok(looks.length >= 2, `${looks.length} steps`);
|
||||
const expected = followOffsetToEnu(offset);
|
||||
const last = looks.at(-1);
|
||||
assert.ok(Math.abs(last.x - expected.east) < 1);
|
||||
assert.ok(Math.abs(last.y - expected.north) < 1);
|
||||
assert.ok(Math.abs(last.z - expected.up) < 1);
|
||||
});
|
||||
for (const kind of ['fake', 'cesium']) {
|
||||
test(`${kind}: a shared offset swings round without crossing the target`, () => {
|
||||
const fixture = kind === 'cesium' ? createCesiumMoversEngine() : null;
|
||||
const engine = fixture?.engine ?? createFakeEngine();
|
||||
const frame = fixture?.frame ?? (() => engine.fake.frame());
|
||||
const target = Cesium.Cartesian3.fromDegrees(FIX.lon, FIX.lat, FIX.alt);
|
||||
const handle = engine.camera.follow({
|
||||
position: () => target,
|
||||
viewFrom: { x: 0, y: -4800, z: 3300 },
|
||||
label: { id: 'flights:abc123', position: () => target },
|
||||
});
|
||||
frame();
|
||||
const offset = { range: 5800, heading: 180, pitch: -35 };
|
||||
const stop = applyShareFollowOffset(engine, handle, offset);
|
||||
let previous = enuOffset(target, engine.camera.pose().position);
|
||||
let turns = 0;
|
||||
for (let i = 0; i < 10; i++) {
|
||||
frame();
|
||||
const now = enuOffset(target, engine.camera.pose().position);
|
||||
const angle = Cesium.Cartesian3.angleBetween(previous, now);
|
||||
assert.ok(angle <= Math.PI / 3 + 1e-8);
|
||||
if (angle > 1e-8) turns++;
|
||||
previous = now;
|
||||
}
|
||||
assert.ok(turns >= 2);
|
||||
const expected = followOffsetToEnu(offset);
|
||||
assert.ok(Math.abs(previous.x - expected.east) < 1);
|
||||
assert.ok(Math.abs(previous.y - expected.north) < 1);
|
||||
assert.ok(Math.abs(previous.z - expected.up) < 1);
|
||||
assert.deepEqual(readShareFollowSubject({ engine }).offset, offset);
|
||||
stop();
|
||||
stop();
|
||||
handle.stop();
|
||||
assert.equal(readShareFollowSubject({ engine }), null);
|
||||
engine.destroy();
|
||||
});
|
||||
|
||||
test('applying a follow offset gives up when the follow ends', () => {
|
||||
const listeners = [];
|
||||
const viewer = {
|
||||
scene: {
|
||||
preUpdate: {
|
||||
addEventListener(fn) {
|
||||
listeners.push(fn);
|
||||
return () => listeners.splice(listeners.indexOf(fn), 1);
|
||||
},
|
||||
},
|
||||
},
|
||||
trackedEntity: null,
|
||||
};
|
||||
applyShareFollowOffset(viewer, {}, OFFSET);
|
||||
listeners[0]();
|
||||
assert.equal(listeners.length, 0);
|
||||
});
|
||||
test(`${kind}: cancelling a swing or ending its follow releases the camera`, () => {
|
||||
const fixture = kind === 'cesium' ? createCesiumMoversEngine() : null;
|
||||
const engine = fixture?.engine ?? createFakeEngine();
|
||||
const frame = fixture?.frame ?? (() => engine.fake.frame());
|
||||
const target = Cesium.Cartesian3.fromDegrees(FIX.lon, FIX.lat, FIX.alt);
|
||||
const handle = engine.camera.follow({
|
||||
position: () => target,
|
||||
viewFrom: { x: 0, y: -4800, z: 3300 },
|
||||
});
|
||||
frame();
|
||||
const stop = applyShareFollowOffset(engine, handle, OFFSET);
|
||||
stop();
|
||||
const before = engine.camera.pose().position;
|
||||
frame();
|
||||
frame();
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.distance(before, engine.camera.pose().position) < 1e-6,
|
||||
);
|
||||
applyShareFollowOffset(engine, handle, OFFSET);
|
||||
handle.stop();
|
||||
engine.camera.setView({ destination: target });
|
||||
const released = engine.camera.pose().position;
|
||||
frame();
|
||||
frame();
|
||||
assert.ok(
|
||||
Cesium.Cartesian3.distance(released, engine.camera.pose().position) <
|
||||
1e-6,
|
||||
);
|
||||
engine.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
test('long links and hash navigation are unaffected by a share code start', async (t) => {
|
||||
// A long link still opens from the hash.
|
||||
@@ -572,3 +579,28 @@ test('long links and hash navigation are unaffected by a share code start', asyn
|
||||
assert.equal(page.restores.length, 2);
|
||||
assert.equal(page.restores[1].style, 'normal');
|
||||
});
|
||||
|
||||
test('a share reads the displayed label fix without advancing follow interpolation', () => {
|
||||
const engine = createFakeEngine();
|
||||
const target = Cesium.Cartesian3.fromDegrees(FIX.lon, FIX.lat, FIX.alt);
|
||||
const local = followOffsetToEnu(OFFSET);
|
||||
engine.camera.setView({
|
||||
destination: Cesium.Matrix4.multiplyByPoint(
|
||||
Cesium.Transforms.eastNorthUpToFixedFrame(target),
|
||||
new Cesium.Cartesian3(local.east, local.north, local.up),
|
||||
new Cesium.Cartesian3(),
|
||||
),
|
||||
});
|
||||
engine.camera.follow({
|
||||
position: () => {
|
||||
throw new Error('must use the display cache');
|
||||
},
|
||||
viewFrom: { x: 0, y: -900, z: 400 },
|
||||
label: { id: 'flights:cached', position: () => target },
|
||||
});
|
||||
const subject = readShareFollowSubject({ engine });
|
||||
assert.equal(subject.id, 'cached');
|
||||
assert.deepEqual(subject.offset, OFFSET);
|
||||
assert.ok(Math.abs(subject.lastKnown.alt - FIX.alt) < 0.01);
|
||||
engine.destroy();
|
||||
});
|
||||
@@ -108,8 +108,8 @@ export function sharedFixNotice(entity, observedAtMs, nowMs = Date.now()) {
|
||||
/** Own initial share restoration, durable layer state and restoration notices. */
|
||||
export class ShareRestoration {
|
||||
constructor({
|
||||
viewer,
|
||||
canvas = viewer?.canvas,
|
||||
engine,
|
||||
canvas = engine?.host.canvas,
|
||||
handoffLayers = null,
|
||||
navigation,
|
||||
syncShareState,
|
||||
@@ -120,7 +120,7 @@ export class ShareRestoration {
|
||||
applyFollowOffset = null,
|
||||
}) {
|
||||
Object.assign(this, {
|
||||
viewer,
|
||||
engine,
|
||||
canvas,
|
||||
handoffLayers,
|
||||
navigation,
|
||||
@@ -129,7 +129,7 @@ export class ShareRestoration {
|
||||
showStatus,
|
||||
feedback,
|
||||
updateFeedback,
|
||||
// (entity, offset) => disposer: frame a followed entity from a shared
|
||||
// (handle, offset) => disposer: frame a followed entity from a shared
|
||||
// follow offset (shareFollow.js).
|
||||
applyFollowOffset,
|
||||
});
|
||||
@@ -477,17 +477,17 @@ export class ShareRestoration {
|
||||
/** Frame a shared entity the camera now follows from the shared offset. */
|
||||
_applySharedFollowOffset(result) {
|
||||
const view = this._sharedThingFor(result);
|
||||
const entity = this.viewer?.trackedEntity;
|
||||
const handle = this.engine?.camera.following();
|
||||
// Only a link made while following carries a real offset (with the fix);
|
||||
// a long link's follow keeps the app's own framing.
|
||||
if (
|
||||
!view?.lastKnown ||
|
||||
String(entity?.gevTrackedId || '') !==
|
||||
String(handle?.label?.id || handle?.native?.gevTrackedId || '') !==
|
||||
`${result.layerId}:${result.targetId}`
|
||||
)
|
||||
return;
|
||||
this._stopFollowOffset?.();
|
||||
this._stopFollowOffset = this.applyFollowOffset?.(entity, view.offset);
|
||||
this._stopFollowOffset = this.applyFollowOffset?.(handle, view.offset);
|
||||
}
|
||||
|
||||
cancelSelection() {
|
||||
|
||||
@@ -69,7 +69,7 @@ test('share teardown settles its promise, removes gestures and rejects a retaine
|
||||
let stamps = 0;
|
||||
let applies = 0;
|
||||
const owner = new ShareRestoration({
|
||||
viewer: { canvas },
|
||||
engine: { host: { canvas } },
|
||||
navigation: {
|
||||
_beginDeferredNavigation: () => 1,
|
||||
_reassertNavigationHandoff: () => true,
|
||||
|
||||
Reference in new issue
Block a user