本文へ移動

Chizu地図

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

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

目次

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

orderByPosition関数

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

The choices in the order they run across the map, west to east.

Handles numbered by the option's place in a shuffled list read 3 2 4 1 from left to right, and the number keys pointed at nothing you could see. Numbering by position makes the handles a row to read and makes 1 mean the leftmost one.

It gives nothing away. Where a place sits is the entire question being asked, so ordering the choices by it tells the player only what the map already shows them. Ties break north to south, and anything with no centre keeps its order at the end rather than disappearing. centreOf says where an option is: (option) => region.centroid.

インポート

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

定義

function orderByPosition<T>(options: readonly T[], centreOf: (option: T) => readonly [number, number] | null | undefined): T[]

引数

名前型説明
optionsreadonly T[]

The optional native drawing, matching, layout or quiz settings described by this signature.

centreOf(option: T) => readonly [number, number] | null | undefined

The function that reads an entry’s native centre.

戻り値

T[]

The choices in the order they run across the map, west to east.

例

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

const places = [{ name: "east", at: [90, 10] as const }, { name: "west", at: [10, 10] as const }, { name: "middle", at: [50, 10] as const }];
console.log(orderByPosition(places, (place) => place.at).map((place) => place.name).join(" "));
// west middle east
west middle east

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

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

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