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
| Name | Type | Description |
|---|---|---|
map | Frameable | The native map or map fields required by this signature; coordinates and region codes belong to its canvas. |
zoom | 1 | 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)