Choropleth
Visualize data by coloring geographic regions based on values.
Installation
First, make sure you have the base map component installed:
npx shadcn@latest add https://www.terrae.dev/map.jsonThen install the choropleth component:
npx shadcn@latest add https://www.terrae.dev/choropleth.jsonColor Scales
The colorScale prop defines how values map to colors. You can use linear interpolation for smooth gradients or step for discrete color bands.
const colorScale = {
stops: [
{ value: 0, color: "#f7fbff" },
{ value: 100, color: "#6baed6" },
{ value: 500, color: "#08519c" },
],
interpolation: "linear",
}Interactive Features
Enable hover highlighting with hoverEnabled and handle clicks with onClick. Click on a province to see details in a popup.
Custom Styling
World countries colored by population using Tailwind CSS blue gradient colors. The popup also uses Tailwind gradient styling.
Neon Gradient
Enable animated neon gradient fill with neonAnimated. The fill color smoothly transitions through the specified colors in a continuous loop. Customize the colors with neonColors and the animation duration with neonDuration.
Properties
| Property | Type | Description |
|---|---|---|
data | string | FeatureCollection | GeoJSON URL or FeatureCollection with Polygon/MultiPolygon features |
valueProperty | string | Property name in feature.properties to use for coloring |
colorScale | ChoroplethColorScale | Color scale configuration with stops and interpolation type |
fillOpacity | number | Fill opacity (0-1) |
strokeColor | string | Border color between regions |
strokeWidth | number | Border width in pixels |
strokeOpacity | number | Border opacity (0-1) |
hoverEnabled | boolean | Enable hover highlighting effect |
hoverFillOpacity | number | Fill opacity when hovered |
hoverStrokeColor | string | Border color when hovered |
hoverStrokeWidth | number | Border width when hovered |
onClick | function | Callback when a region is clicked |
onHover | function | Callback when hovering over regions |
neonAnimated | boolean | Enable animated neon gradient fill |
neonColors | string[] | Colors to cycle through for the neon gradient |
neonDuration | number | Animation cycle duration in milliseconds |
Color Scale Type
| Property | Type | Description |
|---|---|---|
stops | { value: number, color: string }[] | Array of value-to-color mappings |
interpolation | "linear" | "step" | How to interpolate colors between stops |
nullColor | string | Color for regions with null/missing values |
Use Cases
Election Maps
Visualize voting results by region
Population Density
Show demographic data across areas