本文へ移動

Chizu地図

SVGの地図を描き、地域を表示範囲に収め、番号付きの注記や地理クイズを英語と日本語の名前で作れます。

「地図」は、土地や場所を図で表したものです。 名前について(英語)

目次

リファレンス · 表示範囲・形・クイズの道具

zoomToFit関数

リファレンスの説明と例は英語です。見出しと目次は日本語です。

The zoom step and centre that show all of these regions at once: for opening a region from its heading, which wants it filling the view and not the whole map with a few regions lit somewhere in it.

It picks the closest step whose window still holds everything, with the same room around it that a focus box leaves; a set that will not fit at 2× is shown at 1× rather than cut. Measured where the regions are drawn, so an inset's region is its box and not its true position out at sea. The room is a share of each side, and a set that cannot fit closer with the margin gets one more try at the bare shape before it is shown at 1×: the margin is what makes a fit comfortable, not what makes it a fit.

インポート

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

定義

function zoomToFit(map: Frameable, codes: ReadonlyArray<string | number>): { zoom: MapZoom; centre: { x: number; y: number; }; }

引数

名前型説明
mapFrameable

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

codesreadonly (string | number)[]

Native region codes from this map, in the requested order.

戻り値

{ zoom: MapZoom; centre: { x: number; y: number; }; }

The zoom step and centre that show all of these regions at once: for opening a region from its heading, which wants it filling the view and not the whole map with a few regions lit somewhere in it.

例

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

const fit = zoomToFit(WORLD, ["GB", "IE"]);
console.log(fit.zoom, Math.round(fit.centre.x), Math.round(fit.centre.y));
// 10 58 148
10 58 148

出力(このページを作ったときに実行した結果)

ソースを見るGitHub で編集@johnmorrisdotca/chizu 1.5.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。