@tangram.gl/basemap-layers 0.0.0 → 10.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +12 -7
  2. package/THIRD-PARTY-NOTICES.md +7 -5
  3. package/dist/geojson-task-worker.js +3166 -0
  4. package/dist/geojson-task-worker.js.map +6 -0
  5. package/dist/geojson-worker.js +1089 -7
  6. package/dist/geojson-worker.js.map +3 -3
  7. package/dist/index.cjs +9588 -2093
  8. package/dist/index.cjs.map +3 -3
  9. package/dist/index.js +9599 -2090
  10. package/dist/index.js.map +3 -3
  11. package/dist/map-style.cjs +456 -20
  12. package/dist/map-style.cjs.map +3 -3
  13. package/dist/map-style.js +456 -19
  14. package/dist/map-style.js.map +2 -2
  15. package/dist/types/basemap-error.d.ts +52 -0
  16. package/dist/types/basemap-layer.d.ts +378 -25
  17. package/dist/types/basemap-protocol.d.ts +91 -0
  18. package/dist/types/basemap-request.d.ts +73 -0
  19. package/dist/types/circle-layer.d.ts +65 -8
  20. package/dist/types/color-relief-layer.d.ts +184 -0
  21. package/dist/types/dem-pixels.d.ts +40 -0
  22. package/dist/types/feature-state.d.ts +55 -0
  23. package/dist/types/fill-extrusion-lighting-extension.d.ts +1 -2
  24. package/dist/types/fill-outline-extension.d.ts +2 -3
  25. package/dist/types/fill-pattern.d.ts +35 -3
  26. package/dist/types/fill-style-extensions.d.ts +11 -59
  27. package/dist/types/geojson-resource.d.ts +18 -0
  28. package/dist/types/geojson-source.d.ts +13 -2
  29. package/dist/types/geojson-task-handler.d.ts +2 -0
  30. package/dist/types/geojson-task.d.ts +26 -0
  31. package/dist/types/geojson-tiler.d.ts +29 -2
  32. package/dist/types/geojson-worker.d.ts +5 -1
  33. package/dist/types/globe-horizon-extension.d.ts +2 -45
  34. package/dist/types/globe-layers.d.ts +141 -45
  35. package/dist/types/globe-line-angle-extension.d.ts +20 -17
  36. package/dist/types/glyph-store.d.ts +10 -1
  37. package/dist/types/heatmap-layer.d.ts +99 -0
  38. package/dist/types/hillshade-layer.d.ts +159 -27
  39. package/dist/types/icon-text-fit.d.ts +92 -0
  40. package/dist/types/image-source-layer.d.ts +142 -0
  41. package/dist/types/index.d.ts +25 -1
  42. package/dist/types/line-blur-extension.d.ts +3 -11
  43. package/dist/types/line-dash-extension.d.ts +53 -0
  44. package/dist/types/line-gradient-extension.d.ts +69 -0
  45. package/dist/types/line-metrics.d.ts +24 -0
  46. package/dist/types/line-pattern-extension.d.ts +50 -0
  47. package/dist/types/line-shape-extension.d.ts +76 -0
  48. package/dist/types/map-style-loader.d.ts +1 -1
  49. package/dist/types/map-style.d.ts +2 -2
  50. package/dist/types/mvt-label-layer.d.ts +111 -20
  51. package/dist/types/pmtiles-source.d.ts +38 -0
  52. package/dist/types/projected-background-layer.d.ts +63 -0
  53. package/dist/types/projected-bitmap-layer.d.ts +58 -0
  54. package/dist/types/projected-tile-data.d.ts +16 -0
  55. package/dist/types/projected-tile-selection.d.ts +72 -0
  56. package/dist/types/projected-tileset.d.ts +92 -0
  57. package/dist/types/projected-viewport.d.ts +76 -0
  58. package/dist/types/raster-color-extension.d.ts +4 -7
  59. package/dist/types/raster-fade.d.ts +155 -0
  60. package/dist/types/raster-tile-fingerprint.d.ts +11 -0
  61. package/dist/types/raster-tile-loader.d.ts +80 -0
  62. package/dist/types/shader-injection-plugin.d.ts +8 -0
  63. package/dist/types/source-features.d.ts +58 -0
  64. package/dist/types/source-tiles.d.ts +32 -0
  65. package/dist/types/sprite.d.ts +37 -3
  66. package/dist/types/stretch-icon-layer.d.ts +28 -0
  67. package/dist/types/style-accessor.d.ts +50 -12
  68. package/dist/types/style-expression.d.ts +22 -2
  69. package/dist/types/style-resolver.d.ts +47 -2
  70. package/dist/types/terrain-query.d.ts +39 -0
  71. package/dist/types/zoom-load-gate.d.ts +22 -0
  72. package/dist/types/zoom-paint-extension.d.ts +80 -11
  73. package/package.json +24 -21
  74. package/src/basemap-error.ts +82 -0
  75. package/src/basemap-layer.ts +1289 -101
  76. package/src/basemap-protocol.ts +353 -0
  77. package/src/basemap-request.ts +212 -0
  78. package/src/circle-layer.ts +430 -54
  79. package/src/color-relief-layer.ts +572 -0
  80. package/src/dem-pixels.ts +174 -0
  81. package/src/feature-state.ts +164 -0
  82. package/src/fill-extrusion-lighting-extension.ts +126 -9
  83. package/src/fill-outline-extension.ts +4 -4
  84. package/src/fill-pattern.ts +87 -9
  85. package/src/fill-style-extensions.ts +114 -44
  86. package/src/geojson-resource.ts +58 -0
  87. package/src/geojson-source.ts +106 -85
  88. package/src/geojson-task-handler.ts +11 -0
  89. package/src/geojson-task-worker.ts +8 -0
  90. package/src/geojson-task.ts +34 -0
  91. package/src/geojson-tiler.ts +270 -4
  92. package/src/geojson-worker.ts +36 -6
  93. package/src/globe-horizon-extension.ts +14 -4
  94. package/src/globe-layers.ts +1905 -406
  95. package/src/globe-line-angle-extension.ts +183 -23
  96. package/src/glyph-store.ts +28 -6
  97. package/src/heatmap-layer.ts +591 -0
  98. package/src/hillshade-layer.ts +309 -88
  99. package/src/icon-text-fit.ts +358 -0
  100. package/src/image-source-layer.ts +380 -0
  101. package/src/index.ts +58 -1
  102. package/src/line-blur-extension.ts +14 -12
  103. package/src/line-dash-extension.ts +303 -0
  104. package/src/line-gradient-extension.ts +191 -0
  105. package/src/line-metrics.ts +90 -0
  106. package/src/line-pattern-extension.ts +173 -0
  107. package/src/line-shape-extension.ts +272 -0
  108. package/src/map-style-loader.ts +5 -4
  109. package/src/map-style.ts +2 -1
  110. package/src/mvt-label-layer.ts +568 -144
  111. package/src/pmtiles-source.ts +276 -0
  112. package/src/projected-background-layer.ts +202 -0
  113. package/src/projected-bitmap-layer.ts +262 -0
  114. package/src/projected-tile-data.ts +132 -0
  115. package/src/projected-tile-selection.ts +605 -0
  116. package/src/projected-tileset.ts +183 -0
  117. package/src/projected-viewport.ts +254 -0
  118. package/src/raster-color-extension.ts +43 -18
  119. package/src/raster-fade.ts +319 -0
  120. package/src/raster-tile-fingerprint.ts +31 -0
  121. package/src/raster-tile-loader.ts +211 -0
  122. package/src/shader-injection-plugin.ts +25 -0
  123. package/src/source-features.ts +170 -0
  124. package/src/source-tiles.ts +102 -0
  125. package/src/sprite.ts +122 -15
  126. package/src/stretch-icon-layer.ts +87 -0
  127. package/src/style-accessor.ts +105 -17
  128. package/src/style-expression.ts +80 -3
  129. package/src/style-resolver.ts +200 -22
  130. package/src/terrain-query.ts +86 -0
  131. package/src/text-layout.ts +2 -3
  132. package/src/zoom-load-gate.ts +57 -0
  133. package/src/zoom-paint-extension.ts +245 -47
  134. package/dist/types/arabic-shaping.d.ts +0 -7
  135. package/dist/types/bidi.d.ts +0 -8
  136. package/dist/types/polylabel.d.ts +0 -17
  137. package/src/arabic-shaping.ts +0 -366
  138. package/src/bidi.ts +0 -199
  139. package/src/polylabel.ts +0 -312
@@ -0,0 +1,52 @@
1
+ /** The resource of a style that failed to load (see {@link BasemapLoadError}). */
2
+ export type BasemapLoadErrorKind = 'style' | 'source' | 'tile' | 'sprite' | 'glyphs' | 'image';
3
+ /** What a {@link BasemapLoadError} tells about the resource that failed. */
4
+ export type BasemapLoadErrorDetails = {
5
+ /** The style source of a `source`, `tile` or `image` failure. */
6
+ sourceId?: string;
7
+ /** The URL that failed, when it is known. */
8
+ url?: string;
9
+ /** The HTTP status of the response, when the server answered. */
10
+ status?: number;
11
+ /** The index of the tile, for a `tile` failure. */
12
+ tile?: {
13
+ x: number;
14
+ y: number;
15
+ z: number;
16
+ };
17
+ };
18
+ /**
19
+ * A resource of the style that failed to load. `BasemapLayer` gives it to deck.gl's `onError`
20
+ * layer prop, and then to the `onError` of the `Deck`. It carries the fields of MapLibre GL JS's
21
+ * `error` event (`sourceId`, `tile`), and the error the load failed with as `cause`.
22
+ */
23
+ export declare class BasemapLoadError extends Error implements BasemapLoadErrorDetails {
24
+ /** What failed to load. */
25
+ readonly kind: BasemapLoadErrorKind;
26
+ readonly sourceId?: string;
27
+ readonly url?: string;
28
+ readonly status?: number;
29
+ readonly tile?: {
30
+ x: number;
31
+ y: number;
32
+ z: number;
33
+ };
34
+ /** The error the load failed with. */
35
+ readonly cause: Error;
36
+ constructor(kind: BasemapLoadErrorKind, cause: Error, details?: BasemapLoadErrorDetails);
37
+ }
38
+ /** Receives each resource of the style that fails to load. */
39
+ export type BasemapLoadErrorHandler = (error: BasemapLoadError) => void;
40
+ /** A response with an error status: keeps the URL and status for {@link BasemapLoadError}. */
41
+ export declare class BasemapFetchError extends Error {
42
+ readonly url: string;
43
+ readonly status: number;
44
+ constructor(message: string, url: string, status: number);
45
+ }
46
+ /** Whether `error` is a cancelled request, which is not a load failure. */
47
+ export declare function isAbortError(error: unknown): boolean;
48
+ /**
49
+ * The load error of a failure. The URL and status come from `error` when it has them, such as a
50
+ * {@link BasemapFetchError} or a loaders.gl `FetchError`.
51
+ */
52
+ export declare function getBasemapLoadError(kind: BasemapLoadErrorKind, error: unknown, details?: BasemapLoadErrorDetails): BasemapLoadError;
@@ -1,39 +1,116 @@
1
- import { SharedTileset2D } from '@deck.gl-community/geo-layers';
2
- import type { BasemapSource } from "./style-resolver.js";
3
- import { CompositeLayer, type DefaultProps, type UpdateParameters, type Viewport } from '@deck.gl/core';
1
+ import { SharedTileset2D, type SharedTile2DHeader } from '@deck.gl-community/layers/geo-layers';
2
+ import { type Tile2DHeader } from '@deck.gl/geo-layers';
3
+ import { type TerrainSurface, type TerrainSurfaceHit } from "./terrain-query.js";
4
+ import { ZoomLoadGate } from "./zoom-load-gate.js";
5
+ import { type BasemapSource } from "./style-resolver.js";
6
+ import type { BasemapFeatureState } from "./feature-state.js";
7
+ import { CompositeLayer, type DefaultProps, type GetPickingInfoParams, type Layer, type LayersList, type PickingInfo, type UpdateParameters, type Viewport } from '@deck.gl/core';
8
+ import { type BasemapTransformRequest } from "./basemap-request.js";
9
+ import { type StyleLayerPropsMap, type StyleLayerSubLayerProps } from "./globe-layers.js";
4
10
  import { LabelPlacement } from "./label-placement.js";
5
- import type { BasemapStyle, ResolvedBasemapStyle } from "./style-resolver.js";
11
+ import type { BasemapLoadOptions, BasemapStyle, ResolvedBasemapStyle, ResolvedBasemapStyleLayer } from "./style-resolver.js";
6
12
  import { GlyphStore } from "./glyph-store.js";
7
13
  import type { SpriteAtlas } from "./sprite.js";
8
14
  import type { LabelFontFamily } from "./text-font.js";
15
+ import type { RejectRasterTile } from "./raster-tile-loader.js";
16
+ import { type BasemapLoadError } from "./basemap-error.js";
17
+ import { type BasemapSourceFeature, type QuerySourceFeaturesOptions } from "./source-features.js";
9
18
  /**
10
- * Globe-related runtime toggles used by {@link BasemapLayer}.
19
+ * Drawing toggles of the basemap helpers (`getBasemapLayers`). They apply in every mode, not only
20
+ * on a globe. `BasemapLayer` takes them as the flat `labels` and `atmosphere` props.
11
21
  */
12
22
  export type BasemapGlobeConfig = {
13
- /** Renders the atmosphere overlays returned by the globe helpers when available. */
23
+ /** Draws the atmosphere in globe mode. Default `false`. */
14
24
  atmosphere?: boolean;
15
- /** Renders the main globe basemap content when `true`. */
25
+ /** Draws the style layers. Default `true`. `false` draws only the atmosphere. */
16
26
  basemap?: boolean;
17
- /** Enables symbol-label rendering on the globe path when `true`. */
27
+ /** Draws the style's symbol layers (labels and icons). Default `true`. */
18
28
  labels?: boolean;
19
29
  };
30
+ /** A tile given to `onTileLoad` and `onViewportLoad`: deck.gl's tile header. */
31
+ export type BasemapTile = Tile2DHeader | SharedTile2DHeader;
32
+ /**
33
+ * The data of a `geojson` source in {@link BasemapLayerProps.sourceData}: a GeoJSON object, or the
34
+ * URL of one, as the source's `data` in the style.
35
+ */
36
+ export type BasemapSourceData = object | string;
37
+ /**
38
+ * deck.gl layers that {@link BasemapLayer} draws inside the style order (see
39
+ * `BasemapLayerProps.insertLayers`).
40
+ */
41
+ export type BasemapInsertion = {
42
+ /**
43
+ * The id of the style layer to draw `layers` before, as the `beforeId` of MapLibre GL JS's
44
+ * `addLayer`. Omit it to draw `layers` over the whole basemap.
45
+ */
46
+ beforeId?: string | null;
47
+ /** The deck.gl layers to draw. */
48
+ layers: LayersList;
49
+ };
50
+ /** The `loadOptions` of {@link BasemapLayer}: basemap request options and loaders.gl options. */
51
+ export type BasemapLayerLoadOptions = NonNullable<BasemapLoadOptions> & Record<string, unknown>;
20
52
  /**
21
53
  * Props accepted by {@link BasemapLayer}.
22
54
  */
23
55
  export type BasemapLayerProps = {
24
56
  /** Optional deck.gl layer identifier. */
25
57
  id?: string;
26
- /** MapLibre or Mapbox style JSON, or a URL that resolves to one. */
27
- style: string | BasemapStyle | null;
28
- /** Load options forwarded to {@link resolveBasemapStyle}. */
29
- loadOptions?: Record<string, unknown> | null;
30
- /** Selects whether deck layers are generated for a flat map or a globe. */
31
- mode?: 'map' | 'globe';
32
- /** Optional globe-specific configuration used when `mode` is `'globe'`. */
58
+ /**
59
+ * MapLibre or Mapbox style JSON, a URL that resolves to one, or a resolved style. A resolved
60
+ * style draws at once without fetching its TileJSON and GeoJSON data again. A copy resolves again.
61
+ * Default `null`.
62
+ */
63
+ style?: string | BasemapStyle | ResolvedBasemapStyle | null;
64
+ /**
65
+ * Options for the requests of the layer, and loaders.gl options for its tiles:
66
+ * - `baseUrl`, `fetch` and `fetchOptions` apply to the TileJSON, GeoJSON `data`, sprite and
67
+ * glyph requests (see `resolveBasemapStyle`). With `rejectRasterTile`, they also apply to
68
+ * raster tiles.
69
+ * - loaders.gl namespaces such as `mvt` and `core` go to the tile loaders, with the deck.gl
70
+ * `fetch` prop.
71
+ * - A style URL loads with `MapStyleLoader`, with these options as its `mapStyle` options.
72
+ */
73
+ loadOptions?: BasemapLayerLoadOptions | null;
74
+ /**
75
+ * Changes each request the layer makes before it is sent, as MapLibre GL JS's `transformRequest`
76
+ * map option: the style, TileJSON, GeoJSON data, vector, raster and raster-dem tiles, sprites and
77
+ * glyphs. It receives the absolute URL and the resource type (see `BasemapResourceType`), and
78
+ * returns the URL to request, with `headers`, `credentials`, `method`, `body` or `cache`, or
79
+ * nothing to send the request as it is. The request is then sent with `loadOptions.fetch`.
80
+ * Fields it returns replace those of `loadOptions.fetchOptions`; headers merge by name. Pass a
81
+ * stable function: the style and its tiles load again when it changes.
82
+ */
83
+ transformRequest?: BasemapTransformRequest | null;
84
+ /**
85
+ * Selects whether the sublayers draw as a flat map or on a globe. `'auto'` (the default) reads
86
+ * it from the viewport: globe sublayers in a deck.gl `GlobeView`, map sublayers in other views.
87
+ * `'map'` and `'globe'` override the viewport.
88
+ */
89
+ mode?: 'auto' | 'map' | 'globe';
90
+ /**
91
+ * The state of features, which `["feature-state", key]` reads in paint properties, as MapLibre
92
+ * GL JS's `setFeatureState` sets it: by source id, then, for a `vector` source, by source layer,
93
+ * then by feature id. Pass a new object to change a state; a change computes again only the paint
94
+ * attributes of the style layers that read the changed states, and keeps their geometry.
95
+ */
96
+ featureState?: BasemapFeatureState | null;
97
+ /**
98
+ * Draws the style's symbol layers (labels and icons). Default `true`. It applies in every mode.
99
+ * With `false`, the tiles do not decode the source layers that only symbol layers read.
100
+ */
101
+ labels?: boolean;
102
+ /**
103
+ * Draws the atmosphere around the globe in globe mode. Default `false`. The atmosphere layers
104
+ * are placeholders that draw nothing yet.
105
+ */
106
+ atmosphere?: boolean;
107
+ /**
108
+ * @deprecated Use the `labels` and `atmosphere` props, and deck.gl's `visible` prop in place of
109
+ * `basemap: false`. A field set here overrides the flat prop of the same name.
110
+ */
33
111
  globe?: {
34
- /** Rendering toggles for globe-specific basemap behavior. */
35
112
  config?: BasemapGlobeConfig;
36
- };
113
+ } | null;
37
114
  /**
38
115
  * Draws labels with the browser's fonts instead of the style's `glyphs`. By default labels are
39
116
  * drawn with the style's glyphs, as in MapLibre GL JS, and a style without `glyphs` maps each
@@ -46,7 +123,9 @@ export type BasemapLayerProps = {
46
123
  /**
47
124
  * Milliseconds between two placements of the labels while the view keeps changing, as MapLibre
48
125
  * GL JS's `fadeDuration` (default 300). The view the map comes to rest in is always placed; 0
49
- * places every frame.
126
+ * places every frame. The `BasemapLayer`s of a deck share one placement (see
127
+ * `separateLabelPlacement`), which takes the interval of the last of them rendered: give them
128
+ * the same interval.
50
129
  */
51
130
  labelPlacementInterval?: number;
52
131
  /**
@@ -56,6 +135,108 @@ export type BasemapLayerProps = {
56
135
  * are placed first. With `true`, this layer's labels collide only with each other.
57
136
  */
58
137
  separateLabelPlacement?: boolean;
138
+ /**
139
+ * Milliseconds that vector tile loads wait after the last zoom change of a view (default 0: no
140
+ * wait). In a zoom gesture the view passes through several tile zooms; each tile loaded at one
141
+ * of them is decoded and triangulated, and is drawn for a fraction of a second. With a wait, a
142
+ * tile that a loaded ancestor tile draws, enlarged, waits until the zoom comes to rest, and is
143
+ * not loaded if no view selects it then. A tile without a loaded ancestor, such as the new
144
+ * tiles at the edges of a zoom out, loads at once. A pan does not change the zoom, and its
145
+ * loads do not wait.
146
+ */
147
+ zoomLoadDelay?: number;
148
+ /**
149
+ * The stretch limit of the tile selection in a projected view (deck.gl's
150
+ * `_CustomProjectionView`), see `ProjectedTileSelectionOptions.maxStretch`. The default, 4, suits
151
+ * most projections. A projection whose scale grows steeply toward the edge of its area of use,
152
+ * such as a polar stereographic projection, needs a larger limit to draw out to that edge: 16
153
+ * draws an EPSG:3031 view out to latitude 60N. A change reloads the tiles.
154
+ */
155
+ projectedMaxStretch?: number;
156
+ /**
157
+ * Returns `true` for a raster tile that has no map data, such as the placeholder image that some
158
+ * tile services return with status 200 where they have no coverage. The tile is then drawn from
159
+ * its nearest ancestor tile that has data, enlarged, and the placeholder is not drawn. The
160
+ * function receives the bytes of the response (see `RasterTileResponse`). With this prop, raster
161
+ * tiles are requested with the `fetch` and `fetchOptions` of `loadOptions`. Pass a stable
162
+ * function: raster tiles reload when it changes. See `createRasterTileFingerprintFilter`.
163
+ */
164
+ rejectRasterTile?: RejectRasterTile | null;
165
+ /**
166
+ * Called with the resolved style each time a style resolves, as MapLibre GL JS's `style.load`
167
+ * event. Its sprites, glyphs and tiles can still be loading.
168
+ */
169
+ onStyleLoad?: ((style: ResolvedBasemapStyle) => void) | null;
170
+ /**
171
+ * Called when a tile of a vector, raster, raster-dem or geojson source loads, as deck.gl's
172
+ * `TileLayer.onTileLoad`. The style layers of one source share its tiles: each load is reported
173
+ * once.
174
+ */
175
+ onTileLoad?: ((tile: BasemapTile) => void) | null;
176
+ /**
177
+ * Called with the tiles of all sources in the current viewport when they have loaded, as
178
+ * deck.gl's `TileLayer.onViewportLoad` and MapLibre GL JS's `idle` event. The style and its
179
+ * sprites have loaded too. A viewport that selects no tiles is not reported.
180
+ */
181
+ onViewportLoad?: ((tiles: BasemapTile[]) => void) | null;
182
+ /**
183
+ * Called with the `attribution` of the sources that the style draws, when they change, as
184
+ * MapLibre GL JS's `AttributionControl` collects them: a source that only hidden layers draw is
185
+ * left out, each attribution is given once, and one that another contains is left out. The
186
+ * strings are the provider's HTML, not sanitized: display them as safe linked text.
187
+ */
188
+ onAttributionChange?: ((attributions: string[]) => void) | null;
189
+ /**
190
+ * The data of `geojson` sources of the style, by source id, in place of their `data` in the
191
+ * style, as MapLibre GL JS's `GeoJSONSource.setData`. Each entry is compared by identity: when
192
+ * one changes, only that source is indexed again and its tiles cut again. The style is not
193
+ * loaded again, and the other sources keep their tiles. A URL is fetched with the `fetch` and
194
+ * `fetchOptions` of `loadOptions`, relative to the style URL or `loadOptions.baseUrl`, and again
195
+ * when the style URL or `loadOptions` change; the source keeps its previous data until it
196
+ * loads. An entry that is removed, `null` or `undefined` gives the source its data in the style
197
+ * again. An id that is not a `geojson` source of the style is ignored with a warning.
198
+ */
199
+ sourceData?: Record<string, BasemapSourceData | null | undefined> | null;
200
+ /**
201
+ * Extra deck.gl props for the sublayers that draw one style layer, or null for none: for example
202
+ * `extensions` and their props for the roads only. Called for each style layer when the style or
203
+ * the function changes, not for each tile. `extensions` are added after the sublayer's own and
204
+ * `updateTriggers` are merged with its own; `id` and `data` are ignored. A fill or line layer
205
+ * with extra props draws in a sublayer of its own, not batched with its neighbors. Pass a
206
+ * stable function: the tiles regenerate when it changes.
207
+ */
208
+ getStyleLayerProps?: ((styleLayer: ResolvedBasemapStyleLayer) => StyleLayerSubLayerProps | null | undefined) | null;
209
+ /**
210
+ * deck.gl layers drawn inside the style order, as MapLibre GL JS's `addLayer(layer, beforeId)`:
211
+ * each insertion's `layers` draw before the style layer `beforeId`, and over the whole basemap
212
+ * without one. Insertions before the same style layer draw in the order of this list. The layers
213
+ * are sublayers of the basemap, and are picked as if they were top-level layers: their own
214
+ * `onHover` and `onClick` receive the events, and `info.layer` is the inserted layer. A `beforeId`
215
+ * that names no layer of the style raises an error to `onError`, and its layers are not drawn.
216
+ */
217
+ insertLayers?: BasemapInsertion[] | null;
218
+ };
219
+ /** A `sourceData` entry and its GeoJSON: the entry itself, or its URL's once it loads. */
220
+ type SourceDataEntry = {
221
+ /** The entry of the `sourceData` prop. */
222
+ input: BasemapSourceData;
223
+ /** Its GeoJSON object, or the previous entry's until a URL loads, or null. */
224
+ data: object | null;
225
+ /** For a URL, the URL that it resolves against and the `loadOptions` that it loads with. */
226
+ context?: {
227
+ baseUrl: string | undefined;
228
+ loadOptions: BasemapLayerProps['loadOptions'];
229
+ transformRequest: BasemapLayerProps['transformRequest'];
230
+ };
231
+ };
232
+ /** A `geojson` source of the resolved style with the data of its `sourceData` entry. */
233
+ type SourceDataSource = {
234
+ /** The source in the resolved style. */
235
+ base: BasemapSource;
236
+ /** The data of its `sourceData` entry. */
237
+ data: object;
238
+ /** `base` with `data`: the tileset key, kept while neither changes. */
239
+ source: BasemapSource;
59
240
  };
60
241
  /**
61
242
  * Internal state tracked by {@link BasemapLayer}.
@@ -70,6 +251,14 @@ type BasemapLayerState = {
70
251
  sharedLabelPlacementKey: object | null;
71
252
  /** The fully resolved style definition currently backing the generated sublayers. */
72
253
  resolvedStyle: ResolvedBasemapStyle | null;
254
+ /** The `style` prop that `resolvedStyle` was made from. */
255
+ styleInput: BasemapLayerProps['style'];
256
+ /**
257
+ * A copy of `styleInput` when it is an object, as it was when it was read. A style changed in
258
+ * place is compared with this copy. Null while a load runs, and when a source or the sprite of
259
+ * the style failed to load: the next style then loads.
260
+ */
261
+ styleSnapshot: BasemapStyle | null;
73
262
  /** The most recent style-resolution error, if one occurred. */
74
263
  loadError: Error | null;
75
264
  /** Monotonic token used to discard stale async style loads. */
@@ -78,6 +267,16 @@ type BasemapLayerState = {
78
267
  zoomKey: string | null;
79
268
  /** Sprites of the resolved style, once loaded. */
80
269
  spriteAtlases: SpriteAtlas[] | null;
270
+ /** The sprite URLs and pixel ratio of `spriteLoad`. */
271
+ spriteKey: string | null;
272
+ /** The load of the sprites of the resolved style, kept for a new style with the same sprites. */
273
+ spriteLoad: Promise<SpriteAtlas[]> | null;
274
+ /** The sources of the styles resolved with `sourceCacheOptions` (see `BasemapLoadOptions`). */
275
+ sourceCache: Map<string, BasemapSource>;
276
+ /** The `loadOptions` that the sources in `sourceCache` were loaded with. */
277
+ sourceCacheOptions: BasemapLayerProps['loadOptions'] | undefined;
278
+ /** The `loadOptions` that the sources, the sprites and the glyphs were loaded with. */
279
+ styleLoadOptions: BasemapLayerProps['loadOptions'] | undefined;
81
280
  /** The glyphs of the resolved style's `glyphs` URL, or null without one. */
82
281
  glyphs: GlyphStore | null;
83
282
  /** Decoded data caches owned by this basemap, shared across style runs. */
@@ -89,22 +288,96 @@ type BasemapLayerState = {
89
288
  tilesetSourceLayers: Map<BasemapSource, string>;
90
289
  /** Loading configuration used to construct the current source caches. */
91
290
  tileLoadOptions: unknown;
291
+ /** The `projectedMaxStretch` the current source caches select tiles with. */
292
+ tileMaxStretch: number | null;
92
293
  /** Fetch identity, kept separate from render-only props such as view mode. */
93
294
  tileFetch: unknown;
295
+ /** Holds the vector tile loads while a view zooms (see `zoomLoadDelay`). */
296
+ zoomLoadGate: ZoomLoadGate;
297
+ /** The `loadToken` of the last style load that ended. */
298
+ loadedToken: number;
299
+ /** The resolved style that the current sublayers were generated from. */
300
+ renderedStyle: ResolvedBasemapStyle | null;
301
+ /** The content of each tile reported to `onTileLoad`, to report a load once. */
302
+ reportedTiles: WeakMap<object, unknown>;
303
+ /** The tiles last reported to `onViewportLoad`. */
304
+ viewportTiles: BasemapTile[] | null;
305
+ /** The attributions last reported to `onAttributionChange`, as JSON. */
306
+ attributions: string;
307
+ /** The entries of the `sourceData` prop, by source id. */
308
+ sourceData: Map<string, SourceDataEntry>;
309
+ /** The sources that the `sourceData` entries replace, by source id. */
310
+ sourceDataSources: Map<string, SourceDataSource>;
311
+ /** The resolved style with the `sourceData` sources, and the resolved style it was made from. */
312
+ styleWithSourceData: {
313
+ base: ResolvedBasemapStyle;
314
+ style: ResolvedBasemapStyle;
315
+ } | null;
316
+ /** The extra sublayer props of each style layer, and the style and function they came from. */
317
+ styleLayerProps: {
318
+ style: ResolvedBasemapStyle;
319
+ getStyleLayerProps: BasemapLayerProps['getStyleLayerProps'];
320
+ value: StyleLayerPropsMap | null;
321
+ } | null;
322
+ /** The layers of `insertLayers` in the current sublayers, picked as top-level layers. */
323
+ insertedLayers: Set<Layer>;
324
+ /** The style and unknown `beforeId`s that errors were last raised for, to raise them once. */
325
+ insertionError: {
326
+ style: ResolvedBasemapStyle;
327
+ beforeIds: string;
328
+ } | null;
329
+ /** The causes of the errors given to `reportError`, which reports each once. */
330
+ reportedErrors: WeakSet<Error>;
331
+ /** The `transformRequest` the current source caches request tiles with. */
332
+ tileTransformRequest: BasemapTransformRequest | null;
333
+ /** The config `getStyleConfig` last returned, kept while its inputs do not change. */
334
+ styleConfig: {
335
+ labels: unknown;
336
+ atmosphere: unknown;
337
+ globe: unknown;
338
+ value: {
339
+ config: Required<BasemapGlobeConfig>;
340
+ };
341
+ } | null;
94
342
  };
95
343
  /**
96
344
  * A deck.gl {@link CompositeLayer} that loads a style document and renders the
97
345
  * corresponding basemap sublayers.
346
+ *
347
+ * @typeParam ExtraPropsT The props of the layer's `extensions`, such as `MaskExtensionProps`.
98
348
  */
99
- export declare class BasemapLayer extends CompositeLayer<Required<BasemapLayerProps>> {
349
+ export declare class BasemapLayer<ExtraPropsT extends {} = {}> extends CompositeLayer<ExtraPropsT & Required<BasemapLayerProps>> {
100
350
  /** Deck.gl layer name. */
101
351
  static layerName: string;
102
352
  /** Default props for {@link BasemapLayer}. */
103
353
  static defaultProps: DefaultProps<BasemapLayerProps>;
104
354
  /** Current layer state. */
105
355
  state: BasemapLayerState;
356
+ /**
357
+ * Queries a caller-owned displayed terrain surface through the selected deck viewport. The
358
+ * layer adds nothing: this is `pickTerrainSurface(viewport, pixel, surface, commonToSurface)`.
359
+ */
360
+ getTerrainAt(viewport: Viewport, pixel: readonly [number, number], surface: TerrainSurface, commonToSurface: Readonly<ArrayLike<number>>): TerrainSurfaceHit | null;
106
361
  /** Initializes the asynchronous style-loading state. */
107
362
  initializeState(): void;
363
+ /**
364
+ * False while the style, its sprites or the tiles of the current viewport load, as deck.gl's
365
+ * `TileLayer.isLoaded`. A style or tile that failed to load counts as loaded.
366
+ */
367
+ get isLoaded(): boolean;
368
+ /**
369
+ * The extra sublayer props of each style layer of `style` (see `getStyleLayerProps`), computed
370
+ * once per style and function.
371
+ */
372
+ private getStyleLayerPropsMap;
373
+ /**
374
+ * The drawing toggles of the props, in the `{config}` form of the basemap helpers: `labels` and
375
+ * `atmosphere`, with the fields of the deprecated `globe.config` over them. The object keeps
376
+ * its identity while these props do not change.
377
+ */
378
+ getStyleConfig(): {
379
+ config: Required<BasemapGlobeConfig>;
380
+ };
108
381
  /**
109
382
  * Sublayers depend on the zoom, but only through `getStyleZoomKey`: style values step every
110
383
  * `STYLE_ZOOM_STEP`, filters at integer zooms, and layer visibility changes at
@@ -114,23 +387,67 @@ export declare class BasemapLayer extends CompositeLayer<Required<BasemapLayerPr
114
387
  /** Returns the key of what the sublayers depend on in `viewport`, for a resolved style. */
115
388
  getZoomKey(resolvedStyle: ResolvedBasemapStyle, viewport: Viewport | undefined): string;
116
389
  /**
117
- * The mode the sublayers are drawn in. Above zoom 12, `GlobeView` draws with a Web Mercator
118
- * viewport, so a globe basemap draws as a map there: globe depth and culling parameters assume
119
- * longitude/latitude geometry on a sphere.
390
+ * The mode the sublayers are drawn in. With `mode: 'auto'`, a globe viewport draws globe
391
+ * sublayers and any other viewport draws map sublayers. Above zoom 12, `GlobeView` draws with a
392
+ * Web Mercator viewport, so a globe basemap draws as a map there: globe depth and culling
393
+ * parameters assume longitude/latitude geometry on a sphere.
120
394
  */
121
395
  getDrawMode(viewport: Viewport | undefined): 'map' | 'globe';
396
+ /**
397
+ * Raises a load failure (see `BasemapLoadError`) to the layer's `onError`, and to the deck's
398
+ * `onError` unless the layer's returns `true`. A cancelled request is not a failure. Tile layers
399
+ * that share a tileset each report its failed tiles: a failure is raised once.
400
+ */
401
+ reportError(error: BasemapLoadError): void;
122
402
  /** Reacts to changes in the input style definition. */
123
403
  updateState({ props, oldProps, changeFlags }: UpdateParameters<this>): void;
404
+ /**
405
+ * Takes the entries of the `sourceData` prop. An entry that is the same as before keeps its data;
406
+ * a GeoJSON object is used as it is, and a URL is fetched. A URL is fetched again when the URL
407
+ * that it resolves against or the `loadOptions` change.
408
+ */
409
+ private updateSourceData;
410
+ /** Fetches the GeoJSON of a `sourceData` URL, unless the entry has changed by then. */
411
+ private loadSourceData;
412
+ /**
413
+ * The resolved style with the data of the `sourceData` entries in its `geojson` sources. A source
414
+ * is a new object only when its entry or its source in the resolved style changes, and the style
415
+ * only when one of its sources does: the tilesets are keyed by source object, so the other sources
416
+ * keep their tiles.
417
+ */
418
+ private getStyleWithSourceData;
419
+ /**
420
+ * Applies a new style object as MapLibre GL JS's `setStyle(style, {diff: true})` applies it. A
421
+ * change that loads nothing, such as a paint or layout value, a filter, a zoom range or the order
422
+ * of the layers, makes a new resolved style with the sources of the current one, in this update.
423
+ * Returns false when the style must load: a source, the sprite or the glyphs changed, or the
424
+ * styles cannot be compared.
425
+ */
426
+ private updateStyleByDiff;
124
427
  /**
125
428
  * Resolves the configured style input and stores the latest successful result
126
429
  * in layer state.
127
430
  */
128
- loadStyle(style: BasemapLayerProps['style'], loadOptions: BasemapLayerProps['loadOptions']): void;
431
+ loadStyle(style: BasemapLayerProps['style'], layerLoadOptions: BasemapLayerProps['loadOptions'], transformRequest?: BasemapTransformRequest | null): void;
432
+ /** Draws `resolvedStyle`, the resolved form of the `style` prop, and loads its sprites. */
433
+ private setResolvedStyle;
129
434
  /**
130
435
  * Loads the resolved style's sprites, if it has any, and stores them for the icon layers.
131
436
  * Relative sprite URLs resolve against the style URL.
132
437
  */
133
- loadSprites(resolvedStyle: ResolvedBasemapStyle, style: BasemapLayerProps['style'], loadOptions: BasemapLayerProps['loadOptions'], loadToken: number): void;
438
+ loadSprites(resolvedStyle: ResolvedBasemapStyle, style: BasemapLayerProps['style'], loadOptions: BasemapLayerProps['loadOptions'], loadToken: number, sameOptions: boolean): void;
439
+ /**
440
+ * Returns the features of a `vector` or `geojson` source in the tiles that are loaded and drawn
441
+ * now, as MapLibre GL JS's `Map#querySourceFeatures`: every feature of `sourceLayer` that matches
442
+ * `filter`, whether a style layer draws it or not, in longitude and latitude. Tiles outside the
443
+ * view are not read. A feature that crosses a tile edge, or a point in the buffer of two tiles,
444
+ * is returned once per tile: compare `id`s to merge them. A source with no loaded tiles, a raster
445
+ * source, or an unknown id returns `[]`.
446
+ *
447
+ * Tiles decode only the source layers that the style draws, so a source layer that no style layer
448
+ * reads has no features here.
449
+ */
450
+ querySourceFeatures(sourceId: string, options?: QuerySourceFeaturesOptions | null): BasemapSourceFeature[];
134
451
  /** The basemap owns caches; style-run consumers only attach/detach. */
135
452
  finalizeState(): void;
136
453
  /**
@@ -144,7 +461,43 @@ export declare class BasemapLayer extends CompositeLayer<Required<BasemapLayerPr
144
461
  private updateSourceTilesets;
145
462
  /** The label placement, with the interval of the current props. */
146
463
  private getLabelPlacement;
464
+ /** The props of the current layer: an async load can end after the props changed. */
465
+ private getCurrentProps;
466
+ /** Gives each tile load once to `onTileLoad`: the style layers of a source share its tiles. */
467
+ private reportTileLoad;
468
+ /**
469
+ * Calls `onViewportLoad` when the style, its sprites and the tiles that every tile sublayer
470
+ * selects have loaded, and the tiles are not those last reported. As in deck.gl's `TileLayer`,
471
+ * the tiles count, not the layers drawn from them.
472
+ */
473
+ private checkViewportLoad;
474
+ /** Calls `onAttributionChange` when the attributions of the drawn sources change. */
475
+ private updateAttributions;
476
+ /**
477
+ * Adds this layer's tile and viewport callbacks to its tile sublayers, after their own. The
478
+ * layer manager runs a sublayer's callbacks with the props of its latest render.
479
+ */
480
+ private addTileCallbacks;
147
481
  /** Renders the sublayers generated from the resolved style definition. */
148
- renderLayers(): any[];
482
+ renderLayers(): Layer<{}>[] | LayersList[];
483
+ /**
484
+ * A basemap sublayer with the extensions of this layer and the props of those extensions, as
485
+ * `getSubLayerProps` gives them: the sublayers are not made with `getSubLayerProps`. A sublayer
486
+ * keeps its own extensions, and runs them first.
487
+ */
488
+ private addExtensions;
489
+ /** Records the drawn layers of `insertions`, which picking reads (see `getPickingInfo`). */
490
+ private setInsertedLayers;
491
+ /**
492
+ * The insertions of `insertLayers` whose `beforeId` names a layer of `resolvedStyle`. Each one
493
+ * that does not raises an error to `onError`, once for each style and `insertLayers`, as
494
+ * MapLibre GL JS's `addLayer` fires an `error` event for an unknown `beforeId`.
495
+ */
496
+ private getValidInsertions;
497
+ /**
498
+ * Picks an inserted layer as a top-level layer: `info.layer` is the inserted layer, so that deck
499
+ * calls its `onHover` and `onClick`, and not those of the basemap.
500
+ */
501
+ getPickingInfo(params: GetPickingInfoParams): PickingInfo;
149
502
  }
150
503
  export {};
@@ -0,0 +1,91 @@
1
+ import { Layer, type LayerProps } from '@deck.gl/core';
2
+ /**
3
+ * The kind of resource a request expects, as MapLibre GL JS's `RequestParameters.type`: `'json'`
4
+ * for a style, a TileJSON, a sprite index or GeoJSON data, `'arrayBuffer'` for a vector tile or a
5
+ * glyph range, `'image'` for a raster or raster-dem tile or a sprite image.
6
+ */
7
+ export type BasemapRequestType = 'string' | 'json' | 'arrayBuffer' | 'image';
8
+ /** The request a protocol handler receives, shaped as MapLibre GL JS's `RequestParameters`. */
9
+ export type BasemapRequestParameters = {
10
+ /** The URL requested, with its scheme. */
11
+ url: string;
12
+ /** The kind of resource expected. */
13
+ type: BasemapRequestType;
14
+ /** The headers of the request's `fetchOptions`. */
15
+ headers?: HeadersInit;
16
+ /** The method of the request's `fetchOptions`. */
17
+ method?: string;
18
+ /** The body of the request's `fetchOptions`. */
19
+ body?: BodyInit | null;
20
+ /** The credentials mode of the request's `fetchOptions`. */
21
+ credentials?: RequestCredentials;
22
+ /** The cache mode of the request's `fetchOptions`. */
23
+ cache?: RequestCache;
24
+ };
25
+ /** What a protocol handler resolves with, as MapLibre GL JS's `GetResourceResponse`. */
26
+ export type BasemapResourceResponse = {
27
+ /**
28
+ * The resource: an `ArrayBuffer`, a typed array or a `Blob` of its bytes (an image is its
29
+ * encoded bytes), a string, or, for a `'json'` request, the parsed JSON value. `null` or
30
+ * `undefined` is an empty resource, such as a tile without data.
31
+ */
32
+ data: unknown;
33
+ /** Accepted for MapLibre GL JS compatibility; not used. */
34
+ cacheControl?: string | null;
35
+ /** Accepted for MapLibre GL JS compatibility; not used. */
36
+ expires?: string | Date | null;
37
+ };
38
+ /**
39
+ * Loads the resource of a URL with a registered scheme. `abortController` aborts when the request
40
+ * is cancelled, for example when deck.gl no longer needs a tile. The same function works as a
41
+ * MapLibre GL JS `addProtocol` handler.
42
+ */
43
+ export type BasemapProtocolHandler = (requestParameters: BasemapRequestParameters, abortController: AbortController) => Promise<BasemapResourceResponse>;
44
+ /**
45
+ * Loads every URL `<scheme>://...` that `BasemapLayer` requests with `handler`: the style, TileJSON,
46
+ * vector, raster and raster-dem tiles, sprites, glyphs and GeoJSON data. A second registration of
47
+ * the same scheme replaces the first. As in MapLibre GL JS, `http`, `https` and `file` URLs always
48
+ * load with `fetch`.
49
+ */
50
+ export declare function registerBasemapProtocol(scheme: string, handler: BasemapProtocolHandler): void;
51
+ /** Removes the handler of `scheme`. Its URLs then fail to load. */
52
+ export declare function unregisterBasemapProtocol(scheme: string): void;
53
+ /**
54
+ * Whether `url` is `<scheme>://...` with a scheme other than `http`, `https` and `file`: a URL that
55
+ * only a protocol handler loads.
56
+ */
57
+ export declare function hasCustomScheme(url: string): boolean;
58
+ /** Whether `url` has a scheme with a registered handler. Such a URL is not resolved against a base. */
59
+ export declare function isBasemapProtocolUrl(url: unknown): url is string;
60
+ /**
61
+ * A `fetch` that loads URLs with a registered scheme with their handler, as a `Response`, and
62
+ * every other URL with `fetchFn`, or the global `fetch` without one. Without `fetchFn`, a URL
63
+ * with another scheme than `http`, `https` and `file` and no handler fails with an error that names
64
+ * the scheme.
65
+ */
66
+ export declare function getBasemapFetch(fetchFn: typeof fetch | undefined, type: BasemapRequestType): typeof fetch;
67
+ /** A deck.gl layer `fetch` prop. */
68
+ export type BasemapLayerFetch = NonNullable<LayerProps['fetch']>;
69
+ /**
70
+ * A deck.gl layer `fetch` prop that loads URLs with a registered scheme with their handler, then
71
+ * parses the bytes with the layer's loaders, and every other URL with `nextFetch`. A tile that
72
+ * deck.gl cancels aborts the handler. The same function is returned for the same `nextFetch` and
73
+ * `type`, so that a layer's props stay equal.
74
+ */
75
+ export declare function getBasemapLayerFetch(nextFetch: BasemapLayerFetch, type: BasemapRequestType): BasemapLayerFetch;
76
+ /** deck.gl's default layer `fetch`, which loads with loaders.gl and the global `fetch`. */
77
+ export declare const DEFAULT_LAYER_FETCH: (url: string, context: {
78
+ propName: string;
79
+ layer: Layer;
80
+ loaders?: import("@loaders.gl/core").Loader[];
81
+ loadOptions?: any;
82
+ signal?: AbortSignal;
83
+ }) => any;
84
+ /** `SharedMVTLayer`'s default `fetch`, which also loads without a deck.gl context. */
85
+ export declare const DEFAULT_MVT_FETCH: (url: string, context: {
86
+ propName: string;
87
+ layer: Layer;
88
+ loaders?: import("@loaders.gl/core").Loader[];
89
+ loadOptions?: any;
90
+ signal?: AbortSignal;
91
+ }) => any;