@johnmorrisdotca/chikyu-earth 0.30.0 → 0.31.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 +4 -0
- package/NOTICE.md +4 -0
- package/README.md +54 -1
- package/dist/data-door.d.ts +357 -0
- package/dist/data-door.js +393 -0
- package/dist/door/book.d.ts +118 -0
- package/dist/door/book.js +211 -0
- package/dist/door/elements.d.ts +96 -0
- package/dist/door/elements.js +108 -0
- package/dist/door/host.d.ts +30 -0
- package/dist/door/host.js +44 -0
- package/dist/door/index.d.ts +6 -0
- package/dist/door/index.js +10 -0
- package/dist/door/map.d.ts +165 -0
- package/dist/door/map.js +182 -0
- package/dist/door/own.d.ts +36 -0
- package/dist/door/own.js +75 -0
- package/dist/passes/element.d.ts +18 -0
- package/dist/passes/element.js +67 -5
- package/dist/realistic/earth.d.ts +5 -3
- package/dist/realistic/earth.js +2 -1
- package/dist/realistic/element.d.ts +18 -0
- package/dist/realistic/element.js +62 -4
- package/dist/realistic/tile-set.d.ts +27 -2
- package/dist/realistic/tile-set.js +155 -49
- package/package.json +6 -1
package/dist/door/map.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { parseManifest, tileColumns, tileRows } from "../realistic/tiles.js";
|
|
2
|
+
import { OWN_BY_ID, madeHere } from "./own.js";
|
|
3
|
+
const RAD = Math.PI / 180;
|
|
4
|
+
const TAU = Math.PI * 2;
|
|
5
|
+
/** A tile's own edge is not the next tile: places are measured to a billionth of a tile. */
|
|
6
|
+
const EDGE = 1e-9;
|
|
7
|
+
/**
|
|
8
|
+
* The levels a source has when it does not say: levels 3 and 4 (8192 and 16384 pixels across), the two the package's cutter makes beyond its own 4096 pixel picture.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { DEFAULT_LEVELS } from "@johnmorrisdotca/chikyu-earth/door";
|
|
13
|
+
*
|
|
14
|
+
* console.log(DEFAULT_LEVELS.levels.map((level) => level.width));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_LEVELS = Object.freeze({ tileSize: 512, levels: Object.freeze([3, 4].map((level) => ({ level, width: 1024 * 2 ** level }))) });
|
|
18
|
+
const KEY_END = /(\d+)\/(\d+)\/(\d+)$/;
|
|
19
|
+
/**
|
|
20
|
+
* The level, column and row a tile key ends in, or `undefined` for a key that does not end in three numbers.
|
|
21
|
+
*
|
|
22
|
+
* @param key - The tile's key.
|
|
23
|
+
* @returns Where the tile is in the pyramid, or `undefined` for a key that does not end in three numbers.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { tileKeyParts } from "@johnmorrisdotca/chikyu-earth/door";
|
|
28
|
+
*
|
|
29
|
+
* console.log(tileKeyParts("day/3/12/5"));
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function tileKeyParts(key) {
|
|
33
|
+
const found = KEY_END.exec(key);
|
|
34
|
+
return found === null ? undefined : { level: Number(found[1]), col: Number(found[2]), row: Number(found[3]) };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The place a tile covers, in degrees: what a view asks a source about to get that tile's key.
|
|
38
|
+
*
|
|
39
|
+
* @param tile - A tile of the pyramid.
|
|
40
|
+
* @returns The tile's longitude and latitude bounds.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { tilePlace } from "@johnmorrisdotca/chikyu-earth/door";
|
|
45
|
+
*
|
|
46
|
+
* console.log(tilePlace({ level: 3, col: 0, row: 0 }));
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function tilePlace(tile) {
|
|
50
|
+
const columns = tileColumns(tile.level);
|
|
51
|
+
const rows = tileRows(tile.level);
|
|
52
|
+
return { lonMin: -180 + (360 * tile.col) / columns, lonMax: -180 + (360 * (tile.col + 1)) / columns, latMax: 90 - (180 * tile.row) / rows, latMin: 90 - (180 * (tile.row + 1)) / rows };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The keys of the tiles that cover a place at a detail, on the package's pyramid: the level is the lowest whose width is at least `detail` pixels round (or the finest there is), and the tiles are every one the place touches.
|
|
56
|
+
* Pure. A source of your own can build its `need` on it.
|
|
57
|
+
*
|
|
58
|
+
* @param place - The part of the map, in degrees.
|
|
59
|
+
* @param detail - The pixels across the whole circumference wanted.
|
|
60
|
+
* @param layer - The levels the source has; `DEFAULT_LEVELS` where left out.
|
|
61
|
+
* @param prefix - Put before each key (`"day/"`), for a folder of several layers.
|
|
62
|
+
* @returns The keys, `[<prefix>]level/column/row`, row by row; none for a place with no area.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { mapKeys } from "@johnmorrisdotca/chikyu-earth/door";
|
|
67
|
+
*
|
|
68
|
+
* console.log(mapKeys({ lonMin: -10, lonMax: 10, latMin: -5, latMax: 5 }, 8192));
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function mapKeys(place, detail, layer = DEFAULT_LEVELS, prefix = "") {
|
|
72
|
+
if (layer.levels.length === 0 || !(place.lonMax > place.lonMin) || !(place.latMax >= place.latMin))
|
|
73
|
+
return [];
|
|
74
|
+
const level = layer.levels.find((one) => one.width >= detail) ?? layer.levels[layer.levels.length - 1];
|
|
75
|
+
const columns = tileColumns(level.level);
|
|
76
|
+
const rows = tileRows(level.level);
|
|
77
|
+
const span = Math.min(TAU, (place.lonMax - place.lonMin) * RAD);
|
|
78
|
+
const first = Math.floor(((place.lonMin * RAD) / TAU + 0.5) * columns + EDGE);
|
|
79
|
+
const count = span >= TAU - 1e-9 ? columns : Math.min(columns, Math.ceil(((place.lonMin * RAD + span) / TAU + 0.5) * columns - EDGE) - first);
|
|
80
|
+
const row0 = Math.max(0, Math.floor((0.5 - (place.latMax * RAD) / Math.PI) * rows + EDGE));
|
|
81
|
+
const row1 = Math.min(rows, Math.max(row0 + 1, Math.ceil((0.5 - (place.latMin * RAD) / Math.PI) * rows - EDGE)));
|
|
82
|
+
const keys = [];
|
|
83
|
+
for (let row = row0; row < row1; row += 1)
|
|
84
|
+
for (let i = 0; i < count; i += 1)
|
|
85
|
+
keys.push(`${prefix}${level.level}/${(((first + i) % columns) + columns) % columns}/${row}`);
|
|
86
|
+
return keys;
|
|
87
|
+
}
|
|
88
|
+
const slash = (base) => (base.endsWith("/") ? base : `${base}/`);
|
|
89
|
+
/**
|
|
90
|
+
* What a decoded picture holds in memory, with its mipmaps (4/3 of its bytes): the `bytes` of a map source.
|
|
91
|
+
*
|
|
92
|
+
* @param tile - The tile.
|
|
93
|
+
* @returns Bytes.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { imageBytes } from "@johnmorrisdotca/chikyu-earth/door";
|
|
98
|
+
*
|
|
99
|
+
* console.log(imageBytes({ width: 512, height: 512, image: { width: 512, height: 512 } }));
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export function imageBytes(tile) {
|
|
103
|
+
return Math.ceil(tile.width * tile.height * 4 * (4 / 3));
|
|
104
|
+
}
|
|
105
|
+
const folders = new Map();
|
|
106
|
+
/**
|
|
107
|
+
* The package's own finer map tiles as a source: a folder with a `manifest.json` and a tile for each layer, level and place at `<layer>/<level>/<column>/<row>.webp` (made by `scripts/make-earth-tiles.py`). This is what the `tiles`
|
|
108
|
+
* attribute of `<chikyu-earth-realistic>` means, and what the Earth is drawn from where no source of yours covers a layer. It is for every layer in the folder (`layer: "*"`); the manifest says which levels each has, and it is read once
|
|
109
|
+
* for the source, only when a view first wants more than the 4096 pixel picture. Its `id` is `chikyu-tiles`, and a view counts it as the package's own data.
|
|
110
|
+
*
|
|
111
|
+
* @param base - The folder's address, with or without the closing slash.
|
|
112
|
+
* @param options - The `fetch` and the decoder to use.
|
|
113
|
+
* @returns The source.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts no-run
|
|
117
|
+
* import { earthTiles } from "@johnmorrisdotca/chikyu-earth/door";
|
|
118
|
+
*
|
|
119
|
+
* const mine = earthTiles("/tiles/");
|
|
120
|
+
* console.log(mine.need({ lonMin: 0, lonMax: 20, latMin: 0, latMax: 10, layer: "day" }, 8192));
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export function earthTiles(base, options = {}) {
|
|
124
|
+
const folder = slash(base);
|
|
125
|
+
const get = options.fetch ?? ((url, init) => globalThis.fetch(url, init));
|
|
126
|
+
const decode = options.decode ?? ((blob) => createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }));
|
|
127
|
+
let manifest;
|
|
128
|
+
const source = {
|
|
129
|
+
kind: "tiles",
|
|
130
|
+
layer: "*",
|
|
131
|
+
info: OWN_BY_ID.get("chikyu-tiles"),
|
|
132
|
+
need(place, detail) {
|
|
133
|
+
const layer = place.layer;
|
|
134
|
+
if (typeof layer !== "string" || layer === "")
|
|
135
|
+
throw new RangeError("a folder of tiles is asked for a place with its layer");
|
|
136
|
+
return mapKeys(place, detail, DEFAULT_LEVELS, `${layer}/`);
|
|
137
|
+
},
|
|
138
|
+
async levels(layer) {
|
|
139
|
+
// read once: a folder that cannot be read is not asked again by this source, so a view at rest sends nothing
|
|
140
|
+
const asked = (manifest ??= get(`${folder}manifest.json`, { mode: "cors" }).then(async (response) => (response.ok ? parseManifest(await response.json().catch(() => undefined))?.layers : undefined), () => undefined));
|
|
141
|
+
const layers = await asked;
|
|
142
|
+
// an answer that was no folder is not kept: the next view of it (a changed source, a new element) asks again, and a view at rest never does
|
|
143
|
+
if (layers === undefined && manifest === asked)
|
|
144
|
+
manifest = undefined;
|
|
145
|
+
return layers?.[layer];
|
|
146
|
+
},
|
|
147
|
+
async load(key, signal) {
|
|
148
|
+
if (tileKeyParts(key) === undefined)
|
|
149
|
+
throw new RangeError(`"${key}" is not the key of a tile`);
|
|
150
|
+
const response = await get(`${folder}${key}.webp`, { mode: "cors", signal });
|
|
151
|
+
if (!response.ok)
|
|
152
|
+
throw new Error(`The tile ${key} could not be fetched (${response.status})`);
|
|
153
|
+
const image = await decode(await response.blob());
|
|
154
|
+
return { width: image.width > 0 ? image.width : 512, height: image.height > 0 ? image.height : 512, image };
|
|
155
|
+
},
|
|
156
|
+
bytes: (tile) => imageBytes(tile),
|
|
157
|
+
};
|
|
158
|
+
madeHere(source);
|
|
159
|
+
return source;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The folder source of an address, the same object each time: what an element makes of its `tiles` attribute, so that two elements on a page with the same folder share one source and its pictures.
|
|
163
|
+
*
|
|
164
|
+
* @param base - The folder's address.
|
|
165
|
+
* @returns The source `earthTiles` makes for it.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts no-run
|
|
169
|
+
* import { folderSource } from "@johnmorrisdotca/chikyu-earth/door";
|
|
170
|
+
*
|
|
171
|
+
* console.log(folderSource("/tiles/") === folderSource("/tiles/"));
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export function folderSource(base) {
|
|
175
|
+
const folder = slash(base);
|
|
176
|
+
let held = folders.get(folder);
|
|
177
|
+
if (held === undefined) {
|
|
178
|
+
held = earthTiles(folder);
|
|
179
|
+
folders.set(folder, held);
|
|
180
|
+
}
|
|
181
|
+
return held;
|
|
182
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Credit, SourceInfo } from "../data-door.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The package's own data, as sources, written from the rows of `NOTICE.md`: `chikyu-pictures` (the whole-Earth pictures of the realistic Earth: day, night, clouds and water) and `chikyu-tiles` (the finer map tiles cut from NASA's bigger maps).
|
|
4
|
+
* A test holds that none is non-commercial or share-alike, so the package can pass all of it on under the MIT licence. A view's credit line is written from these and from the sources a caller handed in.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { OWN_SOURCES } from "@johnmorrisdotca/chikyu-earth/door";
|
|
9
|
+
*
|
|
10
|
+
* console.log(OWN_SOURCES.map((source) => `${source.id}: ${source.licence.name}`));
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const OWN_SOURCES: readonly SourceInfo[];
|
|
14
|
+
/** The rows of `OWN_SOURCES` by id. */
|
|
15
|
+
export declare const OWN_BY_ID: ReadonlyMap<string, SourceInfo>;
|
|
16
|
+
/** Marks a source object as made by this package. */
|
|
17
|
+
export declare function madeHere<T extends object>(source: T): T;
|
|
18
|
+
/** True for a source object this package made (`earthTiles`), false for any other. */
|
|
19
|
+
export declare const isOwnSource: (source: object) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The credit of one of the package's own sources, for a page that draws something itself: the elements credit their own pictures and tiles in `credits()`, and a page that draws the Earth from the package's pictures
|
|
22
|
+
* puts `ownCredit("chikyu-pictures", 1)` in its credit line.
|
|
23
|
+
*
|
|
24
|
+
* @param id - `chikyu-pictures` or `chikyu-tiles`.
|
|
25
|
+
* @param used - How many marks were drawn from it.
|
|
26
|
+
* @returns The credit, marked as the package's own.
|
|
27
|
+
* @throws RangeError for an id that is not one of `OWN_SOURCES`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { creditLine, ownCredit } from "@johnmorrisdotca/chikyu-earth/door";
|
|
32
|
+
*
|
|
33
|
+
* console.log(creditLine([ownCredit("chikyu-tiles", 6)], "en"));
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function ownCredit(id: string, used: number): Credit;
|
package/dist/door/own.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const NOTICE = "https://github.com/johnmorrisdotca/chikyu-earth/blob/main/NOTICE.md";
|
|
2
|
+
function freeze(value) {
|
|
3
|
+
if (typeof value === "object" && value !== null)
|
|
4
|
+
for (const inner of Object.values(value))
|
|
5
|
+
freeze(inner);
|
|
6
|
+
return Object.freeze(value);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The package's own data, as sources, written from the rows of `NOTICE.md`: `chikyu-pictures` (the whole-Earth pictures of the realistic Earth: day, night, clouds and water) and `chikyu-tiles` (the finer map tiles cut from NASA's bigger maps).
|
|
10
|
+
* A test holds that none is non-commercial or share-alike, so the package can pass all of it on under the MIT licence. A view's credit line is written from these and from the sources a caller handed in.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { OWN_SOURCES } from "@johnmorrisdotca/chikyu-earth/door";
|
|
15
|
+
*
|
|
16
|
+
* console.log(OWN_SOURCES.map((source) => `${source.id}: ${source.licence.name}`));
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const OWN_SOURCES = freeze([
|
|
20
|
+
{
|
|
21
|
+
id: "chikyu-pictures",
|
|
22
|
+
name: { en: "Earth pictures", ja: "地球の画像" },
|
|
23
|
+
credit: {
|
|
24
|
+
en: "Earth pictures: NASA Earth Observatory (Blue Marble, Reto Stöckli; Black Marble, Suomi NPP VIIRS data)",
|
|
25
|
+
ja: "地球の画像:NASA Earth Observatory(ブルーマーブル、Reto Stöckli/ブラックマーブル、Suomi NPP VIIRSデータ)",
|
|
26
|
+
},
|
|
27
|
+
licence: { name: "Public domain", url: `${NOTICE}#the-realistic-earths-pictures` },
|
|
28
|
+
url: "https://github.com/johnmorrisdotca/chikyu-earth/tree/main/textures",
|
|
29
|
+
retrieved: "2026-11-02",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "chikyu-tiles",
|
|
33
|
+
name: { en: "Finer map tiles", ja: "細かい地図のタイル" },
|
|
34
|
+
credit: {
|
|
35
|
+
en: "Finer map tiles: NASA Earth Observatory (Blue Marble: Next Generation; Black Marble, Suomi NPP VIIRS data), cut by Chikyu Earth",
|
|
36
|
+
ja: "細かい地図のタイル:NASA Earth Observatory(ブルーマーブル・ネクストジェネレーション/ブラックマーブル、Suomi NPP VIIRSデータ)、Chikyu Earthで切り出したもの",
|
|
37
|
+
},
|
|
38
|
+
licence: { name: "Public domain", url: `${NOTICE}#the-earth-tiles` },
|
|
39
|
+
url: "https://johnmorrisdotca.github.io/chikyu-earth/tiles/",
|
|
40
|
+
retrieved: "2026-11-08",
|
|
41
|
+
},
|
|
42
|
+
]);
|
|
43
|
+
/** The rows of `OWN_SOURCES` by id. */
|
|
44
|
+
export const OWN_BY_ID = new Map(OWN_SOURCES.map((source) => [source.id, source]));
|
|
45
|
+
/** The source objects this package made itself: only these are its own, whatever id a caller's source gives itself. */
|
|
46
|
+
const MADE_HERE = new WeakSet();
|
|
47
|
+
/** Marks a source object as made by this package. */
|
|
48
|
+
export function madeHere(source) {
|
|
49
|
+
MADE_HERE.add(source);
|
|
50
|
+
return source;
|
|
51
|
+
}
|
|
52
|
+
/** True for a source object this package made (`earthTiles`), false for any other. */
|
|
53
|
+
export const isOwnSource = (source) => MADE_HERE.has(source);
|
|
54
|
+
/**
|
|
55
|
+
* The credit of one of the package's own sources, for a page that draws something itself: the elements credit their own pictures and tiles in `credits()`, and a page that draws the Earth from the package's pictures
|
|
56
|
+
* puts `ownCredit("chikyu-pictures", 1)` in its credit line.
|
|
57
|
+
*
|
|
58
|
+
* @param id - `chikyu-pictures` or `chikyu-tiles`.
|
|
59
|
+
* @param used - How many marks were drawn from it.
|
|
60
|
+
* @returns The credit, marked as the package's own.
|
|
61
|
+
* @throws RangeError for an id that is not one of `OWN_SOURCES`.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { creditLine, ownCredit } from "@johnmorrisdotca/chikyu-earth/door";
|
|
66
|
+
*
|
|
67
|
+
* console.log(creditLine([ownCredit("chikyu-tiles", 6)], "en"));
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export function ownCredit(id, used) {
|
|
71
|
+
const source = OWN_BY_ID.get(id);
|
|
72
|
+
if (source === undefined)
|
|
73
|
+
throw new RangeError(`"${id}" is not one of the package's own sources`);
|
|
74
|
+
return { source, own: true, used };
|
|
75
|
+
}
|
package/dist/passes/element.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ElementSet } from "../satellites/types.ts";
|
|
2
|
+
import { type Credit, type DataSource } from "../data-door.ts";
|
|
2
3
|
import { type SatellitePass } from "./passes.ts";
|
|
3
4
|
type Lang = "en" | "ja";
|
|
4
5
|
/**
|
|
@@ -26,6 +27,23 @@ export declare class ChikyuPasses extends HTMLElement {
|
|
|
26
27
|
/** The orbit data the passes are worked out from. Setting it works the passes out again. */
|
|
27
28
|
get elements(): readonly ElementSet[];
|
|
28
29
|
set elements(sets: readonly ElementSet[]);
|
|
30
|
+
/**
|
|
31
|
+
* The outside sources of orbital elements (the data door): each carries its own licence and credit (`elementsFrom` makes one of an address), is read once when it is added, and its sets are worked out with the page's own.
|
|
32
|
+
* Assign a list to replace them; a source that is refused throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
|
|
33
|
+
*/
|
|
34
|
+
get sources(): readonly DataSource[];
|
|
35
|
+
set sources(list: readonly unknown[]);
|
|
36
|
+
/** Adds a source of orbital elements: checked at once (a `TypeError` for one that is refused). Returns the function that takes it away. */
|
|
37
|
+
addSource(source: unknown): () => void;
|
|
38
|
+
/** Takes a source away by its id. Returns whether there was one. */
|
|
39
|
+
removeSource(id: string): boolean;
|
|
40
|
+
/** Switches a source off (`false`) or on again, and keeps it in the element. The attribute `data="own"` ignores every outside source at once. */
|
|
41
|
+
enableSource(id: string, on: boolean): void;
|
|
42
|
+
/**
|
|
43
|
+
* Whose orbit data is in the list now: each source of the data door that gave a satellite to a pass listed, with how many satellites (`used`). `creditLine(credits, "en" | "ja")` from `@johnmorrisdotca/chikyu-earth/door` writes them
|
|
44
|
+
* as a line with the licences, and the element shows that line under the list (after the text of the `credit` attribute, which stays). `chikyu-creditschange` fires when this set changes, with `detail: { credits }`.
|
|
45
|
+
*/
|
|
46
|
+
credits(): Credit[];
|
|
29
47
|
/** The passes listed now, earliest first. */
|
|
30
48
|
get passes(): readonly SatellitePass[];
|
|
31
49
|
/** The pass pressed, or undefined. */
|
package/dist/passes/element.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// Nothing runs on a timer: it works the passes out when something it shows changes, and reads the clock once, when it first comes into a page (or never, when `from` is given).
|
|
3
3
|
import { adoptStyles } from "../adopt.js";
|
|
4
4
|
import { fetchElements } from "../satellites/source.js";
|
|
5
|
+
import { creditLine } from "../data-door.js";
|
|
6
|
+
import { createDoorHost } from "../door/host.js";
|
|
7
|
+
import { mergeElementSets } from "../door/elements.js";
|
|
5
8
|
import { DEFAULT_DIM_AFTER_DAYS } from "../satellites/limits.js";
|
|
6
9
|
import { findPasses, passPath } from "./passes.js";
|
|
7
10
|
import { skySvg } from "./sky.js";
|
|
@@ -169,8 +172,14 @@ const number = (value, fallback) => (value === null || value.trim() === "" || !N
|
|
|
169
172
|
* ```
|
|
170
173
|
*/
|
|
171
174
|
export class ChikyuPasses extends HTMLElement {
|
|
172
|
-
static observedAttributes = ["latitude", "longitude", "height", "days", "show", "sky", "satellite", "from", "min-altitude", "lang", "time-zone", "utc-offset", "selected", "elements-src", "credit"];
|
|
175
|
+
static observedAttributes = ["latitude", "longitude", "height", "days", "show", "sky", "satellite", "from", "min-altitude", "lang", "time-zone", "utc-offset", "selected", "elements-src", "credit", "data"];
|
|
173
176
|
#sets = [];
|
|
177
|
+
/** The element sets the passes are worked out from: the page's own (`elements`, `elements-src`) and those of the sources of the data door, one set a satellite, the newest epoch winning. */
|
|
178
|
+
#all = [];
|
|
179
|
+
/** Which source each satellite's set came from (`null`: the page's own sets), by NORAD number. */
|
|
180
|
+
#origin = new Map();
|
|
181
|
+
/** The data door: the outside sources of orbital elements, and whose data is on the screen. */
|
|
182
|
+
#door = createDoorHost(this, { own: () => [], used: () => this.#used() }, { kinds: ["records"] }, () => this.#schedule());
|
|
174
183
|
#passes = [];
|
|
175
184
|
#chosen;
|
|
176
185
|
#problem = "";
|
|
@@ -190,6 +199,49 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
190
199
|
this.#problem = "";
|
|
191
200
|
this.#schedule();
|
|
192
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* The outside sources of orbital elements (the data door): each carries its own licence and credit (`elementsFrom` makes one of an address), is read once when it is added, and its sets are worked out with the page's own.
|
|
204
|
+
* Assign a list to replace them; a source that is refused throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
|
|
205
|
+
*/
|
|
206
|
+
get sources() {
|
|
207
|
+
return this.#door.sources();
|
|
208
|
+
}
|
|
209
|
+
set sources(list) {
|
|
210
|
+
this.#door.setSources(list);
|
|
211
|
+
}
|
|
212
|
+
/** Adds a source of orbital elements: checked at once (a `TypeError` for one that is refused). Returns the function that takes it away. */
|
|
213
|
+
addSource(source) {
|
|
214
|
+
return this.#door.book.addSource(source);
|
|
215
|
+
}
|
|
216
|
+
/** Takes a source away by its id. Returns whether there was one. */
|
|
217
|
+
removeSource(id) {
|
|
218
|
+
return this.#door.book.removeSource(id);
|
|
219
|
+
}
|
|
220
|
+
/** Switches a source off (`false`) or on again, and keeps it in the element. The attribute `data="own"` ignores every outside source at once. */
|
|
221
|
+
enableSource(id, on) {
|
|
222
|
+
this.#door.book.enableSource(id, on);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Whose orbit data is in the list now: each source of the data door that gave a satellite to a pass listed, with how many satellites (`used`). `creditLine(credits, "en" | "ja")` from `@johnmorrisdotca/chikyu-earth/door` writes them
|
|
226
|
+
* as a line with the licences, and the element shows that line under the list (after the text of the `credit` attribute, which stays). `chikyu-creditschange` fires when this set changes, with `detail: { credits }`.
|
|
227
|
+
*/
|
|
228
|
+
credits() {
|
|
229
|
+
return this.#door.credits();
|
|
230
|
+
}
|
|
231
|
+
/** How many satellites of the passes listed came from each source of the door, by id. */
|
|
232
|
+
#used() {
|
|
233
|
+
const seen = new Set();
|
|
234
|
+
const used = new Map();
|
|
235
|
+
for (const pass of this.#passes) {
|
|
236
|
+
if (seen.has(pass.noradId))
|
|
237
|
+
continue;
|
|
238
|
+
seen.add(pass.noradId);
|
|
239
|
+
const id = this.#origin.get(pass.noradId);
|
|
240
|
+
if (id !== null && id !== undefined)
|
|
241
|
+
used.set(id, (used.get(id) ?? 0) + 1);
|
|
242
|
+
}
|
|
243
|
+
return used;
|
|
244
|
+
}
|
|
193
245
|
/** The passes listed now, earliest first. */
|
|
194
246
|
get passes() {
|
|
195
247
|
return this.#passes;
|
|
@@ -216,12 +268,15 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
216
268
|
connectedCallback() {
|
|
217
269
|
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
218
270
|
adoptStyles(root, CSS, this.getAttribute("nonce") ?? "");
|
|
271
|
+
this.#door.book.ownOnly(this.getAttribute("data") === "own");
|
|
219
272
|
this.#load();
|
|
220
273
|
this.#schedule();
|
|
221
274
|
}
|
|
222
275
|
attributeChangedCallback(name) {
|
|
223
276
|
if (!this.isConnected)
|
|
224
277
|
return;
|
|
278
|
+
if (name === "data")
|
|
279
|
+
this.#door.book.ownOnly(this.getAttribute("data") === "own");
|
|
225
280
|
if (name === "elements-src")
|
|
226
281
|
this.#load();
|
|
227
282
|
this.#schedule();
|
|
@@ -326,8 +381,13 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
326
381
|
holder.innerHTML = `<p class="empty" role="status">${escape(say("unreadable", { why: this.#problem }))}</p>`;
|
|
327
382
|
return;
|
|
328
383
|
}
|
|
384
|
+
const lists = this.#door.book.elementLists();
|
|
385
|
+
// with no source the page's own sets are used as they are, every one
|
|
386
|
+
const merged = lists.length === 0 ? this.#sets.map((set) => ({ set, id: null })) : mergeElementSets([{ id: null, sets: this.#sets }, ...lists]);
|
|
387
|
+
this.#all = merged.map((one) => one.set);
|
|
388
|
+
this.#origin = new Map(merged.map((one) => [one.set.NORAD_CAT_ID, one.id]));
|
|
329
389
|
const chosenSet = this.getAttribute("satellite");
|
|
330
|
-
const sets = chosenSet ? this.#
|
|
390
|
+
const sets = chosenSet ? this.#all.filter((one) => String(one.NORAD_CAT_ID) === chosenSet) : this.#all;
|
|
331
391
|
if (this.#waiting && sets.length === 0) {
|
|
332
392
|
holder.innerHTML = `<p class="empty" role="status">${escape(say("waiting"))}</p>`;
|
|
333
393
|
return;
|
|
@@ -363,7 +423,8 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
363
423
|
ages.set(pass.noradId, pass);
|
|
364
424
|
const oldest = Math.max(0, ...[...ages.values()].map((one) => one.elementAgeDays));
|
|
365
425
|
const note = `<p class="note">${escape(f.zone)} ${escape(say("reboost"))}${oldest > DEFAULT_DIM_AFTER_DAYS ? ` ${escape(say("stale"))}${lang === "ja" ? "。" : "."}` : ""}</p>`;
|
|
366
|
-
|
|
426
|
+
// the `credit` attribute stays as the page's own words; the sources of the door add their credit line, with the licences, after it
|
|
427
|
+
const credit = [this.getAttribute("credit") ?? "", creditLine(this.#door.credits(), lang)].filter((part) => part.trim() !== "").join(" ");
|
|
367
428
|
const list = this.#passes.length === 0 ? `<p class="empty" role="status">${escape(say(all ? "noneAll" : "none", { days }))}</p>` : `<ul class="list" aria-label="${escape(say("list"))}">${rows}</ul>`;
|
|
368
429
|
holder.innerHTML = `${note}<div class="layout"><div>${list}</div><div class="detail">${this.#chosen ? this.#detail(this.#chosen, f, say, lang) : ""}</div></div>${credit ? `<p class="credit">${escape(credit)}</p>` : ""}`;
|
|
369
430
|
this.dispatchEvent(new CustomEvent("chikyu-passes", { detail: { passes: this.#passes, ageDays: oldest }, bubbles: true, composed: true }));
|
|
@@ -371,11 +432,12 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
371
432
|
const shown = this.#chosen?.highest.ms;
|
|
372
433
|
if (shown !== this.#announced) {
|
|
373
434
|
this.#announced = shown;
|
|
374
|
-
this.dispatchEvent(new CustomEvent("chikyu-pass-select", { detail: { pass: this.#chosen, set: this.#chosen ? this.#
|
|
435
|
+
this.dispatchEvent(new CustomEvent("chikyu-pass-select", { detail: { pass: this.#chosen, set: this.#chosen ? this.#all.find((one) => one.NORAD_CAT_ID === this.#chosen.noradId) : undefined }, bubbles: true, composed: true }));
|
|
375
436
|
}
|
|
437
|
+
this.#door.announce();
|
|
376
438
|
}
|
|
377
439
|
#detail(pass, f, say, lang) {
|
|
378
|
-
const set = this.#
|
|
440
|
+
const set = this.#all.find((one) => one.NORAD_CAT_ID === pass.noradId);
|
|
379
441
|
const place = { latitude: number(this.getAttribute("latitude"), 0), longitude: number(this.getAttribute("longitude"), 0), heightM: number(this.getAttribute("height"), 0) };
|
|
380
442
|
const short = SHORT[pass.noradId]?.[lang] ?? pass.name;
|
|
381
443
|
const labels = { north: say("skyN"), east: say("skyE"), south: say("skyS"), west: say("skyW"), start: say("skyStart"), highest: say("skyHighest"), end: say("skyEnd"), zenith: say("skyZenith") };
|
|
@@ -6,7 +6,7 @@ import { lookAt } from "../view.ts";
|
|
|
6
6
|
import { type SatelliteState } from "../space/satellite-layer.ts";
|
|
7
7
|
import type { Layer } from "./tiers.ts";
|
|
8
8
|
import { type ThreeParts } from "./textures.ts";
|
|
9
|
-
import { type TileSet } from "./tile-set.ts";
|
|
9
|
+
import { type TileSet, type TileSources } from "./tile-set.ts";
|
|
10
10
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
11
11
|
export type { ThreeParts };
|
|
12
12
|
type Three = ThreeParts;
|
|
@@ -92,8 +92,8 @@ export interface EarthDeps {
|
|
|
92
92
|
textureBase: () => string;
|
|
93
93
|
/** The widest texture, 4096 at most. */
|
|
94
94
|
cap: () => number;
|
|
95
|
-
/**
|
|
96
|
-
|
|
95
|
+
/** The map source of each layer now (the data door's: a source a page added, else the `tiles` folder), or none: the Earth then keeps the package's own pictures. */
|
|
96
|
+
sources?: () => TileSources;
|
|
97
97
|
/** Told once when the tile set has been read: the width in pixels of the finest level of each of its layers. */
|
|
98
98
|
onTiles?: (layers: Record<string, number>) => void;
|
|
99
99
|
invalidate: () => void;
|
|
@@ -103,6 +103,8 @@ export interface EarthDeps {
|
|
|
103
103
|
air?: () => "full" | "light";
|
|
104
104
|
/** The satellites could not be drawn (the three.js parts handed over lack `Points`). */
|
|
105
105
|
onSatellitesError?: (error: unknown) => void;
|
|
106
|
+
/** Told after the tiles were put right for a draw: what the draw shows from each source is known now. */
|
|
107
|
+
onTiled?: () => void;
|
|
106
108
|
/** Told at the start of every draw, before anything is read for it. */
|
|
107
109
|
onDraw?: () => void;
|
|
108
110
|
/** Told at every draw where the disc is, for what is laid over it (markers). */
|
package/dist/realistic/earth.js
CHANGED
|
@@ -159,7 +159,7 @@ export function createEarthItem(model, deps) {
|
|
|
159
159
|
});
|
|
160
160
|
const turned = new three.Group();
|
|
161
161
|
const earth = new three.Mesh(grid, surface);
|
|
162
|
-
const tiles = createTileSet(three, turned, { sunDir, lights: surface.uniforms["lights"], boost: surface.uniforms["boost"], ortho: surface.uniforms["ortho"], water: uniform.water, night: uniform.night, extra: { cloudMap: uniform.clouds, sunLocal, cloudShift } }, { assets: deps.assets,
|
|
162
|
+
const tiles = createTileSet(three, turned, { sunDir, lights: surface.uniforms["lights"], boost: surface.uniforms["boost"], ortho: surface.uniforms["ortho"], water: uniform.water, night: uniform.night, extra: { cloudMap: uniform.clouds, sunLocal, cloudShift } }, { assets: deps.assets, sources: () => deps.sources?.() ?? {}, cap: deps.cap, invalidate: deps.invalidate, ...(deps.onTiles ? { onManifest: deps.onTiles } : {}) });
|
|
163
163
|
model.tiles = tiles;
|
|
164
164
|
const clouds = new three.Mesh(grid, cloudMaterial);
|
|
165
165
|
clouds.scale.setScalar(CLOUD_RADIUS);
|
|
@@ -226,6 +226,7 @@ export function createEarthItem(model, deps) {
|
|
|
226
226
|
model.drawn = { view: { ...view }, time: model.time, radius, centre: { ...centre } };
|
|
227
227
|
textures.sync(radius * model.ratio());
|
|
228
228
|
tiles.sync({ lon: look.lon, lat: look.lat, width: size.width, height: size.height, panX: view.panX, panY: view.panY, radius }, [sunDir.value.x, sunDir.value.y, sunDir.value.z], true, model.ratio());
|
|
229
|
+
deps.onTiled?.();
|
|
229
230
|
deps.onPose?.({ lon: look.lon, lat: look.lat, radius, cx: size.width / 2 + view.panX, cy: size.height / 2 + view.panY, width: size.width, height: size.height });
|
|
230
231
|
if (model.meteors.on && !meteors)
|
|
231
232
|
meteors = createMeteorLayer(three, turned, model.meteors);
|
|
@@ -3,6 +3,7 @@ import type { GeoPoint, GlobeView } from "../types.ts";
|
|
|
3
3
|
import { type CameraMode, type LightMode } from "./earth.ts";
|
|
4
4
|
import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
|
|
5
5
|
import { type SatelliteStyle } from "../space/satellite-layer.ts";
|
|
6
|
+
import type { Credit, DataSource } from "../data-door.ts";
|
|
6
7
|
import { setSharedRenderer, setThreeLoader } from "./shared.ts";
|
|
7
8
|
export { setSharedRenderer, setThreeLoader };
|
|
8
9
|
export type { CameraMode };
|
|
@@ -124,6 +125,23 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
124
125
|
set meteorsStrength(value: number);
|
|
125
126
|
/** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
|
|
126
127
|
get controller(): ViewController | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* The outside sources of map this Earth draws from (the data door): each carries its own licence and credit, and a map source for the `day` or `night` layer takes the place of the folder of tiles for that layer. Assign a list to
|
|
130
|
+
* replace them; a source that is refused (an empty credit, no licence, a clashing id, a kind the Earth does not draw, a layer it does not know) throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
|
|
131
|
+
*/
|
|
132
|
+
get sources(): readonly DataSource[];
|
|
133
|
+
set sources(list: readonly unknown[]);
|
|
134
|
+
/** Adds an outside source of map: checked at once (a `TypeError` for one that is refused), and the Earth draws from it. Returns the function that takes it away. */
|
|
135
|
+
addSource(source: unknown): () => void;
|
|
136
|
+
/** Takes a source away by its id: its loads stop, its tiles are freed, its credit goes. Returns whether there was one. */
|
|
137
|
+
removeSource(id: string): boolean;
|
|
138
|
+
/** Switches a source off (`false`) or on again, and keeps it in the Earth: a layers panel's switch. The attribute `data="own"` ignores every outside source at once. */
|
|
139
|
+
enableSource(id: string, on: boolean): void;
|
|
140
|
+
/**
|
|
141
|
+
* Whose data is in the last drawn frame: the package's own first (its pictures; its finer tiles while a window of them is in view) and then each outside source that gave a tile, with how many (`used`). `creditLine(credits, "en" | "ja")`
|
|
142
|
+
* from `@johnmorrisdotca/chikyu-earth/door` writes them as a line with the licences. `chikyu-creditschange` fires when this set changes (not at each frame), with `detail: { credits }`.
|
|
143
|
+
*/
|
|
144
|
+
credits(): Credit[];
|
|
127
145
|
/** Where the finer map tiles are served from (a folder with `manifest.json`), or `null` for none; the attribute `tiles`. The Earth loads only the tiles in view, over its own pictures. */
|
|
128
146
|
get tiles(): string | null;
|
|
129
147
|
set tiles(value: string | null);
|