Skip to the content

Chikyu Earth地球

A line-drawn globe of the world's countries that turns at the Earth's own rate, with an optional realistic Earth from space and markers for any place.

Chikyu is the Japanese word 地球 for the Earth. About the name

Contents

Reference · The realistic Earth's pure parts

layoutCountryNamesfunction

Lays the names out for one draw. Each country in sight is named at the middle of the largest part of it the view shows (snapped to a point of its own land, so a crescent's name is not out at sea), the largest on the screen first, its text sized by that part, only where the text fits within it, inside the Earth's disc, and free of the names already placed and of taken (tried at the middle, a line above and below, then at the next points of its land out from the middle). A country on the far side, or too small for its name, is left out: fewer names when the Earth is small, more as it grows.

Import it

import { layoutCountryNames } from "@johnmorrisdotca/chikyu-earth/realistic";

Definition

function layoutCountryNames(spots: CountrySpots, frame: CountryFrame, lang: "en" | "ja", options: CountryLayoutOptions): CountryName[]

Parameters

NameTypeDescription
spotsCountrySpots

The countries' points (see countrySpots).

frameCountryFrame

Where the Earth is on the screen.

lang"en" | "ja"

The page's language, en or ja.

optionsCountryLayoutOptions

The most names, the text sizes, the boxes taken and how to measure.

Returns

CountryName[]

The names to show, the largest first.

Examples

import { countrySpots, layoutCountryNames } from "@johnmorrisdotca/chikyu-earth/realistic";

const square = { properties: { code: "A", name: "Square", nameJa: "四角" }, geometry: { type: "Polygon", coordinates: [[[-20, -20], [20, -20], [20, 20], [-20, 20], [-20, -20]]] } };
const frame = {
  width: 400, height: 400, radius: 180, disc: { x: 200, y: 200, radius: 180 },
  project: (lon: number, lat: number, out: { x: number; y: number }) => { out.x = 200 + lon * 3; out.y = 200 - lat * 3; return 1; },
};
console.log(layoutCountryNames(countrySpots({ features: [square] }), frame, "en", { max: 10, smallest: 10, largest: 16 }).map((one) => one.text));
[ 'SQUARE' ]

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/chikyu-earth 0.51.1.