diff --git a/scripts/package-boundaries.json b/scripts/package-boundaries.json index db798ef65..b8acca88b 100644 --- a/scripts/package-boundaries.json +++ b/scripts/package-boundaries.json @@ -1048,6 +1048,7 @@ "src/sky/starrySky.js", "src/render/cesium/effects.js", "src/render/cesium/globe.js", + "src/render/baseTilesets.js", "src/render/cesium/imagery.js", "src/render/cesium/tileRequests.js", "src/maps/google3d.js", @@ -1830,6 +1831,7 @@ "modules": [ "src/render/cesium/unbound.js", "src/render/cesium/globe.js", + "src/render/baseTilesets.js", "src/maps/google3d.js", "src/render/cesium/imagery.js", "src/render/cesium/tileRequests.js", @@ -2376,6 +2378,7 @@ "src/sources/requestDeadline.js", "src/layers/traffic/lifecycle.js", "src/render/cesium/globe.js", + "src/render/baseTilesets.js", "src/maps/google3d.js", "src/render/cesium/imagery.js", "src/render/cesium/tileRequests.js", @@ -3020,6 +3023,7 @@ "src/maps/catalog.js", "src/maps/controller.js", "src/render/cesium/globe.js", + "src/render/baseTilesets.js", "src/render/cesium/iconSetPrimitive.js", "src/data/aircraftRecession.js", "src/data/iconSet.js", @@ -3265,6 +3269,7 @@ "src/render/motion/iconMotion.js", "src/render/cesium/query.js", "src/render/cesium/globe.js", + "src/render/baseTilesets.js", "src/render/cesium/drawHit.js", "src/render/cesium/draw.js", "src/render/cesium/drawMeshes.js", @@ -4795,6 +4800,7 @@ "src/layers/recentImagery/model.js", "src/layers/recentImagery/catalog.js", "src/layers/recentImagery/rendering.js", + "src/render/baseTilesets.js", "src/render/cesium/globe.js", "src/layers/recentImagery/thumbnails.js", "src/maps/imageryHost.js", diff --git a/src/app/embed.js b/src/app/embed.js index 897453f40..6cf272584 100644 --- a/src/app/embed.js +++ b/src/app/embed.js @@ -14,6 +14,10 @@ import * as Cesium from 'cesium'; import { announceNavigationAuthority } from '../navigationPolicy.js'; import { cameraOf } from '../render/cesium/camera.js'; +// The application's tools reach `findGlobe` callers too (the Recent Imagery +// panel, Import and others): a viewer with no renderer bound gets its globe +// port from here, as it gets its camera. +import '../render/cesium/globe.js'; import { annotationsFromParams, createView } from '../view/index.js'; const EMBED_VIEW_MESSAGE = 'gev:view'; diff --git a/src/layers/recentImagery/index.test.mjs b/src/layers/recentImagery/index.test.mjs index 6e5be08f7..71cc71f4a 100644 --- a/src/layers/recentImagery/index.test.mjs +++ b/src/layers/recentImagery/index.test.mjs @@ -14,6 +14,7 @@ import { createRecentImageryLayer, } from './index.js'; import { createImageryBoxPreview } from './rendering.js'; +import { fakeDrawPort } from '../../testSupport/fakeDrawPort.mjs'; import { BOX, CANDIDATES, @@ -1408,7 +1409,7 @@ test('with SELECT BOX armed, Escape clears the preview first and the next Escape const tool = initImageryBoxTool({ viewer: fakes.viewer, createPreview: (viewer, dragBox) => - createImageryBoxPreview(viewer, dragBox, { cesium: fakes.cesium }), + createImageryBoxPreview(viewer, dragBox, { draw: fakeDrawPort() }), pickWorld: fakes.pickWorld, documentRef: fakes.documentRef, onBox: (box) => f.layer.setBox(box), diff --git a/src/layers/recentImagery/rendering.js b/src/layers/recentImagery/rendering.js index da5c0bb1d..6edf44ab2 100644 --- a/src/layers/recentImagery/rendering.js +++ b/src/layers/recentImagery/rendering.js @@ -7,13 +7,14 @@ * each layer's admission hook; the renderer's own request limits stay * untouched. */ -// The layer flies through `cameraOf` and drapes through `findGlobe`; this -// renderer is its Cesium side, so it brings the factories a viewer with no -// renderer bound gets those ports from, and marks a tileset host as a base -// the globe port drapes on. -import * as Cesium from 'cesium'; -import '../../render/cesium/camera.js'; -import { markBaseTileset } from '../../render/cesium/globe.js'; +// The imagery drapes through the globe port and the box preview draws +// through `drawOf`, both on the renderer's ports: a viewer with no renderer +// bound gets them once its owner has loaded the package's +// `./render/cesium/unbound` export. A tileset host is marked as a base the +// globe port drapes on (`markBaseTileset`). +import { fromDegrees } from '../../geo/ellipsoid.js'; +import { markBaseTileset } from '../../render/baseTilesets.js'; +import { drawOf } from '../../render/rendererOf.js'; import { PRODUCTS, gibsTemplate } from './model.js'; const SLOT_IDS = ['a', 'b']; @@ -237,96 +238,127 @@ export function createRecentImageryRenderer({ }; } +const PREVIEW_STROKE = Object.freeze([139 / 255, 233 / 255, 1]); +/** Fill alpha and outline alpha of the box being dragged. */ +const PREVIEW_FILL_ALPHA = 0.12; +const PREVIEW_LINE_ALPHA = 0.95; +/** Each preview's draw sets have ids of their own. */ +let previewSeq = 0; + +/** A box with no area has no fill: a press, or a drag along one axis. */ +const hasArea = (box) => + Boolean(box) && box.east > box.west && box.north > box.south; + +/** A box with no extent draws nothing: a press that has not moved yet. */ +const hasExtent = (box) => + Boolean(box) && (box.east > box.west || box.north > box.south); + /** * The box tool's preview: the box being dragged, a translucent fill and a - * dashed outline on the ground (the draw port draws no dashed draped - * lines), read from `dragBox()` each frame it draws. + * dashed outline on the ground, drawn through the draw port. Each change + * moves them where they are (the port draws a moved ground fill and a moved + * draped line in the frame they move), so the box shows every frame of a + * drag. * @param {object} viewer * @param {() => ({west: number, south: number, east: number, north: number}|null)} dragBox * Degrees, or null while no drag is live. - * @param {{cesium?: object}} [options] The Cesium namespace (tests pass a double). + * @param {{draw?: import('../../render/contract/draw').DrawPort}} [options] + * The draw port (tests pass a double); the viewer's by default. * @returns {{setVisible: (visible: boolean) => void, changed: () => void, destroy: () => Promise}} */ export function createImageryBoxPreview( viewer, dragBox, - { cesium = Cesium } = {}, + { draw = drawOf(viewer) } = {}, ) { - const dataSource = new cesium.CustomDataSource( - 'gev-recent-imagery-box-preview', - ); - let attaching = Promise.resolve(viewer.dataSources.add(dataSource)).catch( - () => null, - ); + previewSeq += 1; + const fills = draw.shapes({ + id: `recent-imagery-box:${previewSeq}:fill`, + pickable: false, + }); + const outlines = draw.lines({ + id: `recent-imagery-box:${previewSeq}:outline`, + pickable: false, + }); + let visible = false; let destroyed = false; - const stroke = cesium.Color.fromCssColorString('#8be9ff'); - const previewRectangle = () => { - const box = dragBox(); - return box - ? cesium.Rectangle.fromDegrees(box.west, box.south, box.east, box.north) - : undefined; - }; - const previewOutline = () => { - const box = dragBox(); - if (!box) return []; - return cesium.Cartesian3.fromDegreesArray([ - box.west, - box.south, - box.east, - box.south, - box.east, - box.north, - box.west, - box.north, - box.west, - box.south, + // The sets go at once; every caller gets the same settled promise. + const gone = Promise.resolve(); + // The last box drawn, and the last with an area: a box without one keeps + // it, hidden, so the next one moves it rather than draw it anew. + let drawn = null; + let filled = null; + + function drawFill(box, show) { + const { west, south, east, north } = box; + fills.upsert([ + { + id: 'box', + geometry: { kind: 'rectangle', rect: { west, south, east, north } }, + fill: [...PREVIEW_STROKE, PREVIEW_FILL_ALPHA], + height: 'clampGround', + clampTo: 'both', + show, + }, ]); - }; - const fill = dataSource.entities.add({ - show: false, - rectangle: { - coordinates: new cesium.CallbackProperty(previewRectangle, false), - material: stroke.withAlpha(0.12), - classificationType: cesium.ClassificationType.BOTH, - }, - }); - // A rectangle graphic cannot draw a dashed edge on the ground, so the - // outline is its own draped polyline traced round the same corners. - const outline = dataSource.entities.add({ - show: false, - polyline: { - positions: new cesium.CallbackProperty(previewOutline, false), - width: 2, - clampToGround: true, - classificationType: cesium.ClassificationType.BOTH, - material: new cesium.PolylineDashMaterialProperty({ - color: stroke.withAlpha(0.95), - dashLength: 12, - }), - }, - }); - const requestRender = () => viewer.scene.requestRender?.(); + } + + function drawEdge(box, show) { + const { west, south, east, north } = box; + // A rectangle has no dashed edge on the ground, so the outline is a + // draped line traced round the same corners; a drag along one axis + // draws it as a line along the drag, as the fill has no area. + outlines.upsert([ + { + id: 'edge', + positions: [ + fromDegrees(west, south), + fromDegrees(east, south), + fromDegrees(east, north), + fromDegrees(west, north), + fromDegrees(west, south), + ], + widthPx: 2, + mode: 'draped', + clampTo: 'both', + style: { + kind: 'dash', + color: [...PREVIEW_STROKE, PREVIEW_LINE_ALPHA], + length: 12, + }, + show, + }, + ]); + } + + function update() { + if (destroyed) return; + const box = visible ? dragBox() : null; + if (hasArea(box)) { + filled = { ...box }; + drawFill(filled, true); + } else if (filled) drawFill(filled, false); + if (hasExtent(box)) { + drawn = { ...box }; + drawEdge(drawn, true); + } else if (drawn) drawEdge(drawn, false); + } + return { - setVisible(visible) { - fill.show = visible; - outline.show = visible; - requestRender(); + setVisible(on) { + visible = Boolean(on); + update(); }, /** The box moved: draw it again. */ - changed: requestRender, - /** Detach the preview; resolves once it is gone. */ + changed: update, + /** Take the preview away; resolves once it is gone. */ destroy() { - if (destroyed) return attaching; - destroyed = true; - dataSource.entities.removeAll(); - attaching = attaching.then(() => { - try { - viewer.dataSources.remove(dataSource, true); - } catch { - /* viewer already disposed */ - } - }); - return attaching; + if (!destroyed) { + destroyed = true; + fills.dispose(); + outlines.dispose(); + } + return gone; }, }; } diff --git a/src/layers/recentImagery/rendering.test.mjs b/src/layers/recentImagery/rendering.test.mjs index d75c0414b..70028d43e 100644 --- a/src/layers/recentImagery/rendering.test.mjs +++ b/src/layers/recentImagery/rendering.test.mjs @@ -2,10 +2,12 @@ import test from 'node:test'; import assert from 'node:assert/strict'; import { TILE_RENDER_REASON, + createImageryBoxPreview, createRecentImageryRenderer, } from './rendering.js'; import { BOX } from './testDoubles.mjs'; import { fakeGlobePort } from '../../testSupport/fakeGlobePort.mjs'; +import { fakeDrawPort } from '../../testSupport/fakeDrawPort.mjs'; const S30 = { key: 'S30:2026-09-18', product: 'S30', day: '2026-09-18' }; const L30 = { key: 'L30:2026-09-16', product: 'L30', day: '2026-09-16' }; @@ -203,3 +205,69 @@ test('replacement imagery uses source-owned tile URLs and credit and tears down assert.equal(globe.layers.length, 0); assert.equal(layer.removed, true); }); + +test('the box preview draws a ground fill and a draped dashed edge, hidden rather than dropped between drags', async () => { + const draw = fakeDrawPort(); + let box = null; + const preview = createImageryBoxPreview({}, () => box, { draw }); + const sets = [...draw.sets.values()]; + assert.deepEqual( + sets.map((r) => [r.kind, r.spec.pickable]), + [ + ['shapes', false], + ['lines', false], + ], + ); + const [fills, lines] = sets; + preview.setVisible(true); + assert.equal(fills.items.size, 0, 'no box yet'); + box = { west: -98, south: 30, east: -98, north: 30 }; + preview.changed(); + assert.equal(fills.items.size, 0, 'a press draws nothing'); + assert.equal(lines.items.size, 0); + // Dragged along one axis: the edge draws as a line, the fill has no area. + box = { west: -98, south: 30, east: -97.9, north: 30 }; + preview.changed(); + assert.equal(fills.items.size, 0, 'no fill without an area'); + assert.equal(lines.items.get('edge').show, true, 'the edge along the drag'); + box = { west: -98, south: 30, east: -97.9, north: 30.1 }; + preview.changed(); + const fill = fills.items.get('box'); + assert.deepEqual(fill.geometry.rect, box); + assert.equal(fill.height, 'clampGround'); + assert.equal(fill.clampTo, 'both'); + assert.deepEqual(fill.fill, [139 / 255, 233 / 255, 1, 0.12]); + assert.equal(fill.show, true); + const edge = lines.items.get('edge'); + assert.equal(edge.mode, 'draped'); + assert.equal(edge.clampTo, 'both'); + assert.equal(edge.widthPx, 2); + assert.deepEqual(edge.style, { + kind: 'dash', + color: [139 / 255, 233 / 255, 1, 0.95], + length: 12, + }); + assert.equal(edge.positions.length, 5, 'round the corners and back'); + assert.deepEqual(edge.positions[0], edge.positions[4]); + preview.setVisible(false); + assert.equal(fills.items.get('box').show, false, 'hidden, kept to move'); + assert.equal(lines.items.get('edge').show, false); + // The next drag moves it and shows it again. + box = { west: -97, south: 31, east: -96.5, north: 31.5 }; + preview.setVisible(true); + assert.deepEqual(fills.items.get('box').geometry.rect, box); + assert.equal(fills.items.get('box').show, true); + assert.equal(lines.items.get('edge').show, true); + // A press with no extent hides the last box. + box = { west: -97, south: 31, east: -97, north: 31 }; + preview.changed(); + assert.equal(fills.items.get('box').show, false); + assert.equal(lines.items.get('edge').show, false); + const gone = preview.destroy(); + assert.equal(preview.destroy(), gone, 'the same promise every time'); + await gone; + assert.ok(fills.disposed && lines.disposed); + // Gone: changes after do nothing. + box = { west: -96, south: 32, east: -95, north: 33 }; + assert.doesNotThrow(() => preview.changed()); +}); diff --git a/src/render/baseTilesets.js b/src/render/baseTilesets.js new file mode 100644 index 000000000..594373965 --- /dev/null +++ b/src/render/baseTilesets.js @@ -0,0 +1,24 @@ +/** + * @module render/baseTilesets + * @description Tilesets the application draws as its base outside the + * renderer's globe port, marked so the port drapes imagery on them while + * they are shown. Cesium-free: code that loads its own base, or hands + * a layer one (`recentImagery.attachTileset`), marks it here without + * reaching the renderer; the renderer's globe port reads the marks. + */ + +const marked = new WeakSet(); + +/** + * Mark a tileset as a base the application draws outside the port, so + * imagery drapes on it while it is shown. The port's own photoreal tileset + * needs no mark. + * @param {object} tileset The renderer's tileset object. + */ +export function markBaseTileset(tileset) { + if (tileset && typeof tileset === 'object') marked.add(tileset); +} + +/** Whether `tileset` was marked as a base (`markBaseTileset`). */ +export const isBaseTileset = (tileset) => + Boolean(tileset && typeof tileset === 'object' && marked.has(tileset)); diff --git a/src/render/cesium/draw.test.mjs b/src/render/cesium/draw.test.mjs index 50846e25d..27371264f 100644 --- a/src/render/cesium/draw.test.mjs +++ b/src/render/cesium/draw.test.mjs @@ -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'); +}); diff --git a/src/render/cesium/globe.js b/src/render/cesium/globe.js index 9d5a2c79f..8f59ccd12 100644 --- a/src/render/cesium/globe.js +++ b/src/render/cesium/globe.js @@ -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; } diff --git a/src/render/cesiumAllowList.json b/src/render/cesiumAllowList.json index 3a34c4189..5fc59d323 100644 --- a/src/render/cesiumAllowList.json +++ b/src/render/cesiumAllowList.json @@ -9,7 +9,6 @@ "src/data/geoImportPins.js", "src/input/dispatcher.js", "src/layers/installations/rendering.js", - "src/layers/recentImagery/rendering.js", "src/layers/satellites/rendering.js", "src/layers/traffic/rendering.js", "src/layers/transit/rendering.js", diff --git a/src/render/unboundCamera.test.mjs b/src/render/unboundCamera.test.mjs index c9946b6b9..1a68d1269 100644 --- a/src/render/unboundCamera.test.mjs +++ b/src/render/unboundCamera.test.mjs @@ -52,7 +52,6 @@ const UNBOUND = 'src/render/cesium/unbound.js'; * both factories; without it, their styles keep records and draw nothing. */ const INJECTED = { - './layers/recent-imagery': 'src/layers/recentImagery/rendering.js', './ui/visual-settings': 'src/ui/applicationShell.js', }; @@ -135,6 +134,10 @@ const CAMERA_FROM_CALLER = new Set([ // constant from. './voice/actions', './voice/realtime-session', + // It flies through `findCamera` and drapes through `findGlobe`; the + // renderer the application gives it (`rendering.js`, which draws the box + // preview through `drawOf`) is Cesium-free too. + './layers/recent-imagery', ]); const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')); diff --git a/src/ui/imageryBoxTool.test.mjs b/src/ui/imageryBoxTool.test.mjs index 4aa5eea97..2ac5041a7 100644 --- a/src/ui/imageryBoxTool.test.mjs +++ b/src/ui/imageryBoxTool.test.mjs @@ -12,17 +12,19 @@ import { } from './imageryBoxTool.js'; import { boxToolFakes } from '../layers/recentImagery/testDoubles.mjs'; import { createImageryBoxPreview } from '../layers/recentImagery/rendering.js'; +import { fakeDrawPort } from '../testSupport/fakeDrawPort.mjs'; function fixture(options = {}) { resetPointerOwnership(); const fakes = boxToolFakes(); + const draw = fakeDrawPort(); const boxes = []; const cancels = []; const actives = []; const tool = initImageryBoxTool({ viewer: fakes.viewer, createPreview: (viewer, dragBox) => - createImageryBoxPreview(viewer, dragBox, { cesium: fakes.cesium }), + createImageryBoxPreview(viewer, dragBox, { draw }), pickWorld: fakes.pickWorld, documentRef: fakes.documentRef, onBox: (box) => boxes.push(box), @@ -39,10 +41,27 @@ function fixture(options = {}) { ? fakes.originalClick : fakes.originalDouble : undefined; + // The preview's fill or outline set, while it is live. + const previewSet = (part) => + [...draw.sets.values()].find( + (r) => + !r.disposed && + r.spec.id.startsWith('recent-imagery-box:') && + r.spec.id.endsWith(`:${part}`), + ); + // Whether the box shows: its fill and its outline, drawn and shown. const preview = () => - fakes.viewer.dataSources.sources[0]?.entities.values.every((e) => e.show); + ['fill', 'outline'].every((part) => { + const set = previewSet(part); + return ( + Boolean(set?.items.size) && + [...set.items.values()].every((item) => item.show !== false) + ); + }); return { ...fakes, + draw, + previewSet, tool, boxes, cancels, @@ -63,8 +82,16 @@ test('a session claims the pointer, borrows the stock clicks, freezes the camera assert.equal(f.camera.enableInputs, true, 'not frozen before the press'); f.fire('LEFT_DOWN', { position: { x: 250, y: 125 } }); assert.equal(f.camera.enableInputs, false); - assert.equal(f.preview(), true); + assert.equal(f.preview(), false, 'a press alone has no box to draw'); f.fire('MOUSE_MOVE', { endPosition: { x: 500, y: 250 } }); + assert.equal(f.preview(), true, 'the box shows as it is dragged'); + const rect = () => f.previewSet('fill').items.get('box').geometry.rect; + assert.deepEqual( + Object.values(rect()).map((v) => Math.round(v * 1e6) / 1e6), + [-97.85, 30.3, -97.8, 30.35], + ); + assert.equal(f.previewSet('outline').items.get('edge').style.kind, 'dash'); + assert.equal(f.previewSet('outline').items.get('edge').mode, 'draped'); f.fire('MOUSE_MOVE', { endPosition: { x: 500, y: 10 } }); // sky: ignored f.fire('LEFT_UP', { position: { x: 500, y: 250 } }); assert.equal(f.boxes.length, 1); @@ -151,13 +178,14 @@ test('destroy mid-drag restores the camera, releases the claim and detaches the const f = fixture(); f.tool.start(); f.fire('LEFT_DOWN', { position: { x: 250, y: 125 } }); - assert.equal(f.viewer.dataSources.sources.length, 1); + assert.ok(f.previewSet('fill') && f.previewSet('outline')); const destroying = f.tool.destroy(); assert.equal(f.tool.destroy(), destroying); await destroying; assert.equal(f.camera.enableInputs, true); assert.equal(pointerOwner(), null); - assert.equal(f.viewer.dataSources.sources.length, 0); + assert.equal(f.previewSet('fill'), undefined, 'the preview is gone'); + assert.equal(f.previewSet('outline'), undefined); assert.equal(f.stockAction('LEFT_CLICK'), f.originalClick); assert.equal(f.tool.start(), false); assert.equal(initImageryBoxTool({ viewer: null, onBox() {} }), null);