World maps, drawn in dots.
Dotted World Map draws the world, a region or any country as an SVG of dots or hexagons, with pins where you want them. It returns a string, so it works on the server and in the browser, with any framework or none.
npm install @setkernel/dotted-map-next
Quick start
Make a map, add pins, and ask for the SVG. The result is a plain string: write it to a file, send it from a server, or put it straight into your page.
import dottedMap from '@setkernel/dotted-map-next';
const DottedMap = dottedMap.default; // 2.0 exports { DottedMap } by name
const map = new DottedMap({ height: 60, grid: 'diagonal' });
map.addPin({
lat: 48.8534,
lng: 2.3488,
svgOptions: { color: '#e8590c', radius: 0.6 },
});
const svg = map.getSVG({ shape: 'circle', radius: 0.3, color: '#1f2328' });
Playground
Every 2.0 option, drawn live in your browser by the library from main, before 2.0 is on npm. The code under the map draws what you see, with only the options you changed: the empty fields show the defaults. The address bar keeps your settings, so its link draws the same map.
One grid, any shape of the world
shape: 'hexagon'
region: { lat, lng }
countries: ['JPN']
countries: ['BRA']
What you get
- Any country, any region
- Pass ISO 3166-1 alpha-3 codes, or a box of latitude and longitude. The map fits the grid to what you asked for.
- Pins on the grid
-
A pin snaps to the nearest dot and takes its own colour and size.
Keep pins off the sea with
avoidOuterPins. - Fast repeat maps
-
Compute a map once with
getMapJSON, then draw it from the smallwithout-countriesentry with no country data in your bundle. - Typed
- TypeScript types ship with the package.
Guides
- How do I make a hexagon world map as SVG?
- How do I put a pin on a world map at a latitude and longitude?
- How do I highlight some countries on a dotted map?
- How do I make an SVG map follow dark mode?
- Can I render a dotted map on the server or at the edge?
- How do I make a dotted world map in React?
- How do I add a dotted world map to a Next.js app?
- How do I make a dotted world map in Vue or Nuxt?
- How do I make a dotted world map in Svelte?
- How do I add a dotted world map to an Astro site?
- dotted-map, svg-dotted-map, cobe or this: which one?
Questions
- What is Dotted World Map?
- Dotted World Map is a free, open-source JavaScript library that draws the world, a region or any country as an SVG made of dots or hexagons. You give it a size and, if you like, pins; it gives you back an SVG string.
- How do I make a dotted world map in JavaScript?
- Install
@setkernel/dotted-map-next, create a map with a height, and callgetSVG(), which returns the map as an SVG string. Add pins withaddPin()before that call. - Can it draw one country or one region?
- Yes: pass
countrieswith ISO 3166-1 alpha-3 codes, such as['FRA'], orregionwith a box of latitude and longitude. The grid fits what you asked for. - Does it work with React, Vue, Svelte, Next.js or Astro?
- Yes: the map is an SVG string, so every framework can render it. Use
dangerouslySetInnerHTMLin React,v-htmlin Vue,{@html}in Svelte andset:htmlin Astro. In Next.js or Astro you can draw it on the server, so the browser downloads no map code at all. - Does it run on the server or at the edge?
- Yes: it uses no DOM, no canvas and no Node.js modules, so it runs in Node.js, in edge functions and in the browser. Draw a map once at build time and ship plain SVG, as this page does.
- How do I add pins or markers?
- Call
addPin({ lat, lng })beforegetSVG(). The pin snaps to the nearest dot and can have its own colour and radius;avoidOuterPinskeeps pins off the sea. - Is it free to use?
- Yes: it is open source under the MIT licence, free for personal and commercial use.
2.0 is on its way
Smaller SVG output, typed pin data, maps a screen reader can name, and the playground above, where you can tune every option and copy the code. Follow the work on GitHub.