@johnmorrisdotca/chikyu-earth 0.46.1 → 0.46.4
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 +8 -0
- package/NOTICE.md +10 -0
- package/README.md +2 -2
- package/dist/door/gibs.d.ts +198 -0
- package/dist/door/gibs.js +403 -0
- package/dist/door/grid.d.ts +201 -0
- package/dist/door/grid.js +251 -0
- package/dist/door/index.d.ts +2 -0
- package/dist/door/index.js +2 -0
- package/dist/door/map.d.ts +14 -0
- package/dist/realistic/element-base.d.ts +6 -0
- package/dist/realistic/element-base.js +52 -7
- package/dist/realistic/index.d.ts +1 -1
- package/dist/realistic/index.js +1 -1
- package/dist/realistic/shaders.js +5 -3
- package/dist/realistic/tile-set.d.ts +11 -1
- package/dist/realistic/tile-set.js +148 -19
- package/dist/realistic/tiles.d.ts +20 -0
- package/dist/realistic/tiles.js +94 -1
- package/dist/space/element-base.d.ts +5 -0
- package/dist/space/element-base.js +41 -5
- package/dist/space/scene.d.ts +2 -0
- package/dist/space/scene.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
const EDGE = 1e-9;
|
|
2
|
+
/**
|
|
3
|
+
* Fold a longitude into the half-open range from -180 up to, but not including, 180. 180 and -180 are the same meridian, and both come back as -180.
|
|
4
|
+
*
|
|
5
|
+
* @param lon - A longitude in degrees, which may fall outside one turn.
|
|
6
|
+
* @returns The longitude in `[-180, 180)`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { wrapLon } from "@johnmorrisdotca/chikyu-earth/door";
|
|
11
|
+
*
|
|
12
|
+
* console.log(wrapLon(180), wrapLon(-180), wrapLon(190));
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function wrapLon(lon) {
|
|
16
|
+
const turned = (((lon + 180) % 360) + 360) % 360 - 180;
|
|
17
|
+
return turned === 180 ? -180 : turned;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The level of a grid whose width is at least `detail` pixels across a full turn, or the finest level when none is, or `undefined` when the grid has no level wider than `minWidth`.
|
|
21
|
+
*
|
|
22
|
+
* @param grid - The source's grid.
|
|
23
|
+
* @param detail - The pixels across a full turn the view wants.
|
|
24
|
+
* @param minWidth - Levels no wider than this are left out (the picture already underneath).
|
|
25
|
+
* @returns The level, or `undefined` when nothing in the grid is finer than `minWidth`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { gibsGrid, gridLevelFor } from "@johnmorrisdotca/chikyu-earth/door";
|
|
30
|
+
*
|
|
31
|
+
* console.log(gridLevelFor(gibsGrid("250m"), 40000, 32768)?.level);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function gridLevelFor(grid, detail, minWidth) {
|
|
35
|
+
const levels = grid.levels.filter((level) => level.width > minWidth).sort((a, b) => a.width - b.width);
|
|
36
|
+
if (levels.length === 0 || !(detail > minWidth))
|
|
37
|
+
return undefined;
|
|
38
|
+
return levels.find((level) => level.width >= detail) ?? levels[levels.length - 1];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The longitude and latitude a tile covers, before it is cut to the Earth. The south and east edges may fall past the Earth on a coarse level.
|
|
42
|
+
*
|
|
43
|
+
* @param level - The level the tile is on.
|
|
44
|
+
* @param col - The column, from the west.
|
|
45
|
+
* @param row - The row, from the north.
|
|
46
|
+
* @returns The tile's bounds in degrees.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { gibsGrid, gridSpan } from "@johnmorrisdotca/chikyu-earth/door";
|
|
51
|
+
*
|
|
52
|
+
* console.log(gridSpan(gibsGrid("250m").levels[0]!, 0, 0).latMin < -90);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function gridSpan(level, col, row) {
|
|
56
|
+
const lonMin = level.west + col * level.tileLon;
|
|
57
|
+
const latMax = level.north - row * level.tileLat;
|
|
58
|
+
return { lonMin, lonMax: lonMin + level.tileLon, latMax, latMin: latMax - level.tileLat };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* True when the tile runs past the Earth's extent (a coarse level's tile is wider than the Earth).
|
|
62
|
+
*
|
|
63
|
+
* @param level - The level.
|
|
64
|
+
* @param col - The column.
|
|
65
|
+
* @param row - The row.
|
|
66
|
+
* @returns Whether any edge falls outside -180 to 180 or -90 to 90.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { gibsGrid, gridPastExtent } from "@johnmorrisdotca/chikyu-earth/door";
|
|
71
|
+
*
|
|
72
|
+
* const coarse = gibsGrid("250m").levels[0]!;
|
|
73
|
+
* console.log(gridPastExtent(coarse, 0, 0));
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export function gridPastExtent(level, col, row) {
|
|
77
|
+
const span = gridSpan(level, col, row);
|
|
78
|
+
return span.lonMin < -180 - EDGE || span.lonMax > 180 + EDGE || span.latMin < -90 - EDGE || span.latMax > 90 + EDGE;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The part of a tile that lies on the Earth, or `undefined` when the tile misses the Earth entirely.
|
|
82
|
+
*
|
|
83
|
+
* @param level - The level.
|
|
84
|
+
* @param col - The column.
|
|
85
|
+
* @param row - The row.
|
|
86
|
+
* @param extent - The Earth's extent in degrees.
|
|
87
|
+
* @returns The overlap, or `undefined`.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { gibsGrid, gridOnEarth } from "@johnmorrisdotca/chikyu-earth/door";
|
|
92
|
+
*
|
|
93
|
+
* console.log(gridOnEarth(gibsGrid("250m").levels[3]!, 0, 0, { west: -180, south: -90, east: 180, north: 90 }));
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export function gridOnEarth(level, col, row, extent) {
|
|
97
|
+
const span = gridSpan(level, col, row);
|
|
98
|
+
const lonMin = Math.max(span.lonMin, extent.west);
|
|
99
|
+
const lonMax = Math.min(span.lonMax, extent.east);
|
|
100
|
+
const latMin = Math.max(span.latMin, extent.south);
|
|
101
|
+
const latMax = Math.min(span.latMax, extent.north);
|
|
102
|
+
if (!(lonMax > lonMin) || !(latMax > latMin))
|
|
103
|
+
return undefined;
|
|
104
|
+
return { lonMin, lonMax, latMin, latMax };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The column and row of the tile that holds a point, or `undefined` when the point is off the Earth or the tile that would hold it misses the Earth.
|
|
108
|
+
* A longitude of 180 is the same meridian as -180, and both fall in column 0. A latitude of -90 falls in the last row that still meets the Earth.
|
|
109
|
+
*
|
|
110
|
+
* @param level - The level.
|
|
111
|
+
* @param lon - The longitude in degrees.
|
|
112
|
+
* @param lat - The latitude in degrees.
|
|
113
|
+
* @param extent - The Earth's extent.
|
|
114
|
+
* @returns The tile, or `undefined`.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* import { gibsGrid, gridTileAt } from "@johnmorrisdotca/chikyu-earth/door";
|
|
119
|
+
*
|
|
120
|
+
* const level = gibsGrid("250m").levels[3]!;
|
|
121
|
+
* console.log(gridTileAt(level, 180, 0, gibsGrid("250m").extent));
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export function gridTileAt(level, lon, lat, extent) {
|
|
125
|
+
if (!Number.isFinite(lon) || !Number.isFinite(lat) || lat > extent.north || lat < extent.south)
|
|
126
|
+
return undefined;
|
|
127
|
+
const x = wrapLon(lon);
|
|
128
|
+
let col = Math.floor((x - level.west) / level.tileLon + EDGE);
|
|
129
|
+
let row = Math.floor((level.north - lat) / level.tileLat + EDGE);
|
|
130
|
+
if (col >= level.columns)
|
|
131
|
+
col = level.columns - 1;
|
|
132
|
+
if (row >= level.rows)
|
|
133
|
+
row = level.rows - 1;
|
|
134
|
+
if (col < 0 || row < 0)
|
|
135
|
+
return undefined;
|
|
136
|
+
return gridOnEarth(level, col, row, extent) ? { col, row } : undefined;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The key of the tile that holds a point, `[<prefix>]level/column/row`, or `undefined` when no tile holds it.
|
|
140
|
+
*
|
|
141
|
+
* @param grid - The grid.
|
|
142
|
+
* @param level - The level number.
|
|
143
|
+
* @param lon - The longitude in degrees.
|
|
144
|
+
* @param lat - The latitude in degrees.
|
|
145
|
+
* @param prefix - Put before the key.
|
|
146
|
+
* @returns The key, or `undefined`.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* import { gibsGrid, gridKey } from "@johnmorrisdotca/chikyu-earth/door";
|
|
151
|
+
*
|
|
152
|
+
* console.log(gridKey(gibsGrid("250m"), 3, 0, 0));
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export function gridKey(grid, level, lon, lat, prefix = "") {
|
|
156
|
+
const found = grid.levels.find((one) => one.level === level);
|
|
157
|
+
if (!found)
|
|
158
|
+
return undefined;
|
|
159
|
+
const tile = gridTileAt(found, lon, lat, grid.extent);
|
|
160
|
+
return tile ? `${prefix}${found.level}/${tile.col}/${tile.row}` : undefined;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The keys of the tiles that cover a place at a detail. The longitude may pass 180. A place with no area gives none.
|
|
164
|
+
*
|
|
165
|
+
* @param grid - The grid.
|
|
166
|
+
* @param place - The part of the map, in degrees.
|
|
167
|
+
* @param detail - The pixels across a full turn wanted.
|
|
168
|
+
* @param prefix - Put before each key.
|
|
169
|
+
* @returns The keys, row by row.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* import { gibsGrid, gridKeys } from "@johnmorrisdotca/chikyu-earth/door";
|
|
174
|
+
*
|
|
175
|
+
* console.log(gridKeys(gibsGrid("250m"), { lonMin: 170, lonMax: 190, latMin: -5, latMax: 5 }, 5120));
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export function gridKeys(grid, place, detail, prefix = "") {
|
|
179
|
+
if (!(place.lonMax > place.lonMin) || !(place.latMax > place.latMin))
|
|
180
|
+
return [];
|
|
181
|
+
const level = grid.levels.find((one) => one.width >= detail) ?? grid.levels[grid.levels.length - 1];
|
|
182
|
+
if (!level)
|
|
183
|
+
return [];
|
|
184
|
+
const span = Math.min(360, place.lonMax - place.lonMin);
|
|
185
|
+
const cols = [];
|
|
186
|
+
const seenCol = new Set();
|
|
187
|
+
const stepLon = level.tileLon / 2;
|
|
188
|
+
const midLat = Math.min(place.latMax - EDGE, Math.max(place.latMin + EDGE, (place.latMin + place.latMax) / 2));
|
|
189
|
+
const markCol = (lon) => {
|
|
190
|
+
const tile = gridTileAt(level, lon, midLat, grid.extent);
|
|
191
|
+
if (!tile || seenCol.has(tile.col))
|
|
192
|
+
return;
|
|
193
|
+
seenCol.add(tile.col);
|
|
194
|
+
cols.push(tile.col);
|
|
195
|
+
};
|
|
196
|
+
for (let lon = place.lonMin; lon < place.lonMin + span - EDGE; lon += stepLon)
|
|
197
|
+
markCol(lon);
|
|
198
|
+
markCol(place.lonMin + span - EDGE);
|
|
199
|
+
const rows = [];
|
|
200
|
+
const seenRow = new Set();
|
|
201
|
+
const stepLat = level.tileLat / 2;
|
|
202
|
+
const markRow = (lat) => {
|
|
203
|
+
const tile = gridTileAt(level, place.lonMin, lat, grid.extent);
|
|
204
|
+
if (!tile || seenRow.has(tile.row))
|
|
205
|
+
return;
|
|
206
|
+
seenRow.add(tile.row);
|
|
207
|
+
rows.push(tile.row);
|
|
208
|
+
};
|
|
209
|
+
for (let lat = place.latMax; lat > place.latMin + EDGE; lat -= stepLat)
|
|
210
|
+
markRow(lat);
|
|
211
|
+
markRow(place.latMin + EDGE);
|
|
212
|
+
rows.sort((a, b) => a - b);
|
|
213
|
+
const keys = [];
|
|
214
|
+
for (const row of rows)
|
|
215
|
+
for (const col of cols)
|
|
216
|
+
keys.push(`${prefix}${level.level}/${col}/${row}`);
|
|
217
|
+
return keys;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The Geographic (EPSG:4326) tile matrix NASA's imagery service publishes, read from its capabilities on 2026-11-13.
|
|
221
|
+
* A pixel is `0.5625 / 2^level` degrees. Tiles are 512 pixels, the corner of column 0 and row 0 is longitude -180 and latitude 90, and a level has as many tiles as it takes to cover the Earth, so levels 0, 1 and 2 run past it.
|
|
222
|
+
*
|
|
223
|
+
* @param matrix - `250m` (levels 0 to 8), `500m` (levels 0 to 7) or `31.25m` (levels 0 to 11, the Landsat and shaded-relief layers).
|
|
224
|
+
* @returns The grid.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* import { gibsGrid } from "@johnmorrisdotca/chikyu-earth/door";
|
|
229
|
+
*
|
|
230
|
+
* console.log(gibsGrid("250m").levels[3]);
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export function gibsGrid(matrix) {
|
|
234
|
+
const max = matrix === "31.25m" ? 11 : matrix === "250m" ? 8 : 7;
|
|
235
|
+
const levels = [];
|
|
236
|
+
for (let level = 0; level <= max; level += 1) {
|
|
237
|
+
const pixel = 0.5625 / 2 ** level;
|
|
238
|
+
const tile = 512 * pixel;
|
|
239
|
+
levels.push({
|
|
240
|
+
level,
|
|
241
|
+
width: 360 / pixel,
|
|
242
|
+
columns: Math.ceil((360 - EDGE) / tile),
|
|
243
|
+
rows: Math.ceil((180 - EDGE) / tile),
|
|
244
|
+
west: -180,
|
|
245
|
+
north: 90,
|
|
246
|
+
tileLon: tile,
|
|
247
|
+
tileLat: tile,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return { tileSize: 512, extent: { west: -180, south: -90, east: 180, north: 90 }, levels };
|
|
251
|
+
}
|
package/dist/door/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { createTileStore, creditLine, loadRecords, MAX_IN_FLIGHT, MAX_RECORDS, TILE_BUDGET_BYTES, validateSource } from "../data-door.ts";
|
|
2
2
|
export type { BitmapLike, Credit, DataSource, ImageTile, Licence, MapPlace, RecordsRead, RecordSource, SourceInfo, TileLoader, TileSource, TileStats, TileStore, TileStoreOptions } from "../data-door.ts";
|
|
3
3
|
export { DEFAULT_LEVELS, earthTiles, imageBytes, mapKeys, tileKeyParts, tilePlace, type EarthMapPlace, type EarthMapSource, type EarthTilesOptions, type MapLayer } from "./map.ts";
|
|
4
|
+
export { gibsGrid, gridKey, gridKeys, gridLevelFor, gridOnEarth, gridPastExtent, gridSpan, gridTileAt, wrapLon, type MapGrid, type MapGridLevel } from "./grid.ts";
|
|
5
|
+
export { GIBS_CREDIT, GIBS_ID, GIBS_SLOW_MS, gibsTiles, previousUtcDay, samplesAreBlank, utcDay, type GibsTilesOptions } from "./gibs.ts";
|
|
4
6
|
export { elementsFrom, mergeElementSets, readElementSets, type ElementRecordSource, type ElementSetsRead } from "./elements.ts";
|
|
5
7
|
export { OWN_SOURCES, ownCredit } from "./own.ts";
|
|
6
8
|
export { createSourceBook, creditsOf, type SourceBook, type SourceBookOptions, type SourceStats } from "./book.ts";
|
package/dist/door/index.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
// entries beyond what they use: a page that never uses the door pays nothing. With no outside source every view draws what it always drew. Pure: no DOM, no three.js, no clock.
|
|
6
6
|
export { createTileStore, creditLine, loadRecords, MAX_IN_FLIGHT, MAX_RECORDS, TILE_BUDGET_BYTES, validateSource } from "../data-door.js";
|
|
7
7
|
export { DEFAULT_LEVELS, earthTiles, imageBytes, mapKeys, tileKeyParts, tilePlace } from "./map.js";
|
|
8
|
+
export { gibsGrid, gridKey, gridKeys, gridLevelFor, gridOnEarth, gridPastExtent, gridSpan, gridTileAt, wrapLon } from "./grid.js";
|
|
9
|
+
export { GIBS_CREDIT, GIBS_ID, GIBS_SLOW_MS, gibsTiles, previousUtcDay, samplesAreBlank, utcDay } from "./gibs.js";
|
|
8
10
|
export { elementsFrom, mergeElementSets, readElementSets } from "./elements.js";
|
|
9
11
|
export { OWN_SOURCES, ownCredit } from "./own.js";
|
|
10
12
|
export { createSourceBook, creditsOf } from "./book.js";
|
package/dist/door/map.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BitmapLike, ImageTile, MapPlace, TileSource } from "../data-door.ts";
|
|
2
2
|
import { type TileId, type TileLayer } from "../realistic/tiles.ts";
|
|
3
|
+
import type { MapGrid } from "./grid.ts";
|
|
3
4
|
/**
|
|
4
5
|
* What a map source draws: `day` and `night` are the Earth's pictures, which the realistic Earth lays tiles over; `clouds` and `water` are the door's for the whole-Earth layers they are, which the package does not tile or draw yet.
|
|
5
6
|
*
|
|
@@ -42,6 +43,19 @@ export type EarthMapPlace = MapPlace & {
|
|
|
42
43
|
export type EarthMapSource = TileSource<EarthMapPlace, number, ImageTile> & {
|
|
43
44
|
layer: MapLayer | "*";
|
|
44
45
|
levels?(layer: string, signal: AbortSignal): TileLayer | undefined | Promise<TileLayer | undefined>;
|
|
46
|
+
/**
|
|
47
|
+
* The source's own grid, when it is not the package's pyramid (`2^(L+1)` columns by `2^L` rows). The loader places tiles from this. Left out, the pyramid is unchanged.
|
|
48
|
+
*/
|
|
49
|
+
grid?: MapGrid;
|
|
50
|
+
/** True when the source's tiles may have transparent pixels (a place it has no data for), so the loader draws them blended and the picture underneath shows through. */
|
|
51
|
+
holes?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* How the loader draws this source's tiles, on the graphics card: `clear` is the luminance (0 to 255) at or below which a pixel is wholly transparent and from which it is wholly opaque, and `gain` multiplies each colour. Left out, tiles are drawn as they are.
|
|
54
|
+
*/
|
|
55
|
+
look?: {
|
|
56
|
+
clear: readonly [number, number];
|
|
57
|
+
gain?: readonly [number, number, number];
|
|
58
|
+
};
|
|
45
59
|
};
|
|
46
60
|
/**
|
|
47
61
|
* 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.
|
|
@@ -326,6 +326,12 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
326
326
|
/** 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. */
|
|
327
327
|
get tiles(): string | null;
|
|
328
328
|
set tiles(value: string | null);
|
|
329
|
+
/**
|
|
330
|
+
* Finer imagery than the package's own tiles, read by the browser from NASA's imagery service. `gibs` turns it on; anything else, or leaving it out, leaves it off. The picture is NASA's Landsat annual true-colour mosaic (30 m, no cloud, land only, the year 2000), laid over the package's picture only where the view is closer than the package's own tiles; where it has no data (the sea, Antarctica, the far north) the package's picture stays. A tile that is slow or missing leaves the coarser picture in place.
|
|
331
|
+
* `tiles-finer-layer` is `landsat` (the default), `today` (the daily MODIS Terra picture, with its clouds, for the most recent day that has one, looked for from the day before the moment on show back at most 10 days, one tile a day) or another layer's id. `tiles-finer-date` names a year of the Landsat mosaic by its date (`1990-06-01`), or, for a daily layer, is `latest` (the default), `previous-day`, `shown` or one day `yyyy-mm-dd`. `tiles-finer-timeout` is how many milliseconds a tile is given to arrive before it is left (2000 when the page says nothing).
|
|
332
|
+
*/
|
|
333
|
+
get tilesFiner(): string | null;
|
|
334
|
+
set tilesFiner(value: string | null);
|
|
329
335
|
/** A box laid over the Earth for markers (see `@johnmorrisdotca/chikyu-earth/markers`): where it is, the pose of the last draw, and a way to hear the next. */
|
|
330
336
|
get overlay(): OverlayHost;
|
|
331
337
|
/** Where the view starts: longitude and latitude; the shared controls' yaw and tilt turn it from there. */
|
|
@@ -13,6 +13,7 @@ import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadius
|
|
|
13
13
|
import { readMeteorStrength } from "../meteors/strength.js";
|
|
14
14
|
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
15
15
|
import { createDoorHost } from "../door/host.js";
|
|
16
|
+
import { createFinerHolder, GIBS_ID } from "../door/gibs.js";
|
|
16
17
|
import { folderSource } from "../door/map.js";
|
|
17
18
|
import { ownCredit } from "../door/own.js";
|
|
18
19
|
import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "./body-label.js";
|
|
@@ -160,7 +161,7 @@ export const readTime = (value) => {
|
|
|
160
161
|
* ```
|
|
161
162
|
*/
|
|
162
163
|
export class ChikyuEarthRealistic extends HTMLElement {
|
|
163
|
-
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "satellite-tint", "satellite-streak-max"];
|
|
164
|
+
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "satellite-tint", "satellite-streak-max"];
|
|
164
165
|
#model = newModel();
|
|
165
166
|
#paint = createPaintState();
|
|
166
167
|
#mode = "now";
|
|
@@ -172,6 +173,9 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
172
173
|
/** The page's own clock, in milliseconds, at the last step. */
|
|
173
174
|
#last = 0;
|
|
174
175
|
#announced = -Infinity;
|
|
176
|
+
/** The finer imagery (NASA's tile service), one source while the attributes stay the same. Off unless `tiles-finer="gibs"`. */
|
|
177
|
+
#finerHold = createFinerHolder(() => new Date(this.#model.time), () => this.#gate?.soon());
|
|
178
|
+
#finerNote;
|
|
175
179
|
/** The clock is running (a `running: false` is owed when it holds). */
|
|
176
180
|
#running = false;
|
|
177
181
|
#state = "loading";
|
|
@@ -240,12 +244,13 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
240
244
|
if (!this.hasAttribute("aria-label"))
|
|
241
245
|
this.setAttribute("aria-label", "The Earth from space, with its sunlit and dark sides");
|
|
242
246
|
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
243
|
-
root.innerHTML = `<div id="stage"></div><div id="places"></div><div id="overlay"></div><div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p></div>`;
|
|
247
|
+
root.innerHTML = `<div id="stage"></div><div id="places"></div><div id="overlay"></div><div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p><p id="finer-credit" hidden></p></div>`;
|
|
244
248
|
adoptStyles(root, STYLE, this.nonce);
|
|
245
249
|
this.#stage = root.getElementById("stage");
|
|
246
250
|
this.#overlay = root.getElementById("overlay");
|
|
247
251
|
this.#note = root.getElementById("meteor-note");
|
|
248
252
|
this.#airNote = root.getElementById("air-note");
|
|
253
|
+
this.#finerNote = root.getElementById("finer-credit");
|
|
249
254
|
this.#sky = createSkyHost({
|
|
250
255
|
root,
|
|
251
256
|
attribute: (name) => this.getAttribute(name),
|
|
@@ -325,7 +330,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
325
330
|
air: () => airFor(this.getAttribute("air")),
|
|
326
331
|
invalidate: () => this.#gate?.soon(),
|
|
327
332
|
onDraw: () => this.#gate?.drawn(),
|
|
328
|
-
onTiled: () =>
|
|
333
|
+
onTiled: () => {
|
|
334
|
+
this.#showFinerCredit();
|
|
335
|
+
this.#door.announce();
|
|
336
|
+
},
|
|
329
337
|
onSky: (sky) => this.#sky?.frame(sky),
|
|
330
338
|
onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
331
339
|
placeSprites: () => this.#placeLayer?.sprites ?? null,
|
|
@@ -432,10 +440,12 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
432
440
|
this.light = readLight(value);
|
|
433
441
|
else if (name === "live-seconds")
|
|
434
442
|
this.#startTick();
|
|
435
|
-
else if (name === "tiles")
|
|
443
|
+
else if (name === "tiles" || name === "tiles-finer" || name === "tiles-finer-layer" || name === "tiles-finer-date" || name === "tiles-finer-timeout")
|
|
436
444
|
this.#gate?.soon();
|
|
437
|
-
else if (name === "data")
|
|
445
|
+
else if (name === "data") {
|
|
438
446
|
this.#door.book.ownOnly(value === "own");
|
|
447
|
+
this.#gate?.soon();
|
|
448
|
+
}
|
|
439
449
|
else if (name === "camera")
|
|
440
450
|
this.camera = readCamera(value);
|
|
441
451
|
else if (name === "cloud-drift") {
|
|
@@ -461,6 +471,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
461
471
|
this.#seas?.refresh();
|
|
462
472
|
this.#countries?.refresh();
|
|
463
473
|
this.#here?.refresh();
|
|
474
|
+
this.#showFinerCredit();
|
|
464
475
|
}
|
|
465
476
|
}
|
|
466
477
|
else if (BODY_LABEL_ATTRIBUTES.includes(name))
|
|
@@ -949,7 +960,24 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
949
960
|
const folder = this.tiles === null ? undefined : folderSource(this.tiles);
|
|
950
961
|
const day = this.#door.book.mapSources("day")[0] ?? folder;
|
|
951
962
|
const night = this.#door.book.mapSources("night")[0] ?? folder;
|
|
952
|
-
|
|
963
|
+
const finer = this.#finerHold.source((attr) => this.getAttribute(attr), this.getAttribute("data") === "own");
|
|
964
|
+
return { ...(day ? { day } : {}), ...(night ? { night } : {}), ...(finer ? { finer } : {}) };
|
|
965
|
+
}
|
|
966
|
+
/** The acknowledgement for the finer imagery, shown only while those tiles are on the screen. */
|
|
967
|
+
#showFinerCredit() {
|
|
968
|
+
const note = this.#finerNote;
|
|
969
|
+
if (!note)
|
|
970
|
+
return;
|
|
971
|
+
const count = this.#model.tiles?.stats.used[GIBS_ID] ?? 0;
|
|
972
|
+
const lang = (this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en";
|
|
973
|
+
const finer = this.#finerHold.source((attr) => this.getAttribute(attr), this.getAttribute("data") === "own");
|
|
974
|
+
const text = count > 0 && finer ? finer.info.credit[lang] : "";
|
|
975
|
+
if (note.textContent !== text)
|
|
976
|
+
note.textContent = text;
|
|
977
|
+
if (note.lang !== lang)
|
|
978
|
+
note.lang = lang;
|
|
979
|
+
if (note.hidden !== (text === ""))
|
|
980
|
+
note.hidden = text === "";
|
|
953
981
|
}
|
|
954
982
|
/** The package's own credits for the last drawn frame: its pictures while it is drawn, and its finer tiles when a window of them is in view (unless a page added the folder itself, which the door counts). */
|
|
955
983
|
#ownCredits() {
|
|
@@ -957,6 +985,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
957
985
|
const own = [ownCredit("chikyu-pictures", this.#state === "live" ? 1 : 0)];
|
|
958
986
|
if (this.#door.book.get("chikyu-tiles") === undefined)
|
|
959
987
|
own.push(ownCredit("chikyu-tiles", used["chikyu-tiles"] ?? 0));
|
|
988
|
+
const finer = this.#finerHold.source((attr) => this.getAttribute(attr), this.getAttribute("data") === "own");
|
|
989
|
+
const finerUsed = used[GIBS_ID] ?? 0;
|
|
990
|
+
if (finer && finerUsed > 0)
|
|
991
|
+
own.push({ source: finer.info, own: false, used: finerUsed });
|
|
960
992
|
return own;
|
|
961
993
|
}
|
|
962
994
|
/**
|
|
@@ -1001,6 +1033,19 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1001
1033
|
else
|
|
1002
1034
|
this.setAttribute("tiles", value);
|
|
1003
1035
|
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Finer imagery than the package's own tiles, read by the browser from NASA's imagery service. `gibs` turns it on; anything else, or leaving it out, leaves it off. The picture is NASA's Landsat annual true-colour mosaic (30 m, no cloud, land only, the year 2000), laid over the package's picture only where the view is closer than the package's own tiles; where it has no data (the sea, Antarctica, the far north) the package's picture stays. A tile that is slow or missing leaves the coarser picture in place.
|
|
1038
|
+
* `tiles-finer-layer` is `landsat` (the default), `today` (the daily MODIS Terra picture, with its clouds, for the most recent day that has one, looked for from the day before the moment on show back at most 10 days, one tile a day) or another layer's id. `tiles-finer-date` names a year of the Landsat mosaic by its date (`1990-06-01`), or, for a daily layer, is `latest` (the default), `previous-day`, `shown` or one day `yyyy-mm-dd`. `tiles-finer-timeout` is how many milliseconds a tile is given to arrive before it is left (2000 when the page says nothing).
|
|
1039
|
+
*/
|
|
1040
|
+
get tilesFiner() {
|
|
1041
|
+
return this.getAttribute("tiles-finer") === "gibs" ? "gibs" : null;
|
|
1042
|
+
}
|
|
1043
|
+
set tilesFiner(value) {
|
|
1044
|
+
if (value === "gibs")
|
|
1045
|
+
this.setAttribute("tiles-finer", "gibs");
|
|
1046
|
+
else
|
|
1047
|
+
this.removeAttribute("tiles-finer");
|
|
1048
|
+
}
|
|
1004
1049
|
/** A box laid over the Earth for markers (see `@johnmorrisdotca/chikyu-earth/markers`): where it is, the pose of the last draw, and a way to hear the next. */
|
|
1005
1050
|
get overlay() {
|
|
1006
1051
|
if (!this.#overlay)
|
|
@@ -1132,7 +1177,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1132
1177
|
state: this.#state,
|
|
1133
1178
|
tiers: { ...this.#tiers },
|
|
1134
1179
|
satellites: this.#satelliteStats(),
|
|
1135
|
-
tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0, heldBytes: 0, refused: 0, used: {} },
|
|
1180
|
+
tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0, heldBytes: 0, refused: 0, used: {}, finer: null, fading: false },
|
|
1136
1181
|
draws: stats?.draws ?? 0,
|
|
1137
1182
|
contexts: stats?.contexts ?? 0,
|
|
1138
1183
|
canvas: stats?.canvas ?? { width: 0, height: 0, pixels: 0 },
|
|
@@ -3,7 +3,7 @@ export { chooseTier, textureBytes, textureCap, MAX_TEXTURE, TIERS, TEXELS_PER_RA
|
|
|
3
3
|
export { createGate, frameCap, type Gate } from "./gate.ts";
|
|
4
4
|
export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre, type CameraMode, type LightMode } from "./earth.ts";
|
|
5
5
|
export type { ThreeParts } from "./earth.ts";
|
|
6
|
-
export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type TilePerspective, type VisibleTile } from "./tiles.ts";
|
|
6
|
+
export { TEXEL_SLACK, coveringTile, gridTilesInView, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type TilePerspective, type VisibleTile } from "./tiles.ts";
|
|
7
7
|
export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.ts";
|
|
8
8
|
export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, loadMichroma, setBodyLabelFontUrl, type BodyLabelSettings } from "./body-label.ts";
|
|
9
9
|
export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness, type AirSamples } from "./air.ts";
|
package/dist/realistic/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { greenwichSidereal, subsolarPoint, unitVector, julianDay } from "./sun.j
|
|
|
4
4
|
export { chooseTier, textureBytes, textureCap, MAX_TEXTURE, TIERS, TEXELS_PER_RADIUS_PIXEL } from "./tiers.js";
|
|
5
5
|
export { createGate, frameCap } from "./gate.js";
|
|
6
6
|
export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre } from "./earth.js";
|
|
7
|
-
export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView } from "./tiles.js";
|
|
7
|
+
export { TEXEL_SLACK, coveringTile, gridTilesInView, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView } from "./tiles.js";
|
|
8
8
|
export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.js";
|
|
9
9
|
export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, loadMichroma, setBodyLabelFontUrl } from "./body-label.js";
|
|
10
10
|
export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness } from "./air.js";
|
|
@@ -35,7 +35,7 @@ uniform sampler2D paintMap;
|
|
|
35
35
|
uniform float paintNow;
|
|
36
36
|
uniform float paintSpan;
|
|
37
37
|
uniform float paintOn;
|
|
38
|
-
${tile ? "uniform vec4 nightRect;\nvarying vec2 vUvG;" : ""}
|
|
38
|
+
${tile ? "uniform vec4 nightRect;\nuniform float tileAlpha;\nuniform vec3 tileGain;\nuniform vec2 tileClear;\nvarying vec2 vUvG;" : ""}
|
|
39
39
|
varying vec2 vUv;
|
|
40
40
|
varying vec3 vNormal;
|
|
41
41
|
varying vec3 vWorld;
|
|
@@ -47,7 +47,9 @@ void main() {
|
|
|
47
47
|
float ndv = clamp(dot(n, toEye), 0.0, 1.0);
|
|
48
48
|
float day = smoothstep(-0.10, 0.22, ndl);
|
|
49
49
|
vec2 g = ${tile ? "vUvG" : "vUv"};
|
|
50
|
-
|
|
50
|
+
vec4 texel = texture2D(dayMap, vUv);
|
|
51
|
+
${tile ? "float keep = clamp((dot(texel.rgb, vec3(0.299, 0.587, 0.114)) - tileClear.x) / (tileClear.y - tileClear.x), 0.0, 1.0);\n texel.rgb *= tileGain;" : "float keep = 1.0;"}
|
|
52
|
+
vec3 albedo = texel.rgb;
|
|
51
53
|
float water = texture2D(waterMap, g).r;
|
|
52
54
|
albedo = pow(albedo, vec3(0.86)) * 1.08;
|
|
53
55
|
albedo *= mix(vec3(1.0), vec3(1.05, 1.22, 1.55), water);
|
|
@@ -96,7 +98,7 @@ void main() {
|
|
|
96
98
|
col = mix(col, vec3(1.0, 0.55, 0.12), clamp(show, 0.0, 0.92));
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
gl_FragColor = vec4(col, 1.0);
|
|
101
|
+
gl_FragColor = vec4(col, ${tile ? "tileAlpha * keep * texel.a" : "1.0"});
|
|
100
102
|
}`;
|
|
101
103
|
export const SURFACE_FRAG = surfaceFrag(false);
|
|
102
104
|
/** The same surface for a map tile: the tile's own program. */
|
|
@@ -53,10 +53,14 @@ export interface TileShared {
|
|
|
53
53
|
/** More uniforms the surface program reads (the cloud picture and where the Sun is in the Earth's axes), shared with the sphere's own. */
|
|
54
54
|
extra?: Record<string, Uniform<unknown>>;
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* The map source each layer is drawn from now, or none: read at every draw. A layer's tiles come from its source alone, and the night tiles go with day tiles (no day source, no night tiles).
|
|
58
|
+
* `finer` is laid over the day tiles, and only when the view is closer than the day tiles serve. A source with its own `grid` is placed on that grid.
|
|
59
|
+
*/
|
|
57
60
|
export type TileSources = {
|
|
58
61
|
day?: EarthMapSource;
|
|
59
62
|
night?: EarthMapSource;
|
|
63
|
+
finer?: EarthMapSource;
|
|
60
64
|
};
|
|
61
65
|
export interface TileSetDeps {
|
|
62
66
|
assets: AssetCache;
|
|
@@ -68,6 +72,8 @@ export interface TileSetDeps {
|
|
|
68
72
|
cap: () => number;
|
|
69
73
|
/** Ask for one draw. */
|
|
70
74
|
invalidate: () => void;
|
|
75
|
+
/** A reader who asked for less motion: a finer tile is shown at once, with no fade. */
|
|
76
|
+
reducedMotion?: () => boolean;
|
|
71
77
|
/** Told once when a tile set's manifest has been read: the finest width of each layer. */
|
|
72
78
|
onManifest?: (layers: Record<string, number>) => void;
|
|
73
79
|
limit?: number;
|
|
@@ -92,6 +98,10 @@ export interface TileStats {
|
|
|
92
98
|
refused: number;
|
|
93
99
|
/** The tiles in view that came from each source, by the source's id: what a credit line counts. */
|
|
94
100
|
used: Record<string, number>;
|
|
101
|
+
/** The level of the finer grid now wanted, or `null` when the view is no closer than the tiles underneath. */
|
|
102
|
+
finer: number | null;
|
|
103
|
+
/** True while a finer tile is still fading in. At rest, after the fade, this is false and nothing is drawn for it. */
|
|
104
|
+
fading: boolean;
|
|
95
105
|
}
|
|
96
106
|
export interface TileSet {
|
|
97
107
|
sync(camera: TileCamera, sun: readonly [number, number, number], night: boolean, ratio: number): void;
|