@johnmorrisdotca/chikyu-earth 0.46.6 → 0.47.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 +9 -0
- package/README.md +3 -3
- package/dist/beam/layer.d.ts +1 -1
- package/dist/markers/place-layer.d.ts +4 -0
- package/dist/markers/place-layer.js +20 -6
- package/dist/place/index.d.ts +230 -0
- package/dist/place/index.js +183 -0
- package/dist/place/land.d.ts +30 -0
- package/dist/place/land.js +177 -0
- package/dist/place/water.d.ts +15 -0
- package/dist/place/water.js +63 -0
- package/dist/realistic/earth.d.ts +9 -1
- package/dist/realistic/earth.js +13 -0
- package/dist/realistic/element-base.d.ts +21 -0
- package/dist/realistic/element-base.js +58 -3
- package/dist/space/element-base.d.ts +97 -2
- package/dist/space/element-base.js +280 -8
- package/dist/space/ephemeris.d.ts +1 -1
- package/dist/space/ephemeris.js +4 -2
- package/dist/space/follow.d.ts +36 -0
- package/dist/space/follow.js +46 -0
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -0
- package/dist/space/ride.d.ts +3 -2
- package/dist/space/ride.js +6 -4
- package/dist/space/satellite-hover.d.ts +47 -0
- package/dist/space/satellite-hover.js +183 -0
- package/dist/space/satellite-layer.d.ts +56 -1
- package/dist/space/satellite-layer.js +93 -31
- package/dist/space/satellite-model.d.ts +2 -1
- package/dist/space/satellite-model.js +4 -3
- package/dist/space/scene.d.ts +38 -0
- package/dist/space/scene.js +77 -12
- package/package.json +6 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Which country a point is in, from the same Natural Earth 1:110m outlines the line globe draws (chizu's world-geo).
|
|
2
|
+
// The line is coarse, so a point within PLACE_COAST_KM of an outline but outside every shape is `near`, not a country.
|
|
3
|
+
import { geoContains } from "d3-geo";
|
|
4
|
+
import WORLD_GEO from "@johnmorrisdotca/chizu/world-geo";
|
|
5
|
+
/**
|
|
6
|
+
* How close to a 1:110m outline, in kilometres, still counts as that country nearby.
|
|
7
|
+
* The outlines can sit tens of kilometres off a real coast, so a point this close is not reported as inside.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { PLACE_COAST_KM } from "@johnmorrisdotca/chikyu-earth/place";
|
|
12
|
+
*
|
|
13
|
+
* console.log(PLACE_COAST_KM);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const PLACE_COAST_KM = 50;
|
|
17
|
+
const RAD = Math.PI / 180;
|
|
18
|
+
const MEAN_RADIUS_KM = 6371.0088;
|
|
19
|
+
const CELL = 15;
|
|
20
|
+
const EXPAND = 0.8;
|
|
21
|
+
const toVec = (lon, lat) => {
|
|
22
|
+
const la = lat * RAD;
|
|
23
|
+
const lo = lon * RAD;
|
|
24
|
+
const c = Math.cos(la);
|
|
25
|
+
return [c * Math.cos(lo), c * Math.sin(lo), Math.sin(la)];
|
|
26
|
+
};
|
|
27
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
28
|
+
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
29
|
+
const hypot = (a) => Math.hypot(a[0], a[1], a[2]);
|
|
30
|
+
const angle = (a, b) => Math.acos(Math.min(1, Math.max(-1, dot(a, b))));
|
|
31
|
+
/** Kilometres from `p` to the minor arc `a`–`b`. A segment longer than half a turn uses the nearer end. */
|
|
32
|
+
const segmentKm = (p, a, b) => {
|
|
33
|
+
const ab = angle(a, b);
|
|
34
|
+
if (ab < 1e-8 || ab > Math.PI - 1e-4)
|
|
35
|
+
return Math.min(angle(p, a), angle(p, b)) * MEAN_RADIUS_KM;
|
|
36
|
+
const n = cross(a, b);
|
|
37
|
+
const nn = hypot(n);
|
|
38
|
+
if (nn < 1e-12)
|
|
39
|
+
return angle(p, a) * MEAN_RADIUS_KM;
|
|
40
|
+
const scale = dot(p, n) / (nn * nn);
|
|
41
|
+
const raw = [p[0] - n[0] * scale, p[1] - n[1] * scale, p[2] - n[2] * scale];
|
|
42
|
+
const len = hypot(raw);
|
|
43
|
+
if (len < 1e-12)
|
|
44
|
+
return 0;
|
|
45
|
+
const g = [raw[0] / len, raw[1] / len, raw[2] / len];
|
|
46
|
+
const on = dot(cross(a, g), n) >= -1e-7 && dot(cross(g, b), n) >= -1e-7;
|
|
47
|
+
return (on ? angle(p, g) : Math.min(angle(p, a), angle(p, b))) * MEAN_RADIUS_KM;
|
|
48
|
+
};
|
|
49
|
+
const ringsOf = (geometry) => {
|
|
50
|
+
if (geometry.type === "Polygon")
|
|
51
|
+
return geometry.coordinates;
|
|
52
|
+
if (geometry.type === "MultiPolygon")
|
|
53
|
+
return geometry.coordinates.flat();
|
|
54
|
+
return [];
|
|
55
|
+
};
|
|
56
|
+
const boxesOf = (rings) => {
|
|
57
|
+
let south = 90;
|
|
58
|
+
let north = -90;
|
|
59
|
+
let wraps = false;
|
|
60
|
+
const lons = [];
|
|
61
|
+
for (const ring of rings) {
|
|
62
|
+
for (let i = 0; i < ring.length; i += 1) {
|
|
63
|
+
const lon = ring[i][0];
|
|
64
|
+
const lat = ring[i][1];
|
|
65
|
+
lons.push(lon);
|
|
66
|
+
if (lat < south)
|
|
67
|
+
south = lat;
|
|
68
|
+
if (lat > north)
|
|
69
|
+
north = lat;
|
|
70
|
+
if (i > 0 && Math.abs(lon - ring[i - 1][0]) > 180)
|
|
71
|
+
wraps = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (lons.length === 0)
|
|
75
|
+
return [];
|
|
76
|
+
if (!wraps)
|
|
77
|
+
return [{ west: Math.min(...lons), east: Math.max(...lons), south, north }];
|
|
78
|
+
const east = lons.filter((lon) => lon >= 0);
|
|
79
|
+
const west = lons.filter((lon) => lon < 0);
|
|
80
|
+
const boxes = [];
|
|
81
|
+
if (east.length > 0)
|
|
82
|
+
boxes.push({ west: Math.min(...east), east: 180, south, north });
|
|
83
|
+
if (west.length > 0)
|
|
84
|
+
boxes.push({ west: -180, east: Math.max(...west), south, north });
|
|
85
|
+
return boxes;
|
|
86
|
+
};
|
|
87
|
+
const cellKey = (lon, lat) => {
|
|
88
|
+
const x = Math.max(-180, Math.min(165, Math.floor(lon / CELL) * CELL));
|
|
89
|
+
const y = Math.max(-90, Math.min(75, Math.floor(lat / CELL) * CELL));
|
|
90
|
+
return (x + 180) / CELL + ((y + 90) / CELL) * 24;
|
|
91
|
+
};
|
|
92
|
+
const build = () => {
|
|
93
|
+
const lands = [];
|
|
94
|
+
const grid = new Map();
|
|
95
|
+
for (const feature of WORLD_GEO.features) {
|
|
96
|
+
const geometry = feature.geometry;
|
|
97
|
+
const raw = ringsOf(geometry);
|
|
98
|
+
if (raw.length === 0)
|
|
99
|
+
continue;
|
|
100
|
+
const boxes = boxesOf(raw);
|
|
101
|
+
const rings = raw.map((ring) => ring.map(([lon, lat]) => toVec(lon, lat)));
|
|
102
|
+
const area = boxes.reduce((sum, box) => sum + (box.east - box.west) * (box.north - box.south), 0);
|
|
103
|
+
const index = lands.length;
|
|
104
|
+
const props = feature.properties;
|
|
105
|
+
lands.push({
|
|
106
|
+
code: props.code.length === 2 ? props.code : null,
|
|
107
|
+
name: props.name,
|
|
108
|
+
nameJa: props.nameJa || props.name,
|
|
109
|
+
group: props.group ?? "",
|
|
110
|
+
groupJa: props.groupJa ?? "",
|
|
111
|
+
geometry,
|
|
112
|
+
rings,
|
|
113
|
+
boxes,
|
|
114
|
+
area,
|
|
115
|
+
});
|
|
116
|
+
for (const box of boxes) {
|
|
117
|
+
const west = Math.max(-180, box.west - EXPAND);
|
|
118
|
+
const east = Math.min(180, box.east + EXPAND);
|
|
119
|
+
const south = Math.max(-90, box.south - EXPAND);
|
|
120
|
+
const north = Math.min(90, box.north + EXPAND);
|
|
121
|
+
for (let lat = Math.floor(south / CELL) * CELL; lat <= north; lat += CELL) {
|
|
122
|
+
for (let lon = Math.floor(west / CELL) * CELL; lon <= east; lon += CELL) {
|
|
123
|
+
const key = cellKey(Math.max(-180, Math.min(179.9, lon)), Math.max(-90, Math.min(89.9, lat)));
|
|
124
|
+
const list = grid.get(key);
|
|
125
|
+
if (list)
|
|
126
|
+
list.push(index);
|
|
127
|
+
else
|
|
128
|
+
grid.set(key, [index]);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return { lands, grid };
|
|
134
|
+
};
|
|
135
|
+
let ready = null;
|
|
136
|
+
const index = () => (ready ??= build());
|
|
137
|
+
const nearestKm = (land, point) => {
|
|
138
|
+
let best = Number.POSITIVE_INFINITY;
|
|
139
|
+
for (const ring of land.rings) {
|
|
140
|
+
for (let i = 0; i < ring.length - 1; i += 1) {
|
|
141
|
+
const km = segmentKm(point, ring[i], ring[i + 1]);
|
|
142
|
+
if (km < best)
|
|
143
|
+
best = km;
|
|
144
|
+
if (best === 0)
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return best;
|
|
149
|
+
};
|
|
150
|
+
const asHit = (land) => ({ code: land.code, name: land.name, nameJa: land.nameJa, group: land.group, groupJa: land.groupJa });
|
|
151
|
+
/** The country at a longitude and latitude, or the nearest one when the point is just off a coarse outline. The shapes are Natural Earth 1:110m. */
|
|
152
|
+
export function landAt(lon, lat) {
|
|
153
|
+
const { lands, grid } = index();
|
|
154
|
+
const list = grid.get(cellKey(lon, lat)) ?? [];
|
|
155
|
+
const point = toVec(lon, lat);
|
|
156
|
+
let inside = null;
|
|
157
|
+
for (const id of list) {
|
|
158
|
+
const land = lands[id];
|
|
159
|
+
const feature = { type: "Feature", geometry: land.geometry, properties: {} };
|
|
160
|
+
if (!geoContains(feature, [lon, lat]))
|
|
161
|
+
continue;
|
|
162
|
+
if (!inside || land.area < inside.area)
|
|
163
|
+
inside = land;
|
|
164
|
+
}
|
|
165
|
+
if (inside)
|
|
166
|
+
return { country: asHit(inside), near: null };
|
|
167
|
+
let best = null;
|
|
168
|
+
for (const id of list) {
|
|
169
|
+
const land = lands[id];
|
|
170
|
+
const km = nearestKm(land, point);
|
|
171
|
+
if (km <= PLACE_COAST_KM && (!best || km < best.km))
|
|
172
|
+
best = { land, km };
|
|
173
|
+
}
|
|
174
|
+
if (!best)
|
|
175
|
+
return { country: null, near: null };
|
|
176
|
+
return { country: null, near: { ...asHit(best.land), distanceKm: best.km } };
|
|
177
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SeaFeature } from "../sea-names/geometry.ts";
|
|
2
|
+
/**
|
|
3
|
+
* How far from a sea, gulf or bay's own point, in kilometres, a point still counts as that water.
|
|
4
|
+
* Each reach is wide enough to cover that water and short of the next named water's point.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { SEA_REACH_KM } from "@johnmorrisdotca/chikyu-earth/place";
|
|
9
|
+
*
|
|
10
|
+
* console.log(SEA_REACH_KM["sea-of-japan"] > 0);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const SEA_REACH_KM: Readonly<Record<string, number>>;
|
|
14
|
+
/** The named sea, gulf, bay or ocean a point is over, or null when none is within its reach. A smaller water's point is nearer, so it wins over an ocean. */
|
|
15
|
+
export declare function waterAt(lon: number, lat: number): SeaFeature | null;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { SEA_FEATURES } from "../sea-names/features.js";
|
|
2
|
+
const RAD = Math.PI / 180;
|
|
3
|
+
const MEAN_RADIUS_KM = 6371.0088;
|
|
4
|
+
/**
|
|
5
|
+
* How far from a sea, gulf or bay's own point, in kilometres, a point still counts as that water.
|
|
6
|
+
* Each reach is wide enough to cover that water and short of the next named water's point.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { SEA_REACH_KM } from "@johnmorrisdotca/chikyu-earth/place";
|
|
11
|
+
*
|
|
12
|
+
* console.log(SEA_REACH_KM["sea-of-japan"] > 0);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const SEA_REACH_KM = {
|
|
16
|
+
"arctic-ocean": 3500,
|
|
17
|
+
"southern-ocean": 5500,
|
|
18
|
+
"atlantic-ocean": 10000,
|
|
19
|
+
"pacific-ocean": 12000,
|
|
20
|
+
"indian-ocean": 7000,
|
|
21
|
+
"black-sea": 650,
|
|
22
|
+
"philippine-sea": 1600,
|
|
23
|
+
"tasman-sea": 1100,
|
|
24
|
+
"bay-of-bengal": 1300,
|
|
25
|
+
"south-china-sea": 1400,
|
|
26
|
+
"arabian-sea": 1400,
|
|
27
|
+
"beaufort-sea": 800,
|
|
28
|
+
"caribbean-sea": 1200,
|
|
29
|
+
"gulf-of-mexico": 900,
|
|
30
|
+
"labrador-sea": 800,
|
|
31
|
+
"hudson-bay": 700,
|
|
32
|
+
"caspian-sea": 650,
|
|
33
|
+
"baffin-bay": 800,
|
|
34
|
+
"gulf-of-alaska": 800,
|
|
35
|
+
"red-sea": 1100,
|
|
36
|
+
"sea-of-okhotsk": 900,
|
|
37
|
+
"weddell-sea": 1400,
|
|
38
|
+
"persian-gulf": 450,
|
|
39
|
+
"mediterranean-sea": 1800,
|
|
40
|
+
"ross-sea": 900,
|
|
41
|
+
"coral-sea": 1200,
|
|
42
|
+
"sea-of-japan": 800,
|
|
43
|
+
};
|
|
44
|
+
const waters = SEA_FEATURES.filter((one) => one.kind !== "continent");
|
|
45
|
+
const kmBetween = (lon, lat, feature) => {
|
|
46
|
+
const φ1 = lat * RAD;
|
|
47
|
+
const φ2 = feature.lat * RAD;
|
|
48
|
+
const Δφ = (feature.lat - lat) * RAD;
|
|
49
|
+
const Δλ = (feature.lon - lon) * RAD;
|
|
50
|
+
const h = Math.sin(Δφ / 2) ** 2 + Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ / 2) ** 2;
|
|
51
|
+
return 2 * MEAN_RADIUS_KM * Math.asin(Math.min(1, Math.sqrt(h)));
|
|
52
|
+
};
|
|
53
|
+
/** The named sea, gulf, bay or ocean a point is over, or null when none is within its reach. A smaller water's point is nearer, so it wins over an ocean. */
|
|
54
|
+
export function waterAt(lon, lat) {
|
|
55
|
+
let best = null;
|
|
56
|
+
for (const feature of waters) {
|
|
57
|
+
const reach = SEA_REACH_KM[feature.id] ?? 0;
|
|
58
|
+
const km = kmBetween(lon, lat, feature);
|
|
59
|
+
if (km <= reach && (!best || km < best.km))
|
|
60
|
+
best = { feature, km };
|
|
61
|
+
}
|
|
62
|
+
return best?.feature ?? null;
|
|
63
|
+
}
|
|
@@ -3,7 +3,7 @@ import type { AssetCache, Item3D } from "@johnmorrisdotca/kazoku-ui/renderer";
|
|
|
3
3
|
import type { GeoPoint, GlobeView } from "../types.ts";
|
|
4
4
|
import type { SatelliteRef } from "../satellites/types.ts";
|
|
5
5
|
import { lookAt } from "../view.ts";
|
|
6
|
-
import { type SatelliteState } from "../space/satellite-layer.ts";
|
|
6
|
+
import { type SatelliteScreen, type SatelliteState } from "../space/satellite-layer.ts";
|
|
7
7
|
import type { Layer } from "./tiers.ts";
|
|
8
8
|
import { type ThreeParts } from "./textures.ts";
|
|
9
9
|
import { type TileSet, type TileSources } from "./tile-set.ts";
|
|
@@ -87,6 +87,8 @@ export interface EarthModel {
|
|
|
87
87
|
tiles: TileSet | null;
|
|
88
88
|
/** The satellite at a point of the view (CSS pixels), within a radius, once a draw has been made and one is there. */
|
|
89
89
|
pick: ((x: number, y: number, radius: number) => SatelliteRef | null) | null;
|
|
90
|
+
/** Where a satellite of a shown group is on the screen as of the last draw, or `null`. */
|
|
91
|
+
placeSatellite: ((ref: SatelliteRef) => SatelliteScreen | null) | null;
|
|
90
92
|
/** The pixel ratio the textures are chosen for. */
|
|
91
93
|
ratio(): number;
|
|
92
94
|
/** Meteors seen from space (src/meteors/layer.ts): off unless the element switches them on. */
|
|
@@ -135,6 +137,12 @@ export interface EarthDeps {
|
|
|
135
137
|
width: number;
|
|
136
138
|
height: number;
|
|
137
139
|
}) => void;
|
|
140
|
+
/** Where the satellite under the pointer is, or null. Called at each draw while one is under the pointer (and once when it is let go). */
|
|
141
|
+
onHover?: (place: {
|
|
142
|
+
x: number;
|
|
143
|
+
y: number;
|
|
144
|
+
visible: boolean;
|
|
145
|
+
} | null) => void;
|
|
138
146
|
/** The rings the places' layer wants drawn in one draw call, read right after `onPose`. */
|
|
139
147
|
placeSprites?: () => PlaceSpriteData | null;
|
|
140
148
|
/** Told once, when the rings of the places that are not markers of their own were first wanted: whether the picture can draw them (false when the three.js parts handed over lack `Points`). */
|
package/dist/realistic/earth.js
CHANGED
|
@@ -44,6 +44,7 @@ export const newModel = () => ({
|
|
|
44
44
|
drawn: null,
|
|
45
45
|
tiles: null,
|
|
46
46
|
pick: null,
|
|
47
|
+
placeSatellite: null,
|
|
47
48
|
ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
|
|
48
49
|
meteors: newMeteorState(),
|
|
49
50
|
bodyLabel: newBodyLabelState(),
|
|
@@ -191,6 +192,7 @@ export function createEarthItem(model, deps) {
|
|
|
191
192
|
inertial.add(spun);
|
|
192
193
|
scene.add(inertial);
|
|
193
194
|
let layer;
|
|
195
|
+
let hoverShown = false;
|
|
194
196
|
// far enough in front that a geostationary satellite (6.6 radii out) is never behind the camera: an orthographic picture is the same from anywhere on the line
|
|
195
197
|
const camera = new three.OrthographicCamera(-1, 1, 1, -1, 1, 120);
|
|
196
198
|
camera.position.set(0, 0, 50);
|
|
@@ -242,6 +244,16 @@ export function createEarthItem(model, deps) {
|
|
|
242
244
|
}
|
|
243
245
|
layer?.update(model.time, model.speed, radius);
|
|
244
246
|
model.pick = layer ? (x, y, radius) => layer.pick(x, y, camera, size, radius) : null;
|
|
247
|
+
model.placeSatellite = layer ? (ref) => layer.placeOf(ref, camera, size) : null;
|
|
248
|
+
if (layer && deps.onHover) {
|
|
249
|
+
const hover = model.satellites.hover;
|
|
250
|
+
const ref = hover.enabled && hover.ref && hover.fade > 0 ? hover.ref : null;
|
|
251
|
+
const at = ref ? layer.placeOf(ref, camera, size) : null;
|
|
252
|
+
const place = at ? { x: at.x, y: at.y, visible: at.visible } : null;
|
|
253
|
+
if (place || hoverShown)
|
|
254
|
+
deps.onHover(place);
|
|
255
|
+
hoverShown = place !== null;
|
|
256
|
+
}
|
|
245
257
|
model.drawn = { view: { ...view }, time: model.time, radius, centre: { ...centre } };
|
|
246
258
|
textures.sync(radius * model.ratio());
|
|
247
259
|
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());
|
|
@@ -344,6 +356,7 @@ export function createEarthItem(model, deps) {
|
|
|
344
356
|
dispose() {
|
|
345
357
|
layer?.dispose();
|
|
346
358
|
model.pick = null;
|
|
359
|
+
model.placeSatellite = null;
|
|
347
360
|
clearTimeout(meteorTimer);
|
|
348
361
|
meteors?.dispose();
|
|
349
362
|
nameOn?.dispose();
|
|
@@ -56,6 +56,9 @@ type SatelliteStats = {
|
|
|
56
56
|
averageUpdateMs: number;
|
|
57
57
|
updates: number;
|
|
58
58
|
selectedRing: boolean;
|
|
59
|
+
hoverPath: boolean;
|
|
60
|
+
hoverOpacity: number;
|
|
61
|
+
selectedOpacity: number;
|
|
59
62
|
};
|
|
60
63
|
/**
|
|
61
64
|
* A `speed` attribute: how many seconds pass for each real second.
|
|
@@ -537,8 +540,26 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
537
540
|
ok: false;
|
|
538
541
|
reason: "not-set";
|
|
539
542
|
};
|
|
543
|
+
/**
|
|
544
|
+
* Draw a faint orbit while the pointer rests on a satellite. On unless `hover-path="off"`. Left unset, it is on when `names-on-hover` is on.
|
|
545
|
+
* The colour and the opacity are the custom properties `--chikyu-hover-path` and `--chikyu-hover-path-opacity`.
|
|
546
|
+
*/
|
|
547
|
+
get hoverPath(): boolean;
|
|
548
|
+
set hoverPath(value: boolean);
|
|
549
|
+
/** Show a satellite's name while the pointer rests on it. On unless `names-on-hover="off"`. A touch does not rest, so it shows nothing. */
|
|
550
|
+
get namesOnHover(): boolean;
|
|
551
|
+
set namesOnHover(value: boolean);
|
|
540
552
|
/** Mark one satellite: a larger ring round it and its orbit drawn. `null` lets it go. */
|
|
541
553
|
selectSatellite(ref: SatelliteRef | null): void;
|
|
554
|
+
/**
|
|
555
|
+
* Where a satellite is on the screen as of the last draw: `{ x, y, visible, heightKm }` in CSS pixels from the view's top left, `visible` meaning it is inside the box and not behind the Earth. `null` when its group is not set or not shown, it cannot be placed, or it is behind the camera.
|
|
556
|
+
*/
|
|
557
|
+
placeSatellite(ref: SatelliteRef): {
|
|
558
|
+
x: number;
|
|
559
|
+
y: number;
|
|
560
|
+
visible: boolean;
|
|
561
|
+
heightKm: number;
|
|
562
|
+
} | null;
|
|
542
563
|
/** The satellite marked by `selectSatellite` or by a press on it, if any. */
|
|
543
564
|
get selectedSatellite(): SatelliteRef | null;
|
|
544
565
|
/** Facts about one satellite at the moment shown (name, number, element age, height, speed, period, and `ownerCountry` when the owner is one country); undefined if it cannot be placed then. */
|
|
@@ -10,6 +10,7 @@ import { cameraCentre, createEarthItem, discRadius, lookAt, newModel } from "./e
|
|
|
10
10
|
import { createPaintState, paintedGround, paintedPeriod } from "../paint/buffer.js";
|
|
11
11
|
import { MAX_ORBIT_GROUP, readStreakMax } from "../space/satellite-layer.js";
|
|
12
12
|
import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadiusOf, zoomForOrthographicShell } from "../space/satellite-focus.js";
|
|
13
|
+
import { bindSatelliteHover, hoverPathOn, hoverStyleOf, namesOnHover as namesHoverOn } from "../space/satellite-hover.js";
|
|
13
14
|
import { readMeteorStrength } from "../meteors/strength.js";
|
|
14
15
|
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
15
16
|
import { createDoorHost } from "../door/host.js";
|
|
@@ -39,7 +40,7 @@ import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
|
|
|
39
40
|
export { setSharedRenderer, setThreeLoader };
|
|
40
41
|
import { MAX_TEXTURE, TIERS } from "./tiers.js";
|
|
41
42
|
import { mayWriteZoomMax, raisedZoomMax } from "./zoom-reach.js";
|
|
42
|
-
const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative;isolation:isolate}" + IMMERSIVE_STYLE + "#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}" + PLACE_STYLE + SKY_STYLE + COUNTRY_NAMES_STYLE + SEA_NAMES_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
|
|
43
|
+
const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative;isolation:isolate}" + IMMERSIVE_STYLE + "#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-sat[hidden]{display:none}.sp-sat[data-hover]{transition:opacity 180ms linear}@media (prefers-reduced-motion: reduce){.sp-sat[data-hover]{transition:none}}" + PLACE_STYLE + SKY_STYLE + COUNTRY_NAMES_STYLE + SEA_NAMES_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
|
|
43
44
|
const RAD = Math.PI / 180;
|
|
44
45
|
/** The Sun and the clouds are re-placed this often at real time: 15 degrees an hour is 0.25 degree a minute. */
|
|
45
46
|
const LIVE_TICK_MS = 60_000;
|
|
@@ -161,7 +162,7 @@ export const readTime = (value) => {
|
|
|
161
162
|
* ```
|
|
162
163
|
*/
|
|
163
164
|
export class ChikyuEarthRealistic extends HTMLElement {
|
|
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"];
|
|
165
|
+
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", "hover-path", "names-on-hover"];
|
|
165
166
|
#model = newModel();
|
|
166
167
|
#paint = createPaintState();
|
|
167
168
|
#mode = "now";
|
|
@@ -208,6 +209,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
208
209
|
#hands;
|
|
209
210
|
/** The view from before a satellite group was framed, put back when the focus is cleared. */
|
|
210
211
|
#focusView = null;
|
|
212
|
+
/** The name and the faint orbit while the pointer rests on a satellite. */
|
|
213
|
+
#hover;
|
|
211
214
|
#reach = null;
|
|
212
215
|
/** The page has set a `speed` since the element came into the page: for a reader who prefers reduced motion, that is the Play that lets meteors start. */
|
|
213
216
|
#played = false;
|
|
@@ -358,6 +361,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
358
361
|
},
|
|
359
362
|
onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
|
|
360
363
|
onSatellitesError: (error) => this.dispatchEvent(new CustomEvent("chikyu-satellites-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
364
|
+
onHover: (place) => this.#hover?.follow(place),
|
|
361
365
|
paint: {
|
|
362
366
|
data: () => this.#paint.data,
|
|
363
367
|
width: this.#paint.width,
|
|
@@ -389,10 +393,26 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
389
393
|
// before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
|
|
390
394
|
this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
|
|
391
395
|
this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
|
|
396
|
+
this.#hover = bindSatelliteHover({
|
|
397
|
+
element: this,
|
|
398
|
+
state: this.#model.satellites,
|
|
399
|
+
pick: (x, y) => this.#model.pick?.(x, y, 12) ?? null,
|
|
400
|
+
place: (ref) => this.placeSatellite(ref),
|
|
401
|
+
name: (ref) => this.satelliteInfo(ref)?.name,
|
|
402
|
+
selected: () => this.selectedSatellite,
|
|
403
|
+
request: () => this.#gate?.soon(),
|
|
404
|
+
labelParent: () => this.#overlay ?? null,
|
|
405
|
+
pathOn: () => hoverPathOn(this.getAttribute("hover-path"), this.getAttribute("names-on-hover")),
|
|
406
|
+
namesOn: () => namesHoverOn(this.getAttribute("names-on-hover")),
|
|
407
|
+
style: () => hoverStyleOf(this),
|
|
408
|
+
});
|
|
409
|
+
this.#hover.sync();
|
|
392
410
|
this.#startTick();
|
|
393
411
|
document.addEventListener("visibilitychange", this.#onVisible);
|
|
394
412
|
}
|
|
395
413
|
disconnectedCallback() {
|
|
414
|
+
this.#hover?.stop();
|
|
415
|
+
this.#hover = undefined;
|
|
396
416
|
this.removeEventListener("pointerdown", this.#take);
|
|
397
417
|
this.removeEventListener("pointerdown", this.#down);
|
|
398
418
|
this.removeEventListener("wheel", this.#wheel, { capture: true });
|
|
@@ -519,6 +539,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
519
539
|
this.#model.satellites.orbitTint = value === "orbit";
|
|
520
540
|
this.#gate?.soon();
|
|
521
541
|
}
|
|
542
|
+
else if (name === "hover-path" || name === "names-on-hover")
|
|
543
|
+
this.#hover?.sync();
|
|
522
544
|
else if (name === "satellite-streak-max") {
|
|
523
545
|
this.#model.satellites.streakMax = readStreakMax(value);
|
|
524
546
|
this.#gate?.soon();
|
|
@@ -1286,6 +1308,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1286
1308
|
this.#restoreFocusView();
|
|
1287
1309
|
this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: null, count: 0 }, bubbles: true, composed: true }));
|
|
1288
1310
|
}
|
|
1311
|
+
if (this.#model.satellites.hover.ref?.group === group) {
|
|
1312
|
+
this.#model.satellites.hover.ref = null;
|
|
1313
|
+
this.#model.satellites.hover.fade = 0;
|
|
1314
|
+
}
|
|
1289
1315
|
}
|
|
1290
1316
|
else {
|
|
1291
1317
|
const was = groups.get(group);
|
|
@@ -1371,12 +1397,41 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1371
1397
|
else
|
|
1372
1398
|
this.setView(view, true);
|
|
1373
1399
|
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Draw a faint orbit while the pointer rests on a satellite. On unless `hover-path="off"`. Left unset, it is on when `names-on-hover` is on.
|
|
1402
|
+
* The colour and the opacity are the custom properties `--chikyu-hover-path` and `--chikyu-hover-path-opacity`.
|
|
1403
|
+
*/
|
|
1404
|
+
get hoverPath() {
|
|
1405
|
+
return hoverPathOn(this.getAttribute("hover-path"), this.getAttribute("names-on-hover"));
|
|
1406
|
+
}
|
|
1407
|
+
set hoverPath(value) {
|
|
1408
|
+
if (value)
|
|
1409
|
+
this.setAttribute("hover-path", "");
|
|
1410
|
+
else
|
|
1411
|
+
this.setAttribute("hover-path", "off");
|
|
1412
|
+
}
|
|
1413
|
+
/** Show a satellite's name while the pointer rests on it. On unless `names-on-hover="off"`. A touch does not rest, so it shows nothing. */
|
|
1414
|
+
get namesOnHover() {
|
|
1415
|
+
return namesHoverOn(this.getAttribute("names-on-hover"));
|
|
1416
|
+
}
|
|
1417
|
+
set namesOnHover(value) {
|
|
1418
|
+
if (value)
|
|
1419
|
+
this.removeAttribute("names-on-hover");
|
|
1420
|
+
else
|
|
1421
|
+
this.setAttribute("names-on-hover", "off");
|
|
1422
|
+
}
|
|
1374
1423
|
/** Mark one satellite: a larger ring round it and its orbit drawn. `null` lets it go. */
|
|
1375
1424
|
selectSatellite(ref) {
|
|
1376
1425
|
const found = ref ? this.#model.satellites.groups.get(ref.group) : undefined;
|
|
1377
1426
|
this.#model.satellites.selected = ref && found && ref.index >= 0 && ref.index < found.satellites.count ? { group: ref.group, index: ref.index } : null;
|
|
1378
1427
|
this.#gate?.soon();
|
|
1379
1428
|
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Where a satellite is on the screen as of the last draw: `{ x, y, visible, heightKm }` in CSS pixels from the view's top left, `visible` meaning it is inside the box and not behind the Earth. `null` when its group is not set or not shown, it cannot be placed, or it is behind the camera.
|
|
1431
|
+
*/
|
|
1432
|
+
placeSatellite(ref) {
|
|
1433
|
+
return this.#model.placeSatellite?.(ref) ?? null;
|
|
1434
|
+
}
|
|
1380
1435
|
/** The satellite marked by `selectSatellite` or by a press on it, if any. */
|
|
1381
1436
|
get selectedSatellite() {
|
|
1382
1437
|
const chosen = this.#model.satellites.selected;
|
|
@@ -1399,7 +1454,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1399
1454
|
let epochMs = 0;
|
|
1400
1455
|
for (const group of this.#model.satellites.groups.values())
|
|
1401
1456
|
epochMs = Math.max(epochMs, group.satellites.newestEpochMs);
|
|
1402
|
-
return { groups: this.#model.satellites.groups.size, placed: drawn.placed, segments: drawn.segments, tooFast: drawn.tooFast, dotScale: drawn.dotScale, longestStreakPx: drawn.longestStreakPx, streakCapPx: drawn.streakCapPx, weight: drawn.weight, fade: drawn.fade, earthPx: drawn.earthPx, epochMs, propagations, lastBatchMs, maxBatchMs, updateMs: drawn.updateMs, maxUpdateMs: drawn.maxUpdateMs, averageUpdateMs: drawn.updates ? drawn.totalMs / drawn.updates : 0, updates: drawn.updates, selectedRing: drawn.selectedRing };
|
|
1457
|
+
return { groups: this.#model.satellites.groups.size, placed: drawn.placed, segments: drawn.segments, tooFast: drawn.tooFast, dotScale: drawn.dotScale, longestStreakPx: drawn.longestStreakPx, streakCapPx: drawn.streakCapPx, weight: drawn.weight, fade: drawn.fade, earthPx: drawn.earthPx, epochMs, propagations, lastBatchMs, maxBatchMs, updateMs: drawn.updateMs, maxUpdateMs: drawn.maxUpdateMs, averageUpdateMs: drawn.updates ? drawn.totalMs / drawn.updates : 0, updates: drawn.updates, selectedRing: drawn.selectedRing, hoverPath: drawn.hoverPath, hoverOpacity: drawn.hoverOpacity, selectedOpacity: drawn.selectedOpacity };
|
|
1403
1458
|
}
|
|
1404
1459
|
// A press that does not turn the view (under 6 pixels) on a satellite tells the page, which chooses it with `selectSatellite` if it likes.
|
|
1405
1460
|
#downX = 0;
|