Keep the annotation board across engine switches and draw it again on Cesium

The marks belong to the page session; only their drawing belongs to the attached viewer. A switch takes the drawing off, keeps the marks, and the next Cesium attachment draws them again. Without a viewer the board refuses new annotations instead of failing in the resolver.
This commit is contained in:
German Khokhlov committed 2026-11-03 17:24:39 +04:00
1 parent 05578c61b9
commit 111ba1626c
6 files changed
+239 -28

No files matched your search

+40 -8
View File
@@ -1,5 +1,5 @@
import { SceneDirector } from '../scenes/director.js';
import { initAnnotations } from '../annotations/index.js';
import { createSessionAnnotations } from '../annotations/index.js';
import { initDrawTool } from '../annotations/drawTool.js';
import { initGeoFileImport } from '../ui/geoFileImport.js';
import { useDisplayStore } from '../ui/stores/display.js';
@@ -18,6 +18,38 @@ import {
releaseContinuousRender,
} from '../renderGovernor.js';
/**
* The annotation board: the page session's when there is one (created once,
* destroyed with the page), else this application's.
*/
export function sessionAnnotations({
layerSession,
placeSearch,
resolver,
defer,
}) {
const create = () => createSessionAnnotations({ placeSearch, resolver });
if (!layerSession) {
const annotations = create();
defer(() => destroyAnnotations(annotations));
return annotations;
}
if (!layerSession.annotations) {
const annotations = (layerSession.annotations = create());
layerSession.lifetime.signal.addEventListener(
'abort',
() => destroyAnnotations(annotations),
{ once: true },
);
}
return layerSession.annotations;
}
function destroyAnnotations(annotations) {
if (window.__gevAnnotations === annotations) delete window.__gevAnnotations;
annotations.destroy();
}
/**
* Attach scene tools, rendering listeners and the application debug handle.
* Without a viewer (the experimental Navara engine) the viewer-bound tools
@@ -90,16 +122,16 @@ export function createApplicationTools({
}),
);
}
const annotations = initAnnotations({
viewer,
tileset,
// The annotation board belongs to the page session when there is one: an
// engine switch only takes its drawing off this viewer.
const annotations = sessionAnnotations({
layerSession,
placeSearch,
resolver: operations.annotationResolver,
defer,
});
defer(() => {
if (window.__gevAnnotations === annotations) delete window.__gevAnnotations;
annotations.destroy();
});
annotations.attachScene({ viewer, tileset });
defer(() => annotations.detachScene());
const displayStore = useDisplayStore(applicationPinia());
// The Display panel's controls answer through the store; returns the
// disconnect.