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

orderByPositionfunction

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 it

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

Definition

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

Parameters

NameTypeDescription
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.

Returns

T[]

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

Examples

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

What it prints (run when this page was built)

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