mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Cross-fade Active Fires markers and heatmap; fix the spot size
The far-zoom heatmap now uses the ½× grid (4096 × 2048, ≈10 km per pixel, one-pixel blur), so a lone fire's spot matches its marker at the 3,000 km hand-off. The spot size slider and its share option are gone. Markers and heatmap are both kept built at every zoom and cross-fade by camera height between 2,400 and 3,600 km on every frame, so a fast zoom never shows a beat with neither. The heatmap fades by imagery alpha: hiding a Cesium imagery layer unmaps it from the globe tiles, and showing it again re-mapped them late, which was the gap at the band edge. Under the markers the heatmap is built 150 ms after the data or filter changes.
This commit is contained in:
1 parent
4e950d04e9
commit
f01200b467
31 files changed
+372
-528
No files matched your search
@@ -43,70 +43,6 @@ export function heatColorAt(t) {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Spot size, in percent of the shipped size: the panel slider and share
|
||||
* option `w.s`. Whole percents, half to four times.
|
||||
*/
|
||||
export const HEAT_SPOT_SIZE_MIN = 50;
|
||||
export const HEAT_SPOT_SIZE_MAX = 400;
|
||||
export const HEAT_SPOT_SIZE_DEFAULT = 100;
|
||||
|
||||
/**
|
||||
* Spot size → whole percent inside the bounds, or null.
|
||||
* @param {*} value
|
||||
* @returns {?number}
|
||||
*/
|
||||
export function normalizeHeatSpotSize(value) {
|
||||
const number =
|
||||
typeof value === 'number'
|
||||
? value
|
||||
: typeof value === 'string' && value.trim() !== ''
|
||||
? Number(value)
|
||||
: NaN;
|
||||
if (!Number.isFinite(number)) return null;
|
||||
const rounded = Math.round(number);
|
||||
return rounded >= HEAT_SPOT_SIZE_MIN && rounded <= HEAT_SPOT_SIZE_MAX
|
||||
? rounded
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The grid for a spot size. The same one-pixel blur on a grid that many
|
||||
* times coarser (or finer) scales every spot exactly; widening the blur
|
||||
* instead lowers each spot's peak, so weak lone fires faded as they grew.
|
||||
* @param {{width: number, height: number, sigmaPx: number}} base Shipped grid.
|
||||
* @param {number} spotSize Percent of the shipped size.
|
||||
* @returns {{width: number, height: number, sigmaPx: number}}
|
||||
*/
|
||||
export function heatGridForSpotSize(base, spotSize) {
|
||||
const percent = normalizeHeatSpotSize(spotSize) ?? HEAT_SPOT_SIZE_DEFAULT;
|
||||
const height = Math.round((base.height * HEAT_SPOT_SIZE_DEFAULT) / percent);
|
||||
return { width: height * 2, height, sigmaPx: base.sigmaPx };
|
||||
}
|
||||
|
||||
/**
|
||||
* Slider axis for the spot size: log2, so ½× and 2× sit equally far from 1×.
|
||||
* Values snap to 5 % steps, which is also their share-link form.
|
||||
*/
|
||||
const SPOT_LOG_MIN = Math.log2(HEAT_SPOT_SIZE_MIN / 100);
|
||||
const SPOT_LOG_SPAN = Math.log2(HEAT_SPOT_SIZE_MAX / 100) - SPOT_LOG_MIN;
|
||||
|
||||
/** Track position in 0..1 for a spot size in percent. */
|
||||
export function sliderPositionForSpotSize(spotSize) {
|
||||
const percent = normalizeHeatSpotSize(spotSize) ?? HEAT_SPOT_SIZE_DEFAULT;
|
||||
return (Math.log2(percent / 100) - SPOT_LOG_MIN) / SPOT_LOG_SPAN;
|
||||
}
|
||||
|
||||
/** Spot size in percent for a track position in 0..1. */
|
||||
export function spotSizeForSliderPosition(position) {
|
||||
const p = Number.isFinite(position) ? Math.max(0, Math.min(1, position)) : 0;
|
||||
const percent = 100 * Math.pow(2, SPOT_LOG_MIN + p * SPOT_LOG_SPAN);
|
||||
return Math.min(
|
||||
HEAT_SPOT_SIZE_MAX,
|
||||
Math.max(HEAT_SPOT_SIZE_MIN, Math.round(percent / 5) * 5),
|
||||
);
|
||||
}
|
||||
|
||||
/** Weight of a detection with no or zero FRP, in megawatts. */
|
||||
export const HEAT_MIN_WEIGHT_MW = 0.5;
|
||||
|
||||
|
||||
@@ -7,10 +7,6 @@ import {
|
||||
binFires,
|
||||
blurGaussian,
|
||||
buildHeatRaster,
|
||||
heatGridForSpotSize,
|
||||
normalizeHeatSpotSize,
|
||||
sliderPositionForSpotSize,
|
||||
spotSizeForSliderPosition,
|
||||
} from './firmsHeatRaster.js';
|
||||
|
||||
const fire = (lat, lon, frp = 10) => ({ lat, lon, frp });
|
||||
@@ -120,60 +116,3 @@ 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('a spot size scales the grid, not the blur', () => {
|
||||
const base = { width: 2048, height: 1024, sigmaPx: 1 };
|
||||
assert.deepEqual(heatGridForSpotSize(base, 100), base);
|
||||
assert.deepEqual(heatGridForSpotSize(base, 200), {
|
||||
width: 1024,
|
||||
height: 512,
|
||||
sigmaPx: 1,
|
||||
});
|
||||
assert.deepEqual(heatGridForSpotSize(base, 50), {
|
||||
width: 4096,
|
||||
height: 2048,
|
||||
sigmaPx: 1,
|
||||
});
|
||||
const odd = heatGridForSpotSize(base, 150);
|
||||
assert.equal(odd.width, odd.height * 2, 'the grid stays 2:1');
|
||||
assert.deepEqual(heatGridForSpotSize(base, 9999), base, 'invalid → default');
|
||||
});
|
||||
|
||||
test('twice the spot size paints a lone fire twice as wide', () => {
|
||||
const base = { width: 2048, height: 1024, sigmaPx: 1 };
|
||||
const fires = [fire(0, 0, 5)];
|
||||
for (let i = 0; i < 40; i++) fires.push(fire(-10, 25 + i * 0.05, 300));
|
||||
const widthKm = (spotSize) => {
|
||||
const r = buildHeatRaster(fires, heatGridForSpotSize(base, spotSize));
|
||||
const y = Math.floor(r.height / 2);
|
||||
let painted = 0;
|
||||
for (let x = 0; x < r.width; x++) {
|
||||
const lon = ((x + 0.5) / r.width) * 360 - 180;
|
||||
if (Math.abs(lon) < 10 && r.rgba[(y * r.width + x) * 4 + 3] > 0) {
|
||||
painted += 1;
|
||||
}
|
||||
}
|
||||
return (painted * 40075) / r.width;
|
||||
};
|
||||
const ratio = widthKm(200) / widthKm(100);
|
||||
assert.ok(ratio > 1.7 && ratio < 2.3, `ratio ${ratio.toFixed(2)}`);
|
||||
});
|
||||
|
||||
test('the spot-size slider is log2 with 1x a third along and 5 % steps', () => {
|
||||
assert.equal(sliderPositionForSpotSize(50), 0);
|
||||
assert.equal(sliderPositionForSpotSize(400), 1);
|
||||
assert.ok(Math.abs(sliderPositionForSpotSize(100) - 1 / 3) < 1e-9);
|
||||
assert.ok(Math.abs(sliderPositionForSpotSize(200) - 2 / 3) < 1e-9);
|
||||
assert.equal(spotSizeForSliderPosition(0), 50);
|
||||
assert.equal(spotSizeForSliderPosition(1), 400);
|
||||
assert.equal(spotSizeForSliderPosition(1 / 3), 100);
|
||||
assert.equal(spotSizeForSliderPosition(-1), 50);
|
||||
for (let i = 0; i <= 100; i++) {
|
||||
const percent = spotSizeForSliderPosition(i / 100);
|
||||
assert.equal(percent % 5, 0, `${percent} at ${i}%`);
|
||||
assert.equal(normalizeHeatSpotSize(percent), percent);
|
||||
}
|
||||
assert.equal(normalizeHeatSpotSize('150'), 150);
|
||||
assert.equal(normalizeHeatSpotSize(49), null);
|
||||
assert.equal(normalizeHeatSpotSize(''), null);
|
||||
});
|
||||
@@ -15,6 +15,7 @@ import { WORLD_FOCUS_REQUEST_EVENT } from '../worldFocus.js';
|
||||
import { readLayerSource } from '../testSupport/readLayerSource.mjs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { HEAT_REBUILD_MS } from '../layers/firms/policy.js';
|
||||
|
||||
const LAYER_SOURCE = readLayerSource(
|
||||
path.join(path.dirname(fileURLToPath(import.meta.url)), 'firmsHeatmap.js'),
|
||||
@@ -393,7 +394,58 @@ test('disable cancels a pending source and a late response cannot repopulate the
|
||||
} finally { h.layer.destroy(h.viewer); h.cleanup(); }
|
||||
});
|
||||
|
||||
test('far zoom drapes one heatmap and draws no rectangles; markers and disable hide it', () => {
|
||||
test('the heatmap is preloaded under the markers before the first zoom-out', (t) => {
|
||||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||||
const priorDocument = globalThis.document;
|
||||
globalThis.document = {
|
||||
createElement: () => ({
|
||||
getContext: () => ({
|
||||
createImageData: (w, hh) => ({ data: new Uint8ClampedArray(w * hh * 4) }),
|
||||
putImageData() {},
|
||||
createRadialGradient: () => ({ addColorStop() {} }),
|
||||
fillRect() {},
|
||||
}),
|
||||
toDataURL: () => 'data:image/png;base64,AAAA',
|
||||
}),
|
||||
};
|
||||
const h = harness({
|
||||
withDataSource: true,
|
||||
cameraPosition: Cesium.Cartesian3.fromDegrees(-98, 30, 1_000_000),
|
||||
});
|
||||
h.viewer.camera = { positionCartographic: { height: 1_000_000 } };
|
||||
h.viewer.scene.primitives = { add() {}, remove() {}, raiseToTop() {}, contains: () => true };
|
||||
h.viewer.scene.frameState = { mode: Cesium.SceneMode.SCENE3D };
|
||||
const added = [];
|
||||
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');
|
||||
} finally {
|
||||
h.layer.destroy(h.viewer);
|
||||
h.cleanup();
|
||||
if (priorDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = priorDocument;
|
||||
}
|
||||
});
|
||||
|
||||
test('far zoom drapes one heatmap and the hand-off cross-fades it with the markers', () => {
|
||||
// A canvas stub for the heat drape and the detection glow sprites.
|
||||
const priorDocument = globalThis.document;
|
||||
const restoreDocument = () => {
|
||||
@@ -420,8 +472,16 @@ test('far zoom drapes one heatmap and draws no rectangles; markers and disable h
|
||||
});
|
||||
const added = [];
|
||||
const removed = [];
|
||||
let markers = null;
|
||||
// The fade reads the camera height; the cull reads scene.camera.
|
||||
const setHeight = (height) => {
|
||||
h.viewer.camera = { positionCartographic: { height } };
|
||||
};
|
||||
setHeight(12_000_000);
|
||||
h.viewer.scene.primitives = {
|
||||
add() {},
|
||||
add(primitive) {
|
||||
markers = primitive;
|
||||
},
|
||||
remove() {},
|
||||
raiseToTop() {},
|
||||
contains: () => true,
|
||||
@@ -430,7 +490,7 @@ test('far zoom drapes one heatmap and draws no rectangles; markers and disable h
|
||||
try {
|
||||
const collection = {
|
||||
addImageryProvider: (provider) => {
|
||||
const layer = { provider, show: true };
|
||||
const layer = { provider, show: true, alpha: 1 };
|
||||
added.push(layer);
|
||||
return layer;
|
||||
},
|
||||
@@ -443,17 +503,33 @@ test('far zoom drapes one heatmap and draws no rectangles; markers and disable h
|
||||
h.layer._renderLodForTest('global');
|
||||
assert.equal(added.length, 1, 'one heat imagery layer');
|
||||
assert.equal(added[0].show, true);
|
||||
assert.equal(added[0].alpha, 1);
|
||||
assert.equal(h.layer._entityCountForTest(), 0, 'no rectangle entities');
|
||||
assert.ok(h.published.length > 0, 'the far band still paints cards');
|
||||
assert.equal(markers.length, 2, 'the markers are built under the heatmap');
|
||||
assert.equal(markers.show, false, 'and hidden while the heatmap is whole');
|
||||
|
||||
h.layer._renderLodForTest('regional');
|
||||
assert.equal(added.length, 1, 'switching far bands reuses the raster');
|
||||
|
||||
setHeight(1_000_000);
|
||||
h.layer._renderLodForTest('close');
|
||||
assert.equal(added[0].show, false, 'the markers band hides the heatmap');
|
||||
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(markers.show, true);
|
||||
assert.equal(markers.get(0).color.alpha, 1);
|
||||
|
||||
// Mid hand-off both are drawn, half each, in either band.
|
||||
setHeight(3_000_000);
|
||||
h.layer._applyHandoffFadeForTest();
|
||||
assert.equal(added[0].alpha, 0.5);
|
||||
assert.equal(markers.show, true);
|
||||
assert.equal(markers.get(0).color.alpha, 0.5);
|
||||
h.layer._renderLodForTest('regional');
|
||||
assert.equal(added[0].alpha, 0.5);
|
||||
assert.equal(markers.get(1).color.alpha, 0.5, 'rebuilt markers get the fade');
|
||||
|
||||
h.layer._renderLodForTest('global');
|
||||
assert.equal(added[0].show, true);
|
||||
h.layer.disable();
|
||||
assert.equal(added[0].show, false, 'disable hides the heatmap');
|
||||
|
||||
@@ -467,66 +543,3 @@ test('far zoom drapes one heatmap and draws no rectangles; markers and disable h
|
||||
restoreDocument();
|
||||
}
|
||||
});
|
||||
|
||||
test('the spot-size slider rebuilds only the heatmap, on a proportionally coarser grid', async () => {
|
||||
const priorDocument = globalThis.document;
|
||||
const grids = [];
|
||||
globalThis.document = {
|
||||
createElement: () => ({
|
||||
getContext: () => ({
|
||||
createImageData: (w, hh) => {
|
||||
grids.push([w, hh]);
|
||||
return { data: new Uint8ClampedArray(w * hh * 4) };
|
||||
},
|
||||
putImageData() {},
|
||||
createRadialGradient: () => ({ addColorStop() {} }),
|
||||
fillRect() {},
|
||||
}),
|
||||
toDataURL: () => 'data:image/png;base64,AAAA',
|
||||
}),
|
||||
};
|
||||
const h = harness({
|
||||
fires: [makeFire(), makeFire({ index: 8, lat: 30.6, lon: -98.3, frp: 12 })],
|
||||
withDataSource: true,
|
||||
cameraPosition: Cesium.Cartesian3.fromDegrees(-98, 30, 12_000_000),
|
||||
});
|
||||
h.viewer.scene.primitives = { add() {}, remove() {}, raiseToTop() {}, contains: () => true };
|
||||
h.viewer.scene.frameState = { mode: Cesium.SceneMode.SCENE3D };
|
||||
const collection = {
|
||||
addImageryProvider: (provider) => ({ provider, show: true }),
|
||||
remove() {},
|
||||
raiseToTop() {},
|
||||
};
|
||||
try {
|
||||
h.layer.attachShellServices({ imageryHost: () => ({ kind: 'globe', collection }) });
|
||||
h.layer._renderLodForTest('global');
|
||||
assert.deepEqual(grids.at(-1), [2048, 1024]);
|
||||
assert.deepEqual(
|
||||
h.layer.getRowControls().sliders.map((slider) => slider.id),
|
||||
['min-frp', 'heat-spot-size'],
|
||||
);
|
||||
const spot = h.layer.getRowControls().sliders[1];
|
||||
assert.equal(spot.valueText, '1×');
|
||||
assert.deepEqual(spot.params(1000), { spotSize: 400 });
|
||||
|
||||
let repaints = 0;
|
||||
h.layer.setRowControlsListener(() => repaints++);
|
||||
h.layer.setParams({ spotSize: 200 });
|
||||
assert.equal(h.layer.getParams().spotSize, 200);
|
||||
assert.equal(h.layer.getParams().minFrp, 0, 'the filter is untouched');
|
||||
assert.equal(h.layer.getStats().count, 2, 'every fire still shown');
|
||||
assert.equal(repaints, 1, 'the row repaints its value');
|
||||
assert.equal(h.layer.getRowControls().sliders[1].valueText, '2×');
|
||||
// The rebuild trails a drag (HEAT_REBUILD_MS) and keeps the old drape meanwhile.
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
assert.deepEqual(grids.at(-1), [1024, 512]);
|
||||
|
||||
h.layer.setParams({ spotSize: 'nope' });
|
||||
assert.equal(h.layer.getParams().spotSize, 200, 'invalid input is ignored');
|
||||
} finally {
|
||||
h.layer.destroy(h.viewer);
|
||||
h.cleanup();
|
||||
if (priorDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = priorDocument;
|
||||
}
|
||||
});
|
||||
@@ -298,7 +298,7 @@ function satelliteFilterOption() {
|
||||
}
|
||||
|
||||
const OPTION_GROUPS = Object.freeze({
|
||||
// Active Fires intensity filter and heatmap spot size (HAL-676). `minFrp` is whole megawatts on
|
||||
// Active Fires intensity filter (HAL-676). `minFrp` is whole megawatts on
|
||||
// the codec side; the panel's log slider rounds to it. Both default to
|
||||
// "show everything": many of the strongest fires are rated low confidence.
|
||||
// The bounds and modes mirror MIN_FRP_MW_MAX / FIRMS_CONFIDENCE_MODES in
|
||||
@@ -311,9 +311,6 @@ const OPTION_GROUPS = Object.freeze({
|
||||
nominal: 'n',
|
||||
high: 'h',
|
||||
}),
|
||||
// Heatmap spot size in percent; mirrors HEAT_SPOT_SIZE_* in
|
||||
// firmsHeatRaster.js.
|
||||
boundedIntegerOption('spotSize', 's', 100, { min: 50, max: 400 }),
|
||||
]),
|
||||
traffic: Object.freeze([
|
||||
enumOption('roadMode', 'r', null, ['tomtom', 'osm', 'hybrid'], {
|
||||
|
||||
@@ -30,11 +30,6 @@ import { stampInitialShareGesture } from '../navigationPolicy.js';
|
||||
import { MAX_SINCE_DAYS } from '../layers/streetLevel/policy.js';
|
||||
import { SINCE_STOPS } from '../ui/streetLevelPresentation.js';
|
||||
import { FIRMS_CONFIDENCE_MODES, MIN_FRP_MW_MAX } from './firmsIntensity.js';
|
||||
import {
|
||||
HEAT_SPOT_SIZE_DEFAULT,
|
||||
HEAT_SPOT_SIZE_MAX,
|
||||
HEAT_SPOT_SIZE_MIN,
|
||||
} from './firmsHeatRaster.js';
|
||||
|
||||
function deferred() {
|
||||
let resolve;
|
||||
@@ -3024,14 +3019,9 @@ test('Active Fires: the intensity filter rides share token w and round-trips', (
|
||||
assert.deepEqual(state.options['local-firms'], {
|
||||
minFrp: 0,
|
||||
confidence: 'all',
|
||||
spotSize: 100,
|
||||
});
|
||||
state.enabledLayerIds = ['local-firms'];
|
||||
state.options['local-firms'] = {
|
||||
minFrp: 20,
|
||||
confidence: 'high',
|
||||
spotSize: 250,
|
||||
};
|
||||
state.options['local-firms'] = { minFrp: 20, confidence: 'high' };
|
||||
const encoded = encode(state);
|
||||
assert.equal(new URLSearchParams(encoded).get('l'), 'w');
|
||||
// Other owners write their own explicit defaults into `lo` too (flights 3D,
|
||||
@@ -3039,12 +3029,10 @@ test('Active Fires: the intensity filter rides share token w and round-trips', (
|
||||
const assignments = new URLSearchParams(encoded).get('lo').split('_');
|
||||
assert.ok(assignments.includes('w.f.20'), assignments.join(' '));
|
||||
assert.ok(assignments.includes('w.c.h'), assignments.join(' '));
|
||||
assert.ok(assignments.includes('w.s.250'), assignments.join(' '));
|
||||
const decoded = decodeLayerStateParams(new URLSearchParams(encoded));
|
||||
assert.deepEqual(decoded.options['local-firms'], {
|
||||
minFrp: 20,
|
||||
confidence: 'high',
|
||||
spotSize: 250,
|
||||
});
|
||||
assert.deepEqual(
|
||||
parseStoredLayerState(serializeStoredLayerState(state)).options[
|
||||
@@ -3062,11 +3050,7 @@ test('Active Fires: the intensity filter rides share token w and round-trips', (
|
||||
.filter((assignment) => assignment.startsWith('w.')).length,
|
||||
0,
|
||||
);
|
||||
assert.deepEqual(firmsOptions(''), {
|
||||
minFrp: 0,
|
||||
confidence: 'all',
|
||||
spotSize: 100,
|
||||
});
|
||||
assert.deepEqual(firmsOptions(''), { minFrp: 0, confidence: 'all' });
|
||||
});
|
||||
|
||||
test('Active Fires: the codec accepts whole megawatts in bounds and the three confidence codes', () => {
|
||||
@@ -3094,17 +3078,5 @@ test('Active Fires: the codec accepts whole megawatts in bounds and the three co
|
||||
assert.deepEqual(firmsOptions('w.c.n_w.f.5'), {
|
||||
minFrp: 5,
|
||||
confidence: 'nominal',
|
||||
spotSize: 100,
|
||||
});
|
||||
});
|
||||
|
||||
test('Active Fires: the codec accepts whole-percent spot sizes from half to four times', () => {
|
||||
assert.equal(HEAT_SPOT_SIZE_MIN, 50);
|
||||
assert.equal(HEAT_SPOT_SIZE_MAX, 400);
|
||||
assert.equal(HEAT_SPOT_SIZE_DEFAULT, 100);
|
||||
assert.equal(firmsOptions('w.s.50').spotSize, 50);
|
||||
assert.equal(firmsOptions('w.s.400').spotSize, 400);
|
||||
assert.equal(firmsOptions('w.s.45').spotSize, 100, 'out of bounds → default');
|
||||
assert.equal(firmsOptions('w.s.401').spotSize, 100);
|
||||
assert.equal(firmsOptions('w.s.x').spotSize, 100);
|
||||
});
|
||||
Reference in new issue
Block a user