diff --git a/src/layers/alpr/overlay.js b/src/layers/alpr/overlay.js index 9bb93c18c..a99684818 100644 --- a/src/layers/alpr/overlay.js +++ b/src/layers/alpr/overlay.js @@ -106,19 +106,36 @@ export function createAlprOverlay({ record.longitude, ); if (validAlprGroundHeight(floor)) height = floor + MARKER_FLOOR_LIFT_M; - else if (query) { + else if (query && canSampleHeight()) { if (budget.samples <= 0) return null; budget.samples -= 1; // A miss is tiles still streaming. height = query.sampleHeightNow(point, { exclude: [markers.icons?.id] }); } - if (!validAlprGroundHeight(height)) + // The globe's terrain, while the globe is drawn (hidden under photoreal + // tiles, its height is not what shows). + if (!validAlprGroundHeight(height) && globeShown()) height = query?.sampleHeightNow(point, { against: 'terrain' }); if (!validAlprGroundHeight(height)) return null; setAnchor(record, carrier, height); return alprMarkers.read(carrier)?.canvasPosition; } + /** + * Whether the renderer samples the drawn surface's height (Cesium needs + * depth textures). Without, nothing is sampled or spent from the budget, + * and a marker with no floor yet anchors on the terrain. + */ + function canSampleHeight() { + const capabilities = rendererOf(state.viewer)?.capabilities; + return !capabilities || capabilities.has('sampleHeight'); + } + + /** Whether the globe surface is drawn; true where the renderer cannot say. */ + function globeShown() { + return rendererOf(state.viewer)?.globe?.isGlobeVisible?.() !== false; + } + function floorHeightAt(latitude, longitude) { const floor = services.groundFloor.cachedGroundFloor(latitude, longitude); return validAlprGroundHeight(floor) ? floor + MARKER_FLOOR_LIFT_M : null; @@ -162,7 +179,7 @@ export function createAlprOverlay({ direction: { ...pose.direction }, }; const query = findQuery(state.viewer); - if (!query) return false; + if (!query || !canSampleHeight()) return false; let pending = false; for (const record of records) { const carrier = markers.get(record.id); diff --git a/src/layers/alpr/overlay.test.mjs b/src/layers/alpr/overlay.test.mjs index f8fc003a7..a938373ee 100644 --- a/src/layers/alpr/overlay.test.mjs +++ b/src/layers/alpr/overlay.test.mjs @@ -360,3 +360,23 @@ test('anchors wait for the surface heights answer from: the globe’s terrain wh h.paint(); assert.ok(samples > 0, 'sampled once it has loaded'); }); + +test('without height sampling no sample is spent, and the terrain anchors only while the globe is drawn', (t) => { + for (const shown of [true, false]) { + const h = harness(t, 1); + let samples = 0; + h.state.viewer.scene.sampleHeight = () => (samples++, 172); + const renderer = rendererOf(h.state.viewer); + renderer.capabilities = new Set(); + renderer.globe = { isSettled: () => true, isGlobeVisible: () => shown }; + h.overlay.sync(h.records); + h.paint(); + h.paint(); + assert.equal(samples, 0, 'nothing sampled without the capability'); + assert.equal( + Boolean(alprMarkers.read(h.carrier('camera:0'))?.canvasPosition), + shown, + shown ? 'anchored on the terrain' : 'no terrain under hidden globe', + ); + } +});