# Map Tiles & Layers

Precip serves raster map tiles (256×256 Web Mercator / EPSG:3857) for precipitation, live radar, nowcast, temperature, wind, soil moisture, snow, and climate normals. Tiles work with **Mapbox GL JS**, **MapLibre GL**, **Leaflet**, **OpenLayers**, **Google Maps**, **ArcGIS**, and **QGIS**.

## Tile URL template

```text
https://api.precip.ai/api/v1/map/{serviceName}/ImageServer/tile/{z}/{y}/{x}?apiKey=YOUR_API_KEY
```

:::caution{title="Coordinate order is {z}/{y}/{x} (row before column)"}
Precip tile URLs use **`{z}/{y}/{x}`** order (`y` before `x`), matching Esri / TMS-style row-column paths — **not** the `{z}/{x}/{y}` order used in many Mapbox or Leaflet defaults. Swapping `x` and `y` will place tiles in the wrong part of the map.
:::

- **Authentication:** Pass `apiKey=YOUR_API_KEY` in the query string (easiest for browser maps and GIS clients), or send `Authorization: Bearer YOUR_API_KEY` from a backend or tile proxy. For public web apps, proxy tile requests through your own backend so your API key stays private.
- **Default format:** Tiles return `image/webp` by default for smaller payloads. Pass `?format=png` if your client requires PNG (note: sub-hourly radar/nowcast layers `precip-rate%2F2min` and `precip-rate-v2%2F5min` return WebP only).
- **Native zoom (`maxzoom`):** Most precipitation and nowcast layers have a native max zoom of **7** or **8**. Configure `maxzoom` on your map source so the client overzooms cleanly instead of requesting unnecessary higher-zoom tiles.

---

## Quick examples

### Mapbox GL JS / MapLibre GL

```javascript
map.on("load", () => {
  map.addSource("precip-last-48", {
    type: "raster",
    tiles: [
      "https://api.precip.ai/api/v1/map/last-48/ImageServer/tile/{z}/{y}/{x}?apiKey=YOUR_API_KEY",
    ],
    tileSize: 256,
    maxzoom: 7,
  });

  map.addLayer({
    id: "precip-last-48-layer",
    type: "raster",
    source: "precip-last-48",
    paint: {
      "raster-opacity": 0.75,
    },
  });
});
```

### Leaflet

```javascript
L.tileLayer(
  "https://api.precip.ai/api/v1/map/last-48/ImageServer/tile/{z}/{y}/{x}?apiKey=YOUR_API_KEY",
  {
    tileSize: 256,
    maxNativeZoom: 7,
    maxZoom: 18,
    opacity: 0.75,
    attribution: "Precip",
  }
).addTo(map);
```

### Time-enabled layer (specific hour or summed range)

Pass `time` in **Unix milliseconds** (not ISO 8601 strings) on `/tile/`:

```javascript
// Single hour: 2026-10-15T12:00:00Z
const hourMs = Date.parse("2026-10-15T12:00:00Z");
const singleHourUrl =
  `https://api.precip.ai/api/v1/map/precip-hourly/ImageServer/tile/{z}/{y}/{x}?time=${hourMs}&apiKey=YOUR_API_KEY`;

// 24-hour summed range (up to 192 time steps per tile)
const startMs = Date.parse("2026-10-14T00:00:00Z");
const endMs = Date.parse("2026-10-15T00:00:00Z");
const rangeUrl =
  `https://api.precip.ai/api/v1/map/precip-hourly/ImageServer/tile/{z}/{y}/{x}?time=${startMs},${endMs}&apiKey=YOUR_API_KEY`;
```

For **ArcGIS Online, ArcGIS Pro, ArcGIS JS SDK, and QGIS** instructions, see [ArcGIS & GIS layer access](/arcgis).

---

## Supported layer IDs (`serviceName`)

### Rolling & forecast precipitation totals

Rolling layers always render the latest window and do not take a `time` parameter.

| Layer ID | Max zoom | Description |
| --- | --- | --- |
| `last-12`, `last-24`, `last-48`, `last-168`, `last-720` | 7 | Total precipitation over the last 12h, 24h, 48h, 7 days, or 30 days |
| `next-12`, `next-24`, `next-48`, `next-168` | 7 | Forecast precipitation over the next 12h, 24h, 48h, or 7 days |
| `mtd`, `ytd` | 7 | Month-to-date and year-to-date precipitation |
| `mtd-pct`, `ytd-pct` | 7 | Month-to-date and year-to-date precipitation as % of normal |
| `recent-rain`, `precip-next-rain` | 7 | Most recent rainfall event total / next forecast rain event |
| `last-24-snow`, `last-48-snow`, `last-168-snow`, `next-24-snow`, `next-48-snow` | 7 | Rolling observed and forecast snowfall totals |

### Live radar & sub-hourly nowcast

Because these IDs contain a slash (`/`), **URL-encode `/` as `%2F`** in `{serviceName}` when calling `api.precip.ai`. Both return **WebP only** (`?format=png` returns `501 Not Implemented`).

| Layer ID (`serviceName`) | Max zoom | Time-enabled? | Description |
| --- | --- | --- | --- |
| `precip-rate%2F2min` | 8 | Yes (`time` in Unix ms) | Live 2-minute MRMS radar precipitation rate |
| `precip-rate-v2%2F5min` | 7 | Yes (`time` in Unix ms) | 5-minute precipitation nowcast (next 90 min) |

### Time-enabled hourly & daily weather layers

| Layer ID | Max zoom | Description |
| --- | --- | --- |
| `precip-hourly` (alias `hourly`) | 8 | Hourly precipitation |
| `precip-daily` (alias `daily`) | 8 | Daily precipitation |
| `temperature-hourly` | 8 | Hourly air temperature |
| `tmin-daily`, `tmax-daily` | 8 | Daily minimum and maximum temperature |
| `wind-speed-hourly`, `wind-speed-gust-hourly`, `wind-direction-hourly` | 8 | Hourly wind speed, gusts, and direction (note hyphens, not underscores) |
| `relative-humidity-hourly`, `cloud-cover-hourly`, `dswrf-hourly` | 8 | Hourly relative humidity, cloud cover, and solar radiation |
| `soil-moisture-hourly`, `temp-0-10cm-hourly` | 8 | Hourly 0–10 cm soil moisture and soil temperature |
| `snow-depth-daily` | 8 | Daily snow depth |
| `dew-point-hourly`, `specific-humidity-hourly`, `pressure-hourly`, `visibility-hourly` | 8 | Hourly atmospheric layers (*requires explicit `renderingRule`*) |

### Static soil & frost normals

| Layer ID | Max zoom | Description |
| --- | --- | --- |
| `frost-first-avg-doy`, `frost-last-avg-doy`, `frost-days-above-freezing` | 8 | Average first/last frost day of year and frost-free days |
| `clay-mean-0-5-polaris`, `sand-mean-0-5-polaris`, `silt-mean-0-5-polaris` | 9 | High-resolution POLARIS soil composition layers |
| `soil-texture-classification-polaris` | 9 | POLARIS soil texture classification (*requires explicit `renderingRule`*) |

---

## Tile query parameters

| Parameter | Description |
| --- | --- |
| `apiKey` | API key in the query string (alternative to `Authorization: Bearer`) |
| `format` | `webp` (default) or `png` (`png`, `png24`, `png32`). Sub-hourly nowcast layers support `webp` only. |
| `time` | Unix timestamp in **milliseconds**: single step (`1711411200000`) or range (`1711411200000,1711497600000`). Up to 192 steps per tile. |
| `mosaicRule` | Optional JSON aggregation over a `time` range, e.g. `{"mosaicOperation":"MT_SUM"}` (`MT_SUM`, `MT_MEAN`, `MT_MIN`, `MT_MAX`, `MT_FIRST`, `MT_LAST`). Defaults to sum for precipitation layers and mean for other variables. |
| `units` | `imperial` or `metric` (converts values before applying custom `renderingRule` stops). |
| `unit` | Explicit unit override (e.g. `inches`, `mm`, `fahrenheit`, `celsius`, `mph`, `mps`). |
| `mask` | Region mask: `na` (North America) or `none`. |
| `renderingRule` | Optional JSON Esri Colormap rule (`{"rasterFunction":"Colormap","rasterFunctionArguments":{"colorMap":[[value,r,g,b,a],...]}}`, where `r`, `g`, `b`, `a` are floats in `0..1`) to override the default color ramp. Required on layers marked above without a default colormap. |

---

## Legends & colormaps

Every layer exposes matching legend swatches and raw RGBA colormap stops:

- **Legend swatches & labels (defaults to imperial units):**
  ```bash
  curl "https://api.precip.ai/api/v1/map/last-48/ImageServer/legend?units=imperial" \
    -H "Authorization: Bearer YOUR_API_KEY"
  ```
  Returns `layers[].unit` and `layers[].legend[]` with `label` and base64 PNG `imageData` swatches.

- **Raw RGBA color stops (for custom map legends or shaders):**
  ```bash
  curl "https://api.precip.ai/api/v1/map/last-48/ImageServer/colors.json?units=imperial" \
    -H "Authorization: Bearer YOUR_API_KEY"
  ```
  Returns `{ "unit": "inches", "stops": [{ "value": 0.01, "r": 38, "g": 38, "b": 115, "a": 0 }, ...] }`.

Both endpoints accept `units=imperial|metric`, `unit=…`, and `renderingRule`.

---

## Point sampling (`getSamples`)

`GET /api/v1/map/{serviceName}/ImageServer/getSamples` accepts Esri `esriGeometryMultipoint` JSON (`wkid: 4326`) with `time`, `start`, or `end` parameters.

- **Supported layers:** time-series hourly/daily layers (`hourly`, `precip-hourly`, `temperature-hourly`, `wind-speed-hourly`, `daily`, etc.), `precip-rate%2F2min`, and static `polaris` soil layers.
- **Not supported on rolling rollups:** `last-12`, `last-24`, `last-48`, `last-168`, `next-*`, `mtd`, and `ytd` return `404` on `getSamples`. For point queries on rolling totals or forecasts, use the standard REST endpoints (`/api/v1/last-48`, `/api/v1/daily`, `/api/v1/hourly`) instead.

---

## Rate limits & caching

Every tile request counts as **1 API request** against your plan's rate limit. A single web map viewport typically loads 12–25 tiles on initial render, and panning or zooming loads more:

- **Personal (10 req/min, 100 req/day)** is intended for quick testing, not interactive web maps.
- **Growth (300 req/min)** or **Enterprise** is recommended for live interactive maps.
- **Always set `maxzoom` / `maxNativeZoom`** to match the layer's native max zoom (`7` or `8`), and respect `Cache-Control` response headers (historical finalized tiles and static layers return immutable cache headers; rolling layers cache for 1 hour).
- **Tip for Mapbox / MapLibre:** Tiles are 256×256 px, so `tileSize: 256` renders 1:1 native resolution. Setting `tileSize: 512` scales each tile 2× and cuts tile requests per viewport by roughly 4×.

See [Rate limits & plans](/rate-limits) and the [Map Services API Reference](/api) for full endpoint schemas.
