Skip to content

shadcn.io is an independent project built on shadcn/ui

Crime Heatmap Map Block for React

A live heatmap of neighbourhood reports across Barcelona's ten districts, with type and period toggles and district cells rated per 10,000 residents.

On this page5 sections

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

See where neighbourhood reports gather and how each district compares, with this crime heatmap map for React with Base UI. Lanternwatch, a neighbourhood safety site, warms a live Map of Barcelona with a heatmap of 455 reports from the last 90 days, a seeded sample round real places in the city's ten districts; zoom in past the streets and the heat gives way to each report as a dot. A multi Toggle Group over the map picks the types (theft, damage, disturbance, vehicle) and another above it the period (7, 30 or 90 days), and both re-filter the heat and every count. Each district's pill carries its rate per 10,000 residents scaled to a month, so short and long periods compare, and a scroll-snap row of district cells under the map gives the same rate with its word (Low, Moderate, Elevated, High), its reports and its current rank, in an order that never moves. Choosing a district, by its cell or its pill, outlines its real border, flies the map there and brings its cell into view. Built from Map, Toggle Group, Button and Guides. For neighbourhood safety sites, local news and city dashboards.

FAQ

Where do the reports come from, and what stays local?

The districts, their simplified borders (from OpenStreetMap) and their populations are real. Every report is invented: REPORTS is built once from each district's typed 90-day counts in LINES, with days and places drawn from a fixed seed, so the map looks the same on every load. They are sample data, not crime statistics and not advice. Nothing is fetched but the map tiles, and nothing is sent.

How is a district's rate worked out?

rateOf counts the district's reports that the period and the types let through, scales them to 30 days (times 30, divided by the period's days) and divides by its residents in tens of thousands. Under 0.6 is Low, under 1 Moderate, under 2 Elevated, and 2 or more High. A 7-day rate rests on few reports, so it moves more than a 90-day one.

How do the type and period toggles work?

The types are a multi-select toggle group: turn any off to drop them from the heat, the counts and the rates; the last one can't be turned off, so the map is never empty. The period is a single-select toggle group above the map, and the line beside it counts the reports shown. The ranks in the cells follow the filters while the cells keep their places.

Can I use it without a mouse?

Yes. Both toggle groups take the arrow keys, every district cell is a button that outlines and flies to the district, as clicking its pill does, and the zoom and city buttons work from the keyboard. The focused map takes the arrow keys and plus and minus. A polite status line gives the total, the highest rate and the chosen district once a choice settles.

How does it look on a phone?

The period toggle and the count sit above the map, the type bar floats over its top, and the district pills turn into dots so the map stays readable; the chosen district keeps its name and rate. The district cells scroll sideways under the map, two at a time, and snap into place.

How is the heat drawn?

MapHeatmap blurs the reports into the theme's chart colours, from the faintest where they are few to the strongest where they crowd, and fades into the reports themselves as dots past zoom 15. The district outline is a MapGeoJSON layer that changes with the choice, and the camera frames every report at the start.