Reference · Framing, geometry and quiz tools
placeCitiesfunction
Which cities a window names, and where each name goes: in rank order, each name on the first free side of its dot (right, left, above, below), and a city left out when none is free. On a map of one country alone, only that country's cities are named. A name never covers another name or another city's dot, and no two dots touch. Cities off the window, or on a map that cannot place a point, are left out.
Import it
import { placeCities } from "@johnmorrisdotca/chizu";
Definition
function placeCities(map: Pick<ChizuMap, "projection"> & Partial<Pick<ChizuMap, "kind" | "regions">>, cities: readonly ChizuCity[], box: MapBox, offsets: readonly number[], options: { language: ChizuLanguage; minPopulation?: number; }): ChizuCityPlaced[]
Parameters
| Name | Type | Description |
|---|---|---|
map | Pick<ChizuMap, "projection"> & Partial<Pick<ChizuMap, "regions" | "kind">> | The map the cities go on. |
cities | readonly ChizuCity[] | The cities to choose from. |
box | MapBox | The window. |
offsets | readonly number[] | The copies of the canvas drawn across a wrapping map ( |
options | { language: ChizuLanguage; minPopulation?: number; } | The language, and an optional population floor. |
Returns
ChizuCityPlaced[]
The cities named, with their place and side.
Examples
import WORLD from "@johnmorrisdotca/chizu/world";
import { placeCities, wholeMapBox } from "@johnmorrisdotca/chizu";
const placed = placeCities(WORLD, [{ id: "Q1490", name: { en: "Tokyo", ja: "東京" }, lat: 35.69, lon: 139.69, population: 14_000_000 }], wholeMapBox(WORLD), [0], { language: "ja" });
console.log(placed[0]?.name, placed[0]?.side);
// 東京 right東京 rightWhat it prints (run when this page was built)