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

localCanvasFromBoxfunction

The local canvas that shows the ground a window on a world or country map shows, so a page can hand over from the map to the city at the moment it has zoomed past what the map knows, with nothing jumping: at its own 1× the local map covers the same ground as the window did. null where mapBoxMetres is.

Import it

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

Definition

function localCanvasFromBox(map: Pick<ChizuMap, "projection">, box: MapBox): Required<ChizuLocalCanvas> | null

Parameters

NameTypeDescription
mapPick<ChizuMap, "projection">

A world or country map.

boxMapBox

A window on that map.

Returns

Required<ChizuLocalCanvas> | null

A local canvas covering the window, or null when the map cannot be read back or the window is near a pole.

Examples

import WORLD from "@johnmorrisdotca/chizu/world";
import { localCanvasFromBox, projectPoint } from "@johnmorrisdotca/chizu";

const [x, y] = projectPoint(WORLD, 139.7671, 35.6812)!;
const canvas = localCanvasFromBox(WORLD, { x: x - 1, y: y - 1, width: 2, height: 2 })!;
console.log(canvas.centre.map((value) => value.toFixed(2)).join(", "), Math.round(canvas.widthMetres / 10_000) * 10, "km");
// 139.77, 35.68 70 km
139.77, 35.68 70 km

What it prints (run when this page was built)

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