Examples
All examples share one small data set (website/src/data/CountryData.ts): population in millions and GDP per capita in US dollars, approximate 2024 figures.
Every example except the first follows the site's light or dark mode. A small hook (website/src/components/mapTheme.ts) picks backgroundColor, borderColor, strokeOpacity and the tooltip colors for the current mode, and each example spreads them on WorldMap with {...theme}. The regions example keeps the atlasLight theme in both modes.
examples/regions
- Start here. The best-looking setup in a few props:
theme="atlasLight",projection="equalEarth"andzoomup to 64x, plus the states and provinces of the optionalreact-svg-worldmap-regionspackage. - Zoom in and the map sharpens its borders, names the countries that fit, and draws the regions of the countries in view, with their names where they fit and short names (MA) where they do not (
showRegionLabels); countries do the same with their UN codes (USA,countryLabelFormat: "auto"). Oceans, seas and lakes are named too, and the largest lakes drawn as water (showWater), with Antarctica, which every map shows since 3.0.0. A pin marks every AWS (orange square), Azure (blue diamond) and Google Cloud (red pin) region, with a legend above the map, on land in its state or province, in a row below its name (AWS, Azure, Google Cloud, west to east), or near the city in a country without regions (website/src/data/cloudRegionPins.ts, generated bywebsite/scripts/build-cloud-region-pins.mjs), using each pin'scolorandshape; pins start at half their size, so all of them fit the world view, and grow as you zoom in (pinMinSize), with their names from 8x (pinCaptionMinScale); overlapping pins all stay, and only clashing names are hidden (keepOverlappingPins). Hover a pin, or Tab to it, for its cloud, display name and programmatic name (tooltip). Each country's regions download the first time you zoom in on it. - Without the regions package (drop
detailLevelanddetailProvider), the same map works as before.
examples/equal-earth
- Population map with
projection="equalEarth", plus a menu to compare with Mercator. A good setup to start from without the regions package. - Also turns on
zoomand the automatic country labels, and loads the detailed borders as you zoom in. Drag to pan, double-click or use the buttons to zoom, or hold ctrl (⌘) and scroll. - In Equal Earth, Greenland shrinks and Africa shows its true relative size.
examples/atlas-theme
- GDP per capita with
theme="atlas": blue water, slate borders, and light land for countries without data. Borders stay one pixel wide as you zoom. - Menus switch between the atlas and default themes and between Equal Earth and Mercator.
- The atlas palette is the same in light and dark mode; only the tooltip colors follow the site.
examples/sizing
- The same map at each
size:sm,md,lg,xl(default),xxl,"responsive"and a number of pixels.
examples/custom-style
- A
styleFunctionthat shades countries by value and fills countries without data in grey. - The function receives the country context and returns React
CSSProperties:
| Field | Type | Description |
|---|---|---|
countryCode | string | ISO code of the country |
countryName | string | Name of the country |
countryValue | number | string | undefined | The country's value from data, or undefined |
color | string | The color prop |
minValue | number | The smallest value in data |
maxValue | number | The largest value in data |
dispute | DisputeClassification | undefined | Dispute metadata for supported Tier 1 disputed territories |
examples/localization
- A
tooltipTextFunctionthat shows tooltips in Spanish. Intl.DisplayNamestranslates the country names andIntl.NumberFormatformats the numbers, so no translation table is needed. For example,{ country: "us", value: 345 }shows "Estados Unidos: 345 millones de habitantes".
examples/onclick
- An
onClickFunctionthat stores the clicked country in React state and shows it below the map.
examples/tooltip-and-click
- A custom tooltip (formatted as currency) together with a click that outlines the selected country through
styleFunction.
examples/links
- An
hrefFunctionthat turns each country into a link to its Wikipedia page.
examples/text-labels
- A
textLabelFunctionthat labels the four oceans. - The function receives the current map width, so positions and font size follow the map's size. Besides
label, every key is passed to the<text>element.
examples/rich-interaction
richInteractionturns on zoom: double-click the map, or press+and-.
examples/zoom
zoomwithpinsand the automatic country labels. Switch the pins between the capital cities of every country on the map and the AWS regions (website/src/data/countryCapitalPins.tsandawsRegionLocations.ts, both[longitude, latitude]).- Overlapping pins are dropped (earlier pins win), so zooming in shows more of them.
- Drag to pan, double-click or use the buttons to zoom, or hold ctrl (⌘) and scroll. The pins and labels keep their size, and their colors follow the light or dark theme.
examples/disputes
- The opt-in disputed-territory overlay (
showDisputedTerritories). - Only the disputed territories are highlighted in red (e.g. Crimea, not all of Ukraine; the Kashmir areas, not India, Pakistan, and China), dashed where the metadata suggests it.
- Hovering a territory shows its status and parties. Clicking it shows the dispute, its parties and its UN standing.
examples/string-value
- Values can be text instead of numbers, here a list of trips.
- All text values get the same shade. If you mix text and number values, text values are treated as
minValue.