Add raster imagery to the globe contract and draw FIRMS heat and Recent Imagery through it

engine.imagery draws raster layers over the globe: Web Mercator tile
templates and single images or canvases stretched over a rectangle, with
alpha, show, a left/right split against the engine's split position and
an order. A layer's source can be replaced in place.

- Cesium puts one ImageryLayer per layer on the globe's imagery stack,
  or on the shown 3D tileset's when the globe is hidden, and moves it
  when the surface changes; the Recent Imagery request gate moved here.
- Navara draws them in one screen pass after tone mapping that samples up
  to eight layers by geodetic position from mipmapped textures and a tile
  atlas, under the other drapes and engine.ground.
- The fake engine keeps each layer's state.

The FIRMS far-zoom heat raster and Recent Imagery now draw through it, so
FIRMS' heat seam and both its backends, and Recent Imagery's Cesium and
Navara renderers and tile plan, go. Against HEAD, Cesium's pixels are
identical in all four compared scenes; Navara's orbital heat changes by a
mean of 3.8 from new mipmapping, slightly towards Cesium. The contract
suite passes on both engines (Cesium 68/68, Navara 71/71).

engine.maps.addOverlay stays a Navara-only extension for Sea Marks and
Ski Pistes until imagery has a finer tile path for oblique global views.
This commit is contained in:
German Khokhlov committed 2026-11-07 08:07:57 +04:00
1 parent 1559bd57f4
commit 406dd9122e
52 files changed
+4171 -1988

No files matched your search

+24
View File
@@ -8,6 +8,7 @@ import {
blurGaussian,
buildHeatRaster,
} from './firmsHeatRaster.js';
import { HEAT_RASTER } from '../layers/firms/policy.js';
const fire = (lat, lon, frp = 10) => ({ lat, lon, frp });
@@ -116,3 +117,26 @@ test('buildHeatRaster with no fires is fully transparent', () => {
const r = buildHeatRaster([], { width: 8, height: 4, sigmaPx: 1 });
assert.ok(r.rgba.every((v) => v === 0));
});
test('the shipped raster paints a lone weak fire as a distinct spot', () => {
// A hot cluster elsewhere sets the scale, as Africa does on real data.
const fires = [{ lat: 0, lon: 0, frp: 5 }];
for (let i = 0; i < 40; i++) {
fires.push({ lat: -10 + (i % 5) * 0.1, lon: 25 + i * 0.05, frp: 300 });
}
const r = buildHeatRaster(fires, HEAT_RASTER);
const y = Math.floor((90 / 180) * r.height);
const painted = [];
for (let x = 0; x < r.width; x++) {
const lon = ((x + 0.5) / r.width) * 360 - 180;
if (Math.abs(lon) < 5 && r.rgba[(y * r.width + x) * 4 + 3] > 0) {
painted.push(x);
}
}
const kmPerPx = 40075 / r.width;
assert.ok(painted.length > 0, 'the weak fire still shows');
assert.ok(
painted.length * kmPerPx <= 100,
`spot ${Math.round(painted.length * kmPerPx)} km wide`,
);
});
+25 -42
View File
@@ -44,6 +44,13 @@ function makeFire(overrides = {}) {
};
}
/** The globe's imagery stack, shown: where the engine drapes the heatmap. */
function globeImagery(viewer) {
viewer.imageryLayers = new Cesium.ImageryLayerCollection();
viewer.scene.globe.show = true;
return viewer.imageryLayers;
}
/**
* Stand the layer up far enough to drive one click. `cardHit` is what the
* overlay host reports under the click position — the real host only publishes
@@ -543,28 +550,15 @@ test('the heatmap is preloaded under the markers before the first zoom-out', asy
const h = harness({
cameraPosition: Cesium.Cartesian3.fromDegrees(-98, 30, 1_000_000),
});
const added = [];
// The engine drapes the heatmap on the globe's own imagery.
const added = globeImagery(h.viewer);
try {
h.layer.attachShellServices({
imageryHost: () => ({
kind: 'globe',
collection: {
addImageryProvider: (provider) => {
const layer = { provider, show: true, alpha: 1 };
added.push(layer);
return layer;
},
remove() {},
raiseToTop() {},
},
}),
});
h.layer._renderLodForTest('close');
assert.equal(added.length, 0, 'the markers paint first; the build trails');
t.mock.timers.tick(HEAT_REBUILD_MS);
assert.equal(added.length, 1, 'then the heatmap is draped');
assert.equal(added[0].alpha, 0, 'invisible until the hand-off');
assert.equal(added[0].show, true, 'but mapped onto the globe tiles');
assert.equal(added.get(0).alpha, 0, 'invisible until the hand-off');
assert.equal(added.get(0).show, true, 'but mapped onto the globe tiles');
} finally {
h.cleanup();
if (priorDocument === undefined) delete globalThis.document;
@@ -596,8 +590,9 @@ test('far zoom drapes one heatmap and the hand-off cross-fades it with the marke
fires: [makeFire(), makeFire({ index: 8, lat: 30.6, lon: -98.3, frp: 12 })],
cameraPosition: Cesium.Cartesian3.fromDegrees(-98, 30, 12_000_000),
});
const added = [];
const added = globeImagery(h.viewer);
const removed = [];
added.layerRemoved.addEventListener((layer) => removed.push(layer));
// The markers as drawn: how many the sprite set draws, and their alphas.
const drawn = () => {
const count =
@@ -607,23 +602,12 @@ test('far zoom drapes one heatmap and the hand-off cross-fades it with the marke
return Array.from({ length: count }, (_, i) => markers.get(i).color.alpha);
};
try {
const collection = {
addImageryProvider: (provider) => {
const layer = { provider, show: true, alpha: 1 };
added.push(layer);
return layer;
},
remove: (layer, destroy) => removed.push({ layer, destroy }),
raiseToTop() {},
};
h.layer.attachShellServices({
imageryHost: () => ({ kind: 'globe', collection }),
});
h.layer._renderLodForTest('global');
await settle();
assert.equal(added.length, 1, 'one heat imagery layer');
assert.equal(added[0].show, true);
assert.equal(added[0].alpha, 1);
const heat = added.get(0);
assert.equal(heat.show, true);
assert.equal(heat.alpha, 1);
assert.equal(h.layer._cellCountForTest(), 0, 'no ground cells');
assert.ok(h.published.length > 0, 'the far band still paints cards');
assert.deepEqual(drawn(), [], 'no marker drawn while the heatmap is whole');
@@ -643,34 +627,33 @@ test('far zoom drapes one heatmap and the hand-off cross-fades it with the marke
h.layer._renderLodForTest('regional');
assert.equal(added.length, 1, 'switching far bands reuses the raster');
assert.equal(added.get(0), heat);
h.setHeight(1_000_000);
h.layer._renderLodForTest('close');
await settle();
assert.equal(added.length, 1, 'the markers band keeps the same heat layer');
assert.equal(added[0].show, true, 'still mapped onto the globe tiles');
assert.equal(added[0].alpha, 0, 'faded out under the markers');
assert.equal(added.get(0), heat, 'the markers band keeps the same layer');
assert.equal(heat.show, true, 'still mapped onto the globe tiles');
assert.equal(heat.alpha, 0, 'faded out under the markers');
assert.deepEqual(drawn(), [1, 1]);
// Mid hand-off both are drawn, half each, in either band.
h.setHeight(4_500_000);
h.layer._applyHandoffFadeForTest();
await settle();
assert.equal(added[0].alpha, 0.5);
assert.equal(heat.alpha, 0.5);
assert.deepEqual(drawn(), [0.5, 0.5]);
h.layer._renderLodForTest('regional');
await settle();
assert.equal(added[0].alpha, 0.5);
assert.equal(heat.alpha, 0.5);
assert.deepEqual(drawn(), [0.5, 0.5], 'rebuilt markers get the fade');
h.layer.disable();
assert.equal(added[0].show, false, 'disable hides the heatmap');
assert.equal(heat.show, false, 'disable hides the heatmap');
h.layer.destroy();
assert.deepEqual(
removed.map((entry) => [entry.layer, entry.destroy]),
[[added[0], true]],
);
assert.deepEqual(removed, [heat]);
assert.equal(heat.isDestroyed(), true);
} finally {
h.cleanup();
restoreDocument();