dotted‑world‑map

How do I make a hexagon world map as SVG?

Create a DottedMap from @setkernel/dotted-map-next and call getSVG({ shape: 'hexagon' }): it returns the world as an SVG string of hexagons. Pass countries to the map for one country, and radius to getSVG() to size the hexagons.

npm install @setkernel/dotted-map-next

The world in hexagons

height is the number of rows of the grid. The map's title is what a screen reader says: without one, the map is hidden from it as decoration.

world.mjs
import { DottedMap } from '@setkernel/dotted-map-next';

const map = new DottedMap({ height: 40 });
const svg = map.getSVG({ shape: 'hexagon', title: 'The world in hexagons' });
The world in hexagons
Drawn by world.mjs when this page was built.

One country

countries takes ISO 3166-1 alpha-3 codes, such as 'AUS', and the grid fits what you asked for. At a radius of 0.5, the hexagons touch edge to edge.

country.mjs
import { DottedMap } from '@setkernel/dotted-map-next';

const map = new DottedMap({ height: 40, countries: ['AUS'] });
const svg = map.getSVG({
  shape: 'hexagon',
  radius: 0.5,
  title: 'Australia in hexagons',
});
Australia in hexagons
Drawn by country.mjs when this page was built.

What radius means for a hexagon

radius is in grid units: one unit is the distance between two neighbouring dots in a row. For a hexagon it is the distance from the centre to the middle of a side, so a hexagon is 2 × radius wide and about 2.31 × radius tall, and wraps exactly around the circle of the same radius.

Coming from 1.x, which drew a hexagon √3 times as large for the same radius: multiply the old radius by 1.732 to keep the same picture.