Draw A World Map Chart with React + d3 + TS

Eli Elad Elrom
Master React
Published in
14 min readFeb 8, 2021

--

A world map chart is a great way to be used as the background to show items globally. Integrating d3 + React and TS can create a readable code that takes the best of all worlds. In this article, I will show you how to work with a world map chart to create a rotating map and assign dots based on coordinates.

In this tutorial, I will show you how to work with a world map using React, d3, and TS as type checker. I broke down the process into steps. In each step, I will be adding more and functionality until we have the Rotating round world map chart with dots that represent coordinates.

The steps are broken into five parts and I separate the component into different files so it’s easy to see and compare the change;

  • World Map Atlas — WorldMapAtlas.tsx
  • Round World Map — RoundWorldMap.tsx
  • Rotating Round World Map — RotatingRoundWorldMap.tsx
  • Rotating Round World Map With Coordinates — RotatingRoundWorldMapWithCoordinates.tsx
  • Refactoring — WorldMap.tsx

Setup

The project setup is quick and simple using the CRA with MHL template project;

$ yarn create react-app world-map-chart --template must-have-libraries
$ cd world-map-chart
$ yarn start $ open…

--

--