# react-svg-worldmap [![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://img.shields.io/npm/v/react-svg-worldmap.svg?style=flat)](https://www.npmjs.com/package/react-svg-worldmap) [![CI](https://github.com/yanivam/react-svg-worldmap/actions/workflows/ci.yml/badge.svg)](https://github.com/yanivam/react-svg-worldmap/actions/workflows/ci.yml)

A lightweight React component for rendering a bundled SVG world map for charts, dashboards, and thematic data visualizations.

<p align="center">
  <img src="https://raw.githubusercontent.com/yanivam/react-svg-worldmap/main/docs/media/hero.gif" alt="World map demo: Equal Earth projection, tooltips and zoom" width="800" />
</p>

## Overview

`react-svg-worldmap` is designed for teams that want a simple client-side world map without a hosted map service, API dependency, or heavyweight geographic stack. The package ships a bundled map and exposes a small React API for coloring countries, attaching interactions, and rendering values.

## Why teams use it

- Bundled map data with no runtime network requests
- Small API surface focused on thematic data visualization
- Works with standard React applications without a map platform dependency
- Ships ESM, CJS, and TypeScript declaration files
- CI enforces automated tests and `>90%` coverage
- Optional dispute metadata and disputed-territory overlay for high-visibility geopolitical cases
- Opt-in Equal Earth projection alongside the default Mercator projection
- Opt-in atlas colour theme
- Opt-in zoom and pan, map pins, and country labels

## Documentation & Examples

Live examples and package documentation are available at [yanivam.github.io/react-svg-worldmap](https://yanivam.github.io/react-svg-worldmap).

## Install

### Minimum requirements

- React `>=16.8`
- `react-dom >=16.8` for browser-rendered applications

### Install from npm

```bash
npm install react-svg-worldmap
```

## Usage

```tsx
import * as React from "react";
import WorldMap from "react-svg-worldmap";
import "./App.css";

function App() {
  const data = [
    { country: "cn", value: 1389618778 },
    { country: "in", value: 1311559204 },
    { country: "us", value: 331883986 },
    { country: "id", value: 264935824 },
    { country: "pk", value: 210797836 },
    { country: "br", value: 210301591 },
    { country: "ng", value: 208679114 },
    { country: "bd", value: 161062905 },
    { country: "ru", value: 141944641 },
    { country: "mx", value: 127318112 },
  ];

  return (
    <div className="App">
      <WorldMap
        color="red"
        title="Top 10 Populous Countries"
        valueSuffix="people"
        size="lg"
        data={data}
      />
    </div>
  );
}
```

## Projections

Mercator is the default. Pass `projection="equalEarth"` for the equal-area [Equal Earth](https://en.wikipedia.org/wiki/Equal_Earth_projection) projection, where countries keep their true relative size. Equal Earth uses a 2:1 SVG frame and draws a globe outline in `borderColor`. Existing maps are unchanged unless you opt in.

```tsx
<WorldMap data={data} projection="equalEarth" />
```

## Themes

Pass `theme="atlas"` for a classic atlas look: blue water, slate borders, and light land for countries without data, with borders that stay one pixel wide. Colour props you set (`backgroundColor`, `borderColor`, `styleFunction`, ...) override the theme. Without `theme`, the map is unchanged.

```tsx
<WorldMap data={data} theme="atlas" />
```

## Zoom, Pins And Labels

Pass `zoom` for zoom and pan with buttons, drag, double-click, keyboard, and ctrl / ⌘ + wheel (a plain wheel still scrolls the page). Zooming also shows country names that fit inside their countries. `pins` draws captioned markers at `[longitude, latitude]`, with or without zoom.

```tsx
<WorldMap
  data={data}
  zoom={{ maxScale: 6 }}
  onZoomChange={(state) => console.log(state.scale)}
  pins={[{ caption: "Paris", coordinates: [2.35, 48.86], countryCode: "FR" }]}
/>
```

When zoomed in to 2x or more, the map draws sharper (Natural Earth 10m) country borders, loaded on demand as a separate file that is not part of the default bundle. With `detailLevel="regions"` and a `detailProvider`, it also draws the regions of the countries in view.

Colors are props: `pinColor`, `pinTextColor`, `pinOutlineColor`, `labelColor`, and `labelHaloColor`. Both projections are supported. Without `zoom`, `richInteraction` and the default render are unchanged. See the [API docs](https://yanivam.github.io/react-svg-worldmap/api#zoom-and-pan).

## Data Sources And Neutrality Policy

The bundled map is a small-scale thematic visualization for charts and dashboards. It is not presented as a legal, diplomatic, or authoritative boundary reference.

The project uses a documented source hierarchy instead of treating one raw dataset as authoritative for every geopolitical question:

1. `UNSD M49` and `UNTERM` for neutral naming, codes, and terminology
2. `Natural Earth Admin 0 Countries` for the bundled small-scale geometry
3. A repo-maintained overrides register for disputed or recognition-sensitive cases

This project aims to stay neutral by documenting how naming, geometry, and disputed territories are handled. For sensitive cases, maintainers prefer reviewable documentation and coarse small-scale representation over silent or over-precise political claims.

The package exposes Tier 1 dispute metadata for Crimea, Palestinian Territories, Taiwan, Kashmir, Western Sahara, and Kosovo, with shapes for the disputed territories themselves (for example Crimea rather than all of Ukraine, and the Kashmir areas rather than India, Pakistan, and China). The default map does not change. Turn on the overlay to highlight the territories, with tooltips listing status, recognized sovereign, controlling power, and parties:

```tsx
import { WorldMap } from "react-svg-worldmap";

<WorldMap
  data={[]}
  showDisputedTerritories
  onDisputedTerritoryClick={({ territoryName, dispute }) =>
    console.log(territoryName, dispute.unStanding)
  }
/>;
```

Country callbacks also receive the metadata as `context.dispute`, for example to style the countries involved.

Source attribution and policy details:

- [Map data policy](https://github.com/yanivam/react-svg-worldmap/blob/main/docs/map-data-policy.md)
- [Sensitive-case overrides register](https://github.com/yanivam/react-svg-worldmap/blob/main/docs/map-data-overrides.json)
- [Natural Earth Admin 0 Countries](https://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-admin-0-countries/)
- [Natural Earth Admin 0 Breakaway and Disputed Areas](https://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-admin-0-breakaway-disputed-areas/) (disputed-territory overlay)
- [UNSD M49](https://unstats.un.org/unsd/methodology/m49/)
- [UNTERM](https://unterm.un.org/)

## Notes

- Country codes use ISO 3166-1 alpha-2 values such as `us`, `fr`, and `jp`.
- The default map is bundled locally with the package.
- The component does not fetch map geometry from a remote API at runtime.

## Accessibility

The component is designed to be WCAG 2.2 AA compliant at the component level:

- The root `<svg>` is annotated with `role="img"` and `aria-labelledby` pointing to an embedded `<title>` element.
- Each country region SVG element carries its own `<title>` with the country name and value.
- The component ships no decorative elements without `aria-hidden`.

### Responsibilities of the consuming application

Because `<WorldMap>` is a self-contained SVG widget and not a full page, the host application should provide page-level landmarks:

| Requirement | WCAG criterion | What to do |
| --- | --- | --- |
| Skip link | 2.4.1 Bypass Blocks | Add a visually-hidden `<a href="#main-content">Skip to main content</a>` as the first focusable element in your page shell |
| `<main>` landmark | 1.3.1 Info and Relationships | Wrap the primary page content in `<main id="main-content">` |
| `<nav>` landmark | 1.3.1 Info and Relationships | Wrap your site navigation in `<nav aria-label="Main">` |
