This library is not production-ready yet. Developers should use it with caution and expect breaking changes.

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.json

Then install the choropleth component:

npx shadcn@latest add https://www.terrae.dev/choropleth.json

Loading US states...

Color 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.

Loading China provinces...

Custom Styling

World countries colored by population using Tailwind CSS blue gradient colors. The popup also uses Tailwind gradient styling.

Loading countries...

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.

Loading US states...

Properties

PropertyTypeDescription
datastring | FeatureCollectionGeoJSON URL or FeatureCollection with Polygon/MultiPolygon features
valuePropertystringProperty name in feature.properties to use for coloring
colorScaleChoroplethColorScaleColor scale configuration with stops and interpolation type
fillOpacitynumberFill opacity (0-1)
strokeColorstringBorder color between regions
strokeWidthnumberBorder width in pixels
strokeOpacitynumberBorder opacity (0-1)
hoverEnabledbooleanEnable hover highlighting effect
hoverFillOpacitynumberFill opacity when hovered
hoverStrokeColorstringBorder color when hovered
hoverStrokeWidthnumberBorder width when hovered
onClickfunctionCallback when a region is clicked
onHoverfunctionCallback when hovering over regions
neonAnimatedbooleanEnable animated neon gradient fill
neonColorsstring[]Colors to cycle through for the neon gradient
neonDurationnumberAnimation cycle duration in milliseconds

Color Scale Type

PropertyTypeDescription
stops{ value: number, color: string }[]Array of value-to-color mappings
interpolation"linear" | "step"How to interpolate colors between stops
nullColorstringColor for regions with null/missing values

Use Cases

Election Maps

Visualize voting results by region

Population Density

Show demographic data across areas