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[]
引数
| 名前 | 型 | 説明 |
|---|---|---|
spots | CountrySpots | The countries' points (see |
frame | CountryFrame | Where the Earth is on the screen. |
lang | "en" | "ja" | The page's language, |
options | CountryLayoutOptions | 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' ]出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。