@johnmorrisdotca/chikyu-earth 0.60.2 → 0.62.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 CHANGED
@@ -1,6 +1,25 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.62.0 - 2026-11-19
4
+
5
+ - **A fly-to on the space view, and moves that bend instead of stopping** (MODULES-1582).
6
+ - **`flyTo(lat, lon, { height, phase, smooth, signal })`** on `<chikyu-space>`: across, the Earth turns under the camera at the height it has until the place is below (a great circle, eased), then down to `height` km over it (30 by default, never under 15). `phase` is `across`, `down` or `both`. It resolves to `FlyEnd` (`arrived`, `redirected` or `stopped`, the place, the height then and what held the descent) and sends `chikyu-fly-start` and `chikyu-fly-end`; `stats.fly` says what it is doing. The controls' own turn is paused for it.
7
+ - **A new move bends the running one.** A `flyTo` or `goToPlace` while a move is going starts with the camera's own speed and acceleration and curves to the new place, so the speed and the way it goes are continuous (no stop, no jump); a descent cut short slows to rest without turning back. The realistic Earth's `goToPlace` is unchanged.
8
+ - **A hand ends it where it is**: a drag, pinch, wheel or key (from the element's own hands or a bound bar), or the `signal`. Reduced motion, `smooth: false` or a picture not live yet jumps there.
9
+ - **The floor.** The descent comes all the way down only with `tiles-finer` over land from 60 degrees south to 80 degrees north (the place is looked up in the 1:110m outlines, loaded only then); elsewhere it stops at 400 km (`FLY_FLOOR_KM`, the height the package's own pictures stay sharp, as the site's ride-above floor), and at a `zoom-max` the page set. Below about 320 km the look camera's nearest distance and near plane follow the descent, and the zoom limit is raised under the page's own; a page that never calls `flyTo` draws as before.
10
+ - **Pure parts** in `/space`: `planFly`, `flyAt`, `flyStateAt`, `flyStill`, `flyAim`, `flyLonLat`, `flyAcrossMs`, `flyDownMs`, `flyDistance`, `descentFloorKm` and the `FLY_*` constants, with unit tests (a redirect mid-turn and mid-descent: the speed carries across within 1 per cent, no step stops or jumps, the height never turns back); `e2e/fly.gl.ts` (the same in a real browser, a drag and a signal ending a move, reduced motion jumping 30 km over Tokyo and holding at 400 km over the sea) and a freeze check (one frame at a time, nothing at rest after). The places guide in English and Japanese.
11
+ - **Not yet:** the next tile level is not fetched ahead of the descent; the tiles load as the camera comes down, as they do for a zoom.
12
+
13
+ - **The clouds fade out when the view is close, so the sharp ground shows** (MODULES-1356). The cloud layer is one whole-Earth picture at most 2048 pixels across (about 20 km a texel) drawn over the ground, so from a few hundred kilometres up it blurred the finer tiles under it (a satellite ride's Below step, 486 km up, showed it). Its strength now goes from 1 to 0 as a texel grows from 8 to 32 device pixels wide, worked out from the pixel scale the map tiles use. Both `<chikyu-earth-realistic>` and `<chikyu-space>` do it; the space view does it for each point of the clouds by its own distance from the camera, so the ground under the camera goes sharp and the far ground and the horizon keep their clouds. `cloud-fade="16"` sets the width at which the clouds are gone (32 when left out, 1 to 1000), `cloud-fade="off"` (or `0`) keeps them at any zoom, and `stats.cloudFade` says how much is shown at the nearest ground (the space view) or over the disc (the realistic Earth). Nothing is drawn at rest. A unit test, `e2e/cloud-fade.gl.ts` on both elements, and the earth-tiles guide in English and Japanese.
14
+
15
+ ## 0.61.0 - 2026-11-18
16
+
17
+ - **Places get a press event, a size and look each, layers, and names that give way to cities** (MODULES-1578). All of it is optional and a page that uses none of it draws as before.
18
+ - **Press.** A press on a place's marker or ring sends `chikyu-place-click` from `<chikyu-space>` and `<chikyu-earth-realistic>` with `detail: { id, kind, layer?, label?, lon, lat, x, y }` (`PlaceClickDetail`), so a page need not read the markers' boxes. A group of several places sends nothing.
19
+ - **Size and look.** A place may have `size: "small"` (a stick about half as long, a ring about 30 per cent smaller) and `look` (`beam`, `pin` or `ring`, over `places-look`).
20
+ - **Layers.** A place may have a `layer`; `place-layers` (`placeLayers`, `setPlaceLayer(name, shown)`) is a JSON object of a layer's name to true or false, and only `false` hides a layer's places, wholly (not drawn, named, grouped or pressable). `stats.places.hidden` counts them. `readPlaceLayers` and `shownPlaces` are the pure parts.
21
+ - **Names.** A place with `namePriority: "low"` has its name laid after the cities' names and left out where a city's name lies; the marker stays. The sea, country and star names keep clear of it once laid.
22
+ - **Tests and docs.** Unit tests for each part, `e2e/places.gl.ts` (a press, a layer, a look, a name giving way to Tokyo's, on both elements), and the places guide in English and Japanese.
4
23
 
5
24
  ## 0.60.2 - 2026-11-17
6
25
 
package/README.md CHANGED
@@ -252,7 +252,7 @@ console.log(bodyLabelText("en"), bodyLabelText("ja"), BODY_LABEL_ATTRIBUTES.leng
252
252
 
253
253
  `route` on `<chikyu-earth>`, `<chikyu-earth-realistic>` and `<chikyu-space>` draws the line between two places (`lon,lat,lon,lat`). `routeInfo` gives the accurate distance on the Earth's real shape, the great-circle distance, the bearings and a flight time at 900 km/h. The line is off until it is set, and nothing is drawn at rest: [guide](docs/guides/routes.md).
254
254
 
255
- `places` on `<chikyu-space>` and `<chikyu-earth-realistic>` marks places on the Earth, each a beam, a pin or a ring (`places-look`) standing out of the ground, turning with the Earth, hidden on its far side and dimmer at night: `kind: "here"` for the reader's own place (brighter, with a quiet pulse) and favourites, quieter, each with an optional `color`. Up to 5,000: the first 32 in sight stand up with their names, the rest are rings in one draw call, crowds are gathered with their count, and `goToPlace(id)` turns the view to one. Names never overlap; nothing is drawn at rest. `here-city` (off by default) names a `here` place with the nearest city within 100 km, in the page's language; kuni is loaded only then. The package never asks for the reader's place and stores or sends nothing: the page asks on a press and rounds the place with `nearby` first: [guide](docs/guides/places.md).
255
+ `places` on `<chikyu-space>` and `<chikyu-earth-realistic>` marks places on the Earth, each a beam, a pin or a ring (`places-look`) standing out of the ground, turning with the Earth, hidden on its far side and dimmer at night: `kind: "here"` for the reader's own place (brighter, with a quiet pulse) and favourites, quieter, each with an optional `color`. Up to 5,000: the first 32 in sight stand up with their names, the rest are rings in one draw call, crowds are gathered with their count, and `goToPlace(id)` turns the view to one. In the space view `flyTo(lat, lon, { height, phase })` goes across at the height the camera has, then down to hover over the place (30 km over land with `tiles-finer`, else 400 km); a new `flyTo` or `goToPlace` bends the running move without stopping it, a hand ends it where it is, and reduced motion jumps there. Names never overlap; nothing is drawn at rest. Each place can have a `layer` (switched with `place-layers`), a `size` or `look` of its own and a `namePriority`, so a harbour is a short mark and its name gives way to a city's; a press on a place sends `chikyu-place-click` with its `id` and `kind`. `here-city` (off by default) names a `here` place with the nearest city within 100 km, in the page's language; kuni is loaded only then. The package never asks for the reader's place and stores or sends nothing: the page asks on a press and rounds the place with `nearby` first: [guide](docs/guides/places.md).
256
256
 
257
257
  ```html
258
258
  <chikyu-space places='[{"id":"me","lon":-79.4,"lat":43.7,"label":"You are here","kind":"here"}]'></chikyu-space>
@@ -615,7 +615,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
615
615
 
616
616
  ## How to cite
617
617
 
618
- > Morris, J. (2026). *Chikyu Earth* (version 0.60.2) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
618
+ > Morris, J. (2026). *Chikyu Earth* (version 0.62.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
619
619
 
620
620
  GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
621
621
 
@@ -3,6 +3,6 @@ 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, 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";
6
+ export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaceLayers, readPlaces, shownPlaces, type Place, type PlaceGroup, type PlaceKind, type PlaceLabelSpot, type PlaceLayout, type PlaceLayoutOptions, type PlaceLook, type PlaceNamePriority, type PlaceShape, type PlaceSize, type PlaceView, type SurfacePoint } from "./places.ts";
7
7
  export { HERE_CITY_KM, HERE_CITY_MAX_KM, HERE_CITY_TIERS, chooseHereCity, hereCityLabels, hereCountries, readHereCity, type HereCityHit, type HereCitySource, type HereTown } from "./here-city.ts";
8
- export { PLACE_DOTS, PLACE_MARKS } from "./place-layer.ts";
8
+ export { PLACE_DOTS, PLACE_MARKS, type PlaceClickDetail } from "./place-layer.ts";
@@ -4,6 +4,6 @@ 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, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaces } from "./places.js";
7
+ export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaceLayers, readPlaces, shownPlaces } from "./places.js";
8
8
  export { HERE_CITY_KM, HERE_CITY_MAX_KM, HERE_CITY_TIERS, chooseHereCity, hereCityLabels, hereCountries, readHereCity } from "./here-city.js";
9
9
  export { PLACE_DOTS, PLACE_MARKS } from "./place-layer.js";
@@ -1,6 +1,6 @@
1
1
  import type { GeoPoint } from "../types.ts";
2
2
  import type { PlaceSpriteData } from "./place-sprites.ts";
3
- import { type Place, type PlaceLook, type PlaceView } from "./places.ts";
3
+ import { type Place, type PlaceKind, type PlaceLook, type PlaceView } from "./places.ts";
4
4
  /** A `places-look` attribute: one of `PLACE_LOOKS`, else `beam`. */
5
5
  export declare const readPlaceLook: (value: string | null) => PlaceLook;
6
6
  /** The places' look, for the element's own style sheet. Colours: `--chikyu-place-here` and `--chikyu-place-favourite` on the element or the page. */
@@ -53,17 +53,55 @@ type Box = {
53
53
  width: number;
54
54
  height: number;
55
55
  };
56
+ /**
57
+ * What `chikyu-place-click` carries in `event.detail`: the place that was pressed, and where the press was in CSS pixels inside the element's box.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * import type { PlaceClickDetail } from "@johnmorrisdotca/chikyu-earth/markers";
62
+ *
63
+ * const on = (event: Event): void => {
64
+ * const { id, kind, layer } = (event as CustomEvent<PlaceClickDetail>).detail;
65
+ * console.log(id, kind, layer ?? "no layer");
66
+ * };
67
+ * console.log(typeof on);
68
+ * ```
69
+ */
70
+ export interface PlaceClickDetail {
71
+ id: string;
72
+ /** `here` or `favourite`. */
73
+ kind: PlaceKind;
74
+ /** The place's `layer`, when it has one. */
75
+ layer?: string;
76
+ label?: string;
77
+ lon: number;
78
+ lat: number;
79
+ /** Where the press was, in CSS pixels inside the element's box. */
80
+ x: number;
81
+ y: number;
82
+ }
83
+ /** The detail of `chikyu-place-click` for a pressed place. */
84
+ export declare const placeClick: (place: Place, x: number, y: number) => PlaceClickDetail;
56
85
  /**
57
86
  * The places' markers in one element: hand it the places and the look, and a view at each draw.
58
87
  */
59
88
  export interface PlaceLayer {
60
89
  set(places: readonly Place[]): void;
90
+ /** Which layers are shown: a layer's name to false hides every place of it (see {@link shownPlaces}). A layer not named is shown. */
91
+ layers: Readonly<Record<string, boolean>>;
61
92
  look: PlaceLook;
62
93
  /**
63
94
  * 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
64
95
  * never over them; `sun` is where the Sun is overhead (null when the whole Earth is lit), for the night side's dimmer markers.
65
96
  */
66
97
  frame(view: PlaceView | null, taken?: readonly Box[], marks?: readonly SatelliteMark[], sun?: GeoPoint | null): void;
98
+ /**
99
+ * Lay the names of the places whose `namePriority` is `low`, after the layers that come before them: `taken` gives those layers' boxes (the cities' names), asked for only when there is a name to lay, and a name with no free place is left out. Call it after each `frame`
100
+ * and again when those layers change; with no such place it does nothing.
101
+ */
102
+ late(taken?: () => readonly Box[]): void;
103
+ /** The place under a point of the element (CSS pixels from its top left) in the last picture: a marker's stick or foot, or a ring, within a few pixels; null when there is none. A group of several is not a place. */
104
+ pick(x: number, y: number): Place | null;
67
105
  /** 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. */
68
106
  readonly sprites: PlaceSpriteData | null;
69
107
  /**
@@ -79,6 +117,7 @@ export interface PlaceLayer {
79
117
  dimOccluded: boolean;
80
118
  readonly stats: {
81
119
  places: number;
120
+ hidden: number;
82
121
  shown: number;
83
122
  labels: number;
84
123
  renders: number;
@@ -90,13 +129,20 @@ export interface PlaceLayer {
90
129
  dots: number;
91
130
  omitted: number;
92
131
  };
93
- /** The boxes the names and the markers' heads take in the picture just drawn, for other names to keep clear of. */
132
+ /** The boxes the names and the markers' heads take in the picture just drawn, for other names to keep clear of; the low-priority names, once `late` has laid them, are in it. */
94
133
  readonly boxes: readonly {
95
134
  left: number;
96
135
  top: number;
97
136
  width: number;
98
137
  height: number;
99
138
  }[];
139
+ /** The same without the low-priority names, which the cities' names are laid out after. */
140
+ readonly earlyBoxes: readonly {
141
+ left: number;
142
+ top: number;
143
+ width: number;
144
+ height: number;
145
+ }[];
100
146
  dispose(): void;
101
147
  }
102
148
  /**
@@ -1,5 +1,5 @@
1
1
  import { placeLabels } from "./labels.js";
2
- import { groupCell, groupPlaces, layoutPlaces, PLACE_LOOKS } from "./places.js";
2
+ import { groupCell, groupPlaces, layoutPlaces, PLACE_LOOKS, shownPlaces, SMALL_RING } from "./places.js";
3
3
  /** A `places-look` attribute: one of `PLACE_LOOKS`, else `beam`. */
4
4
  export const readPlaceLook = (value) => PLACE_LOOKS.includes(value ?? "") ? value : "beam";
5
5
  /** The places' look, for the element's own style sheet. Colours: `--chikyu-place-here` and `--chikyu-place-favourite` on the element or the page. */
@@ -19,10 +19,10 @@ export const PLACE_STYLE = "#places{position:absolute;inset:0;overflow:hidden;po
19
19
  ".pl-head{position:absolute;left:-2.5px;top:-2.5px;width:5px;height:5px;border-radius:50%;background:#fff;box-shadow:0 0 6px 1px var(--c)}" +
20
20
  ".pl-mark[data-kind=favourite] .pl-stick{width:1.5px;opacity:.8}" +
21
21
  ".pl-mark[data-kind=favourite] .pl-head{opacity:.85}" +
22
- "#places[data-look=pin] .pl-stick{background:var(--c);box-shadow:none;width:1.5px}" +
23
- "#places[data-look=pin] .pl-head{left:-4px;top:-4px;width:8px;height:8px;background:var(--c);box-shadow:0 0 0 1.5px rgba(4,10,20,.75)}" +
24
- "#places[data-look=pin] .pl-ring{box-shadow:none;background:none;opacity:.7}" +
25
- "#places[data-look=ring] .pl-stick,#places[data-look=ring] .pl-head{display:none}" +
22
+ ".pl-mark[data-look=pin] .pl-stick{background:var(--c);box-shadow:none;width:1.5px}" +
23
+ ".pl-mark[data-look=pin] .pl-head{left:-4px;top:-4px;width:8px;height:8px;background:var(--c);box-shadow:0 0 0 1.5px rgba(4,10,20,.75)}" +
24
+ ".pl-mark[data-look=pin] .pl-ring{box-shadow:none;background:none;opacity:.7}" +
25
+ ".pl-mark[data-look=ring] .pl-stick,.pl-mark[data-look=ring] .pl-head{display:none}" +
26
26
  ".pl-name{position:absolute;left:0;top:0;box-sizing:border-box;padding:1px 6px;font:600 11px/16px system-ui,-apple-system,'Segoe UI',sans-serif;letter-spacing:.04em;white-space:nowrap;color:#eefcff;background:rgba(4,10,20,.72);border:1px solid color-mix(in srgb,var(--c) 60%,transparent);border-radius:3px;will-change:transform;--c:var(--chikyu-place-favourite,#ffd27a)}" +
27
27
  ".pl-name[data-kind=here]{--c:var(--chikyu-place-here,#7df9ff);color:#fff}" +
28
28
  ".pl-name[data-kind=group]{padding:0 5px;font-size:10px;line-height:14px;border-radius:7px;background:rgba(4,10,20,.6)}" +
@@ -76,6 +76,17 @@ const LIMB = 0.12;
76
76
  const MARGIN = 60;
77
77
  const RING = { here: 9, favourite: 6 };
78
78
  const FALLBACK = { here: "#7df9ff", favourite: "#ffd27a" };
79
+ /** The detail of `chikyu-place-click` for a pressed place. */
80
+ export const placeClick = (place, x, y) => {
81
+ const detail = { id: place.id, kind: place.kind === "here" ? "here" : "favourite", lon: place.lon, lat: place.lat, x, y };
82
+ if (place.layer)
83
+ detail.layer = place.layer;
84
+ if (place.label)
85
+ detail.label = place.label;
86
+ return detail;
87
+ };
88
+ /** How far from a place's mark a press still counts as on it, in CSS pixels, as for a satellite's dot. */
89
+ const PRESS_REACH = 12;
79
90
  /**
80
91
  * Make the places' layer in a box of an element's shadow root (the box is `#places`, styled by {@link PLACE_STYLE}).
81
92
  *
@@ -86,12 +97,14 @@ export function createPlaceLayer(box) {
86
97
  const doc = box.ownerDocument;
87
98
  box.setAttribute("aria-hidden", "true");
88
99
  box.dataset["look"] = "beam";
100
+ let everything = [];
89
101
  let places = [];
102
+ let switches = {};
90
103
  let look = "beam";
91
104
  const marks = [];
92
105
  const names = [];
93
106
  const sizes = new Map();
94
- const stats = { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 };
107
+ const stats = { places: 0, hidden: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 };
95
108
  let grouping = true;
96
109
  let ringsInPicture = true;
97
110
  let dimOccluded = true;
@@ -102,6 +115,15 @@ export function createPlaceLayer(box) {
102
115
  // the ring sizes written last, so a frame that changes none does not copy the buffer
103
116
  let shapeHeld = new Float32Array(0);
104
117
  let boxes = [];
118
+ let earlyBoxes = [];
119
+ // the names that wait for the layers before them, and the last picture's markers, for `late` and `pick`
120
+ let lateItems = [];
121
+ let lateOwners = [];
122
+ let lateFrom = 0;
123
+ let earlyLabels = 0;
124
+ let lastView = null;
125
+ let lastShapes = [];
126
+ let lastOwn = [];
105
127
  const rings = [];
106
128
  const measures = [];
107
129
  // the groups of the places for the cell they were made with, and the rings' data the picture reads
@@ -176,7 +198,7 @@ export function createPlaceLayer(box) {
176
198
  head.className = "pl-head";
177
199
  root.append(disc, stick, head);
178
200
  box.append(root);
179
- mark = { root, disc, stick, head, kind: "", ring: 0, color: "" };
201
+ mark = { root, disc, stick, head, kind: "", look: "", ring: 0, color: "" };
180
202
  marks[i] = mark;
181
203
  }
182
204
  return mark;
@@ -317,6 +339,12 @@ export function createPlaceLayer(box) {
317
339
  stats.groups = 0;
318
340
  stats.sprites = 0;
319
341
  stats.dots = 0;
342
+ lastView = null;
343
+ lastShapes = [];
344
+ lastOwn = [];
345
+ lateItems = [];
346
+ lateOwners = [];
347
+ earlyLabels = 0;
320
348
  if (sprites && sprites.shapes.some((v) => v !== 0)) {
321
349
  sprites.shapes.fill(0);
322
350
  sprites.shapesVersion += 1;
@@ -324,11 +352,28 @@ export function createPlaceLayer(box) {
324
352
  };
325
353
  return {
326
354
  set(next) {
327
- places = next;
355
+ everything = next;
356
+ lastView = null;
357
+ places = shownPlaces(next, switches);
328
358
  stats.places = next.length;
329
- if (next.length === 0) {
359
+ stats.hidden = next.length - places.length;
360
+ if (places.length === 0) {
330
361
  groups = [];
331
- groupedFor = next;
362
+ groupedFor = places;
363
+ sprites = null;
364
+ }
365
+ },
366
+ get layers() {
367
+ return switches;
368
+ },
369
+ set layers(value) {
370
+ switches = value;
371
+ lastView = null;
372
+ places = shownPlaces(everything, switches);
373
+ stats.hidden = everything.length - places.length;
374
+ if (places.length === 0) {
375
+ groups = [];
376
+ groupedFor = places;
332
377
  sprites = null;
333
378
  }
334
379
  },
@@ -368,6 +413,7 @@ export function createPlaceLayer(box) {
368
413
  if (places.length > 0)
369
414
  stats.renders += 1;
370
415
  boxes = [];
416
+ earlyBoxes = [];
371
417
  return;
372
418
  }
373
419
  stats.renders += 1;
@@ -399,7 +445,10 @@ export function createPlaceLayer(box) {
399
445
  const chosen = [...singles.filter((g) => places[groups[g].members[0]].kind === "here"), ...singles.filter((g) => places[groups[g].members[0]].kind !== "here")].slice(0, PLACE_MARKS);
400
446
  const own = chosen.map((g) => places[groups[g].members[0]]);
401
447
  measureAll(own);
402
- const layout = layoutPlaces(own, view, look, { size: (place) => size(place), taken, sun });
448
+ const layout = layoutPlaces(own, view, look, { size: (place) => (place.namePriority === "low" ? null : size(place)), taken, sun });
449
+ lastView = view;
450
+ lastShapes = layout.shapes;
451
+ lastOwn = own;
403
452
  // favourites first, so a `here` marker is drawn over them
404
453
  const order = [...layout.shapes].sort((a, b) => (own[a.index].kind === "here" ? 1 : 0) - (own[b.index].kind === "here" ? 1 : 0));
405
454
  for (const [i, shape] of order.entries()) {
@@ -410,6 +459,11 @@ export function createPlaceLayer(box) {
410
459
  mark.kind = kind;
411
460
  mark.root.dataset["kind"] = kind;
412
461
  }
462
+ const shown = place.look ?? look;
463
+ if (mark.look !== shown) {
464
+ mark.look = shown;
465
+ mark.root.dataset["look"] = shown;
466
+ }
413
467
  if (mark.ring !== shape.ring) {
414
468
  mark.ring = shape.ring;
415
469
  mark.root.style.setProperty("--r", `${shape.ring}px`);
@@ -433,6 +487,16 @@ export function createPlaceLayer(box) {
433
487
  }
434
488
  hideFrom(marks.map((m) => m.root), order.length);
435
489
  const nightOf = new Map(layout.shapes.map((shape) => [shape.index, shape.night]));
490
+ lateItems = [];
491
+ lateOwners = [];
492
+ for (const shape of layout.shapes) {
493
+ const place = own[shape.index];
494
+ const found = place.namePriority === "low" ? size(place) : null;
495
+ if (!found)
496
+ continue;
497
+ lateItems.push({ x: shape.tipX, y: shape.tipY, r: (place.look ?? look) === "ring" ? shape.ring : 3, w: found.width, h: found.height, priority: 0 });
498
+ lateOwners.push(place);
499
+ }
436
500
  for (const [i, spot] of layout.labels.entries()) {
437
501
  const place = own[spot.index];
438
502
  showName(nameAt(i), place.label ?? "", place.kind === "here" ? "here" : "favourite", spot.left, spot.top, place.color, (nightOf.get(spot.index) ?? 0) > 0.5);
@@ -467,7 +531,7 @@ export function createPlaceLayer(box) {
467
531
  const group = groups[g];
468
532
  const n = group.members.length;
469
533
  const first = places[group.members[0]];
470
- const ring = n > 1 ? Math.min(14, 6 + 2.2 * Math.log2(n)) : RING[first.kind === "here" ? "here" : "favourite"];
534
+ const ring = n > 1 ? Math.min(14, 6 + 2.2 * Math.log2(n)) : RING[first.kind === "here" ? "here" : "favourite"] * (first.size === "small" ? SMALL_RING : 1);
471
535
  shapes[g * 2] = ring;
472
536
  shapes[g * 2 + 1] = n > 1 ? 0.3 : 0;
473
537
  if (fallback) {
@@ -553,14 +617,17 @@ export function createPlaceLayer(box) {
553
617
  used += 1;
554
618
  }
555
619
  hideFrom(names, used);
556
- boxes = busy.slice(taken.length);
620
+ earlyBoxes = busy.slice(taken.length);
557
621
  for (const spot of placed)
558
- boxes.push({ left: spot.left, top: spot.top, width: items[spot.item].w, height: items[spot.item].h });
622
+ earlyBoxes.push({ left: spot.left, top: spot.top, width: items[spot.item].w, height: items[spot.item].h });
559
623
  for (const shape of layout.shapes)
560
- boxes.push({ left: shape.tipX - 5, top: shape.tipY - 5, width: 10, height: 10 });
624
+ earlyBoxes.push({ left: shape.tipX - 5, top: shape.tipY - 5, width: 10, height: 10 });
561
625
  // the ring round each satellite that can be seen: other layers' names keep off it as they keep off its name
562
626
  for (const mark of seen)
563
- boxes.push({ left: mark.x - SATELLITE_RING, top: mark.y - SATELLITE_RING, width: SATELLITE_RING * 2, height: SATELLITE_RING * 2 });
627
+ earlyBoxes.push({ left: mark.x - SATELLITE_RING, top: mark.y - SATELLITE_RING, width: SATELLITE_RING * 2, height: SATELLITE_RING * 2 });
628
+ boxes = earlyBoxes;
629
+ lateFrom = used;
630
+ earlyLabels = layout.labels.length;
564
631
  stats.shown = shown;
565
632
  stats.marks = order.length;
566
633
  stats.labels = layout.labels.length;
@@ -574,6 +641,58 @@ export function createPlaceLayer(box) {
574
641
  get boxes() {
575
642
  return boxes;
576
643
  },
644
+ get earlyBoxes() {
645
+ return earlyBoxes;
646
+ },
647
+ late(taken) {
648
+ if (lateItems.length === 0 || !lastView)
649
+ return;
650
+ const placed = placeLabels(lateItems, lastView.width, lastView.height, 16, 64, [...(taken?.() ?? []), ...earlyBoxes]);
651
+ let at = lateFrom;
652
+ const added = [];
653
+ for (const spot of placed) {
654
+ const place = lateOwners[spot.item];
655
+ showName(nameAt(at), place.label ?? "", place.kind === "here" ? "here" : "favourite", spot.left, spot.top, place.color, false);
656
+ added.push({ left: spot.left, top: spot.top, width: lateItems[spot.item].w, height: lateItems[spot.item].h });
657
+ at += 1;
658
+ }
659
+ hideFrom(names, at);
660
+ boxes = [...earlyBoxes, ...added];
661
+ stats.labels = earlyLabels + placed.length;
662
+ },
663
+ pick(x, y) {
664
+ if (!lastView || !groupedFor)
665
+ return null;
666
+ const marked = new Set();
667
+ let best = null;
668
+ let near = PRESS_REACH;
669
+ for (const shape of lastShapes) {
670
+ const place = lastOwn[shape.index];
671
+ marked.add(place);
672
+ // the foot, or anywhere along the stick from the foot to its top
673
+ const dx = shape.tipX - shape.x;
674
+ const dy = shape.tipY - shape.y;
675
+ const along = dx === 0 && dy === 0 ? 0 : Math.max(0, Math.min(1, ((x - shape.x) * dx + (y - shape.y) * dy) / (dx * dx + dy * dy)));
676
+ const d = Math.hypot(x - (shape.x + dx * along), y - (shape.y + dy * along));
677
+ if (d < near || (d === near && best === null)) {
678
+ best = place;
679
+ near = d;
680
+ }
681
+ }
682
+ for (const group of groups) {
683
+ if (group.members.length !== 1)
684
+ continue;
685
+ const place = groupedFor[group.members[0]];
686
+ if (marked.has(place) || !lastView.at(group.lon, group.lat, point) || point.facing <= EDGE)
687
+ continue;
688
+ const d = Math.hypot(x - point.x, y - point.y);
689
+ if (d < near) {
690
+ best = place;
691
+ near = d;
692
+ }
693
+ }
694
+ return best;
695
+ },
577
696
  dispose() {
578
697
  watcher?.disconnect();
579
698
  fonts?.removeEventListener?.("loadingdone", refit);
@@ -38,6 +38,14 @@ export interface Place {
38
38
  kind?: PlaceKind;
39
39
  /** A CSS colour for this place alone (`#e8475f`, `rgb(...)`, `hsl(...)` or a colour's name); left out, the kind's colour. */
40
40
  color?: string;
41
+ /** A set of places (spaceports, harbours) the page shows or hides together with `place-layers`; left out, the place is always shown. */
42
+ layer?: string;
43
+ /** `small` draws a shorter, narrower mark; left out, the kind's own size. */
44
+ size?: PlaceSize;
45
+ /** How this place is drawn, over `places-look`; left out, `places-look`. */
46
+ look?: PlaceLook;
47
+ /** `low` lays this place's name after the cities' names, so it is shown only where it lies over none of them; left out (`high`), it is laid before them. */
48
+ namePriority?: PlaceNamePriority;
41
49
  }
42
50
  /**
43
51
  * How a place is drawn: `beam` (a light rising out of the ground with a ring at its foot), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground).
@@ -62,6 +70,30 @@ export type PlaceLook = "beam" | "pin" | "ring";
62
70
  * ```
63
71
  */
64
72
  export declare const PLACE_LOOKS: readonly PlaceLook[];
73
+ /**
74
+ * How big a place's mark is: `normal` (the default) or `small`, a shorter, narrower stick and a smaller ring, so a harbour can stand beside a city and "You are here" stays the tall beam.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import type { PlaceSize } from "@johnmorrisdotca/chikyu-earth/markers";
79
+ *
80
+ * const size: PlaceSize = "small";
81
+ * console.log(size);
82
+ * ```
83
+ */
84
+ export type PlaceSize = "normal" | "small";
85
+ /**
86
+ * Where a place's name is laid among the others: `high` (the default) before the cities' names, which then keep clear of it, or `low`, after them, so the name is left out where a city's name is.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * import type { PlaceNamePriority } from "@johnmorrisdotca/chikyu-earth/markers";
91
+ *
92
+ * const priority: PlaceNamePriority = "low";
93
+ * console.log(priority);
94
+ * ```
95
+ */
96
+ export type PlaceNamePriority = "high" | "low";
65
97
  /**
66
98
  * The most places one element draws; the rest of a longer list are left out.
67
99
  *
@@ -200,10 +232,13 @@ export interface PlaceLayoutOptions {
200
232
  /** Where the Sun is overhead, for each shape's `night`; left out (or null), every place is in daylight. */
201
233
  sun?: GeoPoint | null;
202
234
  }
235
+ /** What a `small` place's stick and ring are of the kind's own. */
236
+ export declare const SMALL_LENGTH = 0.55;
237
+ export declare const SMALL_RING = 0.7;
203
238
  /**
204
239
  * The places of a list a page handed over, made safe to draw: each needs a longitude from -180 to 180 and a latitude from -90 to 90; one without an `id` is given its place in the list, a
205
- * label is cut to 80 letters, a kind that is not `here` is `favourite`, and a colour is kept only when it is a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name. Anything else is left out,
206
- * and at most {@link MAX_PLACES} are kept.
240
+ * label is cut to 80 letters, a kind that is not `here` is `favourite`, and a colour is kept only when it is a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name. A `layer` is cut to 40 letters,
241
+ * a `size` is kept only when it is `small`, a `look` only when it is one of {@link PLACE_LOOKS} and a `namePriority` only when it is `low`. Anything else is left out, and at most {@link MAX_PLACES} are kept.
207
242
  *
208
243
  * @param list - What the page gave: an array of places, or anything.
209
244
  * @returns The places to draw.
@@ -212,7 +247,7 @@ export interface PlaceLayoutOptions {
212
247
  * ```ts
213
248
  * import { cleanPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
214
249
  *
215
- * console.log(cleanPlaces([{ lon: 2.35, lat: 48.86, label: "Paris", color: "#e8475f" }, { lon: 500, lat: 0 }]));
250
+ * console.log(cleanPlaces([{ lon: 2.35, lat: 48.86, label: "Paris", color: "#e8475f" }, { lon: 500, lat: 0 }, { id: "yvr", lon: -123.18, lat: 49.19, layer: "airports", size: "small", look: "ring" }]));
216
251
  * ```
217
252
  */
218
253
  export declare function cleanPlaces(list: unknown): Place[];
@@ -273,7 +308,7 @@ export declare function orthoView(pose: Pose & {
273
308
  *
274
309
  * @param places - The places, as {@link cleanPlaces} makes them.
275
310
  * @param view - The picture.
276
- * @param look - `beam`, `pin` or `ring`.
311
+ * @param look - `beam`, `pin` or `ring`, for each place that has no `look` of its own; a `small` place has a shorter stick and a smaller ring.
277
312
  * @param options - The size of each name, boxes already used, the most names (16) and where the Sun is overhead.
278
313
  * @returns The markers to draw and where the names go.
279
314
  *
@@ -362,3 +397,34 @@ export declare function groupPlaces(places: readonly Place[], cell: number): Pla
362
397
  * ```
363
398
  */
364
399
  export declare const readPlaceGroups: (value: string | null) => boolean;
400
+ /**
401
+ * Which layers of places are shown (the attribute `place-layers`): a JSON object of layer names to true or false, such as `{"harbours":false}`. A layer that is not named is shown, and so is a place with no layer. Anything
402
+ * that is not an object of that kind is no switches.
403
+ *
404
+ * @param value - The attribute's text, or null.
405
+ * @returns The switches, a name to whether it is shown.
406
+ *
407
+ * @example
408
+ * ```ts
409
+ * import { readPlaceLayers } from "@johnmorrisdotca/chikyu-earth/markers";
410
+ *
411
+ * console.log(readPlaceLayers('{"harbours":false,"airports":true}')); // { harbours: false, airports: true }
412
+ * ```
413
+ */
414
+ export declare function readPlaceLayers(value: string | null | undefined): Record<string, boolean>;
415
+ /**
416
+ * The places whose layer is shown: a place with no layer is always in, and a layer is in unless `layers` says `false` for it. The list is returned as it came when nothing is left out.
417
+ *
418
+ * @param places - The places, as {@link cleanPlaces} makes them.
419
+ * @param layers - The switches, a layer's name to whether it is shown ({@link readPlaceLayers}).
420
+ * @returns The places to draw.
421
+ *
422
+ * @example
423
+ * ```ts
424
+ * import { shownPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
425
+ *
426
+ * const places = [{ id: "yvr", lon: -123.18, lat: 49.19, layer: "airports" }, { id: "cavan", lon: -123.1, lat: 49.29, layer: "harbours" }, { id: "me", lon: -79.4, lat: 43.7 }];
427
+ * console.log(shownPlaces(places, { harbours: false }).map((place) => place.id)); // ["yvr", "me"]
428
+ * ```
429
+ */
430
+ export declare function shownPlaces(places: readonly Place[], layers: Readonly<Record<string, boolean>>): readonly Place[];