isard 1.9.0 → 1.11.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 +86 -0
- package/README.md +9 -4
- package/dist/basemap/vectortiles/requests.d.ts +8 -1
- package/dist/basemap/vectortiles/requests.js +32 -4
- package/dist/basemap/vectortiles/requests.js.map +1 -1
- package/dist/basemap/vectortiles/vectors.d.ts +8 -1
- package/dist/basemap/vectortiles/vectors.js +26 -2
- package/dist/basemap/vectortiles/vectors.js.map +1 -1
- package/dist/basemap/vectortiles.d.ts +15 -9
- package/dist/basemap/vectortiles.js +3 -1
- package/dist/basemap/vectortiles.js.map +1 -1
- package/dist/basemap.worker.js +2 -2
- package/dist/basemap.worker.js.map +4 -4
- package/dist/bind/layers.js +10 -2
- package/dist/bind/layers.js.map +1 -1
- package/dist/data/tileset.d.ts +21 -0
- package/dist/data/tileset.js +101 -0
- package/dist/data/tileset.js.map +1 -0
- package/dist/decoder.worker.js +3 -3
- package/dist/decoder.worker.js.map +3 -3
- package/dist/engine-loader.d.ts +2 -2
- package/dist/engine-loader.js +9 -3
- package/dist/engine-loader.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -0
- 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_tess_bg.wasm +0 -0
- package/dist/layers/features.d.ts +7 -0
- package/dist/layers/features.js +21 -5
- package/dist/layers/features.js.map +1 -1
- package/dist/layers/layers.js +2 -0
- package/dist/layers/layers.js.map +1 -1
- package/dist/layers/tiles3d.d.ts +6 -0
- package/dist/layers/tiles3d.js +57 -3
- package/dist/layers/tiles3d.js.map +1 -1
- package/dist/layers/vectors.d.ts +3 -0
- package/dist/layers/vectors.js +4 -0
- package/dist/layers/vectors.js.map +1 -1
- package/dist/map/events.js +1 -0
- package/dist/map/events.js.map +1 -1
- package/dist/map/quality.d.ts +33 -0
- package/dist/map/quality.js +61 -0
- package/dist/map/quality.js.map +1 -0
- package/dist/map.d.ts +22 -1
- package/dist/map.js +87 -8
- package/dist/map.js.map +1 -1
- package/dist/react/IsardMap.d.ts +1 -0
- package/dist/react/IsardMap.js +2 -0
- package/dist/react/IsardMap.js.map +1 -1
- package/dist/react/VectorGeometry.d.ts +4 -0
- package/dist/react/VectorGeometry.js +6 -3
- package/dist/react/VectorGeometry.js.map +1 -1
- package/dist/react/VectorTiles.d.ts +5 -1
- package/dist/react/VectorTiles.js +8 -0
- package/dist/react/VectorTiles.js.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/types.d.ts +22 -0
- package/dist/types.js.map +1 -1
- package/dist/ui/interaction.d.ts +4 -0
- package/dist/ui/interaction.js +53 -2
- package/dist/ui/interaction.js.map +1 -1
- package/dist/wasm/isard.d.ts +30 -6
- package/dist/wasm/isard.js +61 -7
- package/dist/wasm/isard_core.d.ts +20 -6
- package/dist/wasm/isard_core.js +41 -7
- package/dist/workers/basemap/protocol.d.ts +3 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,92 @@
|
|
|
3
3
|
Every notable change of `isard`. The format follows [Keep a Changelog](https://keepachangelog.com), the
|
|
4
4
|
versions [Semantic Versioning](https://semver.org) (before 1.0.0, a minor version may change an API).
|
|
5
5
|
|
|
6
|
+
## [1.11.0] - 2026-10-27
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- The map's quality, for weaker devices: `quality` (`GeoMapOptions`, `map.setQuality`, `<IsardMap quality>`) draws
|
|
11
|
+
fewer pixels (`'medium'`: at most 1.5 a CSS pixel; `'low'`: one, and no sun's shadows) and coarser 3D Tiles far away;
|
|
12
|
+
`'auto'` starts high and steps down while the frames of a move stay slow (the `'quality'` event, `getQuality`). The
|
|
13
|
+
Bâtiments 3D example takes `'auto'`.
|
|
14
|
+
|
|
15
|
+
- The light way under 3D buildings on the relief, some three times as fast a frame: the ground as images
|
|
16
|
+
(`tiles.raster`), the buildings and the streets alone as geometry (`isStreet`, now exported; `<Raster>` in React's
|
|
17
|
+
`<VectorTiles>`). The Bâtiments 3D example takes it, its streets still glowing at night. `VectorRasterOptions` names
|
|
18
|
+
`raster`'s options.
|
|
19
|
+
|
|
20
|
+
- 3D Tiles colored by their features' properties: `featureColor` (in `addTiles3d`, `setStyle`, and the React layer's
|
|
21
|
+
props) gives each feature a CSS color from its properties (a thematic map of the buildings: their height, their use),
|
|
22
|
+
or the layer's color. Each tile asks once when first drawn and again when it changes, its colors a table on the GPU
|
|
23
|
+
read by the feature's number. The 3D Tiles features example colors its buildings by height.
|
|
24
|
+
- Lines in space: `addLines({ altitudeReference: 'ground' | 'sea' })` stands each point at its third coordinate,
|
|
25
|
+
metres above the ground or the sea, the line drawn in the scene's depth (hidden by the buildings, 3D Tiles and hills
|
|
26
|
+
in front of it); without it, the lines lie on the ground as before. The Measure example draws its line so.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- Hitches while the camera moves over the relief: `unproject` (and `metersPerPixel`, which the trees, the street
|
|
31
|
+
lamps and the furniture ask as they follow the view) read the relief's altitude back from the GPU, a read that waits
|
|
32
|
+
for the frame; it now reads the copy of the relief kept on the CPU, the GPU only where none is loaded. Over the
|
|
33
|
+
Bâtiments 3D example, the longest frame of a turn from 51 ms to 10.
|
|
34
|
+
|
|
35
|
+
- A layer added while the WebGL context was lost but before the browser said so threw (an empty error from the
|
|
36
|
+
engine, React's tree unmounted): it is kept and made with the others on the next engine.
|
|
37
|
+
- 3D Tiles whose upper tiles are empty groupings over tiles of the finest level only (the IGN's Bâtiments 3D) were
|
|
38
|
+
drawn whole up to the horizon in a tilted view, their screen-space error never weighed: an empty grouping tile now
|
|
39
|
+
keeps its own error (as in Cesium), only a grafted external tileset is always gone through. Bâtiments 3D at a pitch
|
|
40
|
+
of 80°: a third less GPU time per frame, and the tiles drawn no longer pile up as the view moves around.
|
|
41
|
+
|
|
42
|
+
## [1.10.0] - 2026-10-27
|
|
43
|
+
|
|
44
|
+
### Added
|
|
45
|
+
|
|
46
|
+
- `isard-react-native` (packages/react-native): the map in a React Native app, `<IsardMapView>` holding isard's page
|
|
47
|
+
in a WebView, driven by its props (the map's options, its layers as `map.add` takes them) and its ref (`flyTo`,
|
|
48
|
+
`easeTo`, `getCamera`, `pickSurface`…), the taps and the camera's stops told back. On the web, the same view holds
|
|
49
|
+
the page in an iframe with the same messages: the Places example runs on React Native for Web, its page in the
|
|
50
|
+
documentation (React, React Native).
|
|
51
|
+
- 3D buildings in the vector map: `vectors({ buildings3d: batiments3d() })` draws a 3D Tiles tileset (the IGN's
|
|
52
|
+
Bâtiments 3D) with the layer, in place of the style's raised buildings where the tileset covers, the style's kept
|
|
53
|
+
elsewhere (a town it has none of yet, abroad). The coverage is read from the tileset's children (`tilesetCoverage`,
|
|
54
|
+
a child tileset read when a tile meets it: Brussels out of the Nord's first box); `layer.buildings3d` for picking;
|
|
55
|
+
`<Geometry buildings3d>` in React. The Bâtiments 3D example uses it.
|
|
56
|
+
- 3D Tiles' facades: `addTiles3d({ facades: true })` or `tiles3dLayer.setFacades(true)` gives the walls of the
|
|
57
|
+
untextured meshes (the IGN's Bâtiments 3D) windows as the vector tiles' buildings have, glass by day and lit at night;
|
|
58
|
+
their faces lit as those buildings' are (the walls by the side they face, the roofs by their slope).
|
|
59
|
+
- A drag that turns and tilts the map (right button, Ctrl or Shift) goes around what it grabbed, a roof or a mesh as
|
|
60
|
+
the relief, which stays under the pointer (as in Google Earth), rather than around the street under the screen's
|
|
61
|
+
center; `map.setRotateAroundPointer(false)` turns around the center again.
|
|
62
|
+
- The Measure example: lengths in space between points clicked on the roofs and the ground (`map.pickSurface`), each
|
|
63
|
+
segment's rise, the line drawn over the map; an application's tool built on the map's API.
|
|
64
|
+
- Touch: two fingers side by side moving up or down together tilt the map (as MapLibre and Google Earth take them);
|
|
65
|
+
any other move of two fingers is still a pinch (zoom, turn, pan). The examples on a phone: their panel along the
|
|
66
|
+
bottom, scrolled within a part of the screen, folded by its title.
|
|
67
|
+
|
|
68
|
+
### Changed
|
|
69
|
+
|
|
70
|
+
- The Bâtiments 3D example: its buildings a neutral grey, without the windows of the facades, the camera tilting up to
|
|
71
|
+
the horizon (`maxPitch: 85`).
|
|
72
|
+
- The documentation: the roadmap by priority (a table at its top, P1 to P4, and what's next on the home page), a
|
|
73
|
+
React Native page, Layers in the API menu.
|
|
74
|
+
|
|
75
|
+
### Fixed
|
|
76
|
+
|
|
77
|
+
- Fills and extrusions: ring offsets running backwards no longer read the same points again and again. A ring starting
|
|
78
|
+
before the end of its polygon's previous rings starts at that end, so a polygon never costs more than its points (the
|
|
79
|
+
fuzzer's input piled one ring as 98 identical holes, earcut taking over 150 ms where it now takes under 1 ms).
|
|
80
|
+
- Tiles that never came on a still map:
|
|
81
|
+
- a raster or relief tile that failed was asked again only at the next move: it now is once its cooldown is over;
|
|
82
|
+
- a raster request that hangs (no answer, a proxy holding the connection) is given up after 30 s and counted a
|
|
83
|
+
failure, where it held one of the requests allowed for good;
|
|
84
|
+
- the vector tiles' requests in the basemap workers are given up after 30 s too;
|
|
85
|
+
- a vector tile that failed (`vectors()`, extrusions, trees, lamps, furniture) is asked again after a pause (1 s,
|
|
86
|
+
doubled up to 30 s), not only at the next move.
|
|
87
|
+
- A lost WebGL context: the map's engine is freed at once and its calls go to one that does nothing until the context
|
|
88
|
+
is restored, the next engine taking the camera set meanwhile. A vector tile uploaded meanwhile threw "more than this
|
|
89
|
+
GPU takes (0 at most)" (the limits of a lost context read 0), and freeing the old engine on the context restored
|
|
90
|
+
raised a warning for each of its GPU objects (#87).
|
|
91
|
+
|
|
6
92
|
## [1.9.0] - 2026-10-26
|
|
7
93
|
|
|
8
94
|
### Changed
|
package/README.md
CHANGED
|
@@ -179,10 +179,15 @@ More in [Develop and release](https://ideal-adventure-zqn6y6p.pages.github.io/gu
|
|
|
179
179
|
|
|
180
180
|
## Roadmap
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
182
|
+
By priority:
|
|
183
|
+
|
|
184
|
+
- **P1**, next: areas and heights in the measure.
|
|
185
|
+
- **P2**, then: rasters draped on the buildings; rasters draped within an area; a clipping volume; a performance report.
|
|
186
|
+
- **P3**, later: objects moving along paths; video in the scene.
|
|
187
|
+
- **P4**, when time allows: the whole MapLibre style drawn as vectors, a 3D vector map to walk through, Panoramax's
|
|
188
|
+
street-level photos, fluids on the globe, several projections on the globe, smaller items.
|
|
189
|
+
|
|
190
|
+
See [Roadmap](https://ideal-adventure-zqn6y6p.pages.github.io/guide/roadmap).
|
|
186
191
|
|
|
187
192
|
## Licence
|
|
188
193
|
|
|
@@ -6,6 +6,11 @@ export declare class TileRequests {
|
|
|
6
6
|
private readonly held;
|
|
7
7
|
/** The requests not answered yet, by key */
|
|
8
8
|
private readonly pending;
|
|
9
|
+
/** What asks again for the tiles that failed (the layer's update), and when it is due */
|
|
10
|
+
private readonly retry;
|
|
11
|
+
/** Asks again for the tiles that failed with `update` (the layer's), after a pause: a still map brings no update of
|
|
12
|
+
* its own, a tile failed would wait for the next move */
|
|
13
|
+
retryWith(update: () => void): void;
|
|
9
14
|
/** Whether the tile is held or asked for */
|
|
10
15
|
has(key: string): boolean;
|
|
11
16
|
/** The keys of the tiles held or asked for (a copy: the tiles can be dropped while it is gone through) */
|
|
@@ -22,7 +27,9 @@ export declare class TileRequests {
|
|
|
22
27
|
answered(keys: Iterable<string>): Promise<void>;
|
|
23
28
|
/** Aborts the tile's request and forgets it */
|
|
24
29
|
drop(key: string): void;
|
|
25
|
-
/** Aborts every request and forgets every tile */
|
|
30
|
+
/** Aborts every request and forgets every tile, a retry due with them */
|
|
26
31
|
abortAll(): void;
|
|
32
|
+
/** A tile failed: the update asked for after the pause, once for every tile failed meanwhile */
|
|
33
|
+
private failed;
|
|
27
34
|
private open;
|
|
28
35
|
}
|
|
@@ -2,10 +2,21 @@
|
|
|
2
2
|
* The requests of a layer whose tiles follow the view (`VectorTiles`' extrusions, streets' wind, trees, vectors): the
|
|
3
3
|
* tiles held or asked for, by key, each with the controller that aborts its request.
|
|
4
4
|
*/
|
|
5
|
+
/** Pause before the tiles that failed are asked for again when no move brings an update (ms), doubled at each failure
|
|
6
|
+
* in a row up to `RETRY_MAX_MS` */
|
|
7
|
+
const RETRY_FIRST_MS = 1000;
|
|
8
|
+
const RETRY_MAX_MS = 30_000;
|
|
5
9
|
export class TileRequests {
|
|
6
10
|
held = new Map();
|
|
7
11
|
/** The requests not answered yet, by key */
|
|
8
12
|
pending = new Map();
|
|
13
|
+
/** What asks again for the tiles that failed (the layer's update), and when it is due */
|
|
14
|
+
retry = { timer: undefined, wait: RETRY_FIRST_MS };
|
|
15
|
+
/** Asks again for the tiles that failed with `update` (the layer's), after a pause: a still map brings no update of
|
|
16
|
+
* its own, a tile failed would wait for the next move */
|
|
17
|
+
retryWith(update) {
|
|
18
|
+
this.retry.update = update;
|
|
19
|
+
}
|
|
9
20
|
/** Whether the tile is held or asked for */
|
|
10
21
|
has(key) {
|
|
11
22
|
return this.held.has(key);
|
|
@@ -25,10 +36,12 @@ export class TileRequests {
|
|
|
25
36
|
*/
|
|
26
37
|
ask(key, request, use) {
|
|
27
38
|
const controller = this.open(key);
|
|
28
|
-
// A later request under the same key is not forgotten by this one's failure
|
|
39
|
+
// A later request under the same key is not forgotten by this one's failure (nor one dropped: it is not wanted)
|
|
29
40
|
const forget = () => {
|
|
30
|
-
if (this.held.get(key)
|
|
31
|
-
|
|
41
|
+
if (this.held.get(key) !== controller)
|
|
42
|
+
return;
|
|
43
|
+
this.held.delete(key);
|
|
44
|
+
this.failed();
|
|
32
45
|
};
|
|
33
46
|
const answered = request(controller.signal)
|
|
34
47
|
.then(async (answer) => {
|
|
@@ -36,6 +49,7 @@ export class TileRequests {
|
|
|
36
49
|
return;
|
|
37
50
|
try {
|
|
38
51
|
await use(answer);
|
|
52
|
+
this.retry.wait = RETRY_FIRST_MS;
|
|
39
53
|
}
|
|
40
54
|
catch (error) {
|
|
41
55
|
console.warn('isard: a vector tile not drawn', error);
|
|
@@ -58,12 +72,26 @@ export class TileRequests {
|
|
|
58
72
|
this.held.get(key)?.abort();
|
|
59
73
|
this.held.delete(key);
|
|
60
74
|
}
|
|
61
|
-
/** Aborts every request and forgets every tile */
|
|
75
|
+
/** Aborts every request and forgets every tile, a retry due with them */
|
|
62
76
|
abortAll() {
|
|
63
77
|
this.held.forEach((controller) => {
|
|
64
78
|
controller.abort();
|
|
65
79
|
});
|
|
66
80
|
this.held.clear();
|
|
81
|
+
clearTimeout(this.retry.timer);
|
|
82
|
+
this.retry.timer = undefined;
|
|
83
|
+
this.retry.wait = RETRY_FIRST_MS;
|
|
84
|
+
}
|
|
85
|
+
/** A tile failed: the update asked for after the pause, once for every tile failed meanwhile */
|
|
86
|
+
failed() {
|
|
87
|
+
const { update, timer, wait } = this.retry;
|
|
88
|
+
if (!update || timer !== undefined)
|
|
89
|
+
return;
|
|
90
|
+
this.retry.timer = setTimeout(() => {
|
|
91
|
+
this.retry.timer = undefined;
|
|
92
|
+
update();
|
|
93
|
+
}, wait);
|
|
94
|
+
this.retry.wait = Math.min(wait * 2, RETRY_MAX_MS);
|
|
67
95
|
}
|
|
68
96
|
open(key) {
|
|
69
97
|
const controller = new AbortController();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.js","sourceRoot":"","sources":["../../../src/basemap/vectortiles/requests.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,OAAO,YAAY;IACN,IAAI,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC3D,4CAA4C;IAC3B,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"requests.js","sourceRoot":"","sources":["../../../src/basemap/vectortiles/requests.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;mCACmC;AACnC,MAAM,cAAc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,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAClB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;QAC7B,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,cAAc,CAAC;IACnC,CAAC;IAED,gGAAgG;IACxF,MAAM;QACZ,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAE3C,IAAI,CAAC,MAAM,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO;QAC3C,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACjC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;YAC7B,MAAM,EAAE,CAAC;QACX,CAAC,EAAE,IAAI,CAAC,CAAC;QACT,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,EAAE,YAAY,CAAC,CAAC;IACrD,CAAC;IAEO,IAAI,CAAC,GAAW;QACtB,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QAEzC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAE/B,OAAO,UAAU,CAAC;IACpB,CAAC;CACF","sourcesContent":["/**\n * The requests of a layer whose tiles follow the view (`VectorTiles`' extrusions, streets' wind, trees, vectors): the\n * tiles held or asked for, by key, each with the controller that aborts its request.\n */\n\n/** Pause before the tiles that failed are asked for again when no move brings an update (ms), doubled at each failure\n * in a row up to `RETRY_MAX_MS` */\nconst RETRY_FIRST_MS = 1000;\nconst RETRY_MAX_MS = 30_000;\n\nexport class TileRequests {\n private readonly held = new Map<string, AbortController>();\n /** The requests not answered yet, by key */\n private readonly pending = new Map<string, Promise<void>>();\n /** What asks again for the tiles that failed (the layer's update), and when it is due */\n private readonly retry: {\n update?: () => void;\n timer: ReturnType<typeof setTimeout> | undefined;\n wait: number;\n } = { timer: undefined, wait: RETRY_FIRST_MS };\n\n /** Asks again for the tiles that failed with `update` (the layer's), after a pause: a still map brings no update of\n * its own, a tile failed would wait for the next move */\n retryWith(update: () => void): void {\n this.retry.update = update;\n }\n\n /** Whether the tile is held or asked for */\n has(key: string): boolean {\n return this.held.has(key);\n }\n\n /** The keys of the tiles held or asked for (a copy: the tiles can be dropped while it is gone through) */\n keys(): string[] {\n return [...this.held.keys()];\n }\n\n /** Holds a new request under `key` (the one it held before is forgotten, not aborted); returns its signal */\n start(key: string): AbortSignal {\n return this.open(key).signal;\n }\n\n /**\n * Asks for a tile (`request`) and does with its answer what `use` does, unless the request was aborted meanwhile. On\n * a failure of either, the tile is forgotten (the next update asks for it again); an error of `use` (the engine\n * refusing the tile) is reported, never left unhandled\n */\n ask<T>(key: string, request: (signal: AbortSignal) => Promise<T>, use: (answer: T) => unknown): Promise<void> {\n const controller = this.open(key);\n // A later request under the same key is not forgotten by this one's failure (nor one dropped: it is not wanted)\n const forget = () => {\n if (this.held.get(key) !== controller) return;\n this.held.delete(key);\n this.failed();\n };\n\n const answered = request(controller.signal)\n .then(async (answer) => {\n if (controller.signal.aborted) return;\n\n try {\n await use(answer);\n this.retry.wait = RETRY_FIRST_MS;\n } catch (error) {\n console.warn('isard: a vector tile not drawn', error);\n forget();\n }\n }, forget)\n .finally(() => {\n if (this.pending.get(key) === answered) this.pending.delete(key);\n });\n\n this.pending.set(key, answered);\n\n return answered;\n }\n\n /** Resolves once the tiles of `keys` asked for, by this update or an earlier one, are answered (or dropped) */\n answered(keys: Iterable<string>): Promise<void> {\n return Promise.all([...keys].map((k) => this.pending.get(k))).then(() => undefined);\n }\n\n /** Aborts the tile's request and forgets it */\n drop(key: string): void {\n this.held.get(key)?.abort();\n this.held.delete(key);\n }\n\n /** Aborts every request and forgets every tile, a retry due with them */\n abortAll(): void {\n this.held.forEach((controller) => {\n controller.abort();\n });\n this.held.clear();\n clearTimeout(this.retry.timer);\n this.retry.timer = undefined;\n this.retry.wait = RETRY_FIRST_MS;\n }\n\n /** A tile failed: the update asked for after the pause, once for every tile failed meanwhile */\n private failed(): void {\n const { update, timer, wait } = this.retry;\n\n if (!update || timer !== undefined) return;\n this.retry.timer = setTimeout(() => {\n this.retry.timer = undefined;\n update();\n }, wait);\n this.retry.wait = Math.min(wait * 2, RETRY_MAX_MS);\n }\n\n private open(key: string): AbortController {\n const controller = new AbortController();\n\n this.held.set(key, controller);\n\n return controller;\n }\n}\n"]}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { Icons } from '../../layers/icons.ts';
|
|
6
6
|
import type { VectorLayer } from '../../layers/vectors.ts';
|
|
7
|
-
import type { Placement } from '../../types.ts';
|
|
7
|
+
import type { Placement, Tiles3dOptions } from '../../types.ts';
|
|
8
8
|
import type { RoofMode } from '../../util/roofs.ts';
|
|
9
9
|
import { type Json, type StyleLayer } from '../vectorstyle.ts';
|
|
10
10
|
import type { VectorTilesContext } from './context.ts';
|
|
@@ -31,5 +31,12 @@ export interface VectorsOptions extends Placement {
|
|
|
31
31
|
roofs?: RoofMode;
|
|
32
32
|
/** The buildings' walls show their windows: glass by day, some lit at night (default false: only the lit ones) */
|
|
33
33
|
facades?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 3D buildings in place of the style's raised ones where they have some: a 3D Tiles tileset (`batiments3d()`: the
|
|
36
|
+
* IGN's Bâtiments 3D over France) drawn with the layer, removed and moved with it (its `companions`); the style's
|
|
37
|
+
* buildings left out where the tileset's children cover (their boxes, read from its `tileset.json`, a child that is
|
|
38
|
+
* a tileset of its own read when a tile meets it), kept elsewhere; their walls' windows with `facades`
|
|
39
|
+
*/
|
|
40
|
+
buildings3d?: Tiles3dOptions;
|
|
34
41
|
}
|
|
35
42
|
export declare const vectors: (context: VectorTilesContext, options?: VectorsOptions) => VectorLayer;
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* The vector layer of a vector basemap (`VectorTiles.vectors`): its fills, lines and buildings cut by the workers
|
|
3
3
|
* into geometry the engine draws, the tiles following the view, and how its style layers are read for the engine.
|
|
4
4
|
*/
|
|
5
|
+
import { tilesetCoverage } from "../../data/tileset.js";
|
|
6
|
+
import { latitude, longitude } from "../../util/geo.js";
|
|
5
7
|
import { FLOATS, STYLE } from "../../util/style-floats.js";
|
|
6
8
|
import { evaluate, isExpression, vectorKind, zoomOnly } from "../vectorstyle.js";
|
|
7
9
|
import { TileRequests } from "./requests.js";
|
|
@@ -82,6 +84,12 @@ export const vectors = (context, options = {}) => {
|
|
|
82
84
|
const { map } = context;
|
|
83
85
|
const { layers = () => true, streets = isStreet, before, roofs = 'data', facades = false } = options;
|
|
84
86
|
const vector = map.addVectorLayer(before);
|
|
87
|
+
// The 3D buildings over the layer's ground, and where they stand
|
|
88
|
+
const buildings = options.buildings3d && map.addTiles3d({ ...options.buildings3d, ...(before && { before }) });
|
|
89
|
+
const coverage = options.buildings3d && tilesetCoverage(options.buildings3d.url);
|
|
90
|
+
if (buildings)
|
|
91
|
+
vector.companions.push(buildings);
|
|
92
|
+
vector.buildings3d = buildings;
|
|
85
93
|
vector.setFacades(facades);
|
|
86
94
|
const state = { renderer: context.renderer((l) => vectorKind(l) !== undefined && layers(l), []), update: 0, style: 0 };
|
|
87
95
|
state.renderer.catch(() => undefined);
|
|
@@ -117,9 +125,25 @@ export const vectors = (context, options = {}) => {
|
|
|
117
125
|
const requests = new TileRequests();
|
|
118
126
|
/** A tile's geometry, or its styles alone, asked of the worker of its tile of the source's level (which keeps the
|
|
119
127
|
* decoded tile its deeper tiles are cut from) */
|
|
120
|
-
const ask = ({ key, maxzoom }, [z, x, y], styles, priority, signal) => {
|
|
128
|
+
const ask = async ({ key, maxzoom }, [z, x, y], styles, priority, signal) => {
|
|
121
129
|
const d = Math.max(0, z - maxzoom);
|
|
122
|
-
|
|
130
|
+
// Where the 3D buildings stand over the source's tile the worker cuts (none known: the style's buildings kept)
|
|
131
|
+
const n = 2 ** (z - d);
|
|
132
|
+
const [tx, ty] = [Math.floor(x / 2 ** d), Math.floor(y / 2 ** d)];
|
|
133
|
+
const covered = await coverage
|
|
134
|
+
?.within([longitude(tx / n), latitude((ty + 1) / n), longitude((tx + 1) / n), latitude(ty / n)])
|
|
135
|
+
.catch(() => undefined);
|
|
136
|
+
const work = {
|
|
137
|
+
type: 'vectors',
|
|
138
|
+
key,
|
|
139
|
+
z,
|
|
140
|
+
x,
|
|
141
|
+
y,
|
|
142
|
+
deepest: deepestLevel(maxzoom),
|
|
143
|
+
roofs,
|
|
144
|
+
...(covered?.length ? { covered } : {}),
|
|
145
|
+
priority,
|
|
146
|
+
};
|
|
123
147
|
// The geometry made ready for the GPU in the workers, with the prisms the relief needs
|
|
124
148
|
return context.request(z - d, Math.floor(x / 2 ** d), Math.floor(y / 2 ** d), styles ? { ...work, styles } : { ...work, prism: map.hasRelief }, signal);
|
|
125
149
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vectors.js","sourceRoot":"","sources":["../../../src/basemap/vectortiles/vectors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAA8B,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7G,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAmB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE/F;;wEAEwE;AACxE,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,6FAA6F;AAC7F,MAAM,YAAY,GAAG,CAAC,OAAe,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,C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AAC;YAED,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAC;IACF,MAAM,CAAC,KAAK,GAAG,GAAG,EAAE;QAClB,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;IACF,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE;QACvD,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YAAE,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;IACH,kCAAkC;IAClC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAErC,kHAAkH;IAClH,mBAAmB;IACnB,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAErD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["/**\n * The vector layer of a vector basemap (`VectorTiles.vectors`): its fills, lines and buildings cut by the workers\n * into geometry the engine draws, the tiles following the view, and how its style layers are read for the engine.\n */\n\nimport type { Icons } from '../../layers/icons.ts';\nimport type { VectorLayer, VectorSublayer } from '../../layers/vectors.ts';\nimport type { Placement } from '../../types.ts';\nimport type { RoofMode } from '../../util/roofs.ts';\nimport { FLOATS, STYLE } from '../../util/style-floats.ts';\nimport type { BasemapWork, Priority } from '../../workers/basemap/protocol.ts';\nimport { evaluate, isExpression, type Json, type StyleLayer, vectorKind, zoomOnly } from '../vectorstyle.ts';\nimport type { Renderer, VectorTilesContext } from './context.ts';\nimport { TileRequests } from './requests.ts';\nimport { nearPriority, parseTileKey, type TileTriple, tileKey, tileTriples } from './tiles.ts';\n\n/** The deepest level `vectors()` cuts its tiles at: past the source's deepest level, its tiles cut again into deeper\n * ones (overzoom, as MapLibre does) down to level 18, their styles those of their level, smaller tiles\n * drawn in a closer view; past it, the tiles of that level stretched */\nconst OVERZOOM_LEVEL = 18;\n\n/** The deepest level of the tiles of `vectors()` over a source whose deepest is `maxzoom` */\nconst deepestLevel = (maxzoom: number): number => Math.max(maxzoom, OVERZOOM_LEVEL);\n\n/** A layout or paint value at a zoom, whatever the feature (an expression evaluated) */\nconst atZoom = (value: Json | undefined, zoom: number): unknown =>\n isExpression(value) ? evaluate(value, { zoom, properties: {}, type: 'Unknown' }) : value;\n\n/**\n * A `line-dasharray` as the engine takes it: two dashes and gaps in line widths (an odd count repeated, as the\n * canvas's `setLineDash`; past four, the first four), zeros for a solid line\n */\nexport const dashes = (value: Json | undefined, zoom: number): [number, number, number, number] => {\n const v = atZoom(value, zoom);\n const list = Array.isArray(v) ? v.map(Number).filter((d) => Number.isFinite(d) && d >= 0) : [];\n const even = list.length % 2 === 1 ? [...list, ...list] : list;\n const [a = 0, b = 0, c = 0, d = 0] = even.length >= 2 && even.some((x) => x > 0) ? even : [];\n\n return [a, b, c, d];\n};\n\n/** Whether a style layer draws streets, which glow at night: its id names a road (OpenMapTiles' styles, PLAN IGN's),\n * not its casing, a railway, a path or a tunnel */\nexport const isStreet = (layer: StyleLayer): boolean =>\n /road|highway|street|motorway|trunk|primary|secondary|tertiary|minor|routier/i.test(layer.id) &&\n !/casing|outline|rail|path|track|ferry|tunnel|pier|area|pattern|label/i.test(layer.id);\n\n/** A `line-cap` as the engine draws it, at the camera's zoom (MapLibre's default: butt) */\nconst lineCap = (value: Json | undefined, zoom: number): 'butt' | 'round' | 'square' => {\n const v = atZoom(value, zoom);\n\n return v === 'round' || v === 'square' ? v : 'butt';\n};\n\n/** A `line-join` as the engine draws it, at the camera's zoom (MapLibre's default: miter) */\nconst lineJoin = (value: Json | undefined, zoom: number): 'miter' | 'bevel' | 'round' => {\n const v = atZoom(value, zoom);\n\n return v === 'round' || v === 'bevel' ? v : 'miter';\n};\n\n/** A `line-miter-limit` at the camera's zoom (MapLibre's default: 2) */\nconst miterLimit = (value: Json | undefined, zoom: number): number => {\n const v = Number(atZoom(value, zoom) ?? 2);\n\n return Number.isFinite(v) ? v : 2;\n};\n\n/** A tile's styles with their patterns placed: each feature's pattern, as its index past one into `names`\n * (`STYLE.fillPattern`, `STYLE.linePattern`), replaced by its image's place in the icon atlas (texels) and pixel\n * ratio; none if the atlas has no such image; the atlas uploaded */\nexport const placePatterns = (\n styles: Float32Array,\n names: readonly string[] | undefined,\n icons: Icons,\n prefix: string,\n): Float32Array => {\n if (!names?.length) return styles;\n // Thousands of features a tile: a loop\n for (let f = 0; f + FLOATS <= styles.length; f += FLOATS) {\n const fill = styles[f + STYLE.fillPattern] ?? 0;\n const line = styles[f + STYLE.linePattern] ?? 0;\n const index = fill > 0 ? fill : line;\n\n if (index <= 0) continue;\n\n const icon = icons.get(prefix + (names[index - 1] ?? ''));\n const place = icon ? [icon.x, icon.y, icon.width, icon.height] : [0, 0, 0, 0];\n const ratio = icon?.pixelRatio ?? 0;\n\n if (fill > 0) styles.set([...place, ratio], f + STYLE.size + 4);\n else {\n styles.set(place, f + STYLE.second);\n styles[f + STYLE.patternRatio] = ratio;\n }\n }\n icons.flush();\n\n return styles;\n};\n\n/** The paint properties of the patterns `vectors()` draws, whose images come from the style's sprite */\nconst PATTERNS = ['fill-pattern', 'background-pattern', 'line-pattern', 'fill-extrusion-pattern'];\n\n/** A `fill-translate` or `line-translate` at the camera's zoom (CSS pixels; none if it is not two numbers) */\nexport const translation = (value: Json | undefined, zoom: number): [number, number] => {\n const v = atZoom(value, zoom);\n const [x, y] = Array.isArray(v) ? v.map(Number) : [];\n\n return Number.isFinite(x) && Number.isFinite(y) ? [x ?? 0, y ?? 0] : [0, 0];\n};\n\n/** The options of `VectorTiles.vectors` */\nexport interface VectorsOptions extends Placement {\n layers?: (layer: StyleLayer) => boolean;\n streets?: (layer: StyleLayer) => boolean;\n /** The buildings' roofs: from their data (`roof:shape`, `roof:height`; flat without, the default), generated from\n * their outline where they have none (hipped, gabled or mansard by size and shape), or all flat */\n roofs?: RoofMode;\n /** The buildings' walls show their windows: glass by day, some lit at night (default false: only the lit ones) */\n facades?: boolean;\n}\n\nexport const vectors = (context: VectorTilesContext, options: VectorsOptions = {}): VectorLayer => {\n const { map } = context;\n const { layers = () => true, streets = isStreet, before, roofs = 'data', facades = false } = options;\n const vector = map.addVectorLayer(before);\n\n vector.setFacades(facades);\n const state: {\n renderer: Promise<Renderer>;\n /** The style layers as the application changed them (`setPaintProperty`…): a copy, its style left as it is */\n own?: StyleLayer[];\n /** Bumped by each update: only the last one drops the tiles out of its view */\n update: number;\n /** Bumped by each restyle: a tile cut under an older style is restyled once it is there */\n style: number;\n } = { renderer: context.renderer((l) => vectorKind(l) !== undefined && layers(l), []), update: 0, style: 0 };\n\n state.renderer.catch(() => undefined);\n\n /** The style's sprites among the map's icons, if a layer drawn has a pattern: waited for before the first tiles */\n const sprites = context.ready\n .then(({ style }) =>\n style.layers.some((l) => layers(l) && PATTERNS.some((k) => l.paint?.[k] !== undefined))\n ? context.addSprites()\n : undefined,\n )\n .catch(() => undefined);\n const placed = (styles: Float32Array, names: readonly string[] | undefined) =>\n placePatterns(styles, names, map.icons, context.iconPrefix);\n context.layers.push(vector);\n\n const sublayers = (list: StyleLayer[]): VectorSublayer[] => {\n const zoom = map.getCamera().zoom;\n\n return list.map((l) => ({\n id: l.id,\n sourceLayer: l['source-layer'],\n kind: vectorKind(l) ?? 'fill',\n minZoom: l.minzoom ?? 0,\n maxZoom: l.maxzoom ?? 24,\n visible: l.layout?.visibility !== 'none',\n opacity: zoomOnly(l.paint?.[`${l.type}-opacity`], 1) ?? 1,\n cap: lineCap(l.layout?.['line-cap'], zoom),\n join: lineJoin(l.layout?.['line-join'], zoom),\n miterLimit: miterLimit(l.layout?.['line-miter-limit'], zoom),\n translate: translation(l.paint?.[`${l.type}-translate`], zoom),\n translateAnchor: l.paint?.[`${l.type}-translate-anchor`] === 'viewport' ? 'viewport' : 'map',\n patterned: l.paint?.['fill-pattern'] !== undefined || l.paint?.['background-pattern'] !== undefined,\n lit: l.type === 'line' && streets(l),\n dash: l.type === 'line' ? dashes(l.paint?.['line-dasharray'], zoom) : [0, 0, 0, 0],\n }));\n };\n\n /** The tiles held or asked for, by `z/x/y` */\n const requests = new TileRequests();\n /** A tile's geometry, or its styles alone, asked of the worker of its tile of the source's level (which keeps the\n * decoded tile its deeper tiles are cut from) */\n const ask = (\n { key, maxzoom }: { key: string; maxzoom: number },\n [z, x, y]: TileTriple,\n styles: boolean,\n priority: Priority,\n signal?: AbortSignal,\n ) => {\n const d = Math.max(0, z - maxzoom);\n const work: BasemapWork = { type: 'vectors', key, z, x, y, deepest: deepestLevel(maxzoom), roofs, priority };\n\n // The geometry made ready for the GPU in the workers, with the prisms the relief needs\n return context.request(\n z - d,\n Math.floor(x / 2 ** d),\n Math.floor(y / 2 ** d),\n styles ? { ...work, styles } : { ...work, prism: map.hasRelief },\n signal,\n );\n };\n\n // The workers tessellate the tiles (the main thread only uploads them), once they know the module\n context.broadcast({ type: 'tess', url: map.tessUrl });\n /** Asks the workers again for the styles of a tile held, under the current style; the tile's geometry stays as it\n * is */\n const restyleTile = async (renderer: { key: string; maxzoom: number }, k: string) => {\n const r = await ask(renderer, parseTileKey(k), true, 'auto').catch(() => undefined);\n\n if (r && 'styles' in r) vector.setTileStyles(k, placed(r.styles, r.patterns));\n };\n const update = async () => {\n if (context.destroyed()) return;\n\n const generation = ++state.update;\n // The style the tiles are cut under: that of the renderer awaited, a restyle meanwhile (a paint property set as the\n // style loads) asking their styles again once they are there\n const style = state.style;\n const { key, maxzoom, layers: list } = await state.renderer;\n\n await sprites;\n\n vector.setSublayers(sublayers(state.own ?? list));\n\n const wanted = tileTriples(map.engine.vectorTilesInView(0, deepestLevel(maxzoom)));\n const keys = new Set(wanted.map((t) => tileKey(...t)));\n const loads = wanted.flatMap((t, index) => {\n const k = tileKey(...t);\n\n if (requests.has(k)) return [];\n\n return [\n requests.ask(\n k,\n (signal) => ask({ key, maxzoom }, t, false, nearPriority(index, 'high', 'auto'), signal),\n async (r) => {\n if (!('vectors' in r)) return;\n await vector.setTile(k, { ...r.vectors, styles: placed(r.vectors.styles, r.vectors.patterns) });\n // Cut under a style changed since: its styles asked for again\n if (style !== state.style) await restyleTile(await state.renderer, k);\n },\n ),\n ];\n });\n // Out of view: those still asked for go at once, those drawn once their replacements are there (no hole). The\n // drawn ones are those the engine shows, held or not (a recut forgets what it held, not what is drawn)\n const drop = (drawn: boolean) => {\n const shown = new Set(vector.tileKeys);\n const known = new Set([...requests.keys(), ...(drawn ? shown : [])]);\n\n known.forEach((k) => {\n if (keys.has(k) || shown.has(k) !== drawn) return;\n requests.drop(k);\n vector.removeTile(k);\n });\n };\n\n drop(false);\n // Every tile of the view, those an earlier update asked for too: a tile out of view stays drawn until all of them\n // are there\n await Promise.all([...loads, requests.answered(keys)]);\n // A later update (the view moved again meanwhile) drops for its own view: these keys are no longer the view\n if (!context.destroyed() && generation === state.update) drop(true);\n };\n const refresh = () => {\n update().catch(() => undefined);\n };\n /** The style layers changed: the workers' copy, then the styles of the tiles held */\n const restyle = async (list: StyleLayer[]) => {\n state.own = list;\n state.style++;\n state.renderer = state.renderer.then(({ key }) => context.renderer(() => false, list, key));\n\n const renderer = await state.renderer;\n\n vector.setSublayers(sublayers(list));\n await Promise.all(vector.tileKeys.map((k) => restyleTile(renderer, k)));\n };\n\n vector.restyle = (id, group, name, value) => {\n state.renderer\n .then(({ layers: list }) => {\n const next = (state.own ?? list).map((l) =>\n l.id === id ? { ...l, [group]: { ...l[group], [name]: value } } : l,\n );\n\n // Visibility and dashes are the engine's: the tiles stay as they are\n if ((group === 'layout' && name === 'visibility') || name === 'line-dasharray') {\n state.own = next;\n vector.setSublayers(sublayers(next));\n\n return undefined;\n }\n // An outline added or taken away: a feature more or less in each tile, cut again\n if (name === 'fill-outline-color' || name === 'fill-antialias') {\n state.own = next;\n state.style++;\n state.renderer = state.renderer.then(({ key }) => context.renderer(() => false, next, key));\n vector.setSublayers(sublayers(next));\n vector.recut?.();\n\n return undefined;\n }\n\n return restyle(next);\n })\n .catch(() => undefined);\n };\n vector.recut = () => {\n requests.abortAll();\n refresh();\n };\n vector.styled = state.renderer.then(({ layers: list }) => {\n if (!context.destroyed()) vector.setSublayers(sublayers(state.own ?? list));\n });\n // Reported by the style's `ready`\n vector.styled.catch(() => undefined);\n\n // While the camera moves, the tiles follow it (as the labels do: a long drag or flight does not leave the view of\n // its start drawn)\n context.followView(vector, update, requests, update);\n\n return vector;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"vectors.js","sourceRoot":"","sources":["../../../src/basemap/vectortiles/vectors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAIxD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAA8B,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7G,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAmB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE/F;;wEAEwE;AACxE,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B,6FAA6F;AAC7F,MAAM,YAAY,GAAG,CAAC,OAAe,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AAEpF,wFAAwF;AACxF,MAAM,MAAM,GAAG,CAAC,KAAuB,EAAE,IAAY,EAAW,EAAE,CAChE,YAAY,CAAC,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AAQ,CAAC,QAAQ,EAAE,CAAC;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;IACF,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE;QACvD,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YAAE,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;IACH,kCAAkC;IAClC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAErC,kHAAkH;IAClH,mBAAmB;IACnB,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAErD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["/**\n * The vector layer of a vector basemap (`VectorTiles.vectors`): its fills, lines and buildings cut by the workers\n * into geometry the engine draws, the tiles following the view, and how its style layers are read for the engine.\n */\n\nimport { tilesetCoverage } from '../../data/tileset.ts';\nimport type { Icons } from '../../layers/icons.ts';\nimport type { VectorLayer, VectorSublayer } from '../../layers/vectors.ts';\nimport type { Placement, Tiles3dOptions } from '../../types.ts';\nimport { latitude, longitude } from '../../util/geo.ts';\nimport type { RoofMode } from '../../util/roofs.ts';\nimport { FLOATS, STYLE } from '../../util/style-floats.ts';\nimport type { BasemapWork, Priority } from '../../workers/basemap/protocol.ts';\nimport { evaluate, isExpression, type Json, type StyleLayer, vectorKind, zoomOnly } from '../vectorstyle.ts';\nimport type { Renderer, VectorTilesContext } from './context.ts';\nimport { TileRequests } from './requests.ts';\nimport { nearPriority, parseTileKey, type TileTriple, tileKey, tileTriples } from './tiles.ts';\n\n/** The deepest level `vectors()` cuts its tiles at: past the source's deepest level, its tiles cut again into deeper\n * ones (overzoom, as MapLibre does) down to level 18, their styles those of their level, smaller tiles\n * drawn in a closer view; past it, the tiles of that level stretched */\nconst OVERZOOM_LEVEL = 18;\n\n/** The deepest level of the tiles of `vectors()` over a source whose deepest is `maxzoom` */\nconst deepestLevel = (maxzoom: number): number => Math.max(maxzoom, OVERZOOM_LEVEL);\n\n/** A layout or paint value at a zoom, whatever the feature (an expression evaluated) */\nconst atZoom = (value: Json | undefined, zoom: number): unknown =>\n isExpression(value) ? evaluate(value, { zoom, properties: {}, type: 'Unknown' }) : value;\n\n/**\n * A `line-dasharray` as the engine takes it: two dashes and gaps in line widths (an odd count repeated, as the\n * canvas's `setLineDash`; past four, the first four), zeros for a solid line\n */\nexport const dashes = (value: Json | undefined, zoom: number): [number, number, number, number] => {\n const v = atZoom(value, zoom);\n const list = Array.isArray(v) ? v.map(Number).filter((d) => Number.isFinite(d) && d >= 0) : [];\n const even = list.length % 2 === 1 ? [...list, ...list] : list;\n const [a = 0, b = 0, c = 0, d = 0] = even.length >= 2 && even.some((x) => x > 0) ? even : [];\n\n return [a, b, c, d];\n};\n\n/** Whether a style layer draws streets, which glow at night: its id names a road (OpenMapTiles' styles, PLAN IGN's),\n * not its casing, a railway, a path or a tunnel */\nexport const isStreet = (layer: StyleLayer): boolean =>\n /road|highway|street|motorway|trunk|primary|secondary|tertiary|minor|routier/i.test(layer.id) &&\n !/casing|outline|rail|path|track|ferry|tunnel|pier|area|pattern|label/i.test(layer.id);\n\n/** A `line-cap` as the engine draws it, at the camera's zoom (MapLibre's default: butt) */\nconst lineCap = (value: Json | undefined, zoom: number): 'butt' | 'round' | 'square' => {\n const v = atZoom(value, zoom);\n\n return v === 'round' || v === 'square' ? v : 'butt';\n};\n\n/** A `line-join` as the engine draws it, at the camera's zoom (MapLibre's default: miter) */\nconst lineJoin = (value: Json | undefined, zoom: number): 'miter' | 'bevel' | 'round' => {\n const v = atZoom(value, zoom);\n\n return v === 'round' || v === 'bevel' ? v : 'miter';\n};\n\n/** A `line-miter-limit` at the camera's zoom (MapLibre's default: 2) */\nconst miterLimit = (value: Json | undefined, zoom: number): number => {\n const v = Number(atZoom(value, zoom) ?? 2);\n\n return Number.isFinite(v) ? v : 2;\n};\n\n/** A tile's styles with their patterns placed: each feature's pattern, as its index past one into `names`\n * (`STYLE.fillPattern`, `STYLE.linePattern`), replaced by its image's place in the icon atlas (texels) and pixel\n * ratio; none if the atlas has no such image; the atlas uploaded */\nexport const placePatterns = (\n styles: Float32Array,\n names: readonly string[] | undefined,\n icons: Icons,\n prefix: string,\n): Float32Array => {\n if (!names?.length) return styles;\n // Thousands of features a tile: a loop\n for (let f = 0; f + FLOATS <= styles.length; f += FLOATS) {\n const fill = styles[f + STYLE.fillPattern] ?? 0;\n const line = styles[f + STYLE.linePattern] ?? 0;\n const index = fill > 0 ? fill : line;\n\n if (index <= 0) continue;\n\n const icon = icons.get(prefix + (names[index - 1] ?? ''));\n const place = icon ? [icon.x, icon.y, icon.width, icon.height] : [0, 0, 0, 0];\n const ratio = icon?.pixelRatio ?? 0;\n\n if (fill > 0) styles.set([...place, ratio], f + STYLE.size + 4);\n else {\n styles.set(place, f + STYLE.second);\n styles[f + STYLE.patternRatio] = ratio;\n }\n }\n icons.flush();\n\n return styles;\n};\n\n/** The paint properties of the patterns `vectors()` draws, whose images come from the style's sprite */\nconst PATTERNS = ['fill-pattern', 'background-pattern', 'line-pattern', 'fill-extrusion-pattern'];\n\n/** A `fill-translate` or `line-translate` at the camera's zoom (CSS pixels; none if it is not two numbers) */\nexport const translation = (value: Json | undefined, zoom: number): [number, number] => {\n const v = atZoom(value, zoom);\n const [x, y] = Array.isArray(v) ? v.map(Number) : [];\n\n return Number.isFinite(x) && Number.isFinite(y) ? [x ?? 0, y ?? 0] : [0, 0];\n};\n\n/** The options of `VectorTiles.vectors` */\nexport interface VectorsOptions extends Placement {\n layers?: (layer: StyleLayer) => boolean;\n streets?: (layer: StyleLayer) => boolean;\n /** The buildings' roofs: from their data (`roof:shape`, `roof:height`; flat without, the default), generated from\n * their outline where they have none (hipped, gabled or mansard by size and shape), or all flat */\n roofs?: RoofMode;\n /** The buildings' walls show their windows: glass by day, some lit at night (default false: only the lit ones) */\n facades?: boolean;\n /**\n * 3D buildings in place of the style's raised ones where they have some: a 3D Tiles tileset (`batiments3d()`: the\n * IGN's Bâtiments 3D over France) drawn with the layer, removed and moved with it (its `companions`); the style's\n * buildings left out where the tileset's children cover (their boxes, read from its `tileset.json`, a child that is\n * a tileset of its own read when a tile meets it), kept elsewhere; their walls' windows with `facades`\n */\n buildings3d?: Tiles3dOptions;\n}\n\nexport const vectors = (context: VectorTilesContext, options: VectorsOptions = {}): VectorLayer => {\n const { map } = context;\n const { layers = () => true, streets = isStreet, before, roofs = 'data', facades = false } = options;\n const vector = map.addVectorLayer(before);\n // The 3D buildings over the layer's ground, and where they stand\n const buildings = options.buildings3d && map.addTiles3d({ ...options.buildings3d, ...(before && { before }) });\n const coverage = options.buildings3d && tilesetCoverage(options.buildings3d.url);\n\n if (buildings) vector.companions.push(buildings);\n vector.buildings3d = buildings;\n vector.setFacades(facades);\n const state: {\n renderer: Promise<Renderer>;\n /** The style layers as the application changed them (`setPaintProperty`…): a copy, its style left as it is */\n own?: StyleLayer[];\n /** Bumped by each update: only the last one drops the tiles out of its view */\n update: number;\n /** Bumped by each restyle: a tile cut under an older style is restyled once it is there */\n style: number;\n } = { renderer: context.renderer((l) => vectorKind(l) !== undefined && layers(l), []), update: 0, style: 0 };\n\n state.renderer.catch(() => undefined);\n\n /** The style's sprites among the map's icons, if a layer drawn has a pattern: waited for before the first tiles */\n const sprites = context.ready\n .then(({ style }) =>\n style.layers.some((l) => layers(l) && PATTERNS.some((k) => l.paint?.[k] !== undefined))\n ? context.addSprites()\n : undefined,\n )\n .catch(() => undefined);\n const placed = (styles: Float32Array, names: readonly string[] | undefined) =>\n placePatterns(styles, names, map.icons, context.iconPrefix);\n context.layers.push(vector);\n\n const sublayers = (list: StyleLayer[]): VectorSublayer[] => {\n const zoom = map.getCamera().zoom;\n\n return list.map((l) => ({\n id: l.id,\n sourceLayer: l['source-layer'],\n kind: vectorKind(l) ?? 'fill',\n minZoom: l.minzoom ?? 0,\n maxZoom: l.maxzoom ?? 24,\n visible: l.layout?.visibility !== 'none',\n opacity: zoomOnly(l.paint?.[`${l.type}-opacity`], 1) ?? 1,\n cap: lineCap(l.layout?.['line-cap'], zoom),\n join: lineJoin(l.layout?.['line-join'], zoom),\n miterLimit: miterLimit(l.layout?.['line-miter-limit'], zoom),\n translate: translation(l.paint?.[`${l.type}-translate`], zoom),\n translateAnchor: l.paint?.[`${l.type}-translate-anchor`] === 'viewport' ? 'viewport' : 'map',\n patterned: l.paint?.['fill-pattern'] !== undefined || l.paint?.['background-pattern'] !== undefined,\n lit: l.type === 'line' && streets(l),\n dash: l.type === 'line' ? dashes(l.paint?.['line-dasharray'], zoom) : [0, 0, 0, 0],\n }));\n };\n\n /** The tiles held or asked for, by `z/x/y` */\n const requests = new TileRequests();\n /** A tile's geometry, or its styles alone, asked of the worker of its tile of the source's level (which keeps the\n * decoded tile its deeper tiles are cut from) */\n const ask = async (\n { key, maxzoom }: { key: string; maxzoom: number },\n [z, x, y]: TileTriple,\n styles: boolean,\n priority: Priority,\n signal?: AbortSignal,\n ) => {\n const d = Math.max(0, z - maxzoom);\n // Where the 3D buildings stand over the source's tile the worker cuts (none known: the style's buildings kept)\n const n = 2 ** (z - d);\n const [tx, ty] = [Math.floor(x / 2 ** d), Math.floor(y / 2 ** d)];\n const covered = await coverage\n ?.within([longitude(tx / n), latitude((ty + 1) / n), longitude((tx + 1) / n), latitude(ty / n)])\n .catch(() => undefined);\n const work: BasemapWork = {\n type: 'vectors',\n key,\n z,\n x,\n y,\n deepest: deepestLevel(maxzoom),\n roofs,\n ...(covered?.length ? { covered } : {}),\n priority,\n };\n\n // The geometry made ready for the GPU in the workers, with the prisms the relief needs\n return context.request(\n z - d,\n Math.floor(x / 2 ** d),\n Math.floor(y / 2 ** d),\n styles ? { ...work, styles } : { ...work, prism: map.hasRelief },\n signal,\n );\n };\n\n // The workers tessellate the tiles (the main thread only uploads them), once they know the module\n context.broadcast({ type: 'tess', url: map.tessUrl });\n /** Asks the workers again for the styles of a tile held, under the current style; the tile's geometry stays as it\n * is */\n const restyleTile = async (renderer: { key: string; maxzoom: number }, k: string) => {\n const r = await ask(renderer, parseTileKey(k), true, 'auto').catch(() => undefined);\n\n if (r && 'styles' in r) vector.setTileStyles(k, placed(r.styles, r.patterns));\n };\n const update = async () => {\n if (context.destroyed()) return;\n\n const generation = ++state.update;\n // The style the tiles are cut under: that of the renderer awaited, a restyle meanwhile (a paint property set as the\n // style loads) asking their styles again once they are there\n const style = state.style;\n const { key, maxzoom, layers: list } = await state.renderer;\n\n await sprites;\n\n vector.setSublayers(sublayers(state.own ?? list));\n\n const wanted = tileTriples(map.engine.vectorTilesInView(0, deepestLevel(maxzoom)));\n const keys = new Set(wanted.map((t) => tileKey(...t)));\n const loads = wanted.flatMap((t, index) => {\n const k = tileKey(...t);\n\n if (requests.has(k)) return [];\n\n return [\n requests.ask(\n k,\n (signal) => ask({ key, maxzoom }, t, false, nearPriority(index, 'high', 'auto'), signal),\n async (r) => {\n if (!('vectors' in r)) return;\n await vector.setTile(k, { ...r.vectors, styles: placed(r.vectors.styles, r.vectors.patterns) });\n // Cut under a style changed since: its styles asked for again\n if (style !== state.style) await restyleTile(await state.renderer, k);\n },\n ),\n ];\n });\n // Out of view: those still asked for go at once, those drawn once their replacements are there (no hole). The\n // drawn ones are those the engine shows, held or not (a recut forgets what it held, not what is drawn)\n const drop = (drawn: boolean) => {\n const shown = new Set(vector.tileKeys);\n const known = new Set([...requests.keys(), ...(drawn ? shown : [])]);\n\n known.forEach((k) => {\n if (keys.has(k) || shown.has(k) !== drawn) return;\n requests.drop(k);\n vector.removeTile(k);\n });\n };\n\n drop(false);\n // Every tile of the view, those an earlier update asked for too: a tile out of view stays drawn until all of them\n // are there\n await Promise.all([...loads, requests.answered(keys)]);\n // A later update (the view moved again meanwhile) drops for its own view: these keys are no longer the view\n if (!context.destroyed() && generation === state.update) drop(true);\n };\n const refresh = () => {\n update().catch(() => undefined);\n };\n /** The style layers changed: the workers' copy, then the styles of the tiles held */\n const restyle = async (list: StyleLayer[]) => {\n state.own = list;\n state.style++;\n state.renderer = state.renderer.then(({ key }) => context.renderer(() => false, list, key));\n\n const renderer = await state.renderer;\n\n vector.setSublayers(sublayers(list));\n await Promise.all(vector.tileKeys.map((k) => restyleTile(renderer, k)));\n };\n\n vector.restyle = (id, group, name, value) => {\n state.renderer\n .then(({ layers: list }) => {\n const next = (state.own ?? list).map((l) =>\n l.id === id ? { ...l, [group]: { ...l[group], [name]: value } } : l,\n );\n\n // Visibility and dashes are the engine's: the tiles stay as they are\n if ((group === 'layout' && name === 'visibility') || name === 'line-dasharray') {\n state.own = next;\n vector.setSublayers(sublayers(next));\n\n return undefined;\n }\n // An outline added or taken away: a feature more or less in each tile, cut again\n if (name === 'fill-outline-color' || name === 'fill-antialias') {\n state.own = next;\n state.style++;\n state.renderer = state.renderer.then(({ key }) => context.renderer(() => false, next, key));\n vector.setSublayers(sublayers(next));\n vector.recut?.();\n\n return undefined;\n }\n\n return restyle(next);\n })\n .catch(() => undefined);\n };\n vector.recut = () => {\n requests.abortAll();\n refresh();\n };\n vector.styled = state.renderer.then(({ layers: list }) => {\n if (!context.destroyed()) vector.setSublayers(sublayers(state.own ?? list));\n });\n // Reported by the style's `ready`\n vector.styled.catch(() => undefined);\n\n // While the camera moves, the tiles follow it (as the labels do: a long drag or flight does not leave the view of\n // its start drawn)\n context.followView(vector, update, requests, update);\n\n return vector;\n};\n"]}
|
|
@@ -28,6 +28,18 @@ import { type LoadedStyle, OPENFREEMAP_STYLES, PLAN_STYLES, styleAttribution, VE
|
|
|
28
28
|
import { type TreesOptions } from './vectortiles/trees.ts';
|
|
29
29
|
import { dashes, type VectorsOptions } from './vectortiles/vectors.ts';
|
|
30
30
|
export { dashes, OPENFREEMAP_STYLES, PLAN_STYLES, size, styleAttribution, tileLabels, VECTOR_BASEMAPS };
|
|
31
|
+
/** The options of `VectorTiles.raster` */
|
|
32
|
+
export interface VectorRasterOptions extends Placement {
|
|
33
|
+
/** The style layers drawn (default all but the symbols) */
|
|
34
|
+
layers?: (layer: StyleLayer) => boolean;
|
|
35
|
+
/** Style layers of the same source drawn after them */
|
|
36
|
+
extraLayers?: StyleLayer[];
|
|
37
|
+
/** Texture size of its tiles (512 by default: sharp lines) */
|
|
38
|
+
size?: number;
|
|
39
|
+
opacity?: number;
|
|
40
|
+
minZoom?: number;
|
|
41
|
+
maxZoom?: number;
|
|
42
|
+
}
|
|
31
43
|
export interface VectorTilesOptions {
|
|
32
44
|
/** A style URL or object (default OpenFreeMap's Positron) */
|
|
33
45
|
style?: string | Style;
|
|
@@ -87,14 +99,7 @@ export declare class VectorTiles {
|
|
|
87
99
|
* A raster layer drawing the style's fills, lines and circles (or those `layers` keeps, then `extraLayers`, of the
|
|
88
100
|
* same source); `size`: texture size of its tiles (512 by default: sharp lines)
|
|
89
101
|
*/
|
|
90
|
-
raster(options?:
|
|
91
|
-
layers?: (layer: StyleLayer) => boolean;
|
|
92
|
-
extraLayers?: StyleLayer[];
|
|
93
|
-
size?: number;
|
|
94
|
-
opacity?: number;
|
|
95
|
-
minZoom?: number;
|
|
96
|
-
maxZoom?: number;
|
|
97
|
-
} & Placement): RasterLayer;
|
|
102
|
+
raster(options?: VectorRasterOptions): RasterLayer;
|
|
98
103
|
/**
|
|
99
104
|
* An extrusion layer of the polygons of the style's fill layers that `layers` keeps (by default its buildings: the
|
|
100
105
|
* fill or fill-extrusion layers of PLAN IGN's `bati_surf` or OpenMapTiles' `building`), raised by the style
|
|
@@ -172,7 +177,8 @@ export declare class VectorTiles {
|
|
|
172
177
|
labels(options?: LabelsOptions): SymbolLayer<LabelCandidate>;
|
|
173
178
|
/**
|
|
174
179
|
* Makes a layer's tiles follow the view: `update` now and where the camera stops (`moveend`), `moving` every
|
|
175
|
-
* `VECTOR_MOVE_REFRESH_MS` while it moves; the `requests` aborted when
|
|
180
|
+
* `VECTOR_MOVE_REFRESH_MS` while it moves, and again after a pause when tiles failed; the `requests` aborted when
|
|
181
|
+
* destroyed or the layer removed
|
|
176
182
|
*/
|
|
177
183
|
private followView;
|
|
178
184
|
/** Calls `stop` when destroyed or once `layer` is removed, whichever comes first */
|
|
@@ -271,7 +271,8 @@ export class VectorTiles {
|
|
|
271
271
|
}
|
|
272
272
|
/**
|
|
273
273
|
* Makes a layer's tiles follow the view: `update` now and where the camera stops (`moveend`), `moving` every
|
|
274
|
-
* `VECTOR_MOVE_REFRESH_MS` while it moves; the `requests` aborted when
|
|
274
|
+
* `VECTOR_MOVE_REFRESH_MS` while it moves, and again after a pause when tiles failed; the `requests` aborted when
|
|
275
|
+
* destroyed or the layer removed
|
|
275
276
|
*/
|
|
276
277
|
followView(layer, update, requests, moving) {
|
|
277
278
|
const refresh = () => {
|
|
@@ -287,6 +288,7 @@ export class VectorTiles {
|
|
|
287
288
|
}, VECTOR_MOVE_REFRESH_MS);
|
|
288
289
|
};
|
|
289
290
|
const [offMove, offEnd] = [this.map.on('move', follow), this.map.on('moveend', refresh)];
|
|
291
|
+
requests.retryWith(refresh);
|
|
290
292
|
this.stopWith(layer, () => {
|
|
291
293
|
offMove();
|
|
292
294
|
offEnd();
|