Nimbo’s rain comes as standard XYZ tiles, so Leaflet draws it with a plain L.tileLayer. This guide builds a complete page that plays the forecast as a loop and keeps itself up to date.
Before you start
You need a key: get one free, no card. Tiles take it in the URL (?key=), never in a header. There is nothing to install, as the page loads Leaflet 1.9 from a CDN.
The complete page
Save it as index.html, put your key in KEY and open it in a browser.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rain radar</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css">
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<style>
html, body, #map { height: 100%; margin: 0; }
#time { position: absolute; z-index: 1000; top: 10px; right: 10px; padding: 4px 8px; background: #fff; font: 14px sans-serif; }
</style>
</head>
<body>
<div id="map"></div>
<div id="time"></div>
<script>
const BASE = "https://nimboweather.com";
const KEY = "nimbo_..."; // a key in a web page can be copied: regenerate it from your dashboard if that happens
const map = L.map("map").setView([48.5, 8], 5);
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 12, attribution: "© OpenStreetMap contributors",
}).addTo(map);
let frames = []; // { time, layer }, one tile layer per forecast frame
let ready = 0; // frames loaded so far
let shown = 0;
async function loadForecast() {
const res = await fetch(`${BASE}/v1/tiles/index?key=${KEY}`);
const index = await res.json();
if (!res.ok) throw new Error(`${index.error}: ${index.message}`);
// every frame from this one index: they belong to the same forecast
const next = index.forecast.map((f) => ({
time: new Date(f.time),
layer: L.tileLayer(`${f.tiles.rain}?key=${KEY}`, {
maxNativeZoom: 8, // tiles stop at zoom 8: Leaflet stretches them above
opacity: 0,
attribution: index.attribution.join(", "),
}),
}));
frames.forEach((f) => f.layer.remove());
frames = next; ready = 0; shown = 0;
// one frame after another, the first one first, rather than all 20 at once (tile rate limit)
for (const f of next) {
await new Promise((done) => f.layer.once("load", done).addTo(map));
if (frames !== next) return; // a newer forecast took over meanwhile
ready += 1;
await new Promise((done) => setTimeout(done, 1000)); // the tile limit refills at 25 tiles a second
}
}
function step() {
if (!ready) return;
frames[shown].layer.setOpacity(0);
shown = (shown + 1) % ready;
frames[shown].layer.setOpacity(0.8);
document.getElementById("time").textContent =
frames[shown].time.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
}
loadForecast();
setInterval(loadForecast, 10 * 60_000); // a new forecast every 10 minutes
setInterval(step, 700);
</script>
</body>
</html>How it works
- One index per forecast.
GET /v1/tiles/indexlists the frames of the latest forecast: every 5 minutes to one hour ahead, then every 15 minutes to three hours, 20 frames. Each frame has a ready tile URL per layer. - One tile layer per frame. All frames come from the same index, so the rain moves smoothly instead of jumping between two forecasts.
- Frames load one after another. The page waits for each layer’s
loadevent, then a second, before adding the next, so the tiles stay within the rate limit. The loop only plays frames that are ready, so it starts at once and grows to the full three hours in about half a minute. - The loop shows one frame at a time by setting its opacity, and the page reads a fresh index every 10 minutes, when a new forecast is out.
What the index holds
| Field | Meaning |
|---|---|
issue_time, data_age_s, stale | When the forecast was made, how old its radar data is, and whether that data is late. |
forecast[].time | The time the frame shows (UTC). |
forecast[].offset_min | Minutes after the issue time: 5, 10, ... 60, then 75, 90, ... 180. |
forecast[].tiles.rain | Tile URL template of the rain rate, with {z}/{x}/{y} for Leaflet to fill. Add ?key=. |
forecast[].tiles.p1 | The same frame as the chance of 1 mm/h or more, drawn as blue of varying opacity. |
attribution | The credit line to show with the tiles, as the example does. |
The colours of each palette and the formula behind them are in the tiles reference.
Common pitfalls
- Blank above zoom 8. Tiles stop at zoom 8. Without
maxNativeZoom: 8Leaflet asks for tiles that do not exist; with it, Leaflet stretches the zoom 8 tiles. tileerroroutside Europe. A tile wholly outside the forecast grid answers204 No Content, which Leaflet reports as atileerror. It is an empty tile, not a fault: ignore it.429 tile_rate_limited. A key may load bursts of 40 tiles, refilled at 25 a second (Pro: 80 and 50). Loading all 20 frames at once runs into it, and Leaflet does not retry a refused tile. Load frames in turn, as above. Panning or zooming reloads every frame on the map, so keep the map small or the loop short if your visitors move around a lot.- Transparent is dry or unseen. A clear area is either dry or out of radar range. The point API tells the two apart at a point, with
coverage: "no_radar". - Late radar. When the index says
stale: true, the newest radar is late; say so on the map rather than present the loop as fresh. - Your key is in the URLs. Tiles need it there, so anyone can read it from the page. Regenerate it from your dashboard if it is misused.
- Tiles count as requests. A tile our server draws for you is one request, on the same count as point forecasts; one already in our cache is free. A small map of about 15 tiles uses about 300 over the 20 frames. See pricing.
For a still image instead of a loop, the latest alias needs no index.