DEV Community

Cover image for d3-maps: a toolkit for interactive SVG maps for React and Vue
Georgii Bukharov
Georgii Bukharov

Posted on • Edited on

d3-maps: a toolkit for interactive SVG maps for React and Vue

Crafting maps with d3.js is often requires a lot of boilerplate around data, config, and rendering.

I built d3-maps to make it simple. Reactive components, plain SVG and d3.js power without low-level wiring.

It helps build choropleth maps, bubble maps, and other geographic data visualizations, using markers, connections, zoom & pan and more.

Features

  • Reactive rendering
  • Responsive by default
  • TopoJSON and GeoJSON support
  • Fully typed
  • SSR friendly
  • Lightweight and tree-shakable

Architecture

@d3-maps/core owns framework-agnostic complex logic. It hides interaction with d3 under the hood and provides simple API.

@d3-maps/react and @d3-maps/vue are adapters, they implement framework-specific integrations using core.

@d3-maps/atlas provides ready-to-use typed TopoJSON datasets: continents, countries, and more. It's not bounded to core or adapters, and can be used standalone.

Usage

Here's a brief snippet of a zoomable map using d3-maps. You can find more examples on docs website, link is below.

React

import { use } from 'react'
import { MapBase, MapFeatures, MapZoom } from '@d3-maps/react'

const worldPromise = import('@d3-maps/atlas/world/countries')
  .then((m) => m.default)

export function MapView() {
  const world = use(worldPromise)

  return (
    <MapBase>
      <MapZoom>
        <MapFeatures data={world} />
      </MapZoom>
    </MapBase>
  )
}
Enter fullscreen mode Exit fullscreen mode

Vue

<script setup lang="ts">
import { MapBase, MapFeatures, MapZoom } from '@d3-maps/vue'

const world = await import('@d3-maps/atlas/world/countries/countries-110m')
  .then((m) => m.default)
</script>

<template>
  <MapBase>
    <MapZoom>
      <MapFeatures :data="world" />
    </MapZoom>
  </MapBase>
</template>
Enter fullscreen mode Exit fullscreen mode

Alternative to react-simple-maps

@d3-maps/reactΒ can fully replace react-simple-maps, supports React 19 an has more features under the hood. Here is migration guide.

Links

Repo: https://github.com/souljorje/d3-maps

Docs & Examples: https://d3-maps.netlify.app

I'd appreciate your star on Github and feedback in comments, thanks!

Top comments (0)