Skip to the content

Chizu地図

Draw SVG maps of the world, its 253 countries and the regions of 33 of them, frame them, place numbered callouts and build geography quizzes, with names in English and Japanese today (Spanish, German and Chinese are planned).

Chizu is the Japanese word 地図 for map. About the name

Contents

How-to

TypeScript and Node

Use the package's types, and draw the same map as SVG text on a server with no DOM.

The package ships its own types, for each entry point. Drawing is pure: map data goes in and SVG text comes out, so the same call gives the same answer in Node, Deno, Bun, a worker and a browser. This file type-checks, then runs under Node 22.18 or later, which strips the types.

import WORLD from "@johnmorrisdotca/chizu/world";
import { drawChizu, type ChizuDrawOptions } from "@johnmorrisdotca/chizu/draw";

const options: ChizuDrawOptions = { language: "ja", style: true, colors: { JP: "#2f6b4f" } };
const svg: string = drawChizu(WORLD, options);
console.log(svg.startsWith("<svg"), WORLD.regions.length);

// @ts-expect-error "neon" is not a language
const language: ChizuDrawOptions["language"] = "neon";
console.log(language);
true 173
neon

@ts-expect-error is there to show that "neon" is not a language the map has names for; the compiler refuses it.

On a server

A server draws the same SVG a browser does. There is no DOM, so the page is a string.

import WORLD from "@johnmorrisdotca/chizu/world";
import { drawChizu } from "@johnmorrisdotca/chizu/draw";

// A server draws the same SVG a browser does: pure, no DOM, no browser globals.
const svg = drawChizu(WORLD, { language: "ja", style: true, colors: { JP: "#2f6b4f" } });
const page = `<!doctype html><title>The world</title>${svg}`;
console.log(page.length > 1000, WORLD.regions.length);
true 173

See getting started for mounting the map in a page and loading maps for the other maps.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/chizu 1.17.0.