本文へ移動

Chikyu Earth地球

世界の国の輪郭を線で描いた地球儀です。地球と同じ速さで回ります。宇宙から見たような地球と、好きな場所の目印も使えます。

「地球」(ちきゅう) は、私たちが住む星の名前です。 名前について(英語)

目次

リファレンス · リアルな地球の計算部分

layoutCountryNames関数

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

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 { layoutCountryNames } from "@johnmorrisdotca/chikyu-earth/realistic";

定義

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

引数

名前型説明
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.

戻り値

CountryName[]

The names to show, the largest first.

例

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' ]

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

ソースを見るGitHub で編集@johnmorrisdotca/chikyu-earth 0.51.1 のソースから作成しました。

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