A small JavaScript library that draws the world, a region or any country as an SVG of dots or hexagons, with pins.
npm install @setkernel/dotted-map-nextimport { writeFileSync } from 'node:fs';
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG();
writeFileSync('map.svg', svg);map.svg is the world in dots. With no options they are drawn in currentColor, so they are black in a file and take the text colour inside a page. On a server it needs Node.js 22.12 or later; it also runs in edge functions and browsers.
Try every option, start from a preset and copy the code in the playground.
shape: 'hexagon'
|
countryColors
|
||
region
|
countries: ['JPN']
|
countries: ['BRA']
|
countries: ['IND']
|
The library drew every map on this page: scripts/render-gallery.mjs writes them into images/, in light and dark.
Each recipe is complete: paste it into a project that has the package installed. The guides show more, with the map each example draws.
<div id="map"></div>
<script type="module">
import { DottedMap } from 'https://cdn.jsdelivr.net/npm/@setkernel/dotted-map-next@2/+esm';
const svg = new DottedMap({ height: 60 }).getSVG({ title: 'World map' });
document.querySelector('#map').innerHTML = svg;
</script>With a build step, such as Vite, esbuild or webpack, install the package and import it by name instead: import { DottedMap } from '@setkernel/dotted-map-next';. In the browser, the precomputed entry is the smaller download.
examples/react/dotted-map.tsx is a React component in the shadcn format: one file, with this package as its one dependency. One command adds it to your project as components/ui/dotted-map.tsx:
npx shadcn@latest add https://dotted-world-map.com/r/dotted-map.jsonimport { DottedMap } from '@/components/ui/dotted-map';
<DottedMap
title="Our offices"
className="text-neutral-300 dark:text-neutral-700"
pins={[{ lat: 51.51, lng: -0.13, label: 'London', color: '#f97316' }]}
/>;It has no hooks and no "use client", so in a React Server Component the browser gets the SVG and none of the library. examples/react has its props, an "our offices" section and a variant for client components.
Or render the SVG string yourself in a server component, the default in the Next.js App Router. The map is drawn on the server, and the library is not sent to the browser:
import { DottedMap } from '@setkernel/dotted-map-next';
export function WorldMap() {
const svg = new DottedMap({ height: 60 }).getSVG({ title: 'World map' });
return <div dangerouslySetInnerHTML={{ __html: svg }} />;
}A client component, which draws again when its pins change:
'use client';
import { useMemo } from 'react';
import { DottedMap } from '@setkernel/dotted-map-next';
export function PinMap({ pins }) {
const svg = useMemo(() => {
const map = new DottedMap({ height: 60 });
for (const pin of pins) map.addPin(pin);
return map.getSVG({ title: 'Our offices' });
}, [pins]);
return <div dangerouslySetInnerHTML={{ __html: svg }} />;
}Keep the pins in a constant or in state, such as const offices = [{ lat: 51.5072, lng: -0.1276 }], and render <PinMap pins={offices} />: the map is drawn again only when pins changes. Guide: React.
<script setup>
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({ title: 'World map' });
</script>
<template>
<div v-html="svg" />
</template>For pins, a country list and themes, copy examples/vue/DottedMap.vue: one single-file component with the React component's props, drawn on the server in Nuxt and Vite SSR. examples/vue has its usage and a variant for client-only apps. Guide: Vue and Nuxt.
examples/svelte/DottedMap.svelte is a Svelte 5 component with the same props as the React component: one file to copy into src/lib/, with this package as its one dependency. It has no onMount, so SvelteKit draws the map on the server or in a prerendered page, and a class on it themes the dots:
<DottedMap
title="Our offices"
class="text-neutral-300 dark:text-neutral-700"
pins={[{ lat: 51.51, lng: -0.13, label: 'London', color: '#f97316' }]}
/>examples/svelte has its props and a variant for client-only apps. Or render the SVG string yourself:
<script>
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({ title: 'World map' });
</script>
{@html svg}Guide: Svelte.
---
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({ title: 'World map' });
---
<Fragment set:html={svg} />Astro draws the map when it builds or renders the page, and the page ships no script for it. examples/astro/DottedMap.astro is a component to copy, with the same props as the React one; examples/astro has its usage and an endpoint that serves the map as an image. Guide: Astro.
The React server component works in app/ as it is. To serve the map as an image, add a route handler in app/world.svg/route.js. Next.js renders it once, at build time:
import { DottedMap } from '@setkernel/dotted-map-next';
export const dynamic = 'force-static';
export function GET() {
const svg = new DottedMap({ height: 60 }).getSVG({ color: '#8c959f' });
return new Response(svg, { headers: { 'content-type': 'image/svg+xml' } });
}Then use <img src="/world.svg" alt="World map" /> on any page. Guide: Next.js.
CommonJS and ES modules both work:
const { writeFileSync } = require('node:fs');
const { DottedMap } = require('@setkernel/dotted-map-next');
const map = new DottedMap({ height: 60 });
map.addPin({ lat: 52.52, lng: 13.405 });
writeFileSync('berlin.svg', map.getSVG({ color: '#1f2328', title: 'Berlin on a world map' }));A module worker, the format Cloudflare Workers runs. The map is drawn once, when the worker starts:
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({ color: '#8c959f' });
export default {
fetch() {
return new Response(svg, { headers: { 'content-type': 'image/svg+xml' } });
},
};Guide: server and edge.
The first map with given settings computes its grid. Compute it once, at build time:
import { writeFileSync } from 'node:fs';
import { getMapJSON } from '@setkernel/dotted-map-next';
writeFileSync('world.json', getMapJSON({ height: 60 }));Then draw it with the without-countries entry, which holds no country data:
import { DottedMap } from '@setkernel/dotted-map-next/without-countries';
import world from './world.json' with { type: 'json' };
const svg = new DottedMap({ map: world }).getSVG({ title: 'World map' });Bundled with its dependencies and this map, it is 7,680 bytes gzipped, against 43,699 bytes for the main entry. The map's settings are fixed when it is computed; pins and every getSVG() option still work. If the map uses avoidOuterPins: true, pass it to getMapJSON too.
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({ color: '#8c959f' });
const src = `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
// <img src={src} alt="World map" />, or in CSS: background-image: url("…")An SVG in an <img> or a CSS background cannot see the page's CSS, so give it a color. With the default, currentColor, it is black.
import { DottedMap } from '@setkernel/dotted-map-next';
const map = new DottedMap({ height: 60 });
map.addPin({ lat: 40.7128, lng: -74.006, data: { name: 'New York' } });
map.addPin({ lat: 35.6762, lng: 139.6503, svgOptions: { color: '#e8590c', radius: 0.6 } });
const svg = map.getSVG({ color: '#8c959f', title: 'Our offices' });A pin takes the grid cell nearest to it. Without svgOptions it is drawn larger than a dot, in the map's colour. getPoints() gives back each pin with its data. With avoidOuterPins: true on the map, a pin at sea is not drawn and addPin returns undefined. Guide: pins.
import { DottedMap } from '@setkernel/dotted-map-next';
const map = new DottedMap({ height: 60, countries: ['FRA'] });
const svg = map.getSVG({ title: 'Map of France' });countries takes ISO 3166-1 alpha-3 codes, and the map fits their bounding box. For a box of your own, pass region: { lat: { min, max }, lng: { min, max } } instead.
Each country's dots are in a <g data-country="…">. On a map inline in a page, CSS colours them:
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({ className: 'markets', title: 'Our markets' });.markets { color: #8c959f; }
.markets [data-country='BRA'],
.markets [data-country='IND'] { color: #e8590c; }For an SVG that leaves the page, such as a file, an <img> or an email, countryColors writes the colours into it:
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({
color: '#8c959f',
countryColors: { BRA: '#e8590c', IND: '#e8590c' },
});Guide: highlight countries.
Put the SVG inline in the page and leave color out:
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({ className: 'world-map', title: 'World map' });.world-map { color: #1f2328; }
@media (prefers-color-scheme: dark) {
.world-map { color: #e6edf3; }
}The dots are currentColor, so the media query recolours them: one SVG, no script. For an <img>, draw one file for each theme and switch between them with <picture>, as this README does. Guide: dark mode.
Measured on 2026-12-04 by node scripts/measure.mjs, which writes docs/numbers.md. The other rows are read from each package's published files at the version compared. A size is a minified browser bundle with every dependency inside, gzipped.
@setkernel/dotted-map-next |
dotted-map |
svg-dotted-map |
cobe |
Source | |
|---|---|---|---|---|---|
| Version compared | main, unreleased 2.0 (package.json: 1.1.2) |
3.1.0 | 2.1.0 | 2.1.0 | docs/numbers.md, "Measured" |
| Runtime dependencies (installed with them) | 1 (7) | 2 (10) | 0 | 0 | docs/numbers.md: "runtime dependencies in package.json", "packages installed with it" |
| Bundle size, main entry | 43,699 B | 154,820 B | 14,075 B | 6,640 B | docs/numbers.md: "main entry bundled with its dependencies, minified: gzip bytes" |
| Bundle size, light entry with a precomputed world map | 7,680 B | 61,881 B | no such entry | no such entry | docs/numbers.md: "light entry with a precomputed world map at height 60, bundled: gzip bytes" |
SVG of the world at height: 60, each at its defaults, gzipped |
10,350 B, 3,085 dots | 6,603 B, 2,659 dots | makes no SVG | makes no SVG | docs/numbers.md: "SVG, world, height 60, circles" rows |
| Output | SVG string; points with getPoints() |
SVG string; points with getPoints() |
an array of points that you draw | a WebGL globe on a <canvas> |
ours: index.d.ts; dotted-map: dist/without-countries.d.mts; svg-dotted-map: createMap in dist/index.d.mts; cobe: createGlobe in dist/index.d.ts |
| Works without client JavaScript | yes | yes | yes, if you draw the points into SVG on the server | no: it draws in the browser | the same files |
| Shapes | circle, hexagon | circle, hexagon | none: you draw each point | dots on a globe | ours: Shape in without-countries.d.ts; dotted-map: SvgSettings in dist/types-F6gvGCSl.d.mts; svg-dotted-map: dist/index.d.mts; cobe: dist/index.d.ts |
| Country maps | yes, countries |
yes, countries |
yes, countries |
no | countries in index.d.ts, dist/types-F6gvGCSl.d.mts and dist/index.d.mts; no such option in cobe's COBEOptions |
| Projections | Web Mercator only | Mercator, equirectangular, Robinson, Equal Earth, Mollweide, Miller, sinusoidal, orthographic, Gall–Peters, Van der Grinten | Web Mercator | a globe; flatten unrolls it into a flat map |
ours: no projection setting in index.d.ts; dotted-map: ProjectionName in dist/types-F6gvGCSl.d.mts; svg-dotted-map: the projection in dist/index.mjs; cobe: flatten in dist/index.d.ts |
| Accessible output | title and description give role="img", aria-label, <title> and <desc>; with no title, aria-hidden="true" |
no role, label or title | you write the markup | a <canvas>, with no text |
ours: SvgSettings in without-countries.d.ts; dotted-map: getSVG in dist/without-countries.mjs; svg-dotted-map: createMap in dist/index.d.mts; cobe: dist/index.d.ts |
Theming with currentColor |
the default color; className and data-country for page CSS |
no: the default fill is current, which is not a colour, so browsers draw black |
you write the markup | no: colours are RGB arrays, such as baseColor |
ours: getSVG in without-countries.d.ts; dotted-map: getSVG in dist/without-countries.mjs; svg-dotted-map: createMap in dist/index.d.mts; cobe: COBEOptions in dist/index.d.ts |
| TypeScript types | yes | yes | yes | yes | docs/numbers.md: "types ship" |
| Licence | MIT | MIT | MIT in LICENSE, not set in package.json |
MIT | docs/numbers.md: "licence field"; svg-dotted-map's LICENSE |
Pick dotted-map for a projection other than Mercator or a smaller gzipped SVG, svg-dotted-map to draw the points yourself with no dependencies, cobe for a spinning globe in the browser, and this package for an SVG of dots or hexagons that page CSS and screen readers can work with. The comparison page has every measured row.
Render the SVG string from getSVG() with dangerouslySetInnerHTML; in a React Server Component the map is drawn on the server and the browser gets only markup.
import { DottedMap } from '@setkernel/dotted-map-next';
export function WorldMap() {
const svg = new DottedMap({ height: 60 }).getSVG({ title: 'World map' });
return <div dangerouslySetInnerHTML={{ __html: svg }} />;
}The React recipe has a client component too.
Call map.addPin({ lat, lng }) before getSVG(), and the pin is drawn on the grid cell nearest to that point.
import { DottedMap } from '@setkernel/dotted-map-next';
const map = new DottedMap({ height: 60 });
map.addPin({ lat: 48.8566, lng: 2.3522, svgOptions: { color: '#e8590c' } });
const svg = map.getSVG({ title: 'Paris on a world map' });Pass its ISO 3166-1 alpha-3 code in countries, and the map draws that country alone, fitted to its bounding box.
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60, countries: ['JPN'] }).getSVG({ title: 'Map of Japan' });Pass shape: 'hexagon' to getSVG(); at radius: 0.5 the hexagons tile edge to edge on the default grid.
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({ shape: 'hexagon', radius: 0.5 });Leave color at its default, currentColor, put the SVG inline in the page, and change the text colour in a prefers-color-scheme: dark media query.
.world-map { color: #1f2328; }
@media (prefers-color-scheme: dark) {
.world-map { color: #e6edf3; }
}The dark mode recipe has the JavaScript.
Yes: the library uses no DOM, no canvas and no Node.js module, so getSVG() returns the same SVG string in Node.js, in an edge function and in the browser.
import { DottedMap } from '@setkernel/dotted-map-next';
export default {
fetch() {
const svg = new DottedMap({ height: 60 }).getSVG({ color: '#8c959f' });
return new Response(svg, { headers: { 'content-type': 'image/svg+xml' } });
},
};No: draw the map on the server or at build time, and the browser gets plain SVG markup with no script.
import { writeFileSync } from 'node:fs';
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({ title: 'World map' });
writeFileSync('index.html', `<!doctype html><title>World map</title>${svg}`);The main entry with its dependencies is 43,699 bytes gzipped in a browser bundle, and the without-countries entry with a precomputed world map is 7,680 bytes.
The SVG of the world at height: 60 is 120,218 bytes, or 10,350 gzipped. Every size comes from docs/numbers.md, which this command writes in a clone of the repository:
npm run build && node scripts/measure.mjsYes: give it a color, because an SVG in an <img> or a CSS background cannot see the page's CSS, then use the file or a data URL.
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({ color: '#8c959f' });
const url = `url("data:image/svg+xml;utf8,${encodeURIComponent(svg)}")`;
// element.style.backgroundImage = url;Yes, when you give it a title: the SVG then has role="img", an aria-label and a <title>, and without one it has aria-hidden="true", so a screen reader skips it.
import { DottedMap } from '@setkernel/dotted-map-next';
const svg = new DottedMap({ height: 60 }).getSVG({ title: 'World map', description: 'Every country, in dots' });
// <svg … role="img" aria-label="World map"><title>World map</title><desc>Every country, in dots</desc>…Web Mercator only; region crops it to a box of latitude and longitude, and for another projection, such as Robinson or Equal Earth, dotted-map has a projection setting.
import { DottedMap } from '@setkernel/dotted-map-next';
const map = new DottedMap({ height: 60, region: { lat: { min: 34, max: 71 }, lng: { min: -25, max: 45 } } });
const svg = map.getSVG({ title: 'Map of Europe' });It started as a fork of dotted-map and keeps its calls, with the projection built in instead of proj4, an SVG that page CSS and screen readers can work with, a type argument for pin data and a smaller precomputed map; dotted-map has more projections and a smaller gzipped SVG.
// was: import DottedMap from 'dotted-map';
import { DottedMap } from '@setkernel/dotted-map-next';
// dotted-map's defaults: the vertical grid, and dots that touch
const svg = new DottedMap({ height: 60, grid: 'vertical' }).getSVG({ radius: 0.5 });The defaults differ: Migrating from dotted-map says what looks different, what throws now and what to type, and the comparison has the numbers.
| Call | Returns | What it does |
|---|---|---|
new DottedMap({ height, width, countries, region, grid, avoidOuterPins }) |
a map | Builds the grid of dots, or reads it from the cache. Give height or width. |
map.addPin({ lat, lng, data, svgOptions }) |
the pin's point, or undefined |
Puts a pin on the grid cell nearest to lat and lng. |
map.getPin({ lat, lng }) |
a point, or undefined |
The point a pin there would take, without adding it. |
map.getPoints() |
(GridDot | Point)[] |
Every dot of the grid, and every pin. |
map.getSVG({ shape, radius, color, backgroundColor, countryColors, className, title, description }) |
a string | The map as SVG. Every option can be left out. |
getMapJSON(settings) |
a string | A precomputed map, for new DottedMap({ map }) from the without-countries entry. |
clearCache() |
nothing | Empties the cache of computed grids. |
Types ship with the package: import type { Pin, Point, SvgSettings } from '@setkernel/dotted-map-next'. Every option, its default and its errors are in the API reference. Coming from 1.x, read Migrating from 1.x to 2.0.
Started as a fork of dotted-map by Basile Bruneau; country outlines from world.geo.json; MIT licence (LICENSE).