feat(perimeters): colour fire perimeters by age

The Fire Perimeters layer now draws a snapshot of fires and the pieces of
their burned area, each piece coloured by its age at the snapshot's moment
(under 6 h, 6-24 h, 1-3 days, older or unknown). Containment stays on the
card; the legend counts fires by last growth and shows the source's note.

- One source method, getSnapshot, returning {at, fetchedAt, stale,
  revision, note, fires, pieces}; getSnapshotDetail is removed.
- WFIGS: one piece per polygon, born at poly_PolygonDateTime, else
  poly_DateCurrent; a time more than 10 minutes ahead is unknown.
- Outlines are drawn apart from fills, so cut pieces have no line along
  the cut; redraws happen only on a new revision or a change of age band.
- The card ages from `at` and adds "last growth ... ago"; with a past
  `at` it links only to an InciWeb incident that began by then.
- perimeterOptions: { inciweb: false } creates no InciWeb sources.
- get_fire_perimeters filters by pieces, places fires at their anchor and
  returns last_growth; analyst items carry lastGrowthTime; spot
  conditions use the anchor.
This commit is contained in:
German Khokhlov committed 2026-11-23 15:48:54 +04:00
1 parent e51853de3d
commit d303d48693
48 files changed
+2127 -734

No files matched your search

+4 -16
View File
@@ -92,19 +92,6 @@ export function compassName(deg) {
return COMPASS[Math.round((((deg % 360) + 360) % 360) / 45) % 8];
}
// The middle of a perimeter's first ring, close enough for "how far".
function perimeterMiddle(row) {
const ring = row?.polygons?.[0]?.[0];
if (!Array.isArray(ring) || !ring.length) return null;
let lat = 0;
let lon = 0;
for (const [x, y] of ring) {
lon += x;
lat += y;
}
return { lat: lat / ring.length, lon: lon / ring.length };
}
/** A storm as "Hurricane Melissa": its class in words when the code has them. */
function stormTitle(storm) {
const word = codeWord('classification', storm.classification);
@@ -129,7 +116,7 @@ export async function hazardsNear(
{ fires: withFires = false, force = false } = {},
) {
const here = { lat, lon };
const [quakeRows, stormSnap, perimeterRows, fireSnap] = await Promise.all([
const [quakeRows, stormSnap, perimeterSnap, fireSnap] = await Promise.all([
quakes(force),
storms(force),
perimeters(force),
@@ -171,8 +158,9 @@ export async function hazardsNear(
at,
});
}
for (const fire of Array.isArray(perimeterRows) ? perimeterRows : []) {
const at = perimeterMiddle(fire);
for (const fire of perimeterSnap?.fires || []) {
// The point the fire's card stands on, close enough for "how far".
const at = fire.anchor;
if (!at || !(distanceKm(here, at) <= radiusKm)) continue;
const acres = Number(fire.acres);
add({
+37
View File
@@ -0,0 +1,37 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { hazardsNear } from './spotConditions.js';
test('a wildfire is placed at its card anchor, not its first ring', async (t) => {
// Two polygons: the larger one, far from the first, carries the anchor.
const square = (lon, lat, size) => [
[
[lon, lat],
[lon + size, lat],
[lon + size, lat + size],
[lon, lat + size],
[lon, lat],
],
];
t.mock.method(globalThis, 'fetch', async (url) =>
String(url) === '/api/fire-perimeters'
? Response.json({
rows: [
{
stableId: 'fire',
name: 'Fixture Fire',
acres: 1200,
containedPct: 30,
updatedTime: Date.now() - 3600000,
polygons: [square(-110, 35, 0.01), square(-108, 35, 0.2)],
},
],
})
: new Response('down', { status: 503 }),
);
const near = await hazardsNear(35.1, -107.9, 30, { force: true });
const fires = near.filter(({ kind }) => kind === 'wildfire');
assert.equal(fires.length, 1);
assert.equal(fires[0].title, 'Fixture Fire');
assert.ok(fires[0].distanceKm < 5, `${fires[0].distanceKm} km`);
});