Bumblebee hexagon map with MapLibre GL JS
Bumblebees spend the winter as lone queens, asleep underground. In spring each queen wakes, finds a nest, and raises workers, so the colony grows all summer, and in fall it dies off, leaving only new queens to sleep through the next winter.
People photograph them on iNaturalist, alongside everything else they find, and other users check what each photo shows. The map plays 2025 week by week, coloring each hexagon by the share of its sightings that were bumblebees, so places where many people take part don't look busier than places where few do. Slide to any week, and click a hexagon for its numbers.
Through January and February the map stays pale. In March the first bumblebees turn up in the inland Northwest, from southern British Columbia to Washington and Idaho, and in scattered places across the South. They spread north and east through spring and summer, and peak in early August, when 2% of everything people photographed was a bumblebee, and 3% or more across much of the Midwest, the Great Lakes, and the Northeast. Then the colonies die off, and by late November the map is pale again, but for a few hexagons in the South.
Each hexagon is 1.6° of longitude wide, about 140 km across the middle of the United States, and smaller further north, since the hexagons keep their shape on the map. Each week counts the sightings of that week and the weeks on either side, which steadies hexagons where few people take part, and a hexagon shows when those three weeks have at least 30 sightings of anything. iNaturalist counts sightings within a distance of a point, so each hexagon is counted in the circle that fits inside it. Sightings follow people, so the share only shows how often bumblebees turn up among what people photograph, not how many there are. The weeks run from Monday to Sunday, from December 30, 2024, to January 4, 2026.
Build it yourself
A Node.js script asks iNaturalist's API how many sightings, and how many bumblebee sightings, there were each week of 2025 in hexagons over the lower 48 states and the edges of Canada and Mexico, and a page colors the hexagons, with a slider to pick the week. It's the map above with bigger hexagons, without the playback, and without cutting the hexagons to the coast. It was tested with MapLibre GL JS 6.15 in Chromium and Node.js 22.
What you need
- Node.js 18 or later.
- A browser key with the Map tiles product, made as API keys shows. Add
http://localhost:*to its allowed origins, so it works from your computer while you build. Map tiles are free, and signing up takes a minute, with no credit card. iNaturalist's API needs no key.
Count the sightings
iNaturalist's /observations/histogram counts sightings in each week of a stretch of days, within a distance of a point, and only of a taxon when you name one. Make a folder for the map, and in it a file called hexagons.mjs:
import { writeFile } from "node:fs/promises";
const width = 2.4;
const start = "2024-12-30";
const weeks = 53;
const end = "2026-01-04";
const rad = Math.PI / 180;
const toY = (lat) => Math.log(Math.tan(Math.PI / 4 + (lat * rad) / 2)) / rad;
const toLat = (y) => (2 * Math.atan(Math.exp(y * rad)) - Math.PI / 2) / rad;
const size = width / Math.sqrt(3);
async function weekly(lon, lat, taxon) {
const query = new URLSearchParams({
quality_grade: "research", interval: "week", date_field: "observed", d1: start, d2: end,
lat, lng: lon, radius: Math.round((width / 2) * 111 * Math.cos(lat * rad)),
});
if (taxon) query.set("taxon_id", taxon);
const response = await fetch(`https://api.inaturalist.org/v1/observations/histogram?${query}`);
if (!response.ok) throw new Error(`iNaturalist answered ${response.status}`);
const { results } = await response.json();
await new Promise((resolve) => setTimeout(resolve, 1000));
return Array.from({ length: weeks }, (_, week) => {
const monday = new Date(Date.parse(start) + week * 7 * 86400000).toISOString().slice(0, 10);
return results.week[monday] ?? 0;
});
}
const features = [];
for (let row = 0, y = toY(25); y < toY(49); row++, y += size * 1.5) {
for (let lon = -125 + (row % 2) * (width / 2); lon < -67; lon += width) {
const lat = toLat(y);
const seen = await weekly(lon, lat);
if (seen.reduce((a, b) => a + b, 0) < 200) continue;
const bees = await weekly(lon, lat, 52775);
const properties = {};
seen.forEach((count, week) => (properties[`w${week}`] = count >= 10 ? bees[week] / count : null));
const ring = [30, 90, 150, 210, 270, 330, 30].map((angle) => [
lon + size * Math.cos(angle * rad),
toLat(y + size * Math.sin(angle * rad)),
]);
features.push({ type: "Feature", properties, geometry: { type: "Polygon", coordinates: [ring] } });
}
}
await writeFile("hexagons.json", JSON.stringify({ type: "FeatureCollection", features }));
console.log(`Saved ${features.length} hexagons`);
- The hexagons are laid out in Web Mercator's y instead of in latitude, with
toYandtoLatconverting between the two, so they keep the same shape on the map from Texas to Canada. Each row is shifted half a hexagon from the one below it, so they fit together. weeklyasks for one hexagon's counts in the circle that fits inside it, with a second between requests, as iNaturalist asks. Its weeks start on Mondays, so each week's count is looked up by its Monday's date.52775is iNaturalist's number for the bumblebee genus, Bombus.- A hexagon with fewer than 200 sightings in the year, such as one over the sea, is skipped before asking about bumblebees. Each week's share is saved as its own property,
w0tow52, and left out of weeks with fewer than 10 sightings, so the page can pick a week with an expression.
Run it:
node hexagons.mjs
It sends about 670 requests, which take about 15 minutes, then prints Saved 298 hexagons, or however many there are today, and writes hexagons.json.
Make the page
Next to hexagons.json, make index.html, with your browser key in place of mapricot_pk_…:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bumblebees through 2025</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maplibre-gl@6.15.0/dist/maplibre-gl.css">
<script type="importmap">
{
"imports": {
"maplibre-gl": "https://cdn.jsdelivr.net/npm/maplibre-gl@6.15.0/+esm"
}
}
</script>
</head>
<body style="margin: 0">
<label style="position: absolute; z-index: 1; top: 10px; left: 10px; padding: 6px 10px; background: white; font: 16px sans-serif">
<span id="week"></span><br>
<input id="slider" type="range" min="0" max="52" value="32" style="width: 220px">
</label>
<div id="map" style="height: 100vh"></div>
<script type="module">
import * as maplibregl from "maplibre-gl";
const start = Date.UTC(2024, 11, 30);
const map = new maplibregl.Map({
container: "map",
style: "https://api.mapricot.com/tiles/v1/styles/light.json?key=mapricot_pk_…",
bounds: [
[-125, 25],
[-67, 49],
],
});
await map.once("load");
map.addSource("hexagons", { type: "geojson", data: "hexagons.json", attribution: "Sightings: iNaturalist" });
map.addLayer({ id: "hexagons", type: "fill", source: "hexagons", paint: { "fill-opacity": 0.8 } });
const slider = document.querySelector("#slider");
function show() {
const share = ["get", `w${slider.value}`];
map.setFilter("hexagons", ["!=", share, null]);
map.setPaintProperty("hexagons", "fill-color", [
"interpolate", ["linear"], share,
0, "#fff9db", 0.015, "#fab005", 0.03, "#7a3e00",
]);
const week = new Date(start + slider.value * 7 * 86400000);
document.querySelector("#week").textContent = `Week of ${week.toLocaleDateString("en-US", { month: "long", day: "numeric", timeZone: "UTC" })}`;
}
slider.addEventListener("input", show);
show();
map.on("click", "hexagons", (event) => {
const share = event.features[0].properties[`w${slider.value}`];
new maplibregl.Popup().setLngLat(event.lngLat).setText(`${(share * 100).toFixed(1)}% of sightings were bumblebees`).addTo(map);
});
</script>
</body>
</html>
- The
filllayer draws every hexagon, andshowpoints it at the week the slider is on:setFilterhides hexagons with too few sightings that week, andsetPaintPropertycolors the rest by their share, from pale yellow for none to brown for 3% or more. - The slider starts on the week of August 11, when bumblebees are near their peak. The date beside it is worked out from the start of the year, in UTC, so it reads the same in every time zone.
- Clicking a hexagon shows its share for the week on the slider.
Open it
Serve the folder with npx serve or python3 -m http.server, and open the address it prints. Opened straight from the file, the map stays blank, as Open the page explains. You should see the middle and east of the country in orange and brown. Slide back to March to see only the Pacific Northwest and the South, and forward to November to watch it fade.
Swap 52775 for another taxon's number from its iNaturalist page, such as 47224 for butterflies, to follow its year instead.
Data
- Sightings: iNaturalist users, research grade, through its API
- Land and lakes: Natural Earth (public domain)
- Map: OpenStreetMap contributors (ODbL), in Mapricot's map tiles