WorldMap
Every example on this page is live, drawn by the library's Storybook, where you can also change its props and see the result.
A monochromatic SVG map of the world, shading its countries using fill patterns and optional numeric labels. Supports three map projections: Natural Earth (default), Mercator, and Equirectangular. The map keeps its proportions, filling as much of its box as it can and centered in the rest, in any box it is laid out in. height="fill" sizes the box to the map instead.
Import
import {
WorldMap,
COUNTRY_NAMES,
countryNameFor,
worldMapAspect,
} from "~lib/data-display/maps/world-map";
Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
data | Partial<Record<CountryName, WorldMapEntry>> | Yes | N/A | Per-country shading and optional value |
projection | "natural-earth" | "mercator" | "equirectangular" | No | "natural-earth" | Map projection to use |
showValues | boolean | No | false | Render numeric labels at country centroids |
markers | MapMarker[] | No | N/A | Places to mark, each in its shape with an optional name beside it |
legend | MapLegendEntry[] | No | N/A | What each marker shape stands for, in a row under the map |
width | number | string | No | 300 | Component width (px or CSS string); with height="fill", the column's width unless given |
height | number | "fill" | string | No | 300 | Component height (px or CSS string), or "fill" to be as tall as its width makes it |
CountryName
Every country the map draws. Examples: "United States", "China", "India", "Brazil", "Russia", "Japan", "Germany", "United Kingdom", "Australia", "South Africa". COUNTRY_NAMES lists them all.