@johnmorrisdotca/chikyu-earth 0.43.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/NOTICE.md +15 -5
- package/README.md +4 -4
- package/dist/door/map.js +5 -1
- package/dist/element.d.ts +30 -0
- package/dist/element.js +82 -2
- package/dist/markers/here-city-host.d.ts +3 -1
- package/dist/markers/here-city-host.js +67 -5
- package/dist/markers/here-city.d.ts +94 -1
- package/dist/markers/here-city.js +69 -1
- package/dist/markers/index.d.ts +1 -1
- package/dist/markers/index.js +1 -1
- package/dist/realistic/element-base.d.ts +37 -0
- package/dist/realistic/element-base.js +86 -14
- package/dist/realistic/index.d.ts +1 -0
- package/dist/realistic/index.js +1 -0
- package/dist/realistic/zoom-reach.d.ts +29 -0
- package/dist/realistic/zoom-reach.js +30 -0
- package/dist/satellites/catalogue.d.ts +52 -1
- package/dist/satellites/catalogue.js +96 -5
- package/dist/satellites/index.d.ts +1 -1
- package/dist/satellites/index.js +1 -1
- package/dist/satellites/track.js +18 -3
- package/dist/satellites/types.d.ts +2 -2
- package/dist/sea-names/features.d.ts +12 -0
- package/dist/sea-names/features.js +46 -0
- package/dist/sea-names/geometry.d.ts +121 -0
- package/dist/sea-names/geometry.js +135 -0
- package/dist/sea-names/host.d.ts +46 -0
- package/dist/sea-names/host.js +111 -0
- package/dist/space/element-base.d.ts +48 -1
- package/dist/space/element-base.js +109 -9
- package/dist/space/generic-satellite.d.ts +46 -0
- package/dist/space/generic-satellite.js +96 -0
- package/dist/space/index.d.ts +2 -1
- package/dist/space/index.js +2 -1
- package/dist/space/ride.d.ts +45 -0
- package/dist/space/ride.js +38 -0
- package/dist/space/satellite-layer.d.ts +37 -0
- package/dist/space/satellite-layer.js +96 -14
- package/dist/space/scene.d.ts +3 -1
- package/dist/space/scene.js +54 -25
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// A small curated catalogue of satellites worth following: the groups the demo offers as buttons and the famous ones by name. Facts (names, NORAD numbers, orbit types) and our own words;
|
|
2
2
|
// no orbital elements are here, and nothing is fetched. The elements come from the page (see docs/satellite-sources.md for the sources and their terms).
|
|
3
|
+
import { SHORT_NAMES } from "./names.js";
|
|
3
4
|
/**
|
|
4
5
|
* The groups, in the order the demo shows them. Each one is a CelesTrak list or a few single numbers; the elements are fetched by the page (or the demo's scheduled build), never by the package.
|
|
5
6
|
*
|
|
@@ -205,7 +206,87 @@ export const CATALOGUE = [
|
|
|
205
206
|
/** A name made easy to compare: upper case, letters and digits only. */
|
|
206
207
|
const squash = (text) => text.toUpperCase().replace(/[^A-Z0-9]+/g, "");
|
|
207
208
|
/**
|
|
208
|
-
*
|
|
209
|
+
* Hiragana readings of the Japanese names already in this catalogue, for a page that indexes by sound.
|
|
210
|
+
* A name that is already kana or Latin has none. These are this package's own readings (NOTICE.md).
|
|
211
|
+
*/
|
|
212
|
+
const READINGS = {
|
|
213
|
+
宇宙ステーション: "うちゅうステーション",
|
|
214
|
+
有名な衛星: "ゆうめいなえいせい",
|
|
215
|
+
科学衛星: "かがくえいせい",
|
|
216
|
+
地球観測: "ちきゅうかんそく",
|
|
217
|
+
気象衛星: "きしょうえいせい",
|
|
218
|
+
静止衛星: "せいしえいせい",
|
|
219
|
+
北斗: "ほくと",
|
|
220
|
+
アマチュア無線: "あまちゅあむせん",
|
|
221
|
+
天宮: "てんぐう",
|
|
222
|
+
};
|
|
223
|
+
const GROUPS_BY_ID = new Map(SATELLITE_GROUPS.map((group) => [group.id, group]));
|
|
224
|
+
/** English and Japanese names. The reading is present only when it adds kana for a name that is not already kana. */
|
|
225
|
+
function rowNames(en, ja) {
|
|
226
|
+
const reading = READINGS[ja];
|
|
227
|
+
return reading !== undefined && reading !== ja ? { en, ja, reading } : { en, ja };
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Other names already written on the catalogue entry: the catalogue's own name when a short name is shown instead, and a designation written in parentheses.
|
|
231
|
+
* Nothing is added that is not in that name. See NOTICE.md.
|
|
232
|
+
*/
|
|
233
|
+
function akaOf(entry) {
|
|
234
|
+
const short = SHORT_NAMES[entry.noradId];
|
|
235
|
+
const en = short?.en ?? entry.name;
|
|
236
|
+
const ja = short?.ja ?? en;
|
|
237
|
+
const extras = [];
|
|
238
|
+
const add = (name) => {
|
|
239
|
+
const trimmed = name.trim();
|
|
240
|
+
if (trimmed === "" || trimmed === en || trimmed === ja || extras.includes(trimmed))
|
|
241
|
+
return;
|
|
242
|
+
extras.push(trimmed);
|
|
243
|
+
};
|
|
244
|
+
if (short)
|
|
245
|
+
add(entry.name);
|
|
246
|
+
const paren = /\(([^)]+)\)/.exec(entry.name);
|
|
247
|
+
if (paren?.[1])
|
|
248
|
+
add(paren[1]);
|
|
249
|
+
return extras.length > 0 ? extras : undefined;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Plain rows for every group and every catalogue satellite, for a page to index. Both languages are on every row: `lang` says which language the page is showing and does not drop the other, so one index serves either.
|
|
253
|
+
* A satellite's Japanese name comes from {@link SHORT_NAMES} where that has one, and is otherwise the English name.
|
|
254
|
+
*
|
|
255
|
+
* @param lang - `en` or `ja`, the language the page is showing. Omit it for the same rows.
|
|
256
|
+
* @returns The groups in their own order, then the satellites in catalogue order.
|
|
257
|
+
* @example
|
|
258
|
+
* ```ts
|
|
259
|
+
* import { catalogueRows } from "@johnmorrisdotca/chikyu-earth/satellites";
|
|
260
|
+
*
|
|
261
|
+
* const hubble = catalogueRows("ja").find((row) => row.noradId === 20580);
|
|
262
|
+
* console.log(hubble?.names.ja, hubble?.aka?.join(", "));
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
export function catalogueRows(lang) {
|
|
266
|
+
if (lang !== undefined && lang !== "en" && lang !== "ja")
|
|
267
|
+
throw new TypeError("catalogueRows lang is en or ja");
|
|
268
|
+
const groups = SATELLITE_GROUPS.map((group) => ({
|
|
269
|
+
kind: "group",
|
|
270
|
+
id: group.id,
|
|
271
|
+
names: rowNames(group.label, group.labelJa),
|
|
272
|
+
orbit: group.orbit,
|
|
273
|
+
}));
|
|
274
|
+
const satellites = CATALOGUE.map((entry) => {
|
|
275
|
+
const short = SHORT_NAMES[entry.noradId];
|
|
276
|
+
const en = short?.en ?? entry.name;
|
|
277
|
+
const ja = short?.ja ?? en;
|
|
278
|
+
const aka = akaOf(entry);
|
|
279
|
+
const row = { kind: "satellite", id: String(entry.noradId), noradId: entry.noradId, names: rowNames(en, ja), group: entry.group, orbit: entry.orbit };
|
|
280
|
+
if (aka)
|
|
281
|
+
row.aka = aka;
|
|
282
|
+
return row;
|
|
283
|
+
});
|
|
284
|
+
return [...groups, ...satellites];
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Find catalogue entries by name, group name, NORAD number, Japanese name or a group's Japanese label: "hubble", "hst", "25544", "weather" or "ハッブル".
|
|
288
|
+
* An English or numeric query ignores case, spaces and punctuation, as before. Kana and kanji are matched as typed: only letter case and character width are folded (NFKC), and that same width fold is applied before the English comparison.
|
|
289
|
+
* A name that starts with the text comes before one that only has it inside.
|
|
209
290
|
*
|
|
210
291
|
* @param text - What the reader typed.
|
|
211
292
|
* @param limit - The most entries to give back (8 by default).
|
|
@@ -215,19 +296,29 @@ const squash = (text) => text.toUpperCase().replace(/[^A-Z0-9]+/g, "");
|
|
|
215
296
|
* import { findInCatalogue } from "@johnmorrisdotca/chikyu-earth/satellites";
|
|
216
297
|
*
|
|
217
298
|
* console.log(findInCatalogue("sentinel 2").map((entry) => entry.name));
|
|
299
|
+
* console.log(findInCatalogue("ハッブル").map((entry) => entry.name));
|
|
218
300
|
* ```
|
|
219
301
|
*/
|
|
220
302
|
export function findInCatalogue(text, limit = 8) {
|
|
221
|
-
const
|
|
222
|
-
|
|
303
|
+
const source = text.normalize("NFKC");
|
|
304
|
+
const wanted = squash(source);
|
|
305
|
+
const folded = source.toLowerCase().trim();
|
|
306
|
+
const japanese = /[-ヿ一-鿿]/.test(source);
|
|
307
|
+
if (!wanted && !japanese)
|
|
223
308
|
return [];
|
|
224
309
|
const starts = [];
|
|
225
310
|
const inside = [];
|
|
226
311
|
for (const entry of CATALOGUE) {
|
|
227
312
|
const name = squash(entry.name);
|
|
228
|
-
|
|
313
|
+
const englishStart = wanted !== "" && (String(entry.noradId) === wanted || name.startsWith(wanted));
|
|
314
|
+
const englishInside = wanted !== "" && (name.includes(wanted) || squash(entry.group).includes(wanted) || squash(entry.about).includes(wanted));
|
|
315
|
+
const jaName = japanese ? (SHORT_NAMES[entry.noradId]?.ja ?? entry.name).normalize("NFKC").toLowerCase() : "";
|
|
316
|
+
const labelJa = japanese ? (GROUPS_BY_ID.get(entry.group)?.labelJa ?? "").normalize("NFKC").toLowerCase() : "";
|
|
317
|
+
const jaStart = japanese && folded !== "" && jaName.startsWith(folded);
|
|
318
|
+
const jaInside = japanese && folded !== "" && (jaName.includes(folded) || labelJa.includes(folded));
|
|
319
|
+
if (englishStart || jaStart)
|
|
229
320
|
starts.push(entry);
|
|
230
|
-
else if (
|
|
321
|
+
else if (englishInside || jaInside)
|
|
231
322
|
inside.push(entry);
|
|
232
323
|
}
|
|
233
324
|
return [...starts, ...inside].slice(0, limit);
|
|
@@ -4,6 +4,6 @@ export { DEFAULT_DIM_AFTER_DAYS, DEFAULT_MAX_AGE_DAYS, MAX_SATELLITE_SPEED } fro
|
|
|
4
4
|
export type { ElementSet, RefusedElementSet, SatelliteInfo, SatelliteRef, Satellites } from "./types.ts";
|
|
5
5
|
export { SHORT_NAMES } from "./names.ts";
|
|
6
6
|
export { OWNER_COUNTRIES, ownerCountry } from "./owners.ts";
|
|
7
|
-
export { CATALOGUE, SATELLITE_GROUPS, catalogueEntry, findInCatalogue, type CatalogueEntry, type OrbitKind, type SatelliteGroupInfo } from "./catalogue.ts";
|
|
7
|
+
export { CATALOGUE, SATELLITE_GROUPS, catalogueEntry, catalogueRows, findInCatalogue, type CatalogueEntry, type CatalogueRow, type OrbitKind, type SatelliteGroupInfo } from "./catalogue.ts";
|
|
8
8
|
export { ElementSourceError, fetchElements, forgetElements, parseElements, type ElementFormat, type ElementSource, type FetchElementsOptions, type ParsedElements } from "./source.ts";
|
|
9
9
|
export { missionElements, missionOf, missionPosition, missions, type HubbleVisit, type Mission, type MissionFile, type MissionPosition, type Orbiter } from "./missions.ts";
|
package/dist/satellites/index.js
CHANGED
|
@@ -4,6 +4,6 @@ export { NEAREST_COUNT, closeApproach, nearest, overheadKm, within } from "./nea
|
|
|
4
4
|
export { DEFAULT_DIM_AFTER_DAYS, DEFAULT_MAX_AGE_DAYS, MAX_SATELLITE_SPEED } from "./limits.js";
|
|
5
5
|
export { SHORT_NAMES } from "./names.js";
|
|
6
6
|
export { OWNER_COUNTRIES, ownerCountry } from "./owners.js";
|
|
7
|
-
export { CATALOGUE, SATELLITE_GROUPS, catalogueEntry, findInCatalogue } from "./catalogue.js";
|
|
7
|
+
export { CATALOGUE, SATELLITE_GROUPS, catalogueEntry, catalogueRows, findInCatalogue } from "./catalogue.js";
|
|
8
8
|
export { ElementSourceError, fetchElements, forgetElements, parseElements } from "./source.js";
|
|
9
9
|
export { missionElements, missionOf, missionPosition, missions } from "./missions.js";
|
package/dist/satellites/track.js
CHANGED
|
@@ -217,9 +217,11 @@ export function createSatellites(sets, options = {}) {
|
|
|
217
217
|
pinMsOf[i] = ms;
|
|
218
218
|
}
|
|
219
219
|
},
|
|
220
|
-
arc(ms, spanMs, positions, segments) {
|
|
220
|
+
arc(ms, spanMs, positions, segments, maxLength = 0) {
|
|
221
221
|
if (n === 0)
|
|
222
222
|
return 0;
|
|
223
|
+
// the longest a streak may be, in Earth radii along the orbit; 0, or anything that is not a positive number, leaves the stretch as long as the span makes it
|
|
224
|
+
const cap = maxLength > 0 && Number.isFinite(maxLength) ? maxLength : 0;
|
|
223
225
|
// a satellite never pinned is pinned now, all together
|
|
224
226
|
if (pinnedCount < n) {
|
|
225
227
|
sample(pinned, pinOk, ms, 0, n, true);
|
|
@@ -249,7 +251,14 @@ export function createSatellites(sets, options = {}) {
|
|
|
249
251
|
segments[w + 3] = place[0];
|
|
250
252
|
segments[w + 4] = place[1];
|
|
251
253
|
segments[w + 5] = place[2];
|
|
252
|
-
|
|
254
|
+
// SGP4 gave the speed here (km/s), so the cap in Earth radii becomes a stretch of time for this satellite and the start is placed by SGP4 that much earlier
|
|
255
|
+
let own = span;
|
|
256
|
+
if (cap > 0) {
|
|
257
|
+
const reach = (Math.hypot(place[3], place[4], place[5]) / EARTH_RADIUS_KM) * (Math.abs(span) / 1000);
|
|
258
|
+
if (reach > cap)
|
|
259
|
+
own = (span * cap) / reach;
|
|
260
|
+
}
|
|
261
|
+
if (exactAt(i, ms - own, place)) {
|
|
253
262
|
segments[w] = place[0];
|
|
254
263
|
segments[w + 1] = place[1];
|
|
255
264
|
segments[w + 2] = place[2];
|
|
@@ -272,7 +281,13 @@ export function createSatellites(sets, options = {}) {
|
|
|
272
281
|
const nx = normal[k];
|
|
273
282
|
const ny = normal[k + 1];
|
|
274
283
|
const nz = normal[k + 2];
|
|
275
|
-
|
|
284
|
+
let sweep = Math.max(-Math.PI, Math.min(Math.PI, rate[i] * span));
|
|
285
|
+
if (cap > 0) {
|
|
286
|
+
// along the orbit a turn of `sweep` is `sweep` times the height in Earth radii, so the cap is a turn of cap / height
|
|
287
|
+
const height = Math.hypot(pinned[k], pinned[k + 1], pinned[k + 2]);
|
|
288
|
+
if (height > 0 && Math.abs(sweep) * height > cap)
|
|
289
|
+
sweep = Math.sign(sweep) * (cap / height);
|
|
290
|
+
}
|
|
276
291
|
const along = rate[i] * (ms - pinMsOf[i]);
|
|
277
292
|
turn(pinned[k], pinned[k + 1], pinned[k + 2], nx, ny, nz, along, positions, k);
|
|
278
293
|
turn(pinned[k], pinned[k + 1], pinned[k + 2], nx, ny, nz, along - sweep, segments, w);
|
|
@@ -175,10 +175,10 @@ export interface Satellites {
|
|
|
175
175
|
pin(ms: number, first?: number, count?: number): void;
|
|
176
176
|
/**
|
|
177
177
|
* The place of each satellite at `ms` into `positions` (3 numbers each) and the stretch of orbit it travels over `spanMs` of game time into `segments` (6 numbers each: where it was `spanMs` earlier, then where it is).
|
|
178
|
-
* The place is the last `pin`, turned about the orbit's axis by the mean motion, so a fast clock does not run SGP4 for every satellite on every frame. A `spanMs` that would turn it more than half a revolution is cut there. An orbit with an eccentricity of 0.02 or more is placed by SGP4 itself instead (two calls a frame), because a turn at the mean motion would put it off its path.
|
|
178
|
+
* The place is the last `pin`, turned about the orbit's axis by the mean motion, so a fast clock does not run SGP4 for every satellite on every frame. A `spanMs` that would turn it more than half a revolution is cut there. `maxLength` (Earth radii, 0 or left out for none) is the longest a streak may be along the orbit: a satellite whose span would carry it further is drawn that long, ending at its place, so the length does not grow with a faster clock. For an orbit placed by SGP4 itself the cap is applied as a shorter span of time, from the speed SGP4 gives there. An orbit with an eccentricity of 0.02 or more is placed by SGP4 itself instead (two calls a frame), because a turn at the mean motion would put it off its path.
|
|
179
179
|
* Returns how many were written.
|
|
180
180
|
*/
|
|
181
|
-
arc(ms: number, spanMs: number, positions: Float32Array, segments: Float32Array): number;
|
|
181
|
+
arc(ms: number, spanMs: number, positions: Float32Array, segments: Float32Array, maxLength?: number): number;
|
|
182
182
|
/** One satellite at exactly `ms` (no interpolation): position in Earth radii and velocity in km/s into `out` (6 numbers). False if its elements are too old or SGP4 gave up. */
|
|
183
183
|
exact(index: number, ms: number, out: Float64Array): boolean;
|
|
184
184
|
/** The path of satellite `index` for one revolution from `ms`, `points` + 1 points in order along it (the last on the first), into a new array of Earth radii. */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SeaFeature } from "./geometry.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The oceans, seas, gulfs, bays and continents that can be named, each with the point its name is set at.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { SEA_FEATURES } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
8
|
+
*
|
|
9
|
+
* console.log(SEA_FEATURES.find((one) => one.id === "africa")?.name.en);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const SEA_FEATURES: readonly SeaFeature[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The oceans, seas, gulfs, bays and continents that can be named, each with the point its name is set at.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { SEA_FEATURES } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
7
|
+
*
|
|
8
|
+
* console.log(SEA_FEATURES.find((one) => one.id === "africa")?.name.en);
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export const SEA_FEATURES = [
|
|
12
|
+
{ id: "arctic-ocean", kind: "ocean", lon: -178.50, lat: 87.71, name: { en: "Arctic Ocean", ja: "北極海" } },
|
|
13
|
+
{ id: "southern-ocean", kind: "ocean", lon: -88.50, lat: -70.76, name: { en: "Southern Ocean", ja: "南極海" } },
|
|
14
|
+
{ id: "atlantic-ocean", kind: "ocean", lon: -28.59, lat: -5.03, name: { en: "Atlantic Ocean", ja: "大西洋" } },
|
|
15
|
+
{ id: "pacific-ocean", kind: "ocean", lon: -145.50, lat: -8.03, name: { en: "Pacific Ocean", ja: "太平洋" } },
|
|
16
|
+
{ id: "indian-ocean", kind: "ocean", lon: 81.12, lat: -38.03, name: { en: "Indian Ocean", ja: "インド洋" } },
|
|
17
|
+
{ id: "south-america", kind: "continent", lon: -59.34, lat: -19.88, name: { en: "South America", ja: "南アメリカ" } },
|
|
18
|
+
{ id: "australia", kind: "continent", lon: 139.18, lat: -25.15, name: { en: "Australia", ja: "オーストラリア大陸" } },
|
|
19
|
+
{ id: "africa", kind: "continent", lon: 16.50, lat: 7.21, name: { en: "Africa", ja: "アフリカ" } },
|
|
20
|
+
{ id: "antarctica", kind: "continent", lon: 34.00, lat: -88.00, name: { en: "Antarctica", ja: "南極大陸" } },
|
|
21
|
+
{ id: "asia", kind: "continent", lon: 96.10, lat: 47.33, name: { en: "Asia", ja: "アジア" } },
|
|
22
|
+
{ id: "europe", kind: "continent", lon: 20.52, lat: 54.03, name: { en: "Europe", ja: "ヨーロッパ" } },
|
|
23
|
+
{ id: "north-america", kind: "continent", lon: -102.09, lat: 61.65, name: { en: "North America", ja: "北アメリカ" } },
|
|
24
|
+
{ id: "black-sea", kind: "sea", lon: 34.98, lat: 42.42, name: { en: "Black Sea", ja: "黒海" } },
|
|
25
|
+
{ id: "philippine-sea", kind: "sea", lon: 134.32, lat: 19.12, name: { en: "Philippine Sea", ja: "フィリピン海" } },
|
|
26
|
+
{ id: "tasman-sea", kind: "sea", lon: 159.86, lat: -40.29, name: { en: "Tasman Sea", ja: "タスマン海" } },
|
|
27
|
+
{ id: "bay-of-bengal", kind: "bay", lon: 87.19, lat: 13.02, name: { en: "Bay of Bengal", ja: "ベンガル湾" } },
|
|
28
|
+
{ id: "south-china-sea", kind: "sea", lon: 112.85, lat: 10.28, name: { en: "South China Sea", ja: "南シナ海" } },
|
|
29
|
+
{ id: "arabian-sea", kind: "sea", lon: 64.53, lat: 12.82, name: { en: "Arabian Sea", ja: "アラビア海" } },
|
|
30
|
+
{ id: "beaufort-sea", kind: "sea", lon: -137.07, lat: 70.71, name: { en: "Beaufort Sea", ja: "ボーフォート海" } },
|
|
31
|
+
{ id: "caribbean-sea", kind: "sea", lon: -74.85, lat: 15.99, name: { en: "Caribbean Sea", ja: "カリブ海" } },
|
|
32
|
+
{ id: "gulf-of-mexico", kind: "gulf", lon: -90.36, lat: 25.30, name: { en: "Gulf of Mexico", ja: "メキシコ湾" } },
|
|
33
|
+
{ id: "labrador-sea", kind: "sea", lon: -54.27, lat: 54.96, name: { en: "Labrador Sea", ja: "ラブラドル海" } },
|
|
34
|
+
{ id: "hudson-bay", kind: "bay", lon: -84.46, lat: 59.20, name: { en: "Hudson Bay", ja: "ハドソン湾" } },
|
|
35
|
+
{ id: "caspian-sea", kind: "sea", lon: 51.21, lat: 41.11, name: { en: "Caspian Sea", ja: "カスピ海" } },
|
|
36
|
+
{ id: "baffin-bay", kind: "bay", lon: -65.57, lat: 74.42, name: { en: "Baffin Bay", ja: "バフィン湾" } },
|
|
37
|
+
{ id: "gulf-of-alaska", kind: "gulf", lon: -149.88, lat: 58.55, name: { en: "Gulf of Alaska", ja: "アラスカ湾" } },
|
|
38
|
+
{ id: "red-sea", kind: "sea", lon: 38.33, lat: 22.96, name: { en: "Red Sea", ja: "紅海" } },
|
|
39
|
+
{ id: "sea-of-okhotsk", kind: "sea", lon: 147.72, lat: 50.78, name: { en: "Sea of Okhotsk", ja: "オホーツク海" } },
|
|
40
|
+
{ id: "weddell-sea", kind: "sea", lon: -46.28, lat: -75.96, name: { en: "Weddell Sea", ja: "ウェッデル海" } },
|
|
41
|
+
{ id: "persian-gulf", kind: "gulf", lon: 52.22, lat: 25.47, name: { en: "Persian Gulf", ja: "ペルシア湾" } },
|
|
42
|
+
{ id: "mediterranean-sea", kind: "sea", lon: 20.41, lat: 35.33, name: { en: "Mediterranean Sea", ja: "地中海" } },
|
|
43
|
+
{ id: "ross-sea", kind: "sea", lon: -169.50, lat: -77.69, name: { en: "Ross Sea", ja: "ロス海" } },
|
|
44
|
+
{ id: "coral-sea", kind: "sea", lon: 156.28, lat: -19.38, name: { en: "Coral Sea", ja: "珊瑚海" } },
|
|
45
|
+
{ id: "sea-of-japan", kind: "sea", lon: 135.81, lat: 41.78, name: { en: "Sea of Japan", ja: "日本海" } },
|
|
46
|
+
];
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { CityFrame } from "../cities/geometry.ts";
|
|
2
|
+
import { SEA_FEATURES } from "./features.ts";
|
|
3
|
+
export { SEA_FEATURES };
|
|
4
|
+
/**
|
|
5
|
+
* One named place: an ocean, a sea, a gulf, a bay or a continent, with the point its name is set at.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import type { SeaFeature } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
10
|
+
*
|
|
11
|
+
* const pacific: SeaFeature = { id: "pacific-ocean", kind: "ocean", lon: -145.5, lat: -8, name: { en: "Pacific Ocean", ja: "太平洋" } };
|
|
12
|
+
* console.log(pacific.name.en);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface SeaFeature {
|
|
16
|
+
id: string;
|
|
17
|
+
kind: "ocean" | "continent" | "sea" | "gulf" | "bay";
|
|
18
|
+
lon: number;
|
|
19
|
+
lat: number;
|
|
20
|
+
name: {
|
|
21
|
+
en: string;
|
|
22
|
+
ja: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A name placed for one draw: its id, the text, and the box it takes.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import type { SeaName } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
31
|
+
*
|
|
32
|
+
* const say = (one: SeaName): string => one.text;
|
|
33
|
+
* console.log(typeof say);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface SeaName {
|
|
37
|
+
id: string;
|
|
38
|
+
kind: SeaFeature["kind"];
|
|
39
|
+
text: string;
|
|
40
|
+
left: number;
|
|
41
|
+
top: number;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
size: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The Earth's radius, in CSS pixels, at which seas, gulfs and bays join the oceans and continents.
|
|
48
|
+
* Below this the view is the wide Earth: only oceans and continents are named.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { SEA_RADIUS } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
53
|
+
*
|
|
54
|
+
* console.log(SEA_RADIUS > 200);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare const SEA_RADIUS = 280;
|
|
58
|
+
/** Space between the letters of a water name, as a share of the text size. Continents use a little less. */
|
|
59
|
+
export declare const SEA_LETTER_SPACING = 0.22;
|
|
60
|
+
export declare const LAND_LETTER_SPACING = 0.06;
|
|
61
|
+
/**
|
|
62
|
+
* The names a view of this size may show: oceans and continents while the Earth is small, and seas, gulfs and bays once it is at least {@link SEA_RADIUS} pixels in radius.
|
|
63
|
+
*
|
|
64
|
+
* @param radius - The Earth's radius on the screen, in CSS pixels.
|
|
65
|
+
* @returns The features, oceans and continents first.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { seaNamesFor } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
70
|
+
*
|
|
71
|
+
* console.log(seaNamesFor(120).some((one) => one.id === "pacific-ocean"));
|
|
72
|
+
* console.log(seaNamesFor(120).some((one) => one.id === "sea-of-japan"));
|
|
73
|
+
* console.log(seaNamesFor(400).some((one) => one.id === "mediterranean-sea"));
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function seaNamesFor(radius: number): readonly SeaFeature[];
|
|
77
|
+
/**
|
|
78
|
+
* Reads the `sea-names` attribute. Absent or `off` is off. A bare attribute, or any other value, is on.
|
|
79
|
+
*
|
|
80
|
+
* @param value - The attribute's value, or null when it is absent.
|
|
81
|
+
* @returns Whether the names are on.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { readSeaNames } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
86
|
+
*
|
|
87
|
+
* console.log(readSeaNames(null), readSeaNames(""), readSeaNames("off"));
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function readSeaNames(value: string | null): boolean;
|
|
91
|
+
/** The attributes the elements watch for these names. */
|
|
92
|
+
export declare const SEA_NAMES_ATTRIBUTES: readonly ["sea-names"];
|
|
93
|
+
/**
|
|
94
|
+
* Lays the names out for one draw. A name on the far side, or off the Earth's disc, is left out. A box in `taken` (a city name, a place, a country) keeps its space: the name moves aside, and if the only room is taken it is left out, so a city that was placed first wins.
|
|
95
|
+
*
|
|
96
|
+
* @param radius - The Earth's radius on the screen. It chooses oceans and continents, or those plus the seas.
|
|
97
|
+
* @param frame - Where the Earth is, and how to project a place. `project` returns how squarely the place faces the viewer.
|
|
98
|
+
* @param lang - `en` or `ja`.
|
|
99
|
+
* @param taken - Boxes already used. A name is not put over one.
|
|
100
|
+
* @returns The names to show.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { layoutSeaNames } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
105
|
+
*
|
|
106
|
+
* const frame = { width: 400, height: 400, radius: 160, project: (lon: number, lat: number, out: { x: number; y: number }) => { out.x = 200 + lon; out.y = 200 - lat; return 1; } };
|
|
107
|
+
* console.log(layoutSeaNames(160, frame, "en", []).some((one) => one.id === "africa"));
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function layoutSeaNames(radius: number, frame: CityFrame & {
|
|
111
|
+
disc?: {
|
|
112
|
+
x: number;
|
|
113
|
+
y: number;
|
|
114
|
+
radius: number;
|
|
115
|
+
};
|
|
116
|
+
}, lang: "en" | "ja", taken: readonly {
|
|
117
|
+
left: number;
|
|
118
|
+
top: number;
|
|
119
|
+
width: number;
|
|
120
|
+
height: number;
|
|
121
|
+
}[]): SeaName[];
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { nameWidth } from "../cities/geometry.js";
|
|
2
|
+
import { SEA_FEATURES } from "./features.js";
|
|
3
|
+
export { SEA_FEATURES };
|
|
4
|
+
/**
|
|
5
|
+
* The Earth's radius, in CSS pixels, at which seas, gulfs and bays join the oceans and continents.
|
|
6
|
+
* Below this the view is the wide Earth: only oceans and continents are named.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { SEA_RADIUS } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
11
|
+
*
|
|
12
|
+
* console.log(SEA_RADIUS > 200);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const SEA_RADIUS = 280;
|
|
16
|
+
/** Space between the letters of a water name, as a share of the text size. Continents use a little less. */
|
|
17
|
+
export const SEA_LETTER_SPACING = 0.22;
|
|
18
|
+
export const LAND_LETTER_SPACING = 0.06;
|
|
19
|
+
const WATER = new Set(["ocean", "sea", "gulf", "bay"]);
|
|
20
|
+
const FACING = 0.25;
|
|
21
|
+
const MAX = 18;
|
|
22
|
+
/**
|
|
23
|
+
* The names a view of this size may show: oceans and continents while the Earth is small, and seas, gulfs and bays once it is at least {@link SEA_RADIUS} pixels in radius.
|
|
24
|
+
*
|
|
25
|
+
* @param radius - The Earth's radius on the screen, in CSS pixels.
|
|
26
|
+
* @returns The features, oceans and continents first.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { seaNamesFor } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
31
|
+
*
|
|
32
|
+
* console.log(seaNamesFor(120).some((one) => one.id === "pacific-ocean"));
|
|
33
|
+
* console.log(seaNamesFor(120).some((one) => one.id === "sea-of-japan"));
|
|
34
|
+
* console.log(seaNamesFor(400).some((one) => one.id === "mediterranean-sea"));
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function seaNamesFor(radius) {
|
|
38
|
+
const wide = SEA_FEATURES.filter((one) => one.kind === "ocean" || one.kind === "continent");
|
|
39
|
+
if (radius < SEA_RADIUS)
|
|
40
|
+
return wide;
|
|
41
|
+
return SEA_FEATURES;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reads the `sea-names` attribute. Absent or `off` is off. A bare attribute, or any other value, is on.
|
|
45
|
+
*
|
|
46
|
+
* @param value - The attribute's value, or null when it is absent.
|
|
47
|
+
* @returns Whether the names are on.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { readSeaNames } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
52
|
+
*
|
|
53
|
+
* console.log(readSeaNames(null), readSeaNames(""), readSeaNames("off"));
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export function readSeaNames(value) {
|
|
57
|
+
return value !== null && value !== "off";
|
|
58
|
+
}
|
|
59
|
+
/** The attributes the elements watch for these names. */
|
|
60
|
+
export const SEA_NAMES_ATTRIBUTES = ["sea-names"];
|
|
61
|
+
const spacingOf = (kind) => (WATER.has(kind) ? SEA_LETTER_SPACING : LAND_LETTER_SPACING);
|
|
62
|
+
const boxOf = (text, size, spacing) => {
|
|
63
|
+
let width = 0;
|
|
64
|
+
for (const char of text)
|
|
65
|
+
width += ((char.codePointAt(0) ?? 0) >= 0x2e80 ? size : size * 0.58) + size * spacing;
|
|
66
|
+
return { width: Math.ceil(Math.max(width, nameWidth(text, size))) + 4, height: Math.ceil(size * 1.35) };
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Lays the names out for one draw. A name on the far side, or off the Earth's disc, is left out. A box in `taken` (a city name, a place, a country) keeps its space: the name moves aside, and if the only room is taken it is left out, so a city that was placed first wins.
|
|
70
|
+
*
|
|
71
|
+
* @param radius - The Earth's radius on the screen. It chooses oceans and continents, or those plus the seas.
|
|
72
|
+
* @param frame - Where the Earth is, and how to project a place. `project` returns how squarely the place faces the viewer.
|
|
73
|
+
* @param lang - `en` or `ja`.
|
|
74
|
+
* @param taken - Boxes already used. A name is not put over one.
|
|
75
|
+
* @returns The names to show.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { layoutSeaNames } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
80
|
+
*
|
|
81
|
+
* const frame = { width: 400, height: 400, radius: 160, project: (lon: number, lat: number, out: { x: number; y: number }) => { out.x = 200 + lon; out.y = 200 - lat; return 1; } };
|
|
82
|
+
* console.log(layoutSeaNames(160, frame, "en", []).some((one) => one.id === "africa"));
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export function layoutSeaNames(radius, frame, lang, taken) {
|
|
86
|
+
const out = { x: 0, y: 0 };
|
|
87
|
+
const disc = frame.disc;
|
|
88
|
+
const blocked = taken.map((box) => ({ l: box.left, t: box.top, r: box.left + box.width, b: box.top + box.height }));
|
|
89
|
+
const placed = [];
|
|
90
|
+
const hits = (box, others) => {
|
|
91
|
+
for (const other of others)
|
|
92
|
+
if (box.l < other.r && box.r > other.l && box.t < other.b && box.b > other.t)
|
|
93
|
+
return true;
|
|
94
|
+
return false;
|
|
95
|
+
};
|
|
96
|
+
const inDisc = (box) => {
|
|
97
|
+
if (!disc)
|
|
98
|
+
return true;
|
|
99
|
+
const reach = disc.radius - 2;
|
|
100
|
+
return Math.hypot(box.l - disc.x, box.t - disc.y) <= reach && Math.hypot(box.r - disc.x, box.t - disc.y) <= reach && Math.hypot(box.l - disc.x, box.b - disc.y) <= reach && Math.hypot(box.r - disc.x, box.b - disc.y) <= reach;
|
|
101
|
+
};
|
|
102
|
+
const names = [];
|
|
103
|
+
const features = [...seaNamesFor(radius)].sort((a, b) => rank(b) - rank(a));
|
|
104
|
+
for (const feature of features) {
|
|
105
|
+
if (names.length >= MAX)
|
|
106
|
+
break;
|
|
107
|
+
const facing = frame.project(feature.lon, feature.lat, out);
|
|
108
|
+
if (facing < FACING)
|
|
109
|
+
continue;
|
|
110
|
+
const text = lang === "ja" ? feature.name.ja : feature.name.en;
|
|
111
|
+
const size = feature.kind === "ocean" || feature.kind === "continent" ? 14 : 12;
|
|
112
|
+
const { width, height } = boxOf(text, size, spacingOf(feature.kind));
|
|
113
|
+
const shifts = [
|
|
114
|
+
[-width / 2, -height / 2],
|
|
115
|
+
[8, -height / 2],
|
|
116
|
+
[-width - 8, -height / 2],
|
|
117
|
+
[-width / 2, -height - 6],
|
|
118
|
+
[-width / 2, 8],
|
|
119
|
+
];
|
|
120
|
+
for (const [dx, dy] of shifts) {
|
|
121
|
+
const left = out.x + dx;
|
|
122
|
+
const top = out.y + dy;
|
|
123
|
+
const box = { l: left, t: top, r: left + width, b: top + height };
|
|
124
|
+
if (box.l < 0 || box.t < 0 || box.r > frame.width || box.b > frame.height)
|
|
125
|
+
continue;
|
|
126
|
+
if (!inDisc(box) || hits(box, blocked) || hits(box, placed))
|
|
127
|
+
continue;
|
|
128
|
+
placed.push(box);
|
|
129
|
+
names.push({ id: feature.id, kind: feature.kind, text, left, top, width, height, size });
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return names;
|
|
134
|
+
}
|
|
135
|
+
const rank = (feature) => (feature.kind === "sea" || feature.kind === "gulf" || feature.kind === "bay" ? 3 : feature.kind === "continent" ? 2 : 1);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type SeaName } from "./geometry.ts";
|
|
2
|
+
import type { CityFrame } from "../cities/geometry.ts";
|
|
3
|
+
/** The styles of the layer (`#sea-names` in the element's shadow root). Water is spaced out; continents a little less. */
|
|
4
|
+
export declare const SEA_NAMES_STYLE: string;
|
|
5
|
+
export interface SeaNamesStats {
|
|
6
|
+
on: boolean;
|
|
7
|
+
radius: number;
|
|
8
|
+
names: number;
|
|
9
|
+
renders: number;
|
|
10
|
+
}
|
|
11
|
+
export interface SeaHost {
|
|
12
|
+
frame(frame: (CityFrame & {
|
|
13
|
+
disc?: {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
radius: number;
|
|
17
|
+
};
|
|
18
|
+
}) | null, taken?: readonly {
|
|
19
|
+
left: number;
|
|
20
|
+
top: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}[]): void;
|
|
24
|
+
refresh(): void;
|
|
25
|
+
readonly shown: readonly SeaName[];
|
|
26
|
+
readonly boxes: readonly {
|
|
27
|
+
left: number;
|
|
28
|
+
top: number;
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
}[];
|
|
32
|
+
readonly stats: SeaNamesStats;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
}
|
|
35
|
+
export interface SeaHostOptions {
|
|
36
|
+
attribute(name: string): string | null;
|
|
37
|
+
language(): "en" | "ja";
|
|
38
|
+
root: ShadowRoot;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Makes the layer of one element. Nothing is added to the root until `sea-names` is on.
|
|
42
|
+
*
|
|
43
|
+
* @param options - The attribute reader, the language and the shadow root.
|
|
44
|
+
* @returns The host.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createSeaHost(options: SeaHostOptions): SeaHost;
|