Draw the last native world labels through the label overlay

The Directions A and B letters and a data pack's media label were the two
Cesium text labels left, kept by an allow-list in noCesiumLabels.test.mjs.
Both now publish entries to the shared world-overlay host, and the
allow-list is gone, so any Cesium label in src is a test failure.

Directions publishes the letters to the directions-markers source; the
markers keep only their points. A clicked endpoint's letter hangs over the
surface that was clicked. One placed without a click stays hidden until its
ground-floor cell resolves, then requests a render, so a still camera shows
it; a cell that settles with no height falls back to the ellipsoid. Each
position is computed once.

A pack resource handle gains label(entry). The application passes its
shared overlay host to SceneDirector through dataPacks.overlayHost; without
one a media pack fails to load rather than drawing a native label. Each
labelled resource takes a source from a pool and returns it on dispose, as
the host never removes a source, so two presentations of one pack never
clear each other's labels and repeat loads add no sources. A label written
after dispose is ignored. The media label is protected, so it always draws
as before.

Live (Denver, keyless globe): a clicked A and a programmatic B both anchor
on their dots over 1.58 km ground. Documented in docs/CURRENT-STATE.md and
docs/DIRECTOR-DATA-PACKS.md.
This commit is contained in:
Sameh Khamis committed 2026-11-04 12:30:31 -08:00
1 parent 18d6e3292d
commit 464c29a9ed
12 files changed
+382 -44

No files matched your search

+51 -8
View File
@@ -5,11 +5,20 @@ import { applicationPinia } from '../../ui/vueRuntime.js';
const xyz = (p) => Cesium.Cartesian3.fromDegrees(...p);
const MEDIA_MARKER_CSS = '#ffff00';
// Key every panel and card on the page, so a new one never reuses an old
// one's DOM.
let panelKeys = 0,
cardKeys = 0;
// Label overlay sources, one per pack resource while it shows text, so two
// presentations of one pack never share or clear each other's labels. The host
// keeps a source once made, so a disposed resource returns its id for reuse
// and the count stays at the most labelled resources ever shown at once.
let labelSources = 0;
const freeLabelSources = [];
/**
* Create rendering adapters; data acquisition and authored placement stay
* independent. Each pack's attribution card is presented to the data packs
@@ -18,7 +27,7 @@ let panelKeys = 0,
export function createPackPresentations(
viewer,
targets = new Map(),
{ store = useDataPacksStore(applicationPinia()) } = {},
{ store = useDataPacksStore(applicationPinia()), overlayHost = null } = {},
) {
const owner = {};
let key,
@@ -56,8 +65,10 @@ export function createPackPresentations(
const entities = [],
primitives = [],
materials = [],
urls = [];
urls = [],
labels = [];
const featureKeys = [];
let labelSource = null;
let card,
destroyed = false;
return {
@@ -72,6 +83,21 @@ export function createPackPresentations(
viewer.scene.requestRender();
return entity;
},
/**
* World text for this pack, as a label-overlay entry in the pack's own
* source. The application passes the shared host; there is no text
* without one, so a pack that needs it fails to load instead.
*/
label(entry) {
if (!overlayHost) throw new Error('Pack labels need an overlay host');
// A late adapter writing after disposal must not take a source again.
if (destroyed) return;
labelSource ||=
freeLabelSources.pop() ?? `data-pack-labels:${++labelSources}`;
labels.push(entry);
overlayHost.setEntries(labelSource, labels.slice());
viewer.scene.requestRender();
},
primitive(value) {
primitives.push(viewer.scene.primitives.add(value));
if (value.appearance?.material)
@@ -98,6 +124,12 @@ export function createPackPresentations(
// The view stops a removed card's player as it goes.
if (card) removeCard(card);
for (const entity of entities.splice(0)) viewer.entities.remove(entity);
if (labelSource) {
labels.length = 0;
overlayHost.clearSource(labelSource);
freeLabelSources.push(labelSource);
labelSource = null;
}
for (const primitive of primitives.splice(0))
viewer.scene.primitives.remove(primitive);
for (const material of materials.splice(0)) {
@@ -200,16 +232,27 @@ export function createPackPresentations(
(item) => item.id === pack.placement.anchorId,
);
if (!anchor) throw new Error('Missing media anchor');
const position = xyz([anchor.lon, anchor.lat, anchor.alt]);
handle.add({
name: pack.id,
position: xyz([anchor.lon, anchor.lat, anchor.alt]),
point: { pixelSize: 16, color: Cesium.Color.YELLOW },
label: {
text: pack.id,
font: '14px sans-serif',
pixelOffset: new Cesium.Cartesian2(0, -24),
position,
point: {
pixelSize: 16,
color: Cesium.Color.fromCssColorString(MEDIA_MARKER_CSS),
},
});
handle.label({
id: 'media',
position,
variant: 'label',
title: pack.id,
accent: MEDIA_MARKER_CSS,
protected: true,
interactive: false,
gapPx: 15,
verticalOnly: true,
placement: 'above',
});
handle.media({
kind: asset.mimeType.startsWith('video/') ? 'video' : 'audio',
src: handle.url(new Blob([asset.bytes], { type: asset.mimeType })),