@johnmorrisdotca/chikyu-earth 0.35.0 → 0.37.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/NOTICE.md +27 -1
  3. package/README.md +20 -2
  4. package/dist/borders/layer.d.ts +75 -0
  5. package/dist/borders/layer.js +136 -0
  6. package/dist/borders/lines.d.ts +138 -0
  7. package/dist/borders/lines.js +227 -0
  8. package/dist/catalogue/index.d.ts +1 -0
  9. package/dist/catalogue/index.js +3 -2
  10. package/dist/catalogue/pack.js +3 -0
  11. package/dist/cities/host.d.ts +9 -0
  12. package/dist/cities/host.js +51 -9
  13. package/dist/country-names/geometry.d.ts +264 -0
  14. package/dist/country-names/geometry.js +372 -0
  15. package/dist/country-names/host.d.ts +82 -0
  16. package/dist/country-names/host.js +212 -0
  17. package/dist/grid/layer.d.ts +45 -0
  18. package/dist/grid/layer.js +66 -0
  19. package/dist/grid/lines.d.ts +85 -0
  20. package/dist/grid/lines.js +113 -0
  21. package/dist/markers/go-to-place.d.ts +27 -0
  22. package/dist/markers/go-to-place.js +35 -0
  23. package/dist/markers/index.d.ts +2 -1
  24. package/dist/markers/index.js +2 -1
  25. package/dist/markers/layer.d.ts +7 -0
  26. package/dist/markers/layer.js +7 -0
  27. package/dist/markers/place-layer.d.ts +58 -7
  28. package/dist/markers/place-layer.js +326 -64
  29. package/dist/markers/place-sprites.d.ts +33 -0
  30. package/dist/markers/place-sprites.js +161 -0
  31. package/dist/markers/places.d.ts +91 -6
  32. package/dist/markers/places.js +135 -6
  33. package/dist/realistic/earth.d.ts +11 -0
  34. package/dist/realistic/earth.js +55 -1
  35. package/dist/realistic/element.d.ts +75 -6
  36. package/dist/realistic/element.js +221 -33
  37. package/dist/realistic/immersive.d.ts +7 -0
  38. package/dist/realistic/immersive.js +17 -0
  39. package/dist/realistic/index.d.ts +6 -0
  40. package/dist/realistic/index.js +3 -0
  41. package/dist/realistic/textures.d.ts +5 -0
  42. package/dist/satellites/index.d.ts +1 -0
  43. package/dist/satellites/index.js +1 -0
  44. package/dist/satellites/limits.d.ts +1 -1
  45. package/dist/satellites/limits.js +1 -1
  46. package/dist/satellites/owners.d.ts +26 -0
  47. package/dist/satellites/owners.js +164 -0
  48. package/dist/satellites/source.js +3 -0
  49. package/dist/satellites/track.d.ts +5 -0
  50. package/dist/satellites/track.js +128 -0
  51. package/dist/satellites/types.d.ts +19 -1
  52. package/dist/space/element.d.ts +111 -12
  53. package/dist/space/element.js +360 -26
  54. package/dist/space/index.d.ts +2 -2
  55. package/dist/space/index.js +1 -1
  56. package/dist/space/ride.d.ts +42 -0
  57. package/dist/space/ride.js +45 -3
  58. package/dist/space/satellite-layer.d.ts +8 -2
  59. package/dist/space/satellite-layer.js +138 -19
  60. package/dist/space/scene.d.ts +56 -6
  61. package/dist/space/scene.js +97 -15
  62. package/package.json +3 -3
@@ -0,0 +1,45 @@
1
+ import type * as THREE from "three";
2
+ import type { ThreeParts } from "../realistic/textures.ts";
3
+ /**
4
+ * What the grid has done: whether it is drawn, whether it shows the lines every 15 degrees (else every 30), how many segments the last draw had, and how many times its lines were made.
5
+ *
6
+ * @example
7
+ * ```ts no-run
8
+ * import type { GridStats } from "@johnmorrisdotca/chikyu-earth/realistic";
9
+ *
10
+ * const none: GridStats = { shown: false, fine: false, segments: 0, builds: 0, failed: false };
11
+ * console.log(none);
12
+ * ```
13
+ */
14
+ export interface GridStats {
15
+ shown: boolean;
16
+ fine: boolean;
17
+ segments: number;
18
+ builds: number;
19
+ failed: boolean;
20
+ }
21
+ /** What the element and the scene share: whether the grid is on, and what it did. */
22
+ export interface GridState {
23
+ on: boolean;
24
+ onError?: (error: unknown) => void;
25
+ stats: GridStats;
26
+ }
27
+ export declare const newGridState: () => GridState;
28
+ export interface GridLayer {
29
+ /** Shows or hides the grid for this draw, finer or coarser by the Earth's radius on the screen (CSS pixels). */
30
+ sync(radius: number): void;
31
+ dispose(): void;
32
+ }
33
+ /**
34
+ * Makes the grid under `parent` (the group that turns with the Earth).
35
+ *
36
+ * @param three - The page's three.js; it must have `LineSegments`.
37
+ * @param parent - The Earth's own group.
38
+ * @param state - The model's grid.
39
+ * @param sunDir - The direction to the Sun in the world's axes, the uniform the Earth's surface is lit by.
40
+ * @param order - The render order: after the ground, before the clouds.
41
+ * @returns The layer.
42
+ */
43
+ export declare function createGridLayer(three: ThreeParts, parent: THREE.Object3D, state: GridState, sunDir: {
44
+ value: THREE.Vector3;
45
+ }, order: number): GridLayer;
@@ -0,0 +1,66 @@
1
+ import { GRID_FINE_RADIUS, gridLines } from "./lines.js";
2
+ /** The lines sit this far above the ground (in Earth radii): over the map tiles and the sphere's flat facets, and under the clouds. */
3
+ const GRID_RADIUS = 1.0015;
4
+ export const newGridState = () => ({ on: false, stats: { shown: false, fine: false, segments: 0, builds: 0, failed: false } });
5
+ const VERT = /* glsl */ `
6
+ attribute vec3 tint;
7
+ uniform vec3 sunDir;
8
+ varying vec3 vTint;
9
+ varying float vDay;
10
+ void main() {
11
+ vTint = tint;
12
+ vDay = smoothstep(-0.12, 0.18, dot(normalize(mat3(modelMatrix) * position), sunDir));
13
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
14
+ }`;
15
+ const FRAG = /* glsl */ `
16
+ uniform float opacity;
17
+ varying vec3 vTint;
18
+ varying float vDay;
19
+ void main() {
20
+ gl_FragColor = vec4(vTint * mix(0.55, 1.0, vDay), opacity * mix(0.45, 1.0, vDay));
21
+ }`;
22
+ /**
23
+ * Makes the grid under `parent` (the group that turns with the Earth).
24
+ *
25
+ * @param three - The page's three.js; it must have `LineSegments`.
26
+ * @param parent - The Earth's own group.
27
+ * @param state - The model's grid.
28
+ * @param sunDir - The direction to the Sun in the world's axes, the uniform the Earth's surface is lit by.
29
+ * @param order - The render order: after the ground, before the clouds.
30
+ * @returns The layer.
31
+ */
32
+ export function createGridLayer(three, parent, state, sunDir, order) {
33
+ const Lines = three.LineSegments;
34
+ if (!Lines)
35
+ throw new Error("the three.js handed over has no LineSegments, which the grid needs");
36
+ const grid = gridLines();
37
+ const geometry = new three.BufferGeometry();
38
+ geometry.setAttribute("position", new three.BufferAttribute(grid.positions, 3));
39
+ geometry.setAttribute("tint", new three.BufferAttribute(grid.colours, 3, true));
40
+ const material = new three.ShaderMaterial({ vertexShader: VERT, fragmentShader: FRAG, uniforms: { sunDir, opacity: { value: 0.6 } }, transparent: true, depthWrite: false });
41
+ const lines = new Lines(geometry, material);
42
+ lines.scale.setScalar(GRID_RADIUS);
43
+ lines.renderOrder = order;
44
+ lines.visible = false;
45
+ parent.add(lines);
46
+ const stats = state.stats;
47
+ stats.builds += 1;
48
+ return {
49
+ sync(radius) {
50
+ const fine = radius >= GRID_FINE_RADIUS;
51
+ const count = fine ? grid.points : grid.coarse;
52
+ geometry.setDrawRange(0, count);
53
+ lines.visible = state.on;
54
+ stats.shown = state.on;
55
+ stats.fine = state.on && fine;
56
+ stats.segments = state.on ? count / 2 : 0;
57
+ },
58
+ dispose() {
59
+ parent.remove(lines);
60
+ geometry.dispose();
61
+ material.dispose();
62
+ stats.shown = false;
63
+ stats.segments = 0;
64
+ },
65
+ };
66
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The Earth's tilt, degrees: the IAU's obliquity of the ecliptic at J2000. The tropics lie at this latitude, the polar circles at 90 degrees less it.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { EARTH_TILT } from "@johnmorrisdotca/chikyu-earth/realistic";
7
+ *
8
+ * console.log(EARTH_TILT, 90 - EARTH_TILT);
9
+ * ```
10
+ */
11
+ export declare const EARTH_TILT = 23.4393;
12
+ /**
13
+ * The Earth's radius on the screen, in CSS pixels, from which the grid has a line every 15 degrees; below it, every 30.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { GRID_FINE_RADIUS } from "@johnmorrisdotca/chikyu-earth/realistic";
18
+ *
19
+ * console.log(GRID_FINE_RADIUS);
20
+ * ```
21
+ */
22
+ export declare const GRID_FINE_RADIUS = 220;
23
+ /**
24
+ * The attributes the grid reads: `grid`.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { GRID_ATTRIBUTES } from "@johnmorrisdotca/chikyu-earth/realistic";
29
+ *
30
+ * console.log(GRID_ATTRIBUTES.join(" "));
31
+ * ```
32
+ */
33
+ export declare const GRID_ATTRIBUTES: readonly ["grid"];
34
+ /**
35
+ * A `grid` attribute: absent (or `off`) draws none, anything else draws it.
36
+ *
37
+ * @param value - The attribute's text, or `null` when it is not there.
38
+ * @returns Whether the grid is drawn.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { readGrid } from "@johnmorrisdotca/chikyu-earth/realistic";
43
+ *
44
+ * console.log(readGrid(null), readGrid(""), readGrid("off"));
45
+ * ```
46
+ */
47
+ export declare function readGrid(value: string | null): boolean;
48
+ /**
49
+ * The grid's lines, ready for one batch of line segments: the special lines first, then the lines every 30 degrees, then the ones every 15 degrees in between, so that the first `coarse` points are
50
+ * the grid of a small Earth and all `points` the grid of a large one.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { gridLines, type GridLines } from "@johnmorrisdotca/chikyu-earth/realistic";
55
+ *
56
+ * const grid: GridLines = gridLines();
57
+ * console.log(grid.coarse < grid.points);
58
+ * ```
59
+ */
60
+ export interface GridLines {
61
+ /** x, y, z of each point, two points to a segment. */
62
+ positions: Float32Array;
63
+ /** r, g, b of each point (0 to 255). */
64
+ colours: Uint8Array;
65
+ /** How many points the special lines and the 30-degree lines take. */
66
+ coarse: number;
67
+ /** How many points there are in all. */
68
+ points: number;
69
+ }
70
+ /**
71
+ * Makes the grid: meridians and parallels every 15 degrees (the parallels from 75 south to 75 north, the meridians to the poles), the equator brightest, the tropics and polar circles bright,
72
+ * the prime meridian in a warm colour. Each line is cut into pieces of at most `step` degrees so it keeps to the sphere.
73
+ *
74
+ * @param step - The longest piece, in degrees (3 when left out).
75
+ * @returns The segments and their colours.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import { gridLines } from "@johnmorrisdotca/chikyu-earth/realistic";
80
+ *
81
+ * const grid = gridLines();
82
+ * console.log(grid.points / 2, grid.coarse / 2);
83
+ * ```
84
+ */
85
+ export declare function gridLines(step?: number): GridLines;
@@ -0,0 +1,113 @@
1
+ // The grid on the Earth: meridians and parallels as line segments on the unit sphere, with the equator, the tropics, the polar circles and the prime meridian picked out.
2
+ // Pure: numbers in, a buffer of points and colours out (the axes of the Earth's own sphere: +z is longitude 0 on the equator, +x east, +y north).
3
+ const RAD = Math.PI / 180;
4
+ /**
5
+ * The Earth's tilt, degrees: the IAU's obliquity of the ecliptic at J2000. The tropics lie at this latitude, the polar circles at 90 degrees less it.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { EARTH_TILT } from "@johnmorrisdotca/chikyu-earth/realistic";
10
+ *
11
+ * console.log(EARTH_TILT, 90 - EARTH_TILT);
12
+ * ```
13
+ */
14
+ export const EARTH_TILT = 23.4393;
15
+ /**
16
+ * The Earth's radius on the screen, in CSS pixels, from which the grid has a line every 15 degrees; below it, every 30.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { GRID_FINE_RADIUS } from "@johnmorrisdotca/chikyu-earth/realistic";
21
+ *
22
+ * console.log(GRID_FINE_RADIUS);
23
+ * ```
24
+ */
25
+ export const GRID_FINE_RADIUS = 220;
26
+ /**
27
+ * The attributes the grid reads: `grid`.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { GRID_ATTRIBUTES } from "@johnmorrisdotca/chikyu-earth/realistic";
32
+ *
33
+ * console.log(GRID_ATTRIBUTES.join(" "));
34
+ * ```
35
+ */
36
+ export const GRID_ATTRIBUTES = ["grid"];
37
+ /**
38
+ * A `grid` attribute: absent (or `off`) draws none, anything else draws it.
39
+ *
40
+ * @param value - The attribute's text, or `null` when it is not there.
41
+ * @returns Whether the grid is drawn.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import { readGrid } from "@johnmorrisdotca/chikyu-earth/realistic";
46
+ *
47
+ * console.log(readGrid(null), readGrid(""), readGrid("off"));
48
+ * ```
49
+ */
50
+ export function readGrid(value) {
51
+ return value !== null && value.trim().toLowerCase() !== "off";
52
+ }
53
+ /** The look of each kind of line: a plain line, the special parallels (equator, tropics, polar circles) and the prime meridian. */
54
+ const PLAIN = [140, 168, 204];
55
+ const CIRCLE = [235, 242, 255];
56
+ const EQUATOR = [255, 255, 255];
57
+ const PRIME = [255, 189, 107];
58
+ /**
59
+ * Makes the grid: meridians and parallels every 15 degrees (the parallels from 75 south to 75 north, the meridians to the poles), the equator brightest, the tropics and polar circles bright,
60
+ * the prime meridian in a warm colour. Each line is cut into pieces of at most `step` degrees so it keeps to the sphere.
61
+ *
62
+ * @param step - The longest piece, in degrees (3 when left out).
63
+ * @returns The segments and their colours.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { gridLines } from "@johnmorrisdotca/chikyu-earth/realistic";
68
+ *
69
+ * const grid = gridLines();
70
+ * console.log(grid.points / 2, grid.coarse / 2);
71
+ * ```
72
+ */
73
+ export function gridLines(step = 3) {
74
+ const positions = [];
75
+ const colours = [];
76
+ const at = (lon, lat) => {
77
+ const phi = lat * RAD;
78
+ const lambda = lon * RAD;
79
+ return [Math.cos(phi) * Math.sin(lambda), Math.sin(phi), Math.cos(phi) * Math.cos(lambda)];
80
+ };
81
+ const segment = (a, b, colour) => {
82
+ positions.push(...a, ...b);
83
+ colours.push(...colour, ...colour);
84
+ };
85
+ const parallel = (lat, colour) => {
86
+ const pieces = Math.max(8, Math.ceil(360 / step));
87
+ for (let i = 0; i < pieces; i += 1)
88
+ segment(at(-180 + (360 * i) / pieces, lat), at(-180 + (360 * (i + 1)) / pieces, lat), colour);
89
+ };
90
+ const meridian = (lon, colour) => {
91
+ const pieces = Math.max(4, Math.ceil(180 / step));
92
+ for (let i = 0; i < pieces; i += 1)
93
+ segment(at(lon, -90 + (180 * i) / pieces), at(lon, -90 + (180 * (i + 1)) / pieces), colour);
94
+ };
95
+ // the special lines
96
+ parallel(0, EQUATOR);
97
+ for (const lat of [EARTH_TILT, -EARTH_TILT, 90 - EARTH_TILT, EARTH_TILT - 90])
98
+ parallel(lat, CIRCLE);
99
+ meridian(0, PRIME);
100
+ // every 30 degrees, then every 15 in between
101
+ const plain = (coarseOnes) => {
102
+ for (let lat = -75; lat <= 75; lat += 15)
103
+ if (lat !== 0 && (lat % 30 === 0) === coarseOnes)
104
+ parallel(lat, PLAIN);
105
+ for (let lon = -165; lon <= 180; lon += 15)
106
+ if (lon !== 0 && (lon % 30 === 0) === coarseOnes)
107
+ meridian(lon, PLAIN);
108
+ };
109
+ plain(true);
110
+ const coarse = positions.length / 3;
111
+ plain(false);
112
+ return { positions: new Float32Array(positions), colours: new Uint8Array(colours), coarse, points: positions.length / 3 };
113
+ }
@@ -0,0 +1,27 @@
1
+ import type { GeoPoint } from "../types.ts";
2
+ import type { Place } from "./places.ts";
3
+ /** How long the turn to a place takes, in milliseconds: slow enough to follow. */
4
+ export declare const PLACE_GLIDE_MS = 900;
5
+ /** The place a page names: by its id, else by its name in any case. */
6
+ export declare const findPlace: (places: readonly Place[], text: string) => Place | undefined;
7
+ /**
8
+ * The yaw and tilt that bring a place to the middle of a view whose yaw and tilt 0 look at `base` (yaw turns west, tilt tips south), the yaw taken the shorter way round from the one now and the tilt
9
+ * held to 90 either way, as the controls hold it.
10
+ */
11
+ export declare function aimAt(base: GeoPoint, place: GeoPoint, now: {
12
+ yaw: number;
13
+ tilt: number;
14
+ }): {
15
+ yaw: number;
16
+ tilt: number;
17
+ };
18
+ /**
19
+ * Move a view's yaw and tilt from `from` to `to`: eased over {@link PLACE_GLIDE_MS} one frame at a time, or at once when `smooth` is false. `alive` false stops it (another glide began, the element left the page).
20
+ */
21
+ export declare function glideView(set: (yaw: number, tilt: number, final: boolean) => void, from: {
22
+ yaw: number;
23
+ tilt: number;
24
+ }, to: {
25
+ yaw: number;
26
+ tilt: number;
27
+ }, smooth: boolean, alive: () => boolean): void;
@@ -0,0 +1,35 @@
1
+ /** How long the turn to a place takes, in milliseconds: slow enough to follow. */
2
+ export const PLACE_GLIDE_MS = 900;
3
+ /** The place a page names: by its id, else by its name in any case. */
4
+ export const findPlace = (places, text) => {
5
+ const name = text.trim().toLowerCase();
6
+ return places.find((place) => place.id === text) ?? places.find((place) => place.label?.toLowerCase() === name);
7
+ };
8
+ /**
9
+ * The yaw and tilt that bring a place to the middle of a view whose yaw and tilt 0 look at `base` (yaw turns west, tilt tips south), the yaw taken the shorter way round from the one now and the tilt
10
+ * held to 90 either way, as the controls hold it.
11
+ */
12
+ export function aimAt(base, place, now) {
13
+ const yaw = base.lon - place.lon;
14
+ return { yaw: now.yaw + ((((yaw - now.yaw + 180) % 360) + 360) % 360) - 180, tilt: Math.max(-90, Math.min(90, base.lat - place.lat)) };
15
+ }
16
+ /**
17
+ * Move a view's yaw and tilt from `from` to `to`: eased over {@link PLACE_GLIDE_MS} one frame at a time, or at once when `smooth` is false. `alive` false stops it (another glide began, the element left the page).
18
+ */
19
+ export function glideView(set, from, to, smooth, alive) {
20
+ if (!smooth || typeof requestAnimationFrame !== "function") {
21
+ set(to.yaw, to.tilt, true);
22
+ return;
23
+ }
24
+ const start = performance.now();
25
+ const step = () => {
26
+ if (!alive())
27
+ return;
28
+ const k = Math.min(1, (performance.now() - start) / PLACE_GLIDE_MS);
29
+ const ease = k * k * (3 - 2 * k);
30
+ set(from.yaw + (to.yaw - from.yaw) * ease, from.tilt + (to.tilt - from.tilt) * ease, k >= 1);
31
+ if (k < 1)
32
+ requestAnimationFrame(step);
33
+ };
34
+ requestAnimationFrame(step);
35
+ }
@@ -3,4 +3,5 @@ export { project, projectAll, canvasRatio, type Pose } from "./project.ts";
3
3
  export { clusterPoints, type Cluster } from "./cluster.ts";
4
4
  export { placeLabels, type LabelItem, type Placement } from "./labels.ts";
5
5
  export type { GroupInfo, MarkerEventDetail, MarkerIcon, MarkerInput } from "./types.ts";
6
- export { cleanPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_LOOKS, readPlaces, type Place, type PlaceKind, type PlaceLabelSpot, type PlaceLayout, type PlaceLayoutOptions, type PlaceLook, type PlaceShape, type PlaceView, type SurfacePoint } from "./places.ts";
6
+ export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaces, type Place, type PlaceGroup, type PlaceKind, type PlaceLabelSpot, type PlaceLayout, type PlaceLayoutOptions, type PlaceLook, type PlaceShape, type PlaceView, type SurfacePoint } from "./places.ts";
7
+ export { PLACE_DOTS, PLACE_MARKS } from "./place-layer.ts";
@@ -4,4 +4,5 @@ export { attachMarkers } from "./layer.js";
4
4
  export { project, projectAll, canvasRatio } from "./project.js";
5
5
  export { clusterPoints } from "./cluster.js";
6
6
  export { placeLabels } from "./labels.js";
7
- export { cleanPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_LOOKS, readPlaces } from "./places.js";
7
+ export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaces } from "./places.js";
8
+ export { PLACE_DOTS, PLACE_MARKS } from "./place-layer.js";
@@ -33,6 +33,13 @@ export interface OverlayHost {
33
33
  readonly overlayRoot: HTMLElement;
34
34
  readonly pose: OverlayPose | null;
35
35
  subscribe(listener: (pose: OverlayPose) => void): () => void;
36
+ /** Tells the element the boxes an overlay's marks and labels take now (an empty list when it is taken away), so the element's own names keep clear of them. */
37
+ claim?(owner: object, boxes: readonly {
38
+ left: number;
39
+ top: number;
40
+ width: number;
41
+ height: number;
42
+ }[]): void;
36
43
  }
37
44
  /**
38
45
  * What {@link attachMarkers} may be asked: the most labels, how close markers gather, and the default colour.
@@ -261,6 +261,12 @@ export function attachMarkers(element, options = {}) {
261
261
  }
262
262
  }
263
263
  shown = placed.length;
264
+ const boxes = [];
265
+ for (const p of placed)
266
+ boxes.push({ left: p.left, top: p.top, width: items[p.item].w, height: items[p.item].h });
267
+ for (let k = 0; k < hitX.length; k += 1)
268
+ boxes.push({ left: hitX[k] - hitR[k], top: hitY[k] - hitR[k], width: hitR[k] * 2, height: hitR[k] * 2 });
269
+ host.claim?.(api, boxes);
264
270
  stats.markers = visible.length - groups.reduce((sum, g) => sum + (g.members.length > 1 ? g.members.length : 0), 0);
265
271
  stats.clusters = clusters;
266
272
  stats.labels = placed.length;
@@ -435,6 +441,7 @@ export function attachMarkers(element, options = {}) {
435
441
  stats,
436
442
  detach() {
437
443
  unsubscribe();
444
+ host.claim?.(api, []);
438
445
  element.removeEventListener("pointermove", onMove);
439
446
  element.removeEventListener("pointerleave", onLeave);
440
447
  element.removeEventListener("pointerdown", onDown);
@@ -1,3 +1,5 @@
1
+ import type { GeoPoint } from "../types.ts";
2
+ import type { PlaceSpriteData } from "./place-sprites.ts";
1
3
  import { type Place, type PlaceLook, type PlaceView } from "./places.ts";
2
4
  /** A `places-look` attribute: one of `PLACE_LOOKS`, else `beam`. */
3
5
  export declare const readPlaceLook: (value: string | null) => PlaceLook;
@@ -11,19 +13,56 @@ export interface SatelliteMark {
11
13
  y: number;
12
14
  visible: boolean;
13
15
  }
16
+ /**
17
+ * The most places in sight drawn as markers of their own (a beam, a pin or a ring standing out of the ground, and a name): `here` first, then the rest in the order given. Every other place is a ring on the ground, all of them one draw call.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { PLACE_MARKS } from "@johnmorrisdotca/chikyu-earth/markers";
22
+ *
23
+ * console.log(PLACE_MARKS); // 32
24
+ * ```
25
+ */
26
+ export declare const PLACE_MARKS = 32;
27
+ /**
28
+ * The most rings the layer draws itself, as small circles in the page, when the picture cannot draw them (the three.js parts handed over lack `Points`). Places in sight beyond it are counted in `stats.omitted`, not dropped quietly.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { PLACE_DOTS } from "@johnmorrisdotca/chikyu-earth/markers";
33
+ *
34
+ * console.log(PLACE_DOTS); // 600
35
+ * ```
36
+ */
37
+ export declare const PLACE_DOTS = 600;
38
+ type Box = {
39
+ left: number;
40
+ top: number;
41
+ width: number;
42
+ height: number;
43
+ };
14
44
  /**
15
45
  * The places' markers in one element: hand it the places and the look, and a view at each draw.
16
46
  */
17
47
  export interface PlaceLayer {
18
48
  set(places: readonly Place[]): void;
19
49
  look: PlaceLook;
20
- /** Lay the places on the picture just drawn; `null` hides them (the Earth is not in the picture). `taken` is boxes other names use; `marks` are satellites to ring and name, after the places' names and never over them. */
21
- frame(view: PlaceView | null, taken?: readonly {
22
- left: number;
23
- top: number;
24
- width: number;
25
- height: number;
26
- }[], marks?: readonly SatelliteMark[]): void;
50
+ /**
51
+ * Lay the places on the picture just drawn; `null` hides them (the Earth is not in the picture). `taken` is boxes other names use; `marks` are satellites to ring and name, after the places' names and
52
+ * never over them; `sun` is where the Sun is overhead (null when the whole Earth is lit), for the night side's dimmer markers.
53
+ */
54
+ frame(view: PlaceView | null, taken?: readonly Box[], marks?: readonly SatelliteMark[], sun?: GeoPoint | null): void;
55
+ /** The rings the picture draws for the places that are not markers of their own, as of the last `frame`; null while there are none. */
56
+ readonly sprites: PlaceSpriteData | null;
57
+ /**
58
+ * Whether places that crowd are gathered into one ring with their count (the attribute `place-groups`; true by default). False leaves every place its own ring.
59
+ */
60
+ grouping: boolean;
61
+ /**
62
+ * Whether the picture draws the rings that are not markers of their own (true by default). False when the three.js parts lack `Points`: the layer then draws those rings itself as small circles in the page, up to {@link PLACE_DOTS},
63
+ * and `stats.omitted` counts the places in sight it had no room for.
64
+ */
65
+ ringsInPicture: boolean;
27
66
  readonly stats: {
28
67
  places: number;
29
68
  shown: number;
@@ -31,7 +70,18 @@ export interface PlaceLayer {
31
70
  renders: number;
32
71
  rings: number;
33
72
  satelliteNames: number;
73
+ marks: number;
74
+ groups: number;
75
+ sprites: number;
76
+ omitted: number;
34
77
  };
78
+ /** The boxes the names and the markers' heads take in the picture just drawn, for other names to keep clear of. */
79
+ readonly boxes: readonly {
80
+ left: number;
81
+ top: number;
82
+ width: number;
83
+ height: number;
84
+ }[];
35
85
  dispose(): void;
36
86
  }
37
87
  /**
@@ -41,3 +91,4 @@ export interface PlaceLayer {
41
91
  * @returns The layer.
42
92
  */
43
93
  export declare function createPlaceLayer(box: HTMLElement): PlaceLayer;
94
+ export {};