Draw the Recent Imagery box preview through the draw port, off the Cesium list

The box being dragged was two Cesium entities on a data source of its own.
It is now a clamped colour rectangle in a shapes set and a draped dashed
outline in a lines set, both unpickable, with the same colour, alpha,
width and dash length. The Cesium draw port now redraws a moved clamped
fill in the frame it moves, so the box shows on every frame of the drag.
The fill shows once the box has an area. The outline shows once the box
has any extent, so a drag along one axis still draws a line. The last box
is kept hidden between drags, and the next drag moves it.

markBaseTileset moves to a Cesium-free module, src/render/baseTilesets.js.
The globe port reads it and re-exports it, so a tileset a caller marks
as its base is still draped on. rendering.js no longer imports Cesium or
reaches the viewer and leaves the Cesium allow-list. The application's
tools loaded the globe factory only through it, so embed.js now loads it.
This commit is contained in:
Sameh Khamis committed 2026-11-08 21:18:56 -08:00
1 parent 3276a3346e
commit 04a764ed86
11 files changed
+307 -104

No files matched your search

+46
View File
@@ -6256,3 +6256,49 @@ test('clamped fills drawn alone by a host still retiring count toward MOVING_SHA
);
set.dispose();
}));
test('the recent imagery box preview drags its ground fill and dashed edge frame by frame on a viewer of its own', async () => {
const { createImageryBoxPreview } =
await import('../../layers/recentImagery/rendering.js');
const destroyed = withImageClasses(() =>
withTerrainHeights(() => {
const scene = fakeScene();
const viewer = { scene, isDestroyed: () => false };
let box = { west: -98, south: 30, east: -97.95, north: 30.05 };
const preview = createImageryBoxPreview(viewer, () => box);
preview.setVisible(true);
const hosts = scene.added.slice();
assert.equal(hosts.length, 2, 'a fill set and an edge set');
const groundIn = (host) => {
for (let i = 0; i < host.length; i++)
if (host.get(i) instanceof Cesium.GroundPrimitive) return host.get(i);
return null;
};
const fillHost = hosts.find((h) => groundIn(h));
assert.ok(fillHost, 'the fill is a ground primitive');
// Each move of the drag is drawn in the frame it is made, in place.
for (const east of [-97.9, -97.85, -97.8]) {
box = { ...box, east };
preview.changed();
const solo = fillHost.get(fillHost.length - 1);
assert.ok(solo instanceof Cesium.GroundPrimitive);
assert.equal(solo.asynchronous, false);
assert.ok(
Cesium.Rectangle.equalsEpsilon(
solo.geometryInstances[0].geometry._rectangle,
Cesium.Rectangle.fromDegrees(-98, 30, east, 30.05),
1e-12,
),
);
}
assert.deepEqual(scene.added, hosts, 'no set rebuilt');
const edgeHost = hosts.find((h) => h !== fillHost);
const edge = edgeHost.get(edgeHost.length - 1);
assert.ok(edge instanceof Cesium.GroundPolylinePrimitive);
assert.equal(edge.asynchronous, false);
assert.equal(edge.appearance.material.type, 'PolylineDash');
return preview.destroy().then(() => scene.added.length);
}),
);
assert.equal(await destroyed, 0, 'both sets let go');
});
+8 -16
View File
@@ -7,9 +7,9 @@
*
* Imagery drapes on the globe, or on the drawn base tileset: the photoreal
* tileset this port loaded, or one the application's map stack marked as
* its base (`markBaseTileset`) while it still loads its own. Where each
* layer drapes follows what is drawn, looked at every frame, so a base
* switched outside the port moves the layers with it.
* its base (`markBaseTileset`, `../baseTilesets.js`) while it still loads
* its own. Where each layer drapes follows what is drawn, looked at every
* frame, so a base switched outside the port moves the layers with it.
*
* The sky reads the scene as it was set up and writes through to it; what
* the scene has no part for (stars without a sky box, say) is kept as set.
@@ -17,21 +17,13 @@
import * as Cesium from 'cesium';
import { loadPhotorealisticTileset } from '../../maps/google3d.js';
import { provideUnboundGlobe } from '../rendererOf.js';
import { isBaseTileset, markBaseTileset } from '../baseTilesets.js';
import { listenerList, uncaught } from './common.js';
import { createCesiumImagery } from './imagery.js';
/** Tilesets the application's map stack draws as its base. */
const baseTilesets = new WeakSet();
/**
* Mark a tileset as a base the application draws outside the port, so
* imagery drapes on it while it is shown. For code that still loads its
* own base; the port's own photoreal tileset needs no mark.
* @param {object} tileset Cesium `Cesium3DTileset`.
*/
export function markBaseTileset(tileset) {
if (tileset && typeof tileset === 'object') baseTilesets.add(tileset);
}
// The base marks live outside the adapter, so code that is not Cesium's can
// mark a base; they are re-exported here for the code that still is.
export { markBaseTileset };
/** Ion's world terrain asset. */
const WORLD_TERRAIN_ASSET = 1;
@@ -195,7 +187,7 @@ export function createCesiumGlobe(
if (photoreal && !photoreal.isDestroyed() && photoreal.show)
return photoreal;
for (const tileset of tilesets())
if (baseTilesets.has(tileset) && tileset.show && !tileset.isDestroyed())
if (isBaseTileset(tileset) && tileset.show && !tileset.isDestroyed())
return tileset;
return null;
}