Draw the session annotation board on Navara: draped areas and routes as clamped meshes, every other mark on the shared screen board over the engine's projector

This commit is contained in:
German Khokhlov committed 2026-11-03 20:59:10 +04:00
1 parent 5b7171f485
commit 96b5b0bb1f
13 files changed
+1147 -84

No files matched your search

+1 -1
View File
@@ -468,7 +468,7 @@ export function attachViewerlessTools(
defer(() => styleManager._clearPersistentStatusNotice?.());
// The page session's annotation board, Draw and Import on this engine
// (src/app/navaraTools.js).
const tools = { engine, view: navaraViews.get(engine) };
const tools = { engine, views: navaraViews.get(engine) };
const context = { operations, placeSearch, layerSession, styleManager };
const annotations = attachNavaraAnnotations(tools, context, {
signal,
+27 -4
View File
@@ -2,12 +2,35 @@
// Navara engine (src/app/sessionTools.js holds the tools themselves). Loaded
// with src/app/navaraMode.js, so the Cesium-mode bundle carries none of it.
import { createNavaraAnnotationRenderer } from '../annotations/navaraAnnotationRenderer.js';
import { sessionAnnotations } from './sessionTools.js';
/**
* The annotation board drawn on this Navara scene. Returns the board, or
* null while the engine draws no annotations.
* The annotation board drawn on this Navara scene: draped areas and routes
* on the engine, every other mark on the shared screen board. The board
* belongs to the page session; an engine switch takes only its drawing off
* this engine. Returns the board (null without the Navara view).
* @param {{ engine: object, views: object }} scene `views`: the Navara view
* and its classes (src/app/navaraMode.js).
*/
export function attachNavaraAnnotations() {
return null;
export function attachNavaraAnnotations(
{ engine, views },
{ layerSession, placeSearch, operations },
{ defer },
) {
if (!views?.view) return null;
const annotations = sessionAnnotations({
layerSession,
placeSearch,
resolver: operations.annotationResolver,
defer,
});
annotations.attachScene({
engine,
renderer: createNavaraAnnotationRenderer(engine, views),
});
defer(() => annotations.detachScene());
return annotations;
}
/** UTILITIES ▸ Draw on this Navara scene; null while it has none. */
+95
View File
@@ -0,0 +1,95 @@
import '../testSupport/registerDom.mjs';
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
import { attachNavaraAnnotations } from './navaraTools.js';
function fakeViews() {
const meshes = [];
class NavaraColor {
setHex() {
return this;
}
toArray() {
return [1, 1, 1];
}
setRGBLinear() {
return this;
}
}
return {
meshes,
views: {
view: {
addMesh(config) {
const mesh = { config, deleted: false };
meshes.push(mesh);
return {
update() {},
delete() {
mesh.deleted = true;
},
};
},
},
NavaraColor,
},
};
}
test('Navara attaches the page session board and its switch takes only the drawing', async () => {
const lifetime = new AbortController();
const layerSession = { lifetime };
const engine = createFakeEngine({ kind: 'navara' });
const { views, meshes } = fakeViews();
const context = {
layerSession,
placeSearch: null,
operations: { annotationResolver: null },
};
const attach = () => {
const cleanups = [];
const board = attachNavaraAnnotations({ engine, views }, context, {
defer: (cleanup) => cleanups.push(cleanup),
});
return { board, detach: () => cleanups.reverse().forEach((c) => c()) };
};
const first = attach();
assert.ok(first.board);
assert.equal(first.board, layerSession.annotations);
assert.equal(first.board.attached, true);
assert.equal(window.__gevAnnotations, first.board);
const result = await first.board.annotate(
[
{
type: 'area',
manual: true,
ring: [
[0, 0],
[1, 0],
[1, 1],
],
},
],
{ flyTo: false },
);
assert.equal(result.drawn, 1);
assert.equal(meshes.filter((mesh) => !mesh.deleted).length, 2);
first.detach();
assert.equal(first.board.attached, false);
assert.equal(first.board.count(), 1, 'the marks stay on the session board');
assert.equal(meshes.filter((mesh) => !mesh.deleted).length, 0);
const second = attach();
assert.equal(second.board, first.board, 'one board for the page session');
assert.equal(meshes.filter((mesh) => !mesh.deleted).length, 2);
second.detach();
lifetime.abort();
assert.equal(window.__gevAnnotations, undefined);
// Without the Navara view there is nothing to draw on.
assert.equal(
attachNavaraAnnotations({ engine, views: undefined }, context, {
defer() {},
}),
null,
);
});