Skip to main content
Skip to main content

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" and zoom up to 64x, plus the states and provinces of the optional react-svg-worldmap-regions package.
  • 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 by website/scripts/build-cloud-region-pins.mjs), using each pin's color and shape; 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 detailLevel and detailProvider), 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 zoom and 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 styleFunction that shades countries by value and fills countries without data in grey.
  • The function receives the country context and returns React CSSProperties:
FieldTypeDescription
countryCodestringISO code of the country
countryNamestringName of the country
countryValuenumber | string | undefinedThe country's value from data, or undefined
colorstringThe color prop
minValuenumberThe smallest value in data
maxValuenumberThe largest value in data
disputeDisputeClassification | undefinedDispute metadata for supported Tier 1 disputed territories

examples/localization​

  • A tooltipTextFunction that shows tooltips in Spanish.
  • Intl.DisplayNames translates the country names and Intl.NumberFormat formats the numbers, so no translation table is needed. For example, { country: "us", value: 345 } shows "Estados Unidos: 345 millones de habitantes".

examples/onclick​

  • An onClickFunction that 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.
  • An hrefFunction that turns each country into a link to its Wikipedia page.

examples/text-labels​

  • A textLabelFunction that 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​

  • richInteraction turns on zoom: double-click the map, or press + and -.

examples/zoom​

  • zoom with pins and 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.ts and awsRegionLocations.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.