# Map and Cameras

KestrelOS shows a **map** with devices, POIs, live sessions (Share live), and ATAK/iTAK positions. Click markers or use **Cameras** page to view streams.

## Map Layers

- **Devices** - Fixed feeds (IPTV, ALPR, CCTV, NVR, etc.) added via API
- **ALPR (OSM / DeFlock)** - Crowdsourced license-plate cameras from OpenStreetMap; toggle on the map (camera icon control). Reference only, no stream.
- **POIs** - Points of interest (admin/leader can edit)
- **Live sessions** - Mobile devices streaming via Share live
- **CoT (ATAK/iTAK)** - Amber markers for connected TAK devices (position only)

## Cameras

A **camera** is either:
1. A **device** - Fixed feed with stream URL
2. A **live session** - Mobile device streaming via Share live

View via map markers or **Cameras** page (sidebar).

## Device Types

| device_type | Use case |
|-------------|----------|
| `alpr`, `nvr`, `doorbell`, `feed`, `traffic`, `ip`, `drone` | Labeling/filtering |

**source_type:** `mjpeg` (MJPEG over HTTP) or `hls` (HLS `.m3u8` playlist)

Stream URLs must be `http://` or `https://`.

## API: Devices

**Create:** `POST /api/devices` (admin/leader)
```json
{
  "name": "Main gate ALPR",
  "device_type": "alpr",
  "lat": 37.7749,
  "lng": -122.4194,
  "stream_url": "https://alpr.example.com/stream.m3u8",
  "source_type": "hls"
}
```

**List:** `GET /api/devices`  
**Update:** `PATCH /api/devices/:id`  
**Delete:** `DELETE /api/devices/:id`

**Cameras endpoint:** `GET /api/cameras` returns devices + live sessions + CoT entities.

## ALPR layer (DeFlock / OpenStreetMap)

deflock.me has no bulk download API. KestrelOS queries OpenStreetMap via Overpass (`surveillance:type=ALPR`) and returns **GeoJSON FeatureCollection** from `GET /api/alpr`.

- **Map:** ALPR layer is on by default (toggle top-left to hide). Marker popups show OSM identifying tags (manufacturer, model, operator, ref, Wikidata, etc.) when contributors tagged them.
- **Offline:** Run `npm run import:alpr` to preload SQLite; cache serves automatically when Overpass is unreachable.

Attribution: © OpenStreetMap contributors.

## POIs

Admins/leaders add/edit from **POI** page (sidebar). POIs appear as map pins (reference only, no stream).
