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

Draw lines, marks and shaded areas from latitude and longitude

Hand the world map numbers, a track, a place, the night side, and it draws them over the land, small enough for an inset.

Hand the map numbers

drawChizu's overlays takes a list of shapes given as [latitude, longitude] in degrees. Chizu knows nothing of what they mean: a satellite's track, a city, the night side are numbers some other code works out. There are three kinds:

  • line: points, in order. Each step is taken the short way round, so a track crosses the date line without a gap (170 to -170 is 20 degrees east, as is 350 to 10) and a track that goes round the world is one line. Give each part its own line for a colour of its own (the part flown, and the part to come).
  • mark: a dot at a point, with an optional label.
  • area: a ring of points, filled, at opacity (0 to 1). It is drawn as given, so its longitudes must run on without a jump (170 to 190, not 170 to -170, which would fill a band round the whole map); a ring round a pole runs along its edge from -180 to 180 and back along the pole.

Colours are CSS colours or var(--name); width and size are in pixels, so a map 240 pixels wide reads as well as a large one. An id is kept as data-id on the shape.

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

const svg = drawChizu(WORLD, {
  style: true,
  overlays: [
    { kind: "area", ring: [[66, -180], [-66, 0], [66, 180], [-90, 180], [-90, -180]], opacity: 0.35 },
    { kind: "line", points: [[0, 150], [20, 175], [30, -160]], color: "#c0392b", width: 2 },
    { kind: "mark", at: [35.68, 139.69], label: "Tokyo", id: "here" },
  ],
});
console.log(svg.includes('class="cz-overlays"'), svg.includes('data-id="here"'));
// true true
true true

On a mounted map, replace them

A map from mountChizu takes the same overlays; map.set({ overlays }) alone draws only them again, not the land, and keeps the zoom and the window, so a track can move every few seconds. A <chizu-map> element has an overlays property that does the same (element.overlays = [...]); setting its options instead builds the map again.

import WORLD from "@johnmorrisdotca/chizu/world";
import { mountChizu } from "@johnmorrisdotca/chizu/mount";

const map = mountChizu(document.querySelector("#inset")!, { map: WORLD, controls: false, selectable: false });
map.set({ overlays: [{ kind: "mark", at: [51.6, -0.1], size: 10 }] });

A small inset

At 240 by 120 pixels a world map shows its land and sea: country names are drawn only when labels asks for them. Turn off the zoom buttons (controls: false) and the choosing (selectable: false) for a map that only shows where something is.

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