isard 1.5.0 → 1.7.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 +213 -1
- package/README.md +3 -2
- package/dist/basemap/furniture.d.ts +26 -0
- package/dist/basemap/furniture.js +95 -0
- package/dist/basemap/furniture.js.map +1 -0
- package/dist/basemap/meshes.d.ts +21 -0
- package/dist/basemap/meshes.js +159 -0
- package/dist/basemap/meshes.js.map +1 -0
- package/dist/basemap/placed.d.ts +13 -0
- package/dist/basemap/placed.js +14 -0
- package/dist/basemap/placed.js.map +1 -0
- package/dist/basemap/trees.d.ts +25 -8
- package/dist/basemap/trees.js +77 -105
- package/dist/basemap/trees.js.map +1 -1
- package/dist/basemap/vectorstyle.d.ts +9 -3
- package/dist/basemap/vectorstyle.js +5 -6
- package/dist/basemap/vectorstyle.js.map +1 -1
- package/dist/basemap/vectortiles/context.d.ts +7 -2
- package/dist/basemap/vectortiles/context.js.map +1 -1
- package/dist/basemap/vectortiles/extrusions.d.ts +4 -0
- package/dist/basemap/vectortiles/extrusions.js +9 -3
- package/dist/basemap/vectortiles/extrusions.js.map +1 -1
- package/dist/basemap/vectortiles/furniture.d.ts +19 -0
- package/dist/basemap/vectortiles/furniture.js +29 -0
- package/dist/basemap/vectortiles/furniture.js.map +1 -0
- package/dist/basemap/vectortiles/labels.d.ts +3 -0
- package/dist/basemap/vectortiles/labels.js +50 -18
- package/dist/basemap/vectortiles/labels.js.map +1 -1
- package/dist/basemap/vectortiles/lamps.d.ts +23 -0
- package/dist/basemap/vectortiles/lamps.js +25 -0
- package/dist/basemap/vectortiles/lamps.js.map +1 -0
- package/dist/basemap/vectortiles/placed.d.ts +38 -0
- package/dist/basemap/vectortiles/placed.js +143 -0
- package/dist/basemap/vectortiles/placed.js.map +1 -0
- package/dist/basemap/vectortiles/requests.d.ts +4 -0
- package/dist/basemap/vectortiles/requests.js +15 -2
- package/dist/basemap/vectortiles/requests.js.map +1 -1
- package/dist/basemap/vectortiles/street-wind.js +4 -6
- package/dist/basemap/vectortiles/street-wind.js.map +1 -1
- package/dist/basemap/vectortiles/trees.d.ts +2 -0
- package/dist/basemap/vectortiles/trees.js +40 -86
- package/dist/basemap/vectortiles/trees.js.map +1 -1
- package/dist/basemap/vectortiles/vectors.d.ts +16 -0
- package/dist/basemap/vectortiles/vectors.js +76 -11
- package/dist/basemap/vectortiles/vectors.js.map +1 -1
- package/dist/basemap/vectortiles.d.ts +37 -7
- package/dist/basemap/vectortiles.js +78 -17
- package/dist/basemap/vectortiles.js.map +1 -1
- package/dist/basemap/wmts.js +2 -2
- package/dist/basemap/wmts.js.map +1 -1
- package/dist/basemap.worker.js +2 -2
- package/dist/basemap.worker.js.map +19 -13
- package/dist/bind/layers.js +1 -0
- package/dist/bind/layers.js.map +1 -1
- package/dist/data/collada.d.ts +19 -0
- package/dist/data/collada.js +305 -0
- package/dist/data/collada.js.map +1 -0
- package/dist/data/crs.js +1 -1
- package/dist/data/crs.js.map +1 -1
- package/dist/data/ifc.d.ts +100 -0
- package/dist/data/ifc.js +371 -0
- package/dist/data/ifc.js.map +1 -0
- package/dist/decoder.worker.js +5 -5
- package/dist/decoder.worker.js.map +3 -3
- package/dist/formats.d.ts +7 -2
- package/dist/formats.js +7 -2
- package/dist/formats.js.map +1 -1
- package/dist/geoplateforme.d.ts +14 -2
- package/dist/geoplateforme.js +24 -2
- package/dist/geoplateforme.js.map +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/isard_bg.wasm +0 -0
- package/dist/isard_core_bg.wasm +0 -0
- package/dist/isard_grid_bg.wasm +0 -0
- package/dist/isard_tess_bg.wasm +0 -0
- package/dist/layers/extrusions.d.ts +10 -0
- package/dist/layers/extrusions.js +33 -6
- package/dist/layers/extrusions.js.map +1 -1
- package/dist/layers/features.d.ts +0 -2
- package/dist/layers/features.js +5 -6
- package/dist/layers/features.js.map +1 -1
- package/dist/layers/layers.d.ts +14 -0
- package/dist/layers/layers.js +55 -1
- package/dist/layers/layers.js.map +1 -1
- package/dist/layers/panoramas.d.ts +32 -10
- package/dist/layers/panoramas.js +55 -28
- package/dist/layers/panoramas.js.map +1 -1
- package/dist/layers/photos.d.ts +48 -0
- package/dist/layers/photos.js +139 -0
- package/dist/layers/photos.js.map +1 -0
- package/dist/layers/symbols.d.ts +5 -1
- package/dist/layers/symbols.js +111 -32
- package/dist/layers/symbols.js.map +1 -1
- package/dist/layers/trees.d.ts +28 -0
- package/dist/layers/trees.js +51 -0
- package/dist/layers/trees.js.map +1 -0
- package/dist/layers/vectors.d.ts +29 -2
- package/dist/layers/vectors.js +98 -9
- package/dist/layers/vectors.js.map +1 -1
- package/dist/map/frame-loop.d.ts +2 -0
- package/dist/map/frame-loop.js +3 -3
- package/dist/map/frame-loop.js.map +1 -1
- package/dist/map/layer-spec.d.ts +3 -0
- package/dist/map/layer-spec.js +2 -0
- package/dist/map/layer-spec.js.map +1 -1
- package/dist/map.d.ts +8 -0
- package/dist/map.js +32 -2
- package/dist/map.js.map +1 -1
- package/dist/panoramax.d.ts +55 -0
- package/dist/panoramax.js +97 -0
- package/dist/panoramax.js.map +1 -0
- package/dist/react/Layer.d.ts +1 -0
- package/dist/react/Layer.js.map +1 -1
- package/dist/react/VectorGeometry.d.ts +22 -8
- package/dist/react/VectorGeometry.js +36 -14
- package/dist/react/VectorGeometry.js.map +1 -1
- package/dist/react/VectorTiles.d.ts +65 -0
- package/dist/react/VectorTiles.js +112 -0
- package/dist/react/VectorTiles.js.map +1 -0
- package/dist/react/context.d.ts +9 -0
- package/dist/react/context.js +32 -0
- package/dist/react/context.js.map +1 -1
- package/dist/react/index.d.ts +7 -1
- package/dist/react/index.js +7 -1
- package/dist/react/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.js.map +1 -1
- package/dist/util/geo.d.ts +8 -0
- package/dist/util/geo.js +8 -0
- package/dist/util/geo.js.map +1 -1
- package/dist/util/gltf.d.ts +26 -0
- package/dist/util/gltf.js +52 -0
- package/dist/util/gltf.js.map +1 -0
- package/dist/util/roofs.d.ts +18 -0
- package/dist/util/roofs.js +44 -0
- package/dist/util/roofs.js.map +1 -0
- package/dist/util/style-floats.d.ts +33 -0
- package/dist/util/style-floats.js +34 -0
- package/dist/util/style-floats.js.map +1 -0
- package/dist/util/sun.js +1 -1
- package/dist/util/sun.js.map +1 -1
- package/dist/wasm/isard.d.ts +56 -17
- package/dist/wasm/isard.js +128 -18
- package/dist/wasm/isard_core.d.ts +44 -17
- package/dist/wasm/isard_core.js +104 -18
- package/dist/wasm/isard_tess.d.ts +6 -3
- package/dist/wasm/isard_tess.js +27 -4
- package/dist/workers/basemap/furniture.d.ts +13 -0
- package/dist/workers/basemap/geometry.d.ts +35 -22
- package/dist/workers/basemap/labels.d.ts +18 -2
- package/dist/workers/basemap/lamps.d.ts +10 -0
- package/dist/workers/basemap/tiles.d.ts +2 -0
- package/dist/workers/basemap/trees.d.ts +6 -1
- package/dist/workers/basemap.worker.d.ts +58 -2
- package/dist/workers/basemap.worker.js +26 -3
- package/dist/workers/basemap.worker.js.map +1 -1
- package/package.json +1 -1
package/dist/layers/vectors.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface VectorSublayer {
|
|
|
13
13
|
id: string;
|
|
14
14
|
/** Its source layer, if any (not for a background) */
|
|
15
15
|
sourceLayer: string | undefined;
|
|
16
|
-
kind: 'fill' | 'line' | 'extrusion';
|
|
16
|
+
kind: 'fill' | 'line' | 'extrusion' | 'circle';
|
|
17
17
|
minZoom: number;
|
|
18
18
|
maxZoom: number;
|
|
19
19
|
visible: boolean;
|
|
@@ -21,8 +21,19 @@ export interface VectorSublayer {
|
|
|
21
21
|
* it) */
|
|
22
22
|
opacity: Size;
|
|
23
23
|
dash: [number, number, number, number];
|
|
24
|
-
/** The caps of its lines' ends (`line-cap
|
|
24
|
+
/** The caps of its lines' ends (`line-cap`) */
|
|
25
25
|
cap: 'butt' | 'round' | 'square';
|
|
26
|
+
/** The joins of its lines' pieces (`line-join`), a miter longer than `miterLimit` line widths bevelled
|
|
27
|
+
* (`line-miter-limit`); round and 2 if left out */
|
|
28
|
+
join?: 'miter' | 'bevel' | 'round';
|
|
29
|
+
miterLimit?: number;
|
|
30
|
+
/** How far its fills or lines move on screen (`fill-translate`, `line-translate`: CSS pixels, x right, y down),
|
|
31
|
+
* turning with the map or staying on the screen (`*-translate-anchor`); none and `map` if left out */
|
|
32
|
+
translate?: [number, number];
|
|
33
|
+
translateAnchor?: 'map' | 'viewport';
|
|
34
|
+
/** Its fills have patterns (`fill-pattern`, `background-pattern`): over the relief, the engine finds the ground under
|
|
35
|
+
* them */
|
|
36
|
+
patterned?: boolean;
|
|
26
37
|
/** Its lines glow at night (the streets: its id names a road, not its casing; `setSun`) */
|
|
27
38
|
lit: boolean;
|
|
28
39
|
}
|
|
@@ -33,10 +44,16 @@ export type VectorFeature = Feature<Record<string, unknown>> & {
|
|
|
33
44
|
};
|
|
34
45
|
export declare class VectorLayer extends Layer {
|
|
35
46
|
private readonly tiles;
|
|
47
|
+
/** The tiles waiting for their upload (`UPLOAD_MS` a frame), each with what resolves its `setTile`; `sent`: in the
|
|
48
|
+
* engine already, its blocks still uploading */
|
|
49
|
+
private readonly queue;
|
|
50
|
+
private flushing;
|
|
36
51
|
private sublayers;
|
|
37
52
|
private nextKey;
|
|
38
53
|
/** The whole layer shown (`setVisible`), over each style layer's visibility */
|
|
39
54
|
private shown;
|
|
55
|
+
/** Its buildings' walls show their windows (`setFacades`) */
|
|
56
|
+
private facades;
|
|
40
57
|
/** Resolves once the style is loaded, its layers drawn known (`layers`), and the map has drawn the layer; rejected
|
|
41
58
|
* if the style fails */
|
|
42
59
|
get ready(): Promise<void>;
|
|
@@ -44,6 +61,14 @@ export declare class VectorLayer extends Layer {
|
|
|
44
61
|
get layers(): readonly VectorSublayer[];
|
|
45
62
|
/** Keys of the tiles held (`z/x/y`) */
|
|
46
63
|
get tileKeys(): string[];
|
|
64
|
+
/** Uploads the waiting tiles on the next frame */
|
|
65
|
+
private flushSoon;
|
|
66
|
+
/** Uploads waiting tiles for `UPLOAD_MS` at most (one at least, or a part of its blocks), the rest on the next
|
|
67
|
+
* frames; a tile's `setTile` resolves once its blocks are all there */
|
|
68
|
+
private flush;
|
|
69
|
+
/** Sends a tile to the engine (its blocks' first part); its key */
|
|
70
|
+
private upload;
|
|
71
|
+
remove(): void;
|
|
47
72
|
/** The feature of a picked index (no geometry: the tiles hold it cut), its properties and style layer. Tiles are
|
|
48
73
|
* numbered one after the other, in the order they were first added */
|
|
49
74
|
featureAt(index: number): VectorFeature | undefined;
|
|
@@ -53,6 +78,8 @@ export declare class VectorLayer extends Layer {
|
|
|
53
78
|
/** Changes a layout property of a style layer drawn (`visibility`: shown or hidden at once), as MapLibre's
|
|
54
79
|
* `setLayoutProperty` */
|
|
55
80
|
setLayoutProperty(layer: string, name: string, value: unknown): void;
|
|
81
|
+
/** Whether its buildings' walls show their windows: glass by day, some lit at night (only the lit ones without) */
|
|
82
|
+
setFacades(facades: boolean): void;
|
|
56
83
|
setVisible(visible: boolean): void;
|
|
57
84
|
private sendSublayers;
|
|
58
85
|
/** A tile to the engine: its mesh uploaded as it is, or without one its geometry, which the engine makes ready */
|
package/dist/layers/vectors.js
CHANGED
|
@@ -4,14 +4,24 @@
|
|
|
4
4
|
* tiles again. The workers cut each vector tile into polygons and lines and style its features; the engine draws the
|
|
5
5
|
* style's layers in their order, each over its zoom range.
|
|
6
6
|
*/
|
|
7
|
-
import { FLOATS
|
|
7
|
+
import { FLOATS } from "../util/style-floats.js";
|
|
8
|
+
import { stops } from "./features.js";
|
|
8
9
|
import { Layer } from "./layers.js";
|
|
10
|
+
/** The main thread's time a frame gives to uploading tiles (ms): tiles arriving together are uploaded over several
|
|
11
|
+
* frames, not all in the one (copying a tile's buffers to the GPU takes milliseconds) */
|
|
12
|
+
const UPLOAD_MS = 4;
|
|
9
13
|
export class VectorLayer extends Layer {
|
|
10
14
|
tiles = new Map();
|
|
15
|
+
/** The tiles waiting for their upload (`UPLOAD_MS` a frame), each with what resolves its `setTile`; `sent`: in the
|
|
16
|
+
* engine already, its blocks still uploading */
|
|
17
|
+
queue = new Map();
|
|
18
|
+
flushing = false;
|
|
11
19
|
sublayers = [];
|
|
12
20
|
nextKey = 0;
|
|
13
21
|
/** The whole layer shown (`setVisible`), over each style layer's visibility */
|
|
14
22
|
shown = true;
|
|
23
|
+
/** Its buildings' walls show their windows (`setFacades`) */
|
|
24
|
+
facades = false;
|
|
15
25
|
/** @internal Resolved once the style is loaded and its layers drawn known (set by its `VectorTiles`) */
|
|
16
26
|
styled = Promise.resolve();
|
|
17
27
|
/** @internal Changes a property of a style layer drawn (set by its `VectorTiles`) */
|
|
@@ -41,24 +51,93 @@ export class VectorLayer extends Layer {
|
|
|
41
51
|
this.sendSublayers(this.map.engine, this.id);
|
|
42
52
|
this.map.requestRender();
|
|
43
53
|
}
|
|
44
|
-
/** @internal Adds or replaces a tile, cut by the workers (and made ready for the GPU there, with its mesh)
|
|
54
|
+
/** @internal Adds or replaces a tile, cut by the workers (and made ready for the GPU there, with its mesh): uploaded
|
|
55
|
+
* on a coming frame, within its share of the frame (`UPLOAD_MS`); resolves once it is (or once dropped meanwhile) */
|
|
45
56
|
setTile(tile, vectors) {
|
|
57
|
+
if (this.removed)
|
|
58
|
+
return Promise.resolve();
|
|
59
|
+
// The map not idle until it is uploaded
|
|
60
|
+
return this.map.track(new Promise((uploaded) => {
|
|
61
|
+
// A newer cut of a tile still waiting takes its place
|
|
62
|
+
this.queue.get(tile)?.uploaded();
|
|
63
|
+
this.queue.set(tile, { vectors, uploaded });
|
|
64
|
+
this.flushSoon();
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
/** Uploads the waiting tiles on the next frame */
|
|
68
|
+
flushSoon() {
|
|
69
|
+
if (this.flushing)
|
|
70
|
+
return;
|
|
71
|
+
this.flushing = true;
|
|
72
|
+
requestAnimationFrame(() => {
|
|
73
|
+
this.flushing = false;
|
|
74
|
+
this.flush();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** Uploads waiting tiles for `UPLOAD_MS` at most (one at least, or a part of its blocks), the rest on the next
|
|
78
|
+
* frames; a tile's `setTile` resolves once its blocks are all there */
|
|
79
|
+
flush() {
|
|
80
|
+
// Removed meanwhile, or between two engines (the new one asks for the tiles again)
|
|
81
|
+
if (this.id < 0)
|
|
82
|
+
return;
|
|
83
|
+
const start = performance.now();
|
|
84
|
+
const within = () => performance.now() - start <= UPLOAD_MS;
|
|
85
|
+
for (const [tile, waiting] of this.queue) {
|
|
86
|
+
waiting.sent ??= this.upload(tile, waiting.vectors);
|
|
87
|
+
// A large tile's blocks (a pitched view's far tiles of a city: 10 MB and more), a part at a time
|
|
88
|
+
let left = this.map.engine.uploadVectorTile(this.id, waiting.sent);
|
|
89
|
+
while (left && within())
|
|
90
|
+
left = this.map.engine.uploadVectorTile(this.id, waiting.sent);
|
|
91
|
+
if (left)
|
|
92
|
+
break;
|
|
93
|
+
this.queue.delete(tile);
|
|
94
|
+
waiting.uploaded();
|
|
95
|
+
if (!within())
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (this.queue.size > 0)
|
|
99
|
+
this.flushSoon();
|
|
100
|
+
this.map.requestRender();
|
|
101
|
+
}
|
|
102
|
+
/** Sends a tile to the engine (its blocks' first part); its key */
|
|
103
|
+
upload(tile, vectors) {
|
|
46
104
|
const key = this.tiles.get(tile)?.key ?? this.nextKey++;
|
|
47
105
|
const { properties, sublayer } = vectors;
|
|
48
106
|
this.tiles.set(tile, { key, vectors: { properties, sublayer } });
|
|
49
107
|
this.sendTile(this.map.engine, this.id, key, vectors);
|
|
50
|
-
|
|
108
|
+
return key;
|
|
51
109
|
}
|
|
52
110
|
/** @internal New styles of a tile's features, as the workers evaluated them (the same features) */
|
|
53
111
|
setTileStyles(tile, styles) {
|
|
112
|
+
const waiting = this.queue.get(tile);
|
|
113
|
+
// Not uploaded yet: uploaded with them
|
|
114
|
+
if (waiting && waiting.sent === undefined) {
|
|
115
|
+
if (styles.length === waiting.vectors.properties.length * FLOATS)
|
|
116
|
+
waiting.vectors.styles = styles;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
54
119
|
const t = this.tiles.get(tile);
|
|
55
120
|
if (!t || styles.length !== t.vectors.properties.length * FLOATS)
|
|
56
121
|
return;
|
|
57
122
|
this.map.engine.setFeatureStyle(this.id, styles, t.key);
|
|
58
123
|
this.map.requestRender();
|
|
59
124
|
}
|
|
125
|
+
remove() {
|
|
126
|
+
super.remove();
|
|
127
|
+
this.dispose();
|
|
128
|
+
}
|
|
129
|
+
/** @internal The tiles waiting resolved (dropped), none held */
|
|
130
|
+
dispose() {
|
|
131
|
+
this.queue.forEach((waiting) => {
|
|
132
|
+
waiting.uploaded();
|
|
133
|
+
});
|
|
134
|
+
this.queue.clear();
|
|
135
|
+
this.tiles.clear();
|
|
136
|
+
}
|
|
60
137
|
/** @internal */
|
|
61
138
|
removeTile(tile) {
|
|
139
|
+
this.queue.get(tile)?.uploaded();
|
|
140
|
+
this.queue.delete(tile);
|
|
62
141
|
const t = this.tiles.get(tile);
|
|
63
142
|
if (!t)
|
|
64
143
|
return;
|
|
@@ -96,6 +175,12 @@ export class VectorLayer extends Layer {
|
|
|
96
175
|
setLayoutProperty(layer, name, value) {
|
|
97
176
|
this.restyle?.(layer, 'layout', name, value);
|
|
98
177
|
}
|
|
178
|
+
/** Whether its buildings' walls show their windows: glass by day, some lit at night (only the lit ones without) */
|
|
179
|
+
setFacades(facades) {
|
|
180
|
+
this.facades = facades;
|
|
181
|
+
this.map.engine.setFacades(this.id, facades);
|
|
182
|
+
this.map.requestRender();
|
|
183
|
+
}
|
|
99
184
|
setVisible(visible) {
|
|
100
185
|
this.shown = visible;
|
|
101
186
|
this.sendSublayers(this.map.engine, this.id);
|
|
@@ -103,26 +188,30 @@ export class VectorLayer extends Layer {
|
|
|
103
188
|
}
|
|
104
189
|
sendSublayers(engine, id) {
|
|
105
190
|
const s = this.sublayers;
|
|
106
|
-
engine.setVectorSublayers(id, Uint8Array.from(s, (l) => ({ fill: 0, line: 1, extrusion: 2 })[l.kind]), Float64Array.from(s.flatMap((l) => [l.minZoom, l.maxZoom])), Uint8Array.from(s, (l) => (l.visible && this.shown ? 1 : 0)), Float32Array.from(s.flatMap((l) => l.dash)), Float32Array.from(s.flatMap((l) => stops(l.opacity))), Uint8Array.from(s, (l) => ({ butt: 0, round: 1, square: 2 })[l.cap]), Uint8Array.from(s, (l) => (l.lit ? 1 : 0)));
|
|
191
|
+
engine.setVectorSublayers(id, Uint8Array.from(s, (l) => ({ fill: 0, line: 1, extrusion: 2, circle: 3 })[l.kind]), Float64Array.from(s.flatMap((l) => [l.minZoom, l.maxZoom])), Uint8Array.from(s, (l) => (l.visible && this.shown ? 1 : 0)), Float32Array.from(s.flatMap((l) => l.dash)), Float32Array.from(s.flatMap((l) => stops(l.opacity))), Uint8Array.from(s, (l) => ({ butt: 0, round: 1, square: 2 })[l.cap]), Uint8Array.from(s, (l) => (l.lit ? 1 : 0)), Float32Array.from(s.flatMap((l) => [{ round: 0, miter: 1, bevel: 2 }[l.join ?? 'round'], l.miterLimit ?? 2])), Float32Array.from(s.flatMap((l) => [...(l.translate ?? [0, 0]), l.translateAnchor === 'viewport' ? 1 : 0])), Uint8Array.from(s, (l) => (l.patterned ? 1 : 0)));
|
|
107
192
|
}
|
|
108
193
|
/** A tile to the engine: its mesh uploaded as it is, or without one its geometry, which the engine makes ready */
|
|
109
194
|
sendTile(engine, id, key, vectors) {
|
|
110
|
-
const { fills, lines, styles, properties, mesh } = vectors;
|
|
195
|
+
const { fills, lines, circles, styles, properties, mesh } = vectors;
|
|
111
196
|
if (mesh) {
|
|
112
197
|
engine.setVectorTileMesh(id, key, fills.points, fills.ringStart, fills.polygonStart, fills.feature, fills.fillStart, mesh.vertices, mesh.indices, mesh.fillRanges, mesh.prism, mesh.pieces, mesh.lineTable, mesh.lineRanges, mesh.blocks, mesh.blockIndices, mesh.blockRanges, mesh.bounds, properties.length);
|
|
113
|
-
engine.setFeatureStyle(id, styles, key);
|
|
114
|
-
return;
|
|
115
198
|
}
|
|
116
|
-
|
|
199
|
+
else {
|
|
200
|
+
engine.setVectorTile(id, key, fills.points, fills.ringStart, fills.polygonStart, fills.feature, fills.fillStart, lines.points, lines.start, lines.feature, lines.lineStart, properties.length, vectors.tile ?? new Float64Array(), fills.roofs ?? new Uint8Array(), fills.roofHeights ?? new Float32Array(), fills.roofOutlines ?? new Float64Array(), fills.roofOutlineStart ?? new Uint32Array(), fills.roofMetres ?? 0);
|
|
201
|
+
}
|
|
202
|
+
// The circles' points, once the tile is there
|
|
203
|
+
if (circles)
|
|
204
|
+
engine.setVectorTilePoints(id, key, circles.points, circles.feature, circles.circleStart);
|
|
117
205
|
engine.setFeatureStyle(id, styles, key);
|
|
118
206
|
}
|
|
119
207
|
/** @internal */
|
|
120
208
|
create(engine) {
|
|
121
209
|
const id = engine.addVectorTiles();
|
|
122
210
|
this.sendSublayers(engine, id);
|
|
211
|
+
engine.setFacades(id, this.facades);
|
|
123
212
|
// An engine made anew (after a context loss, or the one with 3D Tiles): its tiles cut again by the workers, once
|
|
124
213
|
// the layer has its id there. Keeping their geometry here would double the memory they take
|
|
125
|
-
this.
|
|
214
|
+
this.dispose();
|
|
126
215
|
queueMicrotask(() => this.recut?.());
|
|
127
216
|
return id;
|
|
128
217
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vectors.js","sourceRoot":"","sources":["../../src/layers/vectors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAgB,MAAM,EAAa,KAAK,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAiCpC,MAAM,OAAO,WAAY,SAAQ,KAAK;IACnB,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;IACzC,SAAS,GAAqB,EAAE,CAA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ACZ,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,YAAY,EAClB,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,SAAS,EACf,UAAU,CAAC,MAAM,EACjB,OAAO,CAAC,IAAI,IAAI,IAAI,YAAY,EAAE,CACnC,CAAC;QACF,MAAM,CAAC,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1C,CAAC;IAED,gBAAgB;IACN,MAAM,CAAC,MAAc;QAC7B,MAAM,EAAE,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC;QAEnC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC/B,iHAAiH;QACjH,4FAA4F;QAC5F,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,cAAc,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAErC,OAAO,EAAE,CAAC;IACZ,CAAC;CACF","sourcesContent":["/**\n * The fills and lines of a MapLibre style drawn as geometry, tile by tile (`VectorTiles.vectors`), instead of into the\n * images of a raster layer: sharp at any zoom and pitch, on the relief, picked by feature, restyled without cutting the\n * tiles again. The workers cut each vector tile into polygons and lines and style its features; the engine draws the\n * style's layers in their order, each over its zoom range.\n */\n\nimport type { LayerHost } from '../types.ts';\nimport type { Engine } from '../wasm/isard.js';\nimport type { TileVectors } from '../workers/basemap.worker.ts';\nimport { type Feature, FLOATS, type Size, stops } from './features.ts';\nimport { Layer } from './layers.ts';\n\n/** A style layer as the engine draws it: its kind, zoom range, visibility and dashes (dash, gap, dash, gap, in line\n * widths; zeros: solid) */\nexport interface VectorSublayer {\n /** The style layer's id */\n id: string;\n /** Its source layer, if any (not for a background) */\n sourceLayer: string | undefined;\n kind: 'fill' | 'line' | 'extrusion';\n minZoom: number;\n maxZoom: number;\n visible: boolean;\n /** Its opacity when it depends on the zoom only, evaluated at the camera's zoom (else 1: the features' colors hold\n * it) */\n opacity: Size;\n dash: [number, number, number, number];\n /** The caps of its lines' ends (`line-cap`; the joins between their pieces are round) */\n cap: 'butt' | 'round' | 'square';\n /** Its lines glow at night (the streets: its id names a road, not its casing; `setSun`) */\n lit: boolean;\n}\n\n/** The properties of a picked feature, with the style layer that drew it */\nexport type VectorFeature = Feature<Record<string, unknown>> & { layer: string; sourceLayer: string | undefined };\n\ninterface Tile {\n /** Its number in the engine: tiles are numbered for picking in this order */\n key: number;\n /** What picking needs (its geometry and styles are the engine's only: an engine made anew asks the tiles again) */\n vectors: Pick<TileVectors, 'properties' | 'sublayer'>;\n}\n\nexport class VectorLayer extends Layer {\n private readonly tiles = new Map<string, Tile>();\n private sublayers: VectorSublayer[] = [];\n private nextKey = 0;\n /** The whole layer shown (`setVisible`), over each style layer's visibility */\n private shown = true;\n /** @internal Resolved once the style is loaded and its layers drawn known (set by its `VectorTiles`) */\n styled: Promise<void> = Promise.resolve();\n /** @internal Changes a property of a style layer drawn (set by its `VectorTiles`) */\n restyle: ((layer: string, group: 'paint' | 'layout', name: string, value: unknown) => void) | undefined;\n /** @internal Asks the workers for the tiles in view again (set by its `VectorTiles`): an engine made anew has none */\n recut: (() => void) | undefined;\n\n /** @internal */\n constructor(map: LayerHost) {\n super(map);\n }\n\n /** Resolves once the style is loaded, its layers drawn known (`layers`), and the map has drawn the layer; rejected\n * if the style fails */\n override get ready(): Promise<void> {\n return this.styled.then(() => super.ready);\n }\n\n /** The style layers drawn, in order */\n get layers(): readonly VectorSublayer[] {\n return this.sublayers;\n }\n\n /** Keys of the tiles held (`z/x/y`) */\n get tileKeys(): string[] {\n return [...this.tiles.keys()];\n }\n\n /** @internal Sets the style layers drawn, in order (the tiles' sublayers) */\n setSublayers(sublayers: VectorSublayer[]): void {\n this.sublayers = sublayers;\n this.sendSublayers(this.map.engine, this.id);\n this.map.requestRender();\n }\n\n /** @internal Adds or replaces a tile, cut by the workers (and made ready for the GPU there, with its mesh) */\n setTile(tile: string, vectors: TileVectors): void {\n const key = this.tiles.get(tile)?.key ?? this.nextKey++;\n const { properties, sublayer } = vectors;\n\n this.tiles.set(tile, { key, vectors: { properties, sublayer } });\n this.sendTile(this.map.engine, this.id, key, vectors);\n this.map.requestRender();\n }\n\n /** @internal New styles of a tile's features, as the workers evaluated them (the same features) */\n setTileStyles(tile: string, styles: Float32Array): void {\n const t = this.tiles.get(tile);\n\n if (!t || styles.length !== t.vectors.properties.length * FLOATS) return;\n this.map.engine.setFeatureStyle(this.id, styles, t.key);\n this.map.requestRender();\n }\n\n /** @internal */\n removeTile(tile: string): void {\n const t = this.tiles.get(tile);\n\n if (!t) return;\n this.tiles.delete(tile);\n this.map.engine.removeVectorTile(this.id, t.key);\n this.map.requestRender();\n }\n\n /** The feature of a picked index (no geometry: the tiles hold it cut), its properties and style layer. Tiles are\n * numbered one after the other, in the order they were first added */\n featureAt(index: number): VectorFeature | undefined {\n const tiles = [...this.tiles.values()].sort((a, b) => a.key - b.key);\n // The tile holding the index, and the index among its features (one pass, the features of the tiles before\n // taken off)\n const { tile, rest } = tiles.reduce<{ tile?: Tile; rest: number }>(\n (found, t) => {\n if (found.tile) return found;\n\n const count = t.vectors.properties.length;\n\n return found.rest < count ? { tile: t, rest: found.rest } : { rest: found.rest - count };\n },\n { rest: index },\n );\n\n if (!tile) return undefined;\n\n const properties = tile.vectors.properties[rest];\n const sublayer = this.sublayers[tile.vectors.sublayer[rest] ?? -1];\n\n if (properties === undefined || !sublayer) return undefined;\n\n return { type: 'Feature', properties, geometry: null, layer: sublayer.id, sourceLayer: sublayer.sourceLayer };\n }\n\n /** Changes a paint property of a style layer drawn, as MapLibre's `setPaintProperty`: the tiles are restyled, not cut\n * again */\n setPaintProperty(layer: string, name: string, value: unknown): void {\n this.restyle?.(layer, 'paint', name, value);\n }\n\n /** Changes a layout property of a style layer drawn (`visibility`: shown or hidden at once), as MapLibre's\n * `setLayoutProperty` */\n setLayoutProperty(layer: string, name: string, value: unknown): void {\n this.restyle?.(layer, 'layout', name, value);\n }\n\n setVisible(visible: boolean): void {\n this.shown = visible;\n this.sendSublayers(this.map.engine, this.id);\n this.map.requestRender();\n }\n\n private sendSublayers(engine: Engine, id: number): void {\n const s = this.sublayers;\n\n engine.setVectorSublayers(\n id,\n Uint8Array.from(s, (l) => ({ fill: 0, line: 1, extrusion: 2 })[l.kind]),\n Float64Array.from(s.flatMap((l) => [l.minZoom, l.maxZoom])),\n Uint8Array.from(s, (l) => (l.visible && this.shown ? 1 : 0)),\n Float32Array.from(s.flatMap((l) => l.dash)),\n Float32Array.from(s.flatMap((l) => stops(l.opacity))),\n Uint8Array.from(s, (l) => ({ butt: 0, round: 1, square: 2 })[l.cap]),\n Uint8Array.from(s, (l) => (l.lit ? 1 : 0)),\n );\n }\n\n /** A tile to the engine: its mesh uploaded as it is, or without one its geometry, which the engine makes ready */\n private sendTile(engine: Engine, id: number, key: number, vectors: TileVectors): void {\n const { fills, lines, styles, properties, mesh } = vectors;\n\n if (mesh) {\n engine.setVectorTileMesh(\n id,\n key,\n fills.points,\n fills.ringStart,\n fills.polygonStart,\n fills.feature,\n fills.fillStart,\n mesh.vertices,\n mesh.indices,\n mesh.fillRanges,\n mesh.prism,\n mesh.pieces,\n mesh.lineTable,\n mesh.lineRanges,\n mesh.blocks,\n mesh.blockIndices,\n mesh.blockRanges,\n mesh.bounds,\n properties.length,\n );\n engine.setFeatureStyle(id, styles, key);\n\n return;\n }\n engine.setVectorTile(\n id,\n key,\n fills.points,\n fills.ringStart,\n fills.polygonStart,\n fills.feature,\n fills.fillStart,\n lines.points,\n lines.start,\n lines.feature,\n lines.lineStart,\n properties.length,\n vectors.tile ?? new Float64Array(),\n );\n engine.setFeatureStyle(id, styles, key);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id = engine.addVectorTiles();\n\n this.sendSublayers(engine, id);\n // An engine made anew (after a context loss, or the one with 3D Tiles): its tiles cut again by the workers, once\n // the layer has its id there. Keeping their geometry here would double the memory they take\n this.tiles.clear();\n queueMicrotask(() => this.recut?.());\n\n return id;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vectors.js","sourceRoot":"","sources":["../../src/layers/vectors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGjD,OAAO,EAA2B,KAAK,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAqCpC;yFACyF;AACzF,MAAM,SAAS,GAAG,CAAC,CAAC;AASpB,MAAM,OAAO,WAAY,SAAQ,KAAK;IACnB,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;IACjD;oDACgD;IAC/B,KAAK,GAAG,IAAI,GAAG,EAAyE,CAAC;IAClG,QAAQ,GAAG,KAAK,CAAC;IACjB,SAAS,GAAqB,EAAE,CAAC;IACjC,OAAO,GAAG,CAAC,CAAC;IACpB,+EAA+E;IACvE,KAAK,GAAG,IAAI,CAAC;IACrB,6DAA6D;IACrD,OAAO,GAAG,KAAK,CAAC;IACxB,wGAAwG;IACxG,MAAM,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAC1C,qFAAqF;IACrF,OAAO,CAAiG;IACxG,sHAAsH;IACtH,KAAK,CAA2B;IAEhC,gBAAgB;IAChB,YAAY,GAAc;QACxB,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED;4BACwB;IACxB,IAAa,KAAK;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED,uCAAuC;IACvC,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,uCAAuC;IACvC,IAAI,QAAQ;QACV,OAAO,CAAC,GAAG,IAAI,CAAC,KA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,CAAC;IAED,gBAAgB;IACN,MAAM,CAAC,MAAc;QAC7B,MAAM,EAAE,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC;QAEnC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC/B,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,iHAAiH;QACjH,4FAA4F;QAC5F,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,cAAc,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAErC,OAAO,EAAE,CAAC;IACZ,CAAC;CACF","sourcesContent":["/**\n * The fills and lines of a MapLibre style drawn as geometry, tile by tile (`VectorTiles.vectors`), instead of into the\n * images of a raster layer: sharp at any zoom and pitch, on the relief, picked by feature, restyled without cutting the\n * tiles again. The workers cut each vector tile into polygons and lines and style its features; the engine draws the\n * style's layers in their order, each over its zoom range.\n */\n\nimport type { LayerHost } from '../types.ts';\nimport { FLOATS } from '../util/style-floats.ts';\nimport type { Engine } from '../wasm/isard.js';\nimport type { TileVectors } from '../workers/basemap.worker.ts';\nimport { type Feature, type Size, stops } from './features.ts';\nimport { Layer } from './layers.ts';\n\n/** A style layer as the engine draws it: its kind, zoom range, visibility and dashes (dash, gap, dash, gap, in line\n * widths; zeros: solid) */\nexport interface VectorSublayer {\n /** The style layer's id */\n id: string;\n /** Its source layer, if any (not for a background) */\n sourceLayer: string | undefined;\n kind: 'fill' | 'line' | 'extrusion' | 'circle';\n minZoom: number;\n maxZoom: number;\n visible: boolean;\n /** Its opacity when it depends on the zoom only, evaluated at the camera's zoom (else 1: the features' colors hold\n * it) */\n opacity: Size;\n dash: [number, number, number, number];\n /** The caps of its lines' ends (`line-cap`) */\n cap: 'butt' | 'round' | 'square';\n /** The joins of its lines' pieces (`line-join`), a miter longer than `miterLimit` line widths bevelled\n * (`line-miter-limit`); round and 2 if left out */\n join?: 'miter' | 'bevel' | 'round';\n miterLimit?: number;\n /** How far its fills or lines move on screen (`fill-translate`, `line-translate`: CSS pixels, x right, y down),\n * turning with the map or staying on the screen (`*-translate-anchor`); none and `map` if left out */\n translate?: [number, number];\n translateAnchor?: 'map' | 'viewport';\n /** Its fills have patterns (`fill-pattern`, `background-pattern`): over the relief, the engine finds the ground under\n * them */\n patterned?: boolean;\n /** Its lines glow at night (the streets: its id names a road, not its casing; `setSun`) */\n lit: boolean;\n}\n\n/** The properties of a picked feature, with the style layer that drew it */\nexport type VectorFeature = Feature<Record<string, unknown>> & { layer: string; sourceLayer: string | undefined };\n\n/** The main thread's time a frame gives to uploading tiles (ms): tiles arriving together are uploaded over several\n * frames, not all in the one (copying a tile's buffers to the GPU takes milliseconds) */\nconst UPLOAD_MS = 4;\n\ninterface Tile {\n /** Its number in the engine: tiles are numbered for picking in this order */\n key: number;\n /** What picking needs (its geometry and styles are the engine's only: an engine made anew asks the tiles again) */\n vectors: Pick<TileVectors, 'properties' | 'sublayer'>;\n}\n\nexport class VectorLayer extends Layer {\n private readonly tiles = new Map<string, Tile>();\n /** The tiles waiting for their upload (`UPLOAD_MS` a frame), each with what resolves its `setTile`; `sent`: in the\n * engine already, its blocks still uploading */\n private readonly queue = new Map<string, { vectors: TileVectors; uploaded: () => void; sent?: number }>();\n private flushing = false;\n private sublayers: VectorSublayer[] = [];\n private nextKey = 0;\n /** The whole layer shown (`setVisible`), over each style layer's visibility */\n private shown = true;\n /** Its buildings' walls show their windows (`setFacades`) */\n private facades = false;\n /** @internal Resolved once the style is loaded and its layers drawn known (set by its `VectorTiles`) */\n styled: Promise<void> = Promise.resolve();\n /** @internal Changes a property of a style layer drawn (set by its `VectorTiles`) */\n restyle: ((layer: string, group: 'paint' | 'layout', name: string, value: unknown) => void) | undefined;\n /** @internal Asks the workers for the tiles in view again (set by its `VectorTiles`): an engine made anew has none */\n recut: (() => void) | undefined;\n\n /** @internal */\n constructor(map: LayerHost) {\n super(map);\n }\n\n /** Resolves once the style is loaded, its layers drawn known (`layers`), and the map has drawn the layer; rejected\n * if the style fails */\n override get ready(): Promise<void> {\n return this.styled.then(() => super.ready);\n }\n\n /** The style layers drawn, in order */\n get layers(): readonly VectorSublayer[] {\n return this.sublayers;\n }\n\n /** Keys of the tiles held (`z/x/y`) */\n get tileKeys(): string[] {\n return [...this.tiles.keys()];\n }\n\n /** @internal Sets the style layers drawn, in order (the tiles' sublayers) */\n setSublayers(sublayers: VectorSublayer[]): void {\n this.sublayers = sublayers;\n this.sendSublayers(this.map.engine, this.id);\n this.map.requestRender();\n }\n\n /** @internal Adds or replaces a tile, cut by the workers (and made ready for the GPU there, with its mesh): uploaded\n * on a coming frame, within its share of the frame (`UPLOAD_MS`); resolves once it is (or once dropped meanwhile) */\n setTile(tile: string, vectors: TileVectors): Promise<void> {\n if (this.removed) return Promise.resolve();\n // The map not idle until it is uploaded\n return this.map.track(\n new Promise((uploaded) => {\n // A newer cut of a tile still waiting takes its place\n this.queue.get(tile)?.uploaded();\n this.queue.set(tile, { vectors, uploaded });\n this.flushSoon();\n }),\n );\n }\n\n /** Uploads the waiting tiles on the next frame */\n private flushSoon(): void {\n if (this.flushing) return;\n this.flushing = true;\n requestAnimationFrame(() => {\n this.flushing = false;\n this.flush();\n });\n }\n\n /** Uploads waiting tiles for `UPLOAD_MS` at most (one at least, or a part of its blocks), the rest on the next\n * frames; a tile's `setTile` resolves once its blocks are all there */\n private flush(): void {\n // Removed meanwhile, or between two engines (the new one asks for the tiles again)\n if (this.id < 0) return;\n\n const start = performance.now();\n const within = () => performance.now() - start <= UPLOAD_MS;\n\n for (const [tile, waiting] of this.queue) {\n waiting.sent ??= this.upload(tile, waiting.vectors);\n\n // A large tile's blocks (a pitched view's far tiles of a city: 10 MB and more), a part at a time\n let left = this.map.engine.uploadVectorTile(this.id, waiting.sent);\n\n while (left && within()) left = this.map.engine.uploadVectorTile(this.id, waiting.sent);\n if (left) break;\n this.queue.delete(tile);\n waiting.uploaded();\n if (!within()) break;\n }\n if (this.queue.size > 0) this.flushSoon();\n this.map.requestRender();\n }\n\n /** Sends a tile to the engine (its blocks' first part); its key */\n private upload(tile: string, vectors: TileVectors): number {\n const key = this.tiles.get(tile)?.key ?? this.nextKey++;\n const { properties, sublayer } = vectors;\n\n this.tiles.set(tile, { key, vectors: { properties, sublayer } });\n this.sendTile(this.map.engine, this.id, key, vectors);\n\n return key;\n }\n\n /** @internal New styles of a tile's features, as the workers evaluated them (the same features) */\n setTileStyles(tile: string, styles: Float32Array): void {\n const waiting = this.queue.get(tile);\n\n // Not uploaded yet: uploaded with them\n if (waiting && waiting.sent === undefined) {\n if (styles.length === waiting.vectors.properties.length * FLOATS) waiting.vectors.styles = styles;\n\n return;\n }\n\n const t = this.tiles.get(tile);\n\n if (!t || styles.length !== t.vectors.properties.length * FLOATS) return;\n this.map.engine.setFeatureStyle(this.id, styles, t.key);\n this.map.requestRender();\n }\n\n override remove(): void {\n super.remove();\n this.dispose();\n }\n\n /** @internal The tiles waiting resolved (dropped), none held */\n override dispose(): void {\n this.queue.forEach((waiting) => {\n waiting.uploaded();\n });\n this.queue.clear();\n this.tiles.clear();\n }\n\n /** @internal */\n removeTile(tile: string): void {\n this.queue.get(tile)?.uploaded();\n this.queue.delete(tile);\n\n const t = this.tiles.get(tile);\n\n if (!t) return;\n this.tiles.delete(tile);\n this.map.engine.removeVectorTile(this.id, t.key);\n this.map.requestRender();\n }\n\n /** The feature of a picked index (no geometry: the tiles hold it cut), its properties and style layer. Tiles are\n * numbered one after the other, in the order they were first added */\n featureAt(index: number): VectorFeature | undefined {\n const tiles = [...this.tiles.values()].sort((a, b) => a.key - b.key);\n // The tile holding the index, and the index among its features (one pass, the features of the tiles before\n // taken off)\n const { tile, rest } = tiles.reduce<{ tile?: Tile; rest: number }>(\n (found, t) => {\n if (found.tile) return found;\n\n const count = t.vectors.properties.length;\n\n return found.rest < count ? { tile: t, rest: found.rest } : { rest: found.rest - count };\n },\n { rest: index },\n );\n\n if (!tile) return undefined;\n\n const properties = tile.vectors.properties[rest];\n const sublayer = this.sublayers[tile.vectors.sublayer[rest] ?? -1];\n\n if (properties === undefined || !sublayer) return undefined;\n\n return { type: 'Feature', properties, geometry: null, layer: sublayer.id, sourceLayer: sublayer.sourceLayer };\n }\n\n /** Changes a paint property of a style layer drawn, as MapLibre's `setPaintProperty`: the tiles are restyled, not cut\n * again */\n setPaintProperty(layer: string, name: string, value: unknown): void {\n this.restyle?.(layer, 'paint', name, value);\n }\n\n /** Changes a layout property of a style layer drawn (`visibility`: shown or hidden at once), as MapLibre's\n * `setLayoutProperty` */\n setLayoutProperty(layer: string, name: string, value: unknown): void {\n this.restyle?.(layer, 'layout', name, value);\n }\n\n /** Whether its buildings' walls show their windows: glass by day, some lit at night (only the lit ones without) */\n setFacades(facades: boolean): void {\n this.facades = facades;\n this.map.engine.setFacades(this.id, facades);\n this.map.requestRender();\n }\n\n setVisible(visible: boolean): void {\n this.shown = visible;\n this.sendSublayers(this.map.engine, this.id);\n this.map.requestRender();\n }\n\n private sendSublayers(engine: Engine, id: number): void {\n const s = this.sublayers;\n\n engine.setVectorSublayers(\n id,\n Uint8Array.from(s, (l) => ({ fill: 0, line: 1, extrusion: 2, circle: 3 })[l.kind]),\n Float64Array.from(s.flatMap((l) => [l.minZoom, l.maxZoom])),\n Uint8Array.from(s, (l) => (l.visible && this.shown ? 1 : 0)),\n Float32Array.from(s.flatMap((l) => l.dash)),\n Float32Array.from(s.flatMap((l) => stops(l.opacity))),\n Uint8Array.from(s, (l) => ({ butt: 0, round: 1, square: 2 })[l.cap]),\n Uint8Array.from(s, (l) => (l.lit ? 1 : 0)),\n Float32Array.from(s.flatMap((l) => [{ round: 0, miter: 1, bevel: 2 }[l.join ?? 'round'], l.miterLimit ?? 2])),\n Float32Array.from(s.flatMap((l) => [...(l.translate ?? [0, 0]), l.translateAnchor === 'viewport' ? 1 : 0])),\n Uint8Array.from(s, (l) => (l.patterned ? 1 : 0)),\n );\n }\n\n /** A tile to the engine: its mesh uploaded as it is, or without one its geometry, which the engine makes ready */\n private sendTile(engine: Engine, id: number, key: number, vectors: TileVectors): void {\n const { fills, lines, circles, styles, properties, mesh } = vectors;\n\n if (mesh) {\n engine.setVectorTileMesh(\n id,\n key,\n fills.points,\n fills.ringStart,\n fills.polygonStart,\n fills.feature,\n fills.fillStart,\n mesh.vertices,\n mesh.indices,\n mesh.fillRanges,\n mesh.prism,\n mesh.pieces,\n mesh.lineTable,\n mesh.lineRanges,\n mesh.blocks,\n mesh.blockIndices,\n mesh.blockRanges,\n mesh.bounds,\n properties.length,\n );\n } else {\n engine.setVectorTile(\n id,\n key,\n fills.points,\n fills.ringStart,\n fills.polygonStart,\n fills.feature,\n fills.fillStart,\n lines.points,\n lines.start,\n lines.feature,\n lines.lineStart,\n properties.length,\n vectors.tile ?? new Float64Array(),\n fills.roofs ?? new Uint8Array(),\n fills.roofHeights ?? new Float32Array(),\n fills.roofOutlines ?? new Float64Array(),\n fills.roofOutlineStart ?? new Uint32Array(),\n fills.roofMetres ?? 0,\n );\n }\n // The circles' points, once the tile is there\n if (circles) engine.setVectorTilePoints(id, key, circles.points, circles.feature, circles.circleStart);\n engine.setFeatureStyle(id, styles, key);\n }\n\n /** @internal */\n protected create(engine: Engine): number {\n const id = engine.addVectorTiles();\n\n this.sendSublayers(engine, id);\n engine.setFacades(id, this.facades);\n // An engine made anew (after a context loss, or the one with 3D Tiles): its tiles cut again by the workers, once\n // the layer has its id there. Keeping their geometry here would double the memory they take\n this.dispose();\n queueMicrotask(() => this.recut?.());\n\n return id;\n }\n}\n"]}
|
package/dist/map/frame-loop.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface FrameHost {
|
|
|
21
21
|
customLayers(): boolean;
|
|
22
22
|
/** The engine with 3D Tiles is loading: not idle */
|
|
23
23
|
upgrading(): boolean;
|
|
24
|
+
/** Work the page waits on for what it draws (the vector tiles cut in the workers, uploaded over frames): not idle */
|
|
25
|
+
working(): boolean;
|
|
24
26
|
/** The frame is drawn: what follows it (the overlays placed, the hover picking asked for at `hovered`) */
|
|
25
27
|
drawn(hovered: Point | undefined): void;
|
|
26
28
|
}
|
package/dist/map/frame-loop.js
CHANGED
|
@@ -131,9 +131,9 @@ export class FrameLoop {
|
|
|
131
131
|
// A move goes on until a frame finds the camera still: that frame sends 'moveend'
|
|
132
132
|
if (this.animation || (moved && this.moving))
|
|
133
133
|
this.request();
|
|
134
|
-
// Idle: nothing loading (the engine with 3D Tiles neither
|
|
135
|
-
// fades, listeners)
|
|
136
|
-
if (loading || host.upgrading() || this.animation || this.requested !== 0) {
|
|
134
|
+
// Idle: nothing loading (the engine with 3D Tiles neither, nor the page's work for what it draws), no animation,
|
|
135
|
+
// no frame asked for (uploads waiting, fades, listeners)
|
|
136
|
+
if (loading || host.upgrading() || host.working() || this.animation || this.requested !== 0) {
|
|
137
137
|
this.#settled = false;
|
|
138
138
|
}
|
|
139
139
|
else if (!this.#settled) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frame-loop.js","sourceRoot":"","sources":["../../src/map/frame-loop.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAyBH,+CAA+C;AAC/C,MAAM,OAAO,SAAS;IACH,IAAI,CAAY;IAChB,SAAS,CAAe;IACzC,iCAAiC;IACzB,SAAS,GAAG,CAAC,CAAC;IACd,OAAO,GAAG,KAAK,CAAC;IAChB,SAAS,CAAmB;IACpC,gDAAgD;IACxC,UAAU,CAAoB;IAC9B,UAAU,GAAG,EAAE,CAAC;IACxB,gDAAgD;IACxC,MAAM,GAAG,KAAK,CAAC;IACvB,QAAQ,GAAG,KAAK,CAAC;IACjB,OAAO,CAAqB;IAE5B,yDAAyD;IACzD,YAAY,IAAe,EAAE,SAAuB;QAClD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,2DAA2D;IAC3D,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;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;QACrB,kFAAkF;QAClF,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC;YAAE,IAAI,CAAC,OAAO,EAAE,CAAC;QAC7D,+GAA+G;QAC/G,oBAAoB;QACpB,IAAI,OAAO,IAAI,IAAI,CAAC,SAAS,EAAE,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;YAC1E,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACxB,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * The frame loop of a map: frames drawn on demand only (an idle map costs nothing), the running animation stepped in\n * each, and the events of a frame sent with it: the camera's moves, the pointer's position (coalesced to one per\n * frame, so the values computed for it are drawn in the same frame), 'render', and 'idle' once everything is loaded.\n */\n\nimport type { Point } from '../types.ts';\nimport type { Step } from '../util/animation.ts';\nimport type { Camera, Engine } from '../wasm/isard.js';\nimport type { MapListeners } from './events.ts';\n\n/** What the frame loop needs of its map */\nexport interface FrameHost {\n /** The map's engine of the moment */\n engine(): Engine;\n /** The map's camera */\n camera(): Camera;\n /** The WebGL context is lost: nothing is drawn */\n lost(): boolean;\n /** The pointer or the keys are moving the camera: no 'moveend' yet */\n interacting(): boolean;\n /** Custom layers are drawn: they read the camera of the frame */\n customLayers(): boolean;\n /** The engine with 3D Tiles is loading: not idle */\n upgrading(): boolean;\n /** The frame is drawn: what follows it (the overlays placed, the hover picking asked for at `hovered`) */\n drawn(hovered: Point | undefined): void;\n}\n\n/** The frames of a map, asked for and drawn */\nexport class FrameLoop {\n private readonly host: FrameHost;\n private readonly listeners: MapListeners;\n /** Frame asked for, 0 if none */\n private requested = 0;\n private inFrame = false;\n private animation: Step | undefined;\n /** The pointer's position for the next frame */\n private hoverPoint: Point | undefined;\n private lastCamera = '';\n /** The camera moved since the last 'moveend' */\n private moving = false;\n #settled = false;\n #camera: Camera | undefined;\n\n /** `listeners`: the map's, told of the frame's events */\n constructor(host: FrameHost, listeners: MapListeners) {\n this.host = host;\n this.listeners = listeners;\n }\n\n /** The last frame found everything loaded ('idle' sent) */\n get settled(): boolean {\n return this.#settled;\n }\n\n /** The camera of the frame being drawn: what `getCamera` gives the custom layers while the engine is busy */\n get camera(): Camera | undefined {\n return this.#camera;\n }\n\n /** Asks for a frame; several calls before the next frame draw it once */\n request(): void {\n // Changes made by listeners during a frame are drawn by that frame; nothing is drawn without a context\n if (this.inFrame || this.host.lost()) return;\n this.requested ||= requestAnimationFrame((now) => this.frame(now));\n }\n\n /** Asks for a frame that sends 'idle' once everything is loaded, even if the last one already did: the waiters of\n * `whenIdle` on a map already idle (else no frame would change from loading to loaded, and none would send it) */\n requestIdle(): void {\n this.#settled = false;\n this.request();\n }\n\n /** Runs `step` every frame until it returns false; replaces the running animation */\n animate(step: Step | undefined): void {\n // A flight cut short no longer needs its destination\n if (this.animation) this.host.engine().clearPreload();\n this.animation = step;\n this.request();\n }\n\n /** The pointer's position for the next frame (undefined: none) */\n hover(point: Point | undefined): void {\n this.hoverPoint = point;\n }\n\n /** Draws a frame now, in place of the one asked for (a resized canvas is cleared: waiting one frame would flash) */\n drawNow(): void {\n cancelAnimationFrame(this.requested);\n this.frame(performance.now());\n }\n\n /** Cancels the frame asked for (the context is lost); a new one can be asked for */\n cancel(): void {\n cancelAnimationFrame(this.requested);\n this.requested = 0;\n }\n\n /** Cancels the frame asked for, for good (the map is destroyed): it stays marked as asked for */\n stop(): void {\n cancelAnimationFrame(this.requested);\n }\n\n private frame(now: number): void {\n this.requested = 0;\n try {\n this.inFrame = true;\n this.draw(now);\n } finally {\n // Whatever throws in a frame, the next ones are still drawn\n this.inFrame = false;\n }\n }\n\n private draw(now: number): void {\n if (this.animation && !this.animation(now)) this.animation = undefined;\n\n const { host, listeners } = this;\n const camera = host.camera();\n const key = `${camera.center}|${camera.zoom}|${camera.pitch}|${camera.bearing}`;\n const moved = key !== this.lastCamera;\n\n if (moved) {\n // The first frame is no move\n if (!this.moving && this.lastCamera !== '') {\n this.moving = true;\n listeners.emit('movestart', camera);\n }\n this.lastCamera = key;\n listeners.emit('move', camera);\n } else if (this.moving && !this.animation && !host.interacting()) {\n this.moving = false;\n listeners.emit('moveend', camera);\n }\n\n // Values for the pointer position are computed before drawing, in the same frame\n const hovered = this.hoverPoint;\n\n if (hovered) {\n this.hoverPoint = undefined;\n // The position under the pointer for its listeners only (a 'hoverfeature' alone does not need it)\n if (listeners.has('hover')) {\n listeners.emit('hover', { point: hovered, lonLat: host.engine().ground(hovered[0], hovered[1]) });\n }\n }\n\n const t0 = performance.now();\n\n // The engine asks for the next frame while it draws (uploads past the frame budget, fades): not ignored\n this.inFrame = false;\n // As the engine has it now (a listener may have moved it), for the custom layers drawn in the frame\n this.#camera = host.customLayers() ? host.engine().camera() : undefined;\n\n const render = (): boolean => {\n try {\n return host.engine().render();\n } finally {\n this.#camera = undefined;\n }\n };\n const loading = render();\n\n this.inFrame = true;\n host.drawn(hovered);\n listeners.emit('render', { ms: performance.now() - t0 });\n this.inFrame = false;\n // A move goes on until a frame finds the camera still: that frame sends 'moveend'\n if (this.animation || (moved && this.moving)) this.request();\n // Idle: nothing loading (the engine with 3D Tiles neither), no animation, no frame asked for (uploads waiting,\n // fades, listeners)\n if (loading || host.upgrading() || this.animation || this.requested !== 0) {\n this.#settled = false;\n } else if (!this.#settled) {\n this.#settled = true;\n listeners.emit('idle', {});\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"frame-loop.js","sourceRoot":"","sources":["../../src/map/frame-loop.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2BH,+CAA+C;AAC/C,MAAM,OAAO,SAAS;IACH,IAAI,CAAY;IAChB,SAAS,CAAe;IACzC,i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IAAI,CAAC;gBACH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC;YAChC,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;YAC3B,CAAC;QACH,CAAC,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC;QAEzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACpB,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,kFAAkF;QAClF,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC;YAAE,IAAI,CAAC,OAAO,EAAE,CAAC;QAC7D,iHAAiH;QACjH,yDAAyD;QACzD,IAAI,OAAO,IAAI,IAAI,CAAC,SAAS,EAAE,IAAI,IAAI,CAAC,OAAO,EAAE,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;YAC5F,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACxB,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * The frame loop of a map: frames drawn on demand only (an idle map costs nothing), the running animation stepped in\n * each, and the events of a frame sent with it: the camera's moves, the pointer's position (coalesced to one per\n * frame, so the values computed for it are drawn in the same frame), 'render', and 'idle' once everything is loaded.\n */\n\nimport type { Point } from '../types.ts';\nimport type { Step } from '../util/animation.ts';\nimport type { Camera, Engine } from '../wasm/isard.js';\nimport type { MapListeners } from './events.ts';\n\n/** What the frame loop needs of its map */\nexport interface FrameHost {\n /** The map's engine of the moment */\n engine(): Engine;\n /** The map's camera */\n camera(): Camera;\n /** The WebGL context is lost: nothing is drawn */\n lost(): boolean;\n /** The pointer or the keys are moving the camera: no 'moveend' yet */\n interacting(): boolean;\n /** Custom layers are drawn: they read the camera of the frame */\n customLayers(): boolean;\n /** The engine with 3D Tiles is loading: not idle */\n upgrading(): boolean;\n /** Work the page waits on for what it draws (the vector tiles cut in the workers, uploaded over frames): not idle */\n working(): boolean;\n /** The frame is drawn: what follows it (the overlays placed, the hover picking asked for at `hovered`) */\n drawn(hovered: Point | undefined): void;\n}\n\n/** The frames of a map, asked for and drawn */\nexport class FrameLoop {\n private readonly host: FrameHost;\n private readonly listeners: MapListeners;\n /** Frame asked for, 0 if none */\n private requested = 0;\n private inFrame = false;\n private animation: Step | undefined;\n /** The pointer's position for the next frame */\n private hoverPoint: Point | undefined;\n private lastCamera = '';\n /** The camera moved since the last 'moveend' */\n private moving = false;\n #settled = false;\n #camera: Camera | undefined;\n\n /** `listeners`: the map's, told of the frame's events */\n constructor(host: FrameHost, listeners: MapListeners) {\n this.host = host;\n this.listeners = listeners;\n }\n\n /** The last frame found everything loaded ('idle' sent) */\n get settled(): boolean {\n return this.#settled;\n }\n\n /** The camera of the frame being drawn: what `getCamera` gives the custom layers while the engine is busy */\n get camera(): Camera | undefined {\n return this.#camera;\n }\n\n /** Asks for a frame; several calls before the next frame draw it once */\n request(): void {\n // Changes made by listeners during a frame are drawn by that frame; nothing is drawn without a context\n if (this.inFrame || this.host.lost()) return;\n this.requested ||= requestAnimationFrame((now) => this.frame(now));\n }\n\n /** Asks for a frame that sends 'idle' once everything is loaded, even if the last one already did: the waiters of\n * `whenIdle` on a map already idle (else no frame would change from loading to loaded, and none would send it) */\n requestIdle(): void {\n this.#settled = false;\n this.request();\n }\n\n /** Runs `step` every frame until it returns false; replaces the running animation */\n animate(step: Step | undefined): void {\n // A flight cut short no longer needs its destination\n if (this.animation) this.host.engine().clearPreload();\n this.animation = step;\n this.request();\n }\n\n /** The pointer's position for the next frame (undefined: none) */\n hover(point: Point | undefined): void {\n this.hoverPoint = point;\n }\n\n /** Draws a frame now, in place of the one asked for (a resized canvas is cleared: waiting one frame would flash) */\n drawNow(): void {\n cancelAnimationFrame(this.requested);\n this.frame(performance.now());\n }\n\n /** Cancels the frame asked for (the context is lost); a new one can be asked for */\n cancel(): void {\n cancelAnimationFrame(this.requested);\n this.requested = 0;\n }\n\n /** Cancels the frame asked for, for good (the map is destroyed): it stays marked as asked for */\n stop(): void {\n cancelAnimationFrame(this.requested);\n }\n\n private frame(now: number): void {\n this.requested = 0;\n try {\n this.inFrame = true;\n this.draw(now);\n } finally {\n // Whatever throws in a frame, the next ones are still drawn\n this.inFrame = false;\n }\n }\n\n private draw(now: number): void {\n if (this.animation && !this.animation(now)) this.animation = undefined;\n\n const { host, listeners } = this;\n const camera = host.camera();\n const key = `${camera.center}|${camera.zoom}|${camera.pitch}|${camera.bearing}`;\n const moved = key !== this.lastCamera;\n\n if (moved) {\n // The first frame is no move\n if (!this.moving && this.lastCamera !== '') {\n this.moving = true;\n listeners.emit('movestart', camera);\n }\n this.lastCamera = key;\n listeners.emit('move', camera);\n } else if (this.moving && !this.animation && !host.interacting()) {\n this.moving = false;\n listeners.emit('moveend', camera);\n }\n\n // Values for the pointer position are computed before drawing, in the same frame\n const hovered = this.hoverPoint;\n\n if (hovered) {\n this.hoverPoint = undefined;\n // The position under the pointer for its listeners only (a 'hoverfeature' alone does not need it)\n if (listeners.has('hover')) {\n listeners.emit('hover', { point: hovered, lonLat: host.engine().ground(hovered[0], hovered[1]) });\n }\n }\n\n const t0 = performance.now();\n\n // The engine asks for the next frame while it draws (uploads past the frame budget, fades): not ignored\n this.inFrame = false;\n // As the engine has it now (a listener may have moved it), for the custom layers drawn in the frame\n this.#camera = host.customLayers() ? host.engine().camera() : undefined;\n\n const render = (): boolean => {\n try {\n return host.engine().render();\n } finally {\n this.#camera = undefined;\n }\n };\n const loading = render();\n\n this.inFrame = true;\n host.drawn(hovered);\n listeners.emit('render', { ms: performance.now() - t0 });\n this.inFrame = false;\n // A move goes on until a frame finds the camera still: that frame sends 'moveend'\n if (this.animation || (moved && this.moving)) this.request();\n // Idle: nothing loading (the engine with 3D Tiles neither, nor the page's work for what it draws), no animation,\n // no frame asked for (uploads waiting, fades, listeners)\n if (loading || host.upgrading() || host.working() || this.animation || this.requested !== 0) {\n this.#settled = false;\n } else if (!this.#settled) {\n this.#settled = true;\n listeners.emit('idle', {});\n }\n }\n}\n"]}
|
package/dist/map/layer-spec.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { FlowOptions } from '../layers/flow.ts';
|
|
|
5
5
|
import type { GroundOptions, Layer, ModelOptions } from '../layers/layers.ts';
|
|
6
6
|
import type { PointCloudOptions } from '../layers/pointclouds.ts';
|
|
7
7
|
import type { SymbolOptions } from '../layers/symbols.ts';
|
|
8
|
+
import type { TreeOptions } from '../layers/trees.ts';
|
|
8
9
|
import type { GeoMap } from '../map.ts';
|
|
9
10
|
import type { NetworkOptions, RasterOptions, Tiles3dOptions } from '../types.ts';
|
|
10
11
|
/** A layer by its type and the options of its `add…` method (`GeoMap.add`) */
|
|
@@ -39,6 +40,8 @@ export type LayerSpec<P = Record<string, unknown>> = ({
|
|
|
39
40
|
} & ModelOptions & {
|
|
40
41
|
before?: Layer;
|
|
41
42
|
}) | ({
|
|
43
|
+
type: 'trees';
|
|
44
|
+
} & TreeOptions<P>) | ({
|
|
42
45
|
type: 'flow';
|
|
43
46
|
} & FlowOptions);
|
|
44
47
|
/** Adds the layer a description gives with the `add…` method of its type; an unknown type throws */
|
package/dist/map/layer-spec.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer-spec.js","sourceRoot":"","sources":["../../src/map/layer-spec.ts"],"names":[],"mappings":"AAAA,oHAAoH;
|
|
1
|
+
{"version":3,"file":"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B,IAAI,CAAC;YAE1C,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["/** A layer described by its type and options, as an application's configuration gives it, and the map adding it. */\n\nimport type { ExtrusionOptions } from '../layers/extrusions.ts';\nimport type { CircleOptions, FillOptions, LineOptions } from '../layers/features.ts';\nimport type { FlowOptions } from '../layers/flow.ts';\nimport type { GroundOptions, Layer, ModelOptions } from '../layers/layers.ts';\nimport type { PointCloudOptions } from '../layers/pointclouds.ts';\nimport type { SymbolOptions } from '../layers/symbols.ts';\nimport type { TreeOptions } from '../layers/trees.ts';\nimport type { GeoMap } from '../map.ts';\nimport type { NetworkOptions, RasterOptions, Tiles3dOptions } from '../types.ts';\n\n/** A layer by its type and the options of its `add…` method (`GeoMap.add`) */\nexport type LayerSpec<P = Record<string, unknown>> =\n | ({ type: 'lines' } & LineOptions<P>)\n | ({ type: 'circles' } & CircleOptions<P>)\n | ({ type: 'fills' } & FillOptions<P>)\n | ({ type: 'symbols' } & SymbolOptions<P>)\n | ({ type: 'extrusions' } & ExtrusionOptions<P>)\n | ({ type: 'raster' } & RasterOptions & { before?: Layer })\n | ({ type: 'ground' } & GroundOptions & { before?: Layer })\n | ({ type: 'network' } & NetworkOptions)\n | ({ type: 'tiles3d' } & Tiles3dOptions)\n | ({ type: 'pointcloud' } & PointCloudOptions & { before?: Layer })\n | ({ type: 'models' } & ModelOptions & { before?: Layer })\n | ({ type: 'trees' } & TreeOptions<P>)\n | ({ type: 'flow' } & FlowOptions);\n\n/** Adds the layer a description gives with the `add…` method of its type; an unknown type throws */\nexport const addSpec = <P = Record<string, unknown>>(map: GeoMap, spec: LayerSpec<P>): Layer => {\n switch (spec.type) {\n case 'lines':\n return map.addLines<P>(spec);\n case 'circles':\n return map.addCircles<P>(spec);\n case 'fills':\n return map.addFills<P>(spec);\n case 'symbols':\n return map.addSymbols<P>(spec);\n case 'extrusions':\n return map.addExtrusions<P>(spec);\n case 'raster':\n return map.addRaster(spec);\n case 'ground':\n return map.addGround(spec);\n case 'network':\n return map.addNetwork(spec);\n case 'tiles3d':\n return map.addTiles3d(spec);\n case 'pointcloud':\n return map.addPointCloud(spec);\n case 'models':\n return map.addModels(spec);\n case 'trees':\n return map.addTrees<P>(spec);\n case 'flow':\n return map.addFlow(spec);\n default: {\n // Only from an application's configuration, untyped: the cases above cover every type\n const { type }: { type?: unknown } = spec;\n\n throw new Error(`isard: no layer of type ${String(type)}`);\n }\n }\n};\n"]}
|
package/dist/map.d.ts
CHANGED
|
@@ -14,8 +14,10 @@ import { FlowLayer, type FlowOptions } from './layers/flow.ts';
|
|
|
14
14
|
import type { ImageOptions, Pixels } from './layers/icons.ts';
|
|
15
15
|
import { CustomLayer, type CustomLayerInterface, GroundLayer, type GroundOptions, type Layer, ModelLayer, type ModelOptions, NetworkLayer, RasterLayer, Tiles3dLayer } from './layers/layers.ts';
|
|
16
16
|
import { type PanoramaOptions, type Panoramas } from './layers/panoramas.ts';
|
|
17
|
+
import { type PhotoOptions } from './layers/photos.ts';
|
|
17
18
|
import { PointCloudLayer, type PointCloudOptions } from './layers/pointclouds.ts';
|
|
18
19
|
import { SymbolLayer, type SymbolOptions } from './layers/symbols.ts';
|
|
20
|
+
import { type TreeOptions } from './layers/trees.ts';
|
|
19
21
|
import { type HoverPicking } from './map/hover-pick.ts';
|
|
20
22
|
import { type LayerSpec } from './map/layer-spec.ts';
|
|
21
23
|
import type { AnimationOptions, AtmosphereOptions, Basemap, FeatureHit, FirstPersonView, FlyToOptions, GeoMapOptions, LoadingMode, LonLat, MapEvents, NetworkOptions, Point, Projection, RasterOptions, SunOptions, SwipeOptions, TerrainModel, TerrainOptions, Tiles3dOptions, ViewshedOptions } from './types.ts';
|
|
@@ -327,6 +329,12 @@ export declare class GeoMap {
|
|
|
327
329
|
addModels(options: ModelOptions & {
|
|
328
330
|
before?: Layer;
|
|
329
331
|
}): ModelLayer;
|
|
332
|
+
/** Trees at the points of a source that has them (a city's street trees), broadleaved or conifers by their data,
|
|
333
|
+
* scaled to their height (see `TreeOptions`); the conifers on a layer that goes with the one returned */
|
|
334
|
+
addTrees<P = Record<string, unknown>>(options: TreeOptions<P>): ModelLayer;
|
|
335
|
+
/** A photo standing where it was taken, facing its way (see `PhotoOptions`): flat on a frame across its field of
|
|
336
|
+
* view, a 360° one on a band round its camera; resolves once its image is read */
|
|
337
|
+
addPhoto(options: PhotoOptions): Promise<ModelLayer>;
|
|
330
338
|
/**
|
|
331
339
|
* The page's own WebGL drawing at its place among the layers, in every frame (see `CustomLayerInterface`): raw
|
|
332
340
|
* WebGL, three.js… with the matrices of the frame (`frame.matrixAt`); under `before` if given
|
package/dist/map.js
CHANGED
|
@@ -17,8 +17,10 @@ import { CircleLayer, circleStyle, FillLayer, fillStyle, LineLayer, lineStyle, }
|
|
|
17
17
|
import { FlowLayer } from "./layers/flow.js";
|
|
18
18
|
import { CustomLayer, GroundLayer, ModelLayer, NetworkLayer, RasterLayer, Tiles3dLayer, } from "./layers/layers.js";
|
|
19
19
|
import { loadPanoramas } from "./layers/panoramas.js";
|
|
20
|
+
import { addPhoto } from "./layers/photos.js";
|
|
20
21
|
import { PointCloudLayer } from "./layers/pointclouds.js";
|
|
21
22
|
import { SymbolLayer, symbolStyle } from "./layers/symbols.js";
|
|
23
|
+
import { addTrees } from "./layers/trees.js";
|
|
22
24
|
import { VectorLayer } from "./layers/vectors.js";
|
|
23
25
|
import { BasemapLayers } from "./map/basemap-layers.js";
|
|
24
26
|
import { createCanvas, labelCanvas, watchContext, watchPixelRatio } from "./map/canvas.js";
|
|
@@ -48,6 +50,8 @@ const hasFeatures = (layer) => 'featureAt' in layer && typeof layer.featureAt ==
|
|
|
48
50
|
export class GeoMap {
|
|
49
51
|
canvas;
|
|
50
52
|
#engine;
|
|
53
|
+
/** The work the map waits on before it is idle (`track`) */
|
|
54
|
+
#working = 0;
|
|
51
55
|
/** The engine class (core, or with 3D Tiles) and the engine with 3D Tiles loaded when needed */
|
|
52
56
|
engines;
|
|
53
57
|
/** The layers in drawing order and those kept on top */
|
|
@@ -133,6 +137,7 @@ export class GeoMap {
|
|
|
133
137
|
interacting: () => this.interaction?.active === true,
|
|
134
138
|
customLayers: () => this.layers.some((layer) => layer instanceof CustomLayer),
|
|
135
139
|
upgrading: () => this.engines.upgrading !== undefined,
|
|
140
|
+
working: () => this.#working > 0,
|
|
136
141
|
drawn: (hovered) => {
|
|
137
142
|
// The picking pass sees the frame just drawn; its answer comes on a later frame
|
|
138
143
|
if (hovered && this.listeners.has('hoverfeature'))
|
|
@@ -679,13 +684,28 @@ export class GeoMap {
|
|
|
679
684
|
/** @internal A layer made anew from its description, in the place of `old` in the drawing order (old removed) */
|
|
680
685
|
rebuildLayer(old, spec) {
|
|
681
686
|
const index = this.layers.indexOf(old);
|
|
682
|
-
|
|
687
|
+
// The first layer above that goes not with it: its companions are removed with it
|
|
688
|
+
const above = index >= 0 ? this.layers.slice(index + 1).find((l) => !old.companions.includes(l)) : undefined;
|
|
683
689
|
const layer = this.add(spec);
|
|
684
690
|
if (!('before' in spec && spec.before) && index >= 0)
|
|
685
|
-
|
|
691
|
+
layer.moveBefore(above);
|
|
686
692
|
old.remove();
|
|
687
693
|
return layer;
|
|
688
694
|
}
|
|
695
|
+
/**
|
|
696
|
+
* @internal Work the map waits on before it is idle (the vector tiles cut in the workers, uploaded over frames): the
|
|
697
|
+
* engine knows only the tiles it holds, not those coming (an engine made anew holds none until the workers cut them
|
|
698
|
+
* again from their cache, no request on the network meanwhile); a frame once it is done, to tell
|
|
699
|
+
*/
|
|
700
|
+
track(work) {
|
|
701
|
+
this.#working += 1;
|
|
702
|
+
const done = () => {
|
|
703
|
+
this.#working -= 1;
|
|
704
|
+
this.requestRender();
|
|
705
|
+
};
|
|
706
|
+
work.then(done, done);
|
|
707
|
+
return work;
|
|
708
|
+
}
|
|
689
709
|
/** @internal Resolves once the map is idle (everything in view loaded and drawn) */
|
|
690
710
|
whenIdle() {
|
|
691
711
|
if (this.gone)
|
|
@@ -816,6 +836,16 @@ export class GeoMap {
|
|
|
816
836
|
addModels(options) {
|
|
817
837
|
return this.place(new ModelLayer(this, options), options.before);
|
|
818
838
|
}
|
|
839
|
+
/** Trees at the points of a source that has them (a city's street trees), broadleaved or conifers by their data,
|
|
840
|
+
* scaled to their height (see `TreeOptions`); the conifers on a layer that goes with the one returned */
|
|
841
|
+
addTrees(options) {
|
|
842
|
+
return addTrees((o) => this.addModels(o), options);
|
|
843
|
+
}
|
|
844
|
+
/** A photo standing where it was taken, facing its way (see `PhotoOptions`): flat on a frame across its field of
|
|
845
|
+
* view, a 360° one on a band round its camera; resolves once its image is read */
|
|
846
|
+
addPhoto(options) {
|
|
847
|
+
return addPhoto((o) => this.addModels(o), options);
|
|
848
|
+
}
|
|
819
849
|
/**
|
|
820
850
|
* The page's own WebGL drawing at its place among the layers, in every frame (see `CustomLayerInterface`): raw
|
|
821
851
|
* WebGL, three.js… with the matrices of the frame (`frame.matrixAt`); under `before` if given
|