Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-svg-worldmap

yanivam41.4kMIT2.0.0-alpha.16TypeScript support: included

A pure react component to draw a map of world countries. Simple. Free.

react, worldmap, world map, map, component, typescript, svg, countries

readme

react-svg-worldmap License: MIT npm version

A simple, compact and free React SVG world map.

simple example

Documentation & Examples

We use GitHub pages to provide documentation with ample of live examples.

Give it a try at yanivam.github.io/react-svg-worldmap.

Why is it different?

Focus on simple and free.

  • Draw countries on a world map.
  • Free - Really free with no limits.
  • No registration - It is just a pure react component.
  • No internet dependency - All the data is local, no calls to a back-end server.
  • Easy to learn, easy to use, easy to customize.

Yet another package for world map...but why?

It all started with a fun project that I was building and needed to draw simple yet beautiful world's map. Searching for solutions I found many potential solutions like MapBox and Google Maps, but they were "too smart" for what I needed. They needed to "call home" for the data, they supported tons of options I didn't need, and while they included react-integrations, they were not completely native to the react world. There was definitely something missing. And that's when react-svg-worldmap started.

Where are we getting the data for the world map?

We have sourced our data from Natural Earth, a community-driven initiative aimed at creating visually appealing and high-quality maps using cartography or GIS software for small-scale projects. Our use of open source tools in creating this map data is not intended to express any political views, but rather to fulfill the requirements of this project. Link to the data: https://www.naturalearthdata.com/downloads/110m-physical-vectors/110m-land/

Install

In order to install, run the following command:

$ npm install react-svg-worldmap --save

Usage

Here is a simple example:

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

function App() {
  const data = [
    { country: "cn", value: 1389618778 }, // china
    { country: "in", value: 1311559204 }, // india
    { country: "us", value: 331883986 }, // united states
    { country: "id", value: 264935824 }, // indonesia
    { country: "pk", value: 210797836 }, // pakistan
    { country: "br", value: 210301591 }, // brazil
    { country: "ng", value: 208679114 }, // nigeria
    { country: "bd", value: 161062905 }, // bangladesh
    { country: "ru", value: 141944641 }, // russia
    { country: "mx", value: 127318112 }, // mexico
  ];

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

License

MIT

changelog

CHANGELOG

1.0.22

  • On hover - add highlight to border of current country by making the stroke 2 instead of 1.

1.0.23

  • On hover - refine the highlighting.

1.0.24

  • Fixed dependency bug for d3-geo not being a module
  • Added marker type that is still in progress in beta (see README.md file for more detail)

1.0.25

  • Renamed the islands to avoid confusion
  • Added user control over map styling using stylingFunction (see README.md file for more detail)

1.0.26

  • Bug fix returning functionality due to the default styling function

1.0.27

  • Bug fix, console.log that was forgotten, solved issue

1.0.28

  • Marker update, changed the style of markers and updated them to be circular because I believe that those would be more optimal for small countries rather than a larger icon like the old version

1.0.29

  • Reduce the size of the countries.geo.json by limiting number precision to 3 digits

1.0.30

  • Tried to reduce the size of countries.geo.json even more by changing the structure of the file and adding the extra properties programmatically.
  • Changed names so they have spaces in between multiple words ex. UnitedStates -> United States

1.0.31

  • Fixed bug with new data where some countries did not display properly

1.0.32

  • Minify geo json.

1.0.33

  • Uglified our exported files, looking for change in size of file

1.0.34

  • Restored JSON to previous implementation so that it works with the code I wrote and highlights the right things

1.0.35

  • Added localization ability and tooltip text customization through a callback function called tooltipTextFunction
  • Added example of how to use to examples

1.0.36

  • README.md typo

1.0.37

  • Onclick callback as requested, for instructions on usage see README.md, for an example look at the example folder under onclick-example.

1.0.38

1.0.39

  • Added README gif and fixed errors in README
  • Fixed errors in the localization example due to a mismatch of data and title

1.0.40

  • Updated tooltip to allow for multiline functionality
  • Added size xxl which supports 1200x1200 map sizes

1.0.41

  • Responsive size option for different sized layouts (mobile/desktop/tablet/etc...)

1.0.42

  • Deprecated marker functionality to fix improper highlight bug.
  • Erased console.log

1.0.43

  • Restructured file system to enable JavaScript and TypeScript usage and ability (see README.md for usage in JS vs TS)

1.1.0

  • Refactor build and dependency cleanup
  • Moved code to lib folder

2.0.0-alpha.0

  • Move examples and documentation to Website on Github pages
  • Changed master to main
  • New feature: testLabelFunction callback
  • New feature: double-click to zoom map
  • New feature: Export isoCode type
  • New feature: Optional numeric value for 'size'
  • New feature: SSR-compatible rendering