diff --git a/src/layers/alpr/overlay.js b/src/layers/alpr/overlay.js index 728d9fd8a..9bb93c18c 100644 --- a/src/layers/alpr/overlay.js +++ b/src/layers/alpr/overlay.js @@ -138,9 +138,10 @@ export function createAlprOverlay({ /** Whether the visible photoreal tiles (or globe) have finished streaming. */ function surfaceSettled() { const globe = rendererOf(state.viewer)?.globe; + // The globe's terrain while it is shown, otherwise the shown 3D tiles. // A viewer with no renderer of its own cannot say; its samples are // still checked against the floor. - return !globe || (globe.isSettled('terrain') && globe.isSettled('tiles')); + return !globe || globe.isSettled('surface'); } /** diff --git a/src/layers/alpr/overlay.test.mjs b/src/layers/alpr/overlay.test.mjs index 5eee04c7f..f8fc003a7 100644 --- a/src/layers/alpr/overlay.test.mjs +++ b/src/layers/alpr/overlay.test.mjs @@ -11,6 +11,7 @@ import { import { alprMarkers, createAlprMarkerSet } from './markerState.js'; import { fakeDrawPort } from '../../testSupport/fakeDrawPort.mjs'; import { bindFakeCesiumScene } from '../../testSupport/fakeCesiumScene.mjs'; +import { rendererOf } from '../../render/rendererOf.js'; function harness(t, count = 2, { floor = null } = {}) { const previousImage = globalThis.Image; @@ -334,3 +335,28 @@ test('a bearing wedge is plain ECEF at the apex and its two far corners', () => assert.ok(heights.some((h) => Math.abs(h - 160) < 1e-6)); assert.ok(heights.slice(1).some((h) => Math.abs(h - 150) < 1e-6)); }); + +test('anchors wait for the surface heights answer from: the globe’s terrain while shown, else the shown 3D tiles', (t) => { + const h = harness(t, 1, { floor: 150 }); + const scene = h.state.viewer.scene; + h.state.viewer.camera.directionWC = Cesium.Cartesian3.UNIT_X; + scene.sampleHeightSupported = true; + scene.primitives = { length: 0, get: () => null }; + let samples = 0; + scene.sampleHeight = () => (samples++, 172); + // The renderer's own `surface` rule; a non-base tileset still streaming + // over a hidden globe leaves it unsettled. + let surface = false; + const asked = new Set(); + rendererOf(h.state.viewer).globe = { + isSettled: (kind) => (asked.add(kind), kind === 'surface' ? surface : true), + }; + h.overlay.sync(h.records); + h.paint(); + h.paint(); + assert.equal(samples, 0, 'no samples while the surface streams'); + assert.deepEqual([...asked], ['surface']); + surface = true; + h.paint(); + assert.ok(samples > 0, 'sampled once it has loaded'); +});