mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 01:32:19 +00:00
feat(firms): let an application stand in for the fire markers (#1828)
The fire layer takes a stand-in for its markers (setMarkerStandIn({ hitTest })): its glows, heatmap and ambient cards are hidden, and a click the stand-in answers selects and focuses the fire exactly as a marker click does.
This commit is contained in:
1 parent
46e831620e
commit
0421813e26
7 files changed
+234
-13
No files matched your search
@@ -25,6 +25,8 @@ import { fakeDrawPort } from '../testSupport/fakeDrawPort.mjs';
|
||||
import { fakeGlobePort } from '../testSupport/fakeGlobePort.mjs';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import { HEAT_REBUILD_MS } from '../layers/firms/policy.js';
|
||||
import { registerStyleStages } from '../styles/styleStages.js';
|
||||
import { sensorPickPosition } from '../input/sensorPick.js';
|
||||
|
||||
const LAYER_SOURCE = readLayerSource(
|
||||
path.join(path.dirname(fileURLToPath(import.meta.url)), 'firmsHeatmap.js'),
|
||||
@@ -649,6 +651,16 @@ test('far zoom drapes one heatmap and the hand-off cross-fades it with the marke
|
||||
assert.equal(added[0].alpha, 0.5);
|
||||
assert.equal(glow(1).alpha, 0.5, 'rebuilt markers get the fade');
|
||||
|
||||
// An application drawing the detections in their place hides both.
|
||||
h.layer.setMarkerStandIn({ hitTest: () => null });
|
||||
assert.equal(added[0].show, false, 'a stand-in hides the heatmap');
|
||||
assert.equal(markers().show, false, 'and the markers');
|
||||
h.layer._renderLodForTest('global');
|
||||
assert.equal(added[0].show, false, 'through a rebuild too');
|
||||
h.layer.setMarkerStandIn(null);
|
||||
assert.equal(added[0].show, true);
|
||||
assert.equal(markers().show, true);
|
||||
|
||||
h.layer.disable();
|
||||
assert.equal(added[0].show, false, 'disable hides the heatmap');
|
||||
|
||||
@@ -660,3 +672,134 @@ test('far zoom drapes one heatmap and the hand-off cross-fades it with the marke
|
||||
restoreDocument();
|
||||
}
|
||||
});
|
||||
|
||||
test('a click on a fire an application draws in place of the markers selects it as a marker click does', () => {
|
||||
const fire = makeFire();
|
||||
const other = makeFire({ index: 8, lat: 31.2, lon: -97.9, frp: 40 });
|
||||
// The application's records come from the same source, adapted on their own.
|
||||
let answer = { ...fire };
|
||||
const asked = [];
|
||||
const h = harness({ fires: [fire, other], picked: glowPick('firms-8') });
|
||||
try {
|
||||
h.layer.setMarkerStandIn({
|
||||
hitTest: (screen) => {
|
||||
asked.push(screen);
|
||||
return answer;
|
||||
},
|
||||
});
|
||||
assert.equal(h.icons().show, false, 'the glows are hidden');
|
||||
h.published.length = 0;
|
||||
h.click();
|
||||
assert.deepEqual(asked, [{ x: 400, y: 300 }]);
|
||||
assert.equal(h.requests.length, 1, 'the camera moves as for a marker');
|
||||
assert.equal(h.requests[0].kind, 'fire');
|
||||
assert.equal(
|
||||
h.requests[0].id,
|
||||
fireDetectionKey(fire),
|
||||
'the stand-in decides, not the hidden glow under the click',
|
||||
);
|
||||
assert.equal(h.layer.getSelectedInfo().id, fireDetectionKey(fire));
|
||||
assert.equal(getSelectedEntityContext().label, 'Fire · FRP 1520 MW');
|
||||
assert.deepEqual(
|
||||
h.published.map((entry) => entry.id),
|
||||
[`selected-fire:${fireDetectionKey(fire)}`],
|
||||
"only the selected fire's card shows",
|
||||
);
|
||||
|
||||
// Nothing of the application's under the click: empty space.
|
||||
answer = null;
|
||||
h.click();
|
||||
assert.equal(h.requests.length, 1, 'no camera move');
|
||||
assert.equal(h.layer.getSelectedInfo(), null, 'the selection is cleared');
|
||||
} finally {
|
||||
h.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('a stand-in hit on a fire the layer does not show selects nothing', () => {
|
||||
const fire = makeFire();
|
||||
const h = harness({ fires: [fire] });
|
||||
try {
|
||||
h.layer.setMarkerStandIn({
|
||||
hitTest: () => makeFire({ lat: 12.5, lon: 40.1 }),
|
||||
});
|
||||
h.click();
|
||||
assert.equal(h.requests.length, 0);
|
||||
assert.equal(h.layer.getSelectedInfo(), null);
|
||||
} finally {
|
||||
h.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('taking the stand-in away brings the markers and their cards back and keeps the selection', () => {
|
||||
const fire = makeFire();
|
||||
const h = harness({
|
||||
fires: [fire],
|
||||
// Near enough for the markers rather than the heatmap.
|
||||
cameraPosition: Cesium.Cartesian3.fromDegrees(fire.lon, fire.lat, 500_000),
|
||||
});
|
||||
try {
|
||||
h.layer.setMarkerStandIn({ hitTest: () => fire });
|
||||
assert.equal(h.icons().show, false);
|
||||
h.click();
|
||||
h.layer.setMarkerStandIn(null);
|
||||
assert.equal(h.icons().show, true);
|
||||
assert.equal(h.layer.getSelectedInfo().id, fireDetectionKey(fire));
|
||||
const ids = h.published.map((entry) => entry.id);
|
||||
assert.ok(ids.includes(`selected-fire:${fireDetectionKey(fire)}`));
|
||||
} finally {
|
||||
h.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('the stand-in is asked where a marker is picked: the click as the sensor style draws it', () => {
|
||||
const fire = makeFire();
|
||||
const asked = [];
|
||||
const h = harness({ fires: [fire] });
|
||||
try {
|
||||
registerStyleStages(h.viewer.scene, {
|
||||
surveillance: {
|
||||
enabled: true,
|
||||
uniforms: { intensity: 1, pixelation: 4 },
|
||||
},
|
||||
});
|
||||
h.layer.setMarkerStandIn({
|
||||
hitTest: (screen) => {
|
||||
asked.push(screen);
|
||||
return fire;
|
||||
},
|
||||
});
|
||||
h.click();
|
||||
const expected = sensorPickPosition(
|
||||
h.viewer.scene,
|
||||
{ x: 400, y: 300 },
|
||||
h.viewer.scene.canvas,
|
||||
);
|
||||
assert.notDeepEqual([expected.x, expected.y], [400, 300]);
|
||||
assert.deepEqual([asked[0].x, asked[0].y], [expected.x, expected.y]);
|
||||
} finally {
|
||||
h.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("a sibling layer's item over a stand-in fire wins the click", () => {
|
||||
const fire = makeFire();
|
||||
let asked = 0;
|
||||
registerPickOwner('flights', (pickedId) => pickedId === 'a1b2c3');
|
||||
const h = harness({ fires: [fire], picked: { id: 'a1b2c3' } });
|
||||
try {
|
||||
h.layer.setMarkerStandIn({
|
||||
hitTest: () => {
|
||||
asked++;
|
||||
return fire;
|
||||
},
|
||||
});
|
||||
h.click();
|
||||
assert.equal(asked, 0, 'the stand-in is not asked');
|
||||
assert.equal(h.requests.length, 0, 'no camera move');
|
||||
assert.equal(h.layer.getSelectedInfo(), null);
|
||||
} finally {
|
||||
h.cleanup();
|
||||
unregisterPickOwner('flights');
|
||||
}
|
||||
});
|
||||
@@ -76,7 +76,10 @@ export function createCards({
|
||||
const height = canvas.clientHeight;
|
||||
let ambientCount = 0;
|
||||
|
||||
for (const candidate of layerState._labelCandidates) {
|
||||
// An application drawing the detections in place of the markers draws
|
||||
// them unlabelled: only the selected fire's card shows then.
|
||||
const candidates = layerState._standIn ? [] : layerState._labelCandidates;
|
||||
for (const candidate of candidates) {
|
||||
if (ambientCount >= MAX_AMBIENT_LABELS) break;
|
||||
if (candidate.fire && candidate.fire === layerState._selectedFire)
|
||||
continue;
|
||||
|
||||
@@ -52,10 +52,12 @@ export function createLifecycle({
|
||||
if (layerState._cells) layerState._cells.show = true;
|
||||
// The GPU culls the far side each frame, so retained rows are right
|
||||
// for wherever the camera went while the layer was off.
|
||||
if (layerState._icons) layerState._icons.show = true;
|
||||
if (layerState._icons) layerState._icons.show = !layerState._standIn;
|
||||
overlayHost.setVisible(FIRMS_OVERLAY_SOURCE_ID, true);
|
||||
// A filter can leave an old raster cached while the current set is empty.
|
||||
layerState._heatImagery?.setShow(layerState._fires.length > 0);
|
||||
layerState._heatImagery?.setShow(
|
||||
layerState._fires.length > 0 && !layerState._standIn,
|
||||
);
|
||||
// The camera can have crossed the hand-off while the layer was off.
|
||||
components.rendering.applyHandoffFade(true);
|
||||
components.viewport.installLodWatcher();
|
||||
@@ -68,6 +70,29 @@ export function createLifecycle({
|
||||
await components.ingestion.loadHeatmap();
|
||||
},
|
||||
|
||||
/**
|
||||
* Let an application draw the detections in place of the layer's
|
||||
* markers. While a stand-in is set, the glows, the heatmap and the
|
||||
* ambient cards are hidden and everything else works as before: a click
|
||||
* on a fire the stand-in draws (`standIn.hitTest(screenPosition)`, which
|
||||
* answers a detection record from the same source, or null) selects it
|
||||
* and moves the camera to it as a click on its marker does, the selected
|
||||
* fire's card shows, and a click on empty space clears the selection.
|
||||
* `null` brings the markers back. The selection is kept either way.
|
||||
* @param {?{hitTest: (screenPosition: {x: number, y: number}) => ?Object}} standIn
|
||||
*/
|
||||
setMarkerStandIn(standIn) {
|
||||
layerState._standIn =
|
||||
typeof standIn?.hitTest === 'function' ? standIn : null;
|
||||
layerState._heatImagery?.setShow(
|
||||
layerState._enabled &&
|
||||
layerState._fires.length > 0 &&
|
||||
!layerState._standIn,
|
||||
);
|
||||
components.rendering.applyHandoffFade(true);
|
||||
components.cards.rebuildAmbientLabels();
|
||||
},
|
||||
|
||||
disable() {
|
||||
layerState.request?.abort();
|
||||
layerState.request = null;
|
||||
@@ -129,6 +154,7 @@ export function createLifecycle({
|
||||
layerState._currentLodIndex = -1;
|
||||
layerState._lastViewRect = null;
|
||||
layerState._selectedFire = null;
|
||||
layerState._standIn = null;
|
||||
layerState._labelCandidates = [];
|
||||
layerState._labelLodDistance = 0;
|
||||
layerState._pickIndexById.clear();
|
||||
|
||||
@@ -122,7 +122,7 @@ export function createRendering({
|
||||
glowAlpha = alpha;
|
||||
const set = layerState._icons;
|
||||
if (!set) return;
|
||||
set.show = layerState._enabled && heat < 1;
|
||||
set.show = layerState._enabled && !layerState._standIn && heat < 1;
|
||||
if (!changed || !drawnGlows.size) return;
|
||||
const faded = [];
|
||||
for (const drawn of drawnGlows.values()) {
|
||||
@@ -273,7 +273,7 @@ export function createRendering({
|
||||
// The map stack may have changed since the last render.
|
||||
imagery.rehome();
|
||||
ensureHeatRaster(now);
|
||||
imagery.setShow(layerState._enabled);
|
||||
imagery.setShow(layerState._enabled && !layerState._standIn);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -469,7 +469,10 @@ export function createRendering({
|
||||
// Blended as one translucent pass, as its billboards were.
|
||||
blend: 'translucent',
|
||||
horizonCull: true,
|
||||
show: layerState._enabled && !(layerState._handoffHeat >= 1),
|
||||
show:
|
||||
layerState._enabled &&
|
||||
!layerState._standIn &&
|
||||
!(layerState._handoffHeat >= 1),
|
||||
drawOrder: spriteDrawOrder?.('firms') ?? 0,
|
||||
});
|
||||
// Columns of no rows put the set's host in the scene now, rather than
|
||||
|
||||
@@ -35,17 +35,23 @@ export function createSelection({
|
||||
const input = inputFor(layerState._viewer);
|
||||
layerState._clickSubscription = input.onClick((event) => {
|
||||
const picked = event.topHit;
|
||||
const fire = pickedFire(event.drawHit);
|
||||
const pickedId = picked ? resolvePickId(picked) : null;
|
||||
// A pick that belongs to a sibling layer (e.g. an aircraft) is not
|
||||
// "empty space" — leave the selection alone and let that layer handle it.
|
||||
const otherLayer = Boolean(pickedId && isOwnedByOtherLayer(id, pickedId));
|
||||
// The stand-in is asked where markers are picked: the click corrected
|
||||
// for the sensor style (`event.position`), and only when no sibling
|
||||
// layer's item is on top, as a marker under that item would not be hit.
|
||||
const fire = layerState._standIn
|
||||
? otherLayer
|
||||
? null
|
||||
: standInFire(event.position ?? event.screenPosition)
|
||||
: pickedFire(event.drawHit);
|
||||
if (fire) {
|
||||
selectAndFocusFire(fire);
|
||||
return;
|
||||
}
|
||||
// A pick that belongs to a sibling layer (e.g. an aircraft) is not
|
||||
// "empty space" — leave the selection alone and let that layer handle it.
|
||||
if (picked) {
|
||||
const pickedId = resolvePickId(picked);
|
||||
if (pickedId && isOwnedByOtherLayer(id, pickedId)) return;
|
||||
}
|
||||
if (otherLayer) return;
|
||||
const cardHit = overlayHost.hitTest?.(
|
||||
event.screenPosition?.x,
|
||||
event.screenPosition?.y,
|
||||
@@ -93,6 +99,32 @@ export function createSelection({
|
||||
return layerState._pickIndexById.get(hit.id) ?? null;
|
||||
}
|
||||
|
||||
/** The shown detections by their key, for the shown set they were made from. */
|
||||
let keyed = { fires: null, byKey: null };
|
||||
|
||||
/**
|
||||
* Resolve a click to one of this layer's fire records through the
|
||||
* application's stand-in for its markers (`setMarkerStandIn`), or null:
|
||||
* the record its hit test answers, matched by its detection key to a fire
|
||||
* the layer shows now (so one the filter hides is not selected).
|
||||
* @param {?{x: number, y: number}} screenPosition - Where the user clicked.
|
||||
* @returns {?Object} Fire record.
|
||||
*/
|
||||
|
||||
function standInFire(screenPosition) {
|
||||
if (!screenPosition) return null;
|
||||
const record = layerState._standIn?.hitTest(screenPosition);
|
||||
if (!record) return null;
|
||||
if (keyed.fires !== layerState._fires)
|
||||
keyed = {
|
||||
fires: layerState._fires,
|
||||
byKey: new Map(
|
||||
layerState._fires.map((fire) => [fireDetectionKey(fire), fire]),
|
||||
),
|
||||
};
|
||||
return keyed.byKey.get(fireDetectionKey(record)) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a fire: show its detail label and mark it selected in the shared
|
||||
* context store so voice "what's selected" resolves to it.
|
||||
@@ -229,6 +261,7 @@ export function createSelection({
|
||||
removeClickHandler,
|
||||
selectAndFocusFire,
|
||||
pickedFire,
|
||||
standInFire,
|
||||
selectFire,
|
||||
clearFireSelection,
|
||||
refreshContextRegistrations,
|
||||
|
||||
@@ -98,6 +98,14 @@ export function createFirmsState({ services, config }) {
|
||||
|
||||
layerState._selectedFire = null;
|
||||
|
||||
/**
|
||||
* What an application draws in place of the markers (`setMarkerStandIn`):
|
||||
* while set, the glows, heatmap and ambient cards are hidden and clicks
|
||||
* resolve through its `hitTest`.
|
||||
*/
|
||||
|
||||
layerState._standIn = null;
|
||||
|
||||
/** Priority-ordered label candidates from the last rebuild (detections or cells). */
|
||||
|
||||
layerState._labelCandidates = [];
|
||||
|
||||
Reference in new issue
Block a user