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

Reference · Framing, geometry and quiz tools

zoomBoxfunction

The window a zoom step and a centre make.

Kept on the map: a centre near a coast would otherwise frame open sea. Clamping the window rather than the centre means a drag that runs off the edge simply stops there, which is what a reader expects of every other map they have used. On a map that wraps, east and west never stop, so only north and south are held. clamp is off for a fit: a region opened from its address asked for that region in the middle, and a clamp that pushes the window back onto the map puts it somewhere else.

Import it

import { zoomBox } from "@johnmorrisdotca/chizu";

Definition

function zoomBox(map: Frameable, zoom: MapZoom, centre: { x: number; y: number; }, clamp?: boolean): MapBox

Parameters

NameTypeDescription
mapFrameable

The native map or map fields required by this signature; coordinates and region codes belong to its canvas.

zoom1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10

A valid zoom step from MAP_ZOOM_LEVELS.

centre{ x: number; y: number; }

The desired window centre in native map units.

clamp (optional)boolean

Whether to hold a non-wrapping window inside its map canvas.

Returns

MapBox

The window a zoom step and a centre make.

Examples

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

console.log(zoomBox(WORLD, 2, { x: 500, y: 200 }));
// { x: 250, y: 77.75, width: 500, height: 244.5 }
{ x: 250, y: 77.75, width: 500, height: 244.5 }

What it prints (run when this page was built)

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