Skip to content

Commit a6f0213

Browse files
kevinelliottclaude
andcommitted
Compute coverage area from active hex data, not global stats
Coverage area stat now reflects the current time window and transport filter. Computed client-side from the loaded hexData array length multiplied by the area-per-cell for the current H3 resolution (based on zoom level). Switching to Aircraft-only or a shorter time window now shows a smaller coverage area. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5e28c35 commit a6f0213

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

map/src/components/controls/StatsBar.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,29 @@ export default function StatsBar() {
1111
const hexData = useCoverageStore((s) => s.hexData);
1212
const lastUpdated = useCoverageStore((s) => s.lastUpdated);
1313
const timeWindow = useUIStore((s) => s.timeWindow);
14+
const viewState = useUIStore((s) => s.viewState);
1415
const flyTo = useUIStore((s) => s.flyTo);
1516

1617
const totalMessages = stations.reduce((sum, s) => sum + s.messageCount, 0);
1718

19+
// Estimate coverage area from currently loaded hex cells.
20+
// Average area per cell by H3 resolution (km²):
21+
// res 2: ~86,745 res 3: ~12,393 res 4: ~1,770 res 5: ~253 res 6: ~36 res 7: ~5
22+
const coverageAreaKm2 = useMemo(() => {
23+
if (hexData.length === 0) return 0;
24+
// Detect resolution from first cell index length (res 2=15chars, 3=15, 4=15... all 15)
25+
// Instead use the map zoom to infer which resolution was fetched
26+
const zoom = viewState.zoom;
27+
let areaPerCell: number;
28+
if (zoom <= 3) areaPerCell = 86745;
29+
else if (zoom <= 5) areaPerCell = 12393;
30+
else if (zoom <= 7) areaPerCell = 1770;
31+
else if (zoom <= 9) areaPerCell = 253;
32+
else if (zoom <= 11) areaPerCell = 36;
33+
else areaPerCell = 5;
34+
return Math.round(hexData.length * areaPerCell);
35+
}, [hexData, viewState.zoom]);
36+
1837
// Source type breakdown
1938
const sourceBreakdown = useMemo(() => {
2039
const counts: Record<string, number> = {};
@@ -64,7 +83,7 @@ export default function StatsBar() {
6483
{/* Main stats */}
6584
<div className="flex items-center justify-between">
6685
<Stat label="Stations" value={stations.length} />
67-
<Stat label="Coverage" value={formatArea(stats?.coverageAreaKm2 ?? 0)} />
86+
<Stat label="Coverage" value={formatArea(coverageAreaKm2)} />
6887
<Stat label="Messages" value={formatCount(totalMessages)} />
6988
<Stat label="msg/s" value={stats?.messagesPerSecond ?? 0} decimals={1} />
7089
</div>

0 commit comments

Comments
 (0)