Skip to the content

Chizu地図

Draw SVG maps, frame regions, place numbered callouts and build geography quizzes with English and Japanese names.

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

Contents

How-to

Frame regions and insets

Fit native region codes while keeping geographic points separate from drawn inset positions.

Fit a selection

import JAPAN from "@johnmorrisdotca/chizu/divisions/jp";
import { focusRegionFit, regionCentre, wholeMapBox, boxToViewBox } from "@johnmorrisdotca/chizu";
console.log(focusRegionFit(JAPAN,"47")?.zoom,regionCentre(JAPAN,"47"));
console.log(boxToViewBox(wholeMapBox(JAPAN)),focusRegionFit(JAPAN,"unknown"));
3 { x: 315, y: 560 }
0 0 1000 1133 null

Okinawa and other outlying islands are drawn in inset boxes. The framing helpers follow where a region is drawn, so a selected inset stays in view. focusRegionFit and regionCentre return null for a null or unknown region code. focusBox and zoomToFit fall back to the whole map when nothing matches; that is a useful reset, not evidence that the input code matched.

Pan a wrapping world

MAP_ZOOM_LEVELS is a ten-step ladder. stepMapZoom clamps at its ends. The world’s east/west edge wraps, so zoomBox can overhang its horizontal seam; wrapOffsets describes the copies needed for the window. Country maps are clamped by default. Geographic longitude/latitude uses projectPoint and unprojectPoint; inset positions describe the drawing instead.

The detailed framing reference retains the geometry and fit examples.

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