@tangram.gl/basemap-layers 0.0.1 → 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.
- package/README.md +12 -7
- package/THIRD-PARTY-NOTICES.md +7 -5
- package/dist/geojson-task-worker.js +3166 -0
- package/dist/geojson-task-worker.js.map +6 -0
- package/dist/geojson-worker.js +1089 -7
- package/dist/geojson-worker.js.map +3 -3
- package/dist/index.cjs +9588 -2093
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +9599 -2090
- package/dist/index.js.map +3 -3
- package/dist/map-style.cjs +456 -20
- package/dist/map-style.cjs.map +3 -3
- package/dist/map-style.js +456 -19
- package/dist/map-style.js.map +2 -2
- package/dist/types/basemap-error.d.ts +52 -0
- package/dist/types/basemap-layer.d.ts +378 -25
- package/dist/types/basemap-protocol.d.ts +91 -0
- package/dist/types/basemap-request.d.ts +73 -0
- package/dist/types/circle-layer.d.ts +65 -8
- package/dist/types/color-relief-layer.d.ts +184 -0
- package/dist/types/dem-pixels.d.ts +40 -0
- package/dist/types/feature-state.d.ts +55 -0
- package/dist/types/fill-extrusion-lighting-extension.d.ts +1 -2
- package/dist/types/fill-outline-extension.d.ts +2 -3
- package/dist/types/fill-pattern.d.ts +35 -3
- package/dist/types/fill-style-extensions.d.ts +11 -59
- package/dist/types/geojson-resource.d.ts +18 -0
- package/dist/types/geojson-source.d.ts +13 -2
- package/dist/types/geojson-task-handler.d.ts +2 -0
- package/dist/types/geojson-task.d.ts +26 -0
- package/dist/types/geojson-tiler.d.ts +29 -2
- package/dist/types/geojson-worker.d.ts +5 -1
- package/dist/types/globe-horizon-extension.d.ts +2 -45
- package/dist/types/globe-layers.d.ts +141 -45
- package/dist/types/globe-line-angle-extension.d.ts +20 -17
- package/dist/types/glyph-store.d.ts +10 -1
- package/dist/types/heatmap-layer.d.ts +99 -0
- package/dist/types/hillshade-layer.d.ts +159 -27
- package/dist/types/icon-text-fit.d.ts +92 -0
- package/dist/types/image-source-layer.d.ts +142 -0
- package/dist/types/index.d.ts +25 -1
- package/dist/types/line-blur-extension.d.ts +3 -11
- package/dist/types/line-dash-extension.d.ts +53 -0
- package/dist/types/line-gradient-extension.d.ts +69 -0
- package/dist/types/line-metrics.d.ts +24 -0
- package/dist/types/line-pattern-extension.d.ts +50 -0
- package/dist/types/line-shape-extension.d.ts +76 -0
- package/dist/types/map-style-loader.d.ts +1 -1
- package/dist/types/map-style.d.ts +2 -2
- package/dist/types/mvt-label-layer.d.ts +111 -20
- package/dist/types/pmtiles-source.d.ts +38 -0
- package/dist/types/projected-background-layer.d.ts +63 -0
- package/dist/types/projected-bitmap-layer.d.ts +58 -0
- package/dist/types/projected-tile-data.d.ts +16 -0
- package/dist/types/projected-tile-selection.d.ts +72 -0
- package/dist/types/projected-tileset.d.ts +92 -0
- package/dist/types/projected-viewport.d.ts +76 -0
- package/dist/types/raster-color-extension.d.ts +4 -7
- package/dist/types/raster-fade.d.ts +155 -0
- package/dist/types/raster-tile-fingerprint.d.ts +11 -0
- package/dist/types/raster-tile-loader.d.ts +80 -0
- package/dist/types/shader-injection-plugin.d.ts +8 -0
- package/dist/types/source-features.d.ts +58 -0
- package/dist/types/source-tiles.d.ts +32 -0
- package/dist/types/sprite.d.ts +37 -3
- package/dist/types/stretch-icon-layer.d.ts +28 -0
- package/dist/types/style-accessor.d.ts +50 -12
- package/dist/types/style-expression.d.ts +22 -2
- package/dist/types/style-resolver.d.ts +47 -2
- package/dist/types/terrain-query.d.ts +39 -0
- package/dist/types/zoom-load-gate.d.ts +22 -0
- package/dist/types/zoom-paint-extension.d.ts +80 -11
- package/package.json +24 -21
- package/src/basemap-error.ts +82 -0
- package/src/basemap-layer.ts +1289 -101
- package/src/basemap-protocol.ts +353 -0
- package/src/basemap-request.ts +212 -0
- package/src/circle-layer.ts +430 -54
- package/src/color-relief-layer.ts +572 -0
- package/src/dem-pixels.ts +174 -0
- package/src/feature-state.ts +164 -0
- package/src/fill-extrusion-lighting-extension.ts +126 -9
- package/src/fill-outline-extension.ts +4 -4
- package/src/fill-pattern.ts +87 -9
- package/src/fill-style-extensions.ts +114 -44
- package/src/geojson-resource.ts +58 -0
- package/src/geojson-source.ts +106 -85
- package/src/geojson-task-handler.ts +11 -0
- package/src/geojson-task-worker.ts +8 -0
- package/src/geojson-task.ts +34 -0
- package/src/geojson-tiler.ts +270 -4
- package/src/geojson-worker.ts +36 -6
- package/src/globe-horizon-extension.ts +14 -4
- package/src/globe-layers.ts +1905 -406
- package/src/globe-line-angle-extension.ts +183 -23
- package/src/glyph-store.ts +28 -6
- package/src/heatmap-layer.ts +591 -0
- package/src/hillshade-layer.ts +309 -88
- package/src/icon-text-fit.ts +358 -0
- package/src/image-source-layer.ts +380 -0
- package/src/index.ts +58 -1
- package/src/line-blur-extension.ts +14 -12
- package/src/line-dash-extension.ts +303 -0
- package/src/line-gradient-extension.ts +191 -0
- package/src/line-metrics.ts +90 -0
- package/src/line-pattern-extension.ts +173 -0
- package/src/line-shape-extension.ts +272 -0
- package/src/map-style-loader.ts +5 -4
- package/src/map-style.ts +2 -1
- package/src/mvt-label-layer.ts +568 -144
- package/src/pmtiles-source.ts +276 -0
- package/src/projected-background-layer.ts +202 -0
- package/src/projected-bitmap-layer.ts +262 -0
- package/src/projected-tile-data.ts +132 -0
- package/src/projected-tile-selection.ts +605 -0
- package/src/projected-tileset.ts +183 -0
- package/src/projected-viewport.ts +254 -0
- package/src/raster-color-extension.ts +43 -18
- package/src/raster-fade.ts +319 -0
- package/src/raster-tile-fingerprint.ts +31 -0
- package/src/raster-tile-loader.ts +211 -0
- package/src/shader-injection-plugin.ts +25 -0
- package/src/source-features.ts +170 -0
- package/src/source-tiles.ts +102 -0
- package/src/sprite.ts +122 -15
- package/src/stretch-icon-layer.ts +87 -0
- package/src/style-accessor.ts +105 -17
- package/src/style-expression.ts +80 -3
- package/src/style-resolver.ts +200 -22
- package/src/terrain-query.ts +86 -0
- package/src/text-layout.ts +2 -3
- package/src/zoom-load-gate.ts +57 -0
- package/src/zoom-paint-extension.ts +245 -47
- package/dist/types/arabic-shaping.d.ts +0 -7
- package/dist/types/bidi.d.ts +0 -8
- package/dist/types/polylabel.d.ts +0 -17
- package/src/arabic-shaping.ts +0 -366
- package/src/bidi.ts +0 -199
- package/src/polylabel.ts +0 -312
package/src/globe-layers.ts
CHANGED
|
@@ -3,38 +3,92 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {GlyphStore} from './glyph-store';
|
|
6
|
-
import {SharedMVTLayer, SharedTileset2D} from '@deck.gl-community/geo-layers';
|
|
7
|
-
import {
|
|
6
|
+
import {SharedMVTLayer, SharedTile2DLayer, SharedTileset2D} from '@deck.gl-community/layers/geo-layers';
|
|
7
|
+
import {_getURLFromTemplate as getURLFromTemplate} from '@deck.gl/geo-layers';
|
|
8
|
+
import {getStyleZoom, isGeographicViewport, isProjectedViewport} from './projected-viewport';
|
|
9
|
+
import {getTileFeaturesInLngLat} from './projected-tile-data';
|
|
10
|
+
import {getBasemapTilesetAdapter} from './projected-tileset';
|
|
11
|
+
import {RasterFadeExtension, RasterFadeTileLayer} from './raster-fade';
|
|
12
|
+
import {getSourceTileBounds, getSourceTileTemplates} from './source-tiles';
|
|
8
13
|
import {
|
|
9
|
-
|
|
14
|
+
type Color,
|
|
10
15
|
type Layer,
|
|
16
|
+
type LayerExtension,
|
|
17
|
+
type LayerProps,
|
|
11
18
|
type LayersList,
|
|
12
19
|
type UpdateParameters,
|
|
13
20
|
log
|
|
14
21
|
} from '@deck.gl/core';
|
|
15
22
|
import {PathStyleExtension} from '@deck.gl/extensions';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
23
|
+
import {GeoJsonLayer, PolygonLayer, SolidPolygonLayer} from '@deck.gl/layers';
|
|
24
|
+
import {Matrix4} from '@math.gl/core/matrix';
|
|
25
|
+
import {ProjectedBackgroundLayer} from './projected-background-layer';
|
|
26
|
+
import {ProjectedBitmapLayer} from './projected-bitmap-layer';
|
|
27
|
+
import {
|
|
28
|
+
ImageSourceLayer,
|
|
29
|
+
getImageSourceCorners,
|
|
30
|
+
hasFlippedWinding,
|
|
31
|
+
isDrawableImageSource,
|
|
32
|
+
type ImageSourceCorners
|
|
33
|
+
} from './image-source-layer';
|
|
18
34
|
import {getGlobeAtmosphereLayer, getGlobeAtmosphereSkyLayer} from './atmosphere-layer';
|
|
19
35
|
import {createCircleSubLayer} from './circle-layer';
|
|
36
|
+
import {
|
|
37
|
+
createHeatmapSubLayer,
|
|
38
|
+
getHeatmapPoints,
|
|
39
|
+
getTilesWithoutDrawnAncestor,
|
|
40
|
+
type HeatmapPoint
|
|
41
|
+
} from './heatmap-layer';
|
|
42
|
+
import {
|
|
43
|
+
type BasemapFeatureState,
|
|
44
|
+
type FeatureStateLookup,
|
|
45
|
+
getFeatureStateLookup,
|
|
46
|
+
getPickedFeature
|
|
47
|
+
} from './feature-state';
|
|
20
48
|
import {sortFeaturesByKey} from './sort-key';
|
|
21
|
-
import {
|
|
49
|
+
import {
|
|
50
|
+
getGeoJsonMaxZoom,
|
|
51
|
+
getGeoJsonTileFeatures,
|
|
52
|
+
isGeoJsonSource,
|
|
53
|
+
type GeoJsonTileOptions
|
|
54
|
+
} from './geojson-source';
|
|
22
55
|
import {
|
|
23
56
|
type FillPatternGroup,
|
|
24
57
|
getFeaturesWithoutPattern,
|
|
25
58
|
getFillPatternGroups,
|
|
59
|
+
getPatternRuns,
|
|
60
|
+
getLinePatternProps,
|
|
26
61
|
getFillPatternProps
|
|
27
62
|
} from './fill-pattern';
|
|
28
|
-
import {
|
|
63
|
+
import {
|
|
64
|
+
FillPatternExtension,
|
|
65
|
+
FillTranslateExtension,
|
|
66
|
+
type FillTranslateAnchor
|
|
67
|
+
} from './fill-style-extensions';
|
|
29
68
|
import {FillOutlineExtension} from './fill-outline-extension';
|
|
30
69
|
import {LineBlurExtension, getBlurredLineWidth} from './line-blur-extension';
|
|
70
|
+
import {LineDashExtension, getDashPattern, getDashPatternRow} from './line-dash-extension';
|
|
71
|
+
import {
|
|
72
|
+
LineGradientExtension,
|
|
73
|
+
type LineGradientRamp,
|
|
74
|
+
getLineClip,
|
|
75
|
+
getLineGradientRamp
|
|
76
|
+
} from './line-gradient-extension';
|
|
77
|
+
import {LinePatternExtension} from './line-pattern-extension';
|
|
78
|
+
import {
|
|
79
|
+
GapCapOffsetExtension,
|
|
80
|
+
LineShapeExtension,
|
|
81
|
+
MAX_LINE_SHAPE_MITER_RATIO
|
|
82
|
+
} from './line-shape-extension';
|
|
31
83
|
import {
|
|
32
84
|
HillshadeTileLayer,
|
|
33
85
|
createSharedDemTileset,
|
|
86
|
+
getDemUnpackVector,
|
|
34
87
|
getHillshadeParameters,
|
|
35
88
|
type DemTile,
|
|
36
89
|
type DemTilesetOwner
|
|
37
90
|
} from './hillshade-layer';
|
|
91
|
+
import {ColorReliefTileLayer, createColorRamp, isColorRampVisible} from './color-relief-layer';
|
|
38
92
|
import type {LabelPlacement} from './label-placement';
|
|
39
93
|
import {MVTLabelLayer, type LabelTile} from './mvt-label-layer';
|
|
40
94
|
import {isSameList} from './util';
|
|
@@ -46,14 +100,22 @@ import {
|
|
|
46
100
|
import {filterFeatures, parseProperties} from './map-style';
|
|
47
101
|
import {
|
|
48
102
|
STYLE_ZOOM_STEP,
|
|
103
|
+
type PaintProperty,
|
|
49
104
|
type StyleAccessor,
|
|
105
|
+
compileZoomPaintProperty,
|
|
50
106
|
getFilterZoom,
|
|
51
107
|
getStyleAccessor,
|
|
52
108
|
getStyleZoomKey,
|
|
53
109
|
getZoomBucket,
|
|
110
|
+
getZoomPaintZoom,
|
|
54
111
|
withOpacity
|
|
55
112
|
} from './style-accessor';
|
|
56
|
-
import {
|
|
113
|
+
import {
|
|
114
|
+
evaluateStyleLight,
|
|
115
|
+
getCompiledStyleProperty,
|
|
116
|
+
getStylePropertyDefault,
|
|
117
|
+
getZoomInterpolationFactor
|
|
118
|
+
} from './style-expression';
|
|
57
119
|
import {
|
|
58
120
|
DEFAULT_FILL_EXTRUSION_LIGHT,
|
|
59
121
|
type FillExtrusionLight,
|
|
@@ -62,15 +124,23 @@ import {
|
|
|
62
124
|
import {
|
|
63
125
|
MAX_ZOOM_PAINT_PARTS,
|
|
64
126
|
ZOOM_PAINT_FILL_COLOR_ROW,
|
|
127
|
+
ZOOM_PAINT_INTERPOLATION_ROW,
|
|
65
128
|
ZOOM_PAINT_LINE_COLOR_ROW,
|
|
66
129
|
ZOOM_PAINT_WIDTH_ROW,
|
|
67
130
|
ZoomPaint,
|
|
68
131
|
ZoomPaintExtension,
|
|
132
|
+
type ZoomPaintExtensionProps,
|
|
69
133
|
type ZoomPaintValues,
|
|
70
134
|
createZoomPaintValues,
|
|
71
|
-
getZoomPaintOffset
|
|
135
|
+
getZoomPaintOffset,
|
|
136
|
+
packZoomPaintColor
|
|
72
137
|
} from './zoom-paint-extension';
|
|
73
|
-
import type {BasemapGlobeConfig, BasemapLayerProps} from './basemap-layer';
|
|
138
|
+
import type {BasemapGlobeConfig, BasemapInsertion, BasemapLayerProps} from './basemap-layer';
|
|
139
|
+
import {type RejectRasterTile, getRasterTileLoader} from './raster-tile-loader';
|
|
140
|
+
import {getTileLoadOptions} from './pmtiles-source';
|
|
141
|
+
import {type BasemapLoadErrorHandler, getBasemapLoadError} from './basemap-error';
|
|
142
|
+
import {DEFAULT_LAYER_FETCH, DEFAULT_MVT_FETCH} from './basemap-protocol';
|
|
143
|
+
import {getBasemapTileFetch, type BasemapTransformRequest} from './basemap-request';
|
|
74
144
|
import type {SpriteAtlas} from './sprite';
|
|
75
145
|
import type {LabelFontFamily} from './text-font';
|
|
76
146
|
import type {
|
|
@@ -80,7 +150,8 @@ import type {
|
|
|
80
150
|
ResolvedBasemapStyle
|
|
81
151
|
} from './style-resolver';
|
|
82
152
|
|
|
83
|
-
|
|
153
|
+
/** The mode the sublayers draw in; `BasemapLayer` resolves its `'auto'` mode to one of these. */
|
|
154
|
+
type BasemapMode = 'map' | 'globe';
|
|
84
155
|
|
|
85
156
|
type BasemapLayerConfig = {
|
|
86
157
|
atmosphere: boolean;
|
|
@@ -93,8 +164,17 @@ type BasemapLayerGroup = {
|
|
|
93
164
|
mode?: BasemapMode;
|
|
94
165
|
globe?: {config?: BasemapGlobeConfig};
|
|
95
166
|
styleDefinition: ResolvedBasemapStyle;
|
|
167
|
+
/** Builds the style at this zoom, also used for WebGL paint outside its viewport zoom step. */
|
|
96
168
|
zoom?: number;
|
|
97
169
|
loadOptions?: BasemapLoadOptions;
|
|
170
|
+
/** Loads the tiles of raster sources (see deck.gl's `fetch` layer prop). */
|
|
171
|
+
fetch?: LayerProps['fetch'];
|
|
172
|
+
/** Changes each tile request before it is sent (see `BasemapLayerProps.transformRequest`). */
|
|
173
|
+
transformRequest?: BasemapTransformRequest | null;
|
|
174
|
+
/** Matches the raster tiles that have no data (see `BasemapLayerProps.rejectRasterTile`). */
|
|
175
|
+
rejectRasterTile?: RejectRasterTile | null;
|
|
176
|
+
/** Receives the tiles that fail to load, in place of the log (see `BasemapLoadError`). */
|
|
177
|
+
onError?: BasemapLoadErrorHandler | null;
|
|
98
178
|
/**
|
|
99
179
|
* Sprites loaded for the style; symbol layers draw `icon-image` from them. `null` means the
|
|
100
180
|
* sprites are still loading: no icons are drawn, and labels are placed as if each symbol had its
|
|
@@ -107,16 +187,99 @@ type BasemapLayerGroup = {
|
|
|
107
187
|
glyphs?: GlyphStore | null;
|
|
108
188
|
/** The label placement shared by the map's label layers (see `LabelPlacement`). */
|
|
109
189
|
labelPlacement?: LabelPlacement | null;
|
|
190
|
+
/** The states that `["feature-state", ...]` reads (see `BasemapLayerProps.featureState`). */
|
|
191
|
+
featureState?: BasemapFeatureState | null;
|
|
192
|
+
/** Makes the features of vector and GeoJSON sources pickable (see `BasemapPickedFeature`). */
|
|
193
|
+
pickable?: LayerProps['pickable'];
|
|
110
194
|
/** Externally owned source caches; BasemapLayer supplies and finalizes these. */
|
|
111
195
|
tilesets?: Map<BasemapSource, SharedTileset2D>;
|
|
196
|
+
/**
|
|
197
|
+
* Whether the layers are drawn in a projected view (deck.gl's `_CustomProjectionView`), where a
|
|
198
|
+
* `background` layer fills the screen around the view (see `ProjectedBackgroundLayer`).
|
|
199
|
+
*/
|
|
200
|
+
projected?: boolean;
|
|
201
|
+
/** Draw an ordinary background locally for a geographic first-person camera. */
|
|
202
|
+
firstPerson?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* The stretch limit of the tile selection in a projected view (see
|
|
205
|
+
* `ProjectedTileSelectionOptions.maxStretch`). It applies to the tilesets these layers create.
|
|
206
|
+
*/
|
|
207
|
+
projectedMaxStretch?: number;
|
|
208
|
+
/**
|
|
209
|
+
* Extra deck.gl props for the sublayers of some style layers, by style layer (see
|
|
210
|
+
* `BasemapLayerProps.getStyleLayerProps` and `getStyleLayerPropsMap`). Compared by identity:
|
|
211
|
+
* the tiles regenerate when it changes.
|
|
212
|
+
*/
|
|
213
|
+
styleLayerProps?: StyleLayerPropsMap | null;
|
|
214
|
+
/**
|
|
215
|
+
* deck.gl layers drawn inside the style order (see `BasemapLayerProps.insertLayers`). An
|
|
216
|
+
* insertion whose `beforeId` names no layer of the style throws an error.
|
|
217
|
+
*/
|
|
218
|
+
insertLayers?: BasemapInsertion[] | null;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Extra deck.gl props for the sublayers that draw one style layer. `extensions` are added after
|
|
223
|
+
* the sublayer's own, and `updateTriggers` are merged with the sublayer's own. `id` and `data`
|
|
224
|
+
* are ignored.
|
|
225
|
+
*/
|
|
226
|
+
export type StyleLayerSubLayerProps = Partial<LayerProps> & {
|
|
227
|
+
extensions?: LayerExtension[];
|
|
228
|
+
updateTriggers?: Record<string, unknown>;
|
|
229
|
+
[key: string]: unknown;
|
|
112
230
|
};
|
|
113
231
|
|
|
232
|
+
/** Extra sublayer props by style layer; style layers without extra props have no entry. */
|
|
233
|
+
export type StyleLayerPropsMap = ReadonlyMap<BasemapStyleLayer, StyleLayerSubLayerProps>;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The extra sublayer props of each style layer of `styleDefinition`, from `getProps`, or null when
|
|
237
|
+
* no style layer has any.
|
|
238
|
+
*/
|
|
239
|
+
export function getStyleLayerPropsMap(
|
|
240
|
+
styleDefinition: ResolvedBasemapStyle,
|
|
241
|
+
getProps: ((styleLayer: BasemapStyleLayer) => StyleLayerSubLayerProps | null | undefined) | null
|
|
242
|
+
): StyleLayerPropsMap | null {
|
|
243
|
+
if (!getProps) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
const map = new Map<BasemapStyleLayer, StyleLayerSubLayerProps>();
|
|
247
|
+
for (const styleLayer of styleDefinition.layers || []) {
|
|
248
|
+
const props = getProps(styleLayer);
|
|
249
|
+
if (props) {
|
|
250
|
+
map.set(styleLayer, props);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return map.size > 0 ? map : null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* `layers`, the sublayers of one style layer, with its extra props (see
|
|
258
|
+
* `StyleLayerSubLayerProps`). Without extra props, `layers` is returned as it is.
|
|
259
|
+
*/
|
|
260
|
+
function withStyleLayerProps<T>(layers: T, props: StyleLayerSubLayerProps | undefined): T {
|
|
261
|
+
if (!props || !layers) {
|
|
262
|
+
return layers;
|
|
263
|
+
}
|
|
264
|
+
if (Array.isArray(layers)) {
|
|
265
|
+
return layers.map(layer => withStyleLayerProps(layer, props)) as T;
|
|
266
|
+
}
|
|
267
|
+
const layer = layers as unknown as Layer;
|
|
268
|
+
const {id: _id, data: _data, extensions, updateTriggers, ...rest} = props;
|
|
269
|
+
const ownProps = layer.props as {extensions?: LayerExtension[]; updateTriggers?: object};
|
|
270
|
+
return layer.clone({
|
|
271
|
+
...rest,
|
|
272
|
+
...(extensions?.length ? {extensions: [...(ownProps.extensions || []), ...extensions]} : {}),
|
|
273
|
+
...(updateTriggers ? {updateTriggers: {...ownProps.updateTriggers, ...updateTriggers}} : {})
|
|
274
|
+
}) as unknown as T;
|
|
275
|
+
}
|
|
276
|
+
|
|
114
277
|
/**
|
|
115
|
-
* Style layers that draw together, in style order: a background, raster
|
|
116
|
-
* own, or consecutive style layers of one vector source, which share one tile layer.
|
|
278
|
+
* Style layers that draw together, in style order: a background, raster, hillshade or color-relief
|
|
279
|
+
* layer on its own, or consecutive style layers of one vector source, which share one tile layer.
|
|
117
280
|
*/
|
|
118
281
|
export type StyleLayerRun = {
|
|
119
|
-
type: 'background' | 'raster' | 'hillshade' | 'vector';
|
|
282
|
+
type: 'background' | 'raster' | 'hillshade' | 'color-relief' | 'vector';
|
|
120
283
|
/** The deck.gl layer id, without the basemap's id prefix. */
|
|
121
284
|
id: string;
|
|
122
285
|
sourceId?: string;
|
|
@@ -132,11 +295,51 @@ function logBasemapRuntimeError(message: string, error: unknown, details?: unkno
|
|
|
132
295
|
log.error(`[BasemapLayer] ${message}`, details || '', error)();
|
|
133
296
|
}
|
|
134
297
|
|
|
298
|
+
/**
|
|
299
|
+
* Gives a tile that failed to load to `onError`, with its URL and index, or logs it without one.
|
|
300
|
+
* With `missingIsEmpty`, a tile that answers 404 is a tile without data, not a failure, as a vector
|
|
301
|
+
* tile is in MapLibre GL JS.
|
|
302
|
+
*/
|
|
303
|
+
function reportTileError(
|
|
304
|
+
onError: BasemapLoadErrorHandler | null | undefined,
|
|
305
|
+
error: unknown,
|
|
306
|
+
tile: {index?: unknown} | undefined,
|
|
307
|
+
{source, sourceId, message, details, missingIsEmpty}: {
|
|
308
|
+
source: BasemapSource;
|
|
309
|
+
sourceId?: string;
|
|
310
|
+
message: string;
|
|
311
|
+
details: Record<string, unknown>;
|
|
312
|
+
missingIsEmpty?: boolean;
|
|
313
|
+
}
|
|
314
|
+
): void {
|
|
315
|
+
if (!onError) {
|
|
316
|
+
logBasemapRuntimeError(message, error, details);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const index = tile?.index as {x: number; y: number; z: number} | undefined;
|
|
320
|
+
const url =
|
|
321
|
+
index && source.tiles
|
|
322
|
+
? getURLFromTemplate(source.tiles, {index, id: `${index.x}-${index.y}-${index.z}`})
|
|
323
|
+
: null;
|
|
324
|
+
const loadError = getBasemapLoadError('tile', error, {
|
|
325
|
+
sourceId,
|
|
326
|
+
...(url ? {url} : {}),
|
|
327
|
+
...(index ? {tile: {x: index.x, y: index.y, z: index.z}} : {})
|
|
328
|
+
});
|
|
329
|
+
if (!(missingIsEmpty && loadError.status === 404)) {
|
|
330
|
+
onError(loadError);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Depth parameters are set as luma.gl sets them on both backends: `depthCompare: 'always'` turns
|
|
336
|
+
* the depth test off. WebGPU has no `depthTest` parameter, and luma.gl logs an error for it.
|
|
337
|
+
*/
|
|
135
338
|
function getBackgroundParameters(mode: BasemapMode) {
|
|
136
339
|
return (
|
|
137
340
|
mode === 'globe'
|
|
138
|
-
? {
|
|
139
|
-
: {
|
|
341
|
+
? {depthWriteEnabled: true, depthCompare: 'less-equal', cullMode: 'back'}
|
|
342
|
+
: {depthCompare: 'always', cullMode: 'none'}
|
|
140
343
|
) as any;
|
|
141
344
|
}
|
|
142
345
|
|
|
@@ -154,10 +357,9 @@ function getBackgroundParameters(mode: BasemapMode) {
|
|
|
154
357
|
*/
|
|
155
358
|
function getTileParameters(mode: BasemapMode, depthTested = false) {
|
|
156
359
|
if (mode === 'globe' && !depthTested) {
|
|
157
|
-
return {
|
|
360
|
+
return {depthCompare: 'always', depthWriteEnabled: false, cullMode: 'back'} as any;
|
|
158
361
|
}
|
|
159
362
|
return {
|
|
160
|
-
depthTest: true,
|
|
161
363
|
depthWriteEnabled: false,
|
|
162
364
|
depthCompare: 'less-equal',
|
|
163
365
|
cullMode: mode === 'globe' ? 'back' : 'none'
|
|
@@ -175,16 +377,26 @@ const BACKGROUND_DATA = [
|
|
|
175
377
|
]
|
|
176
378
|
];
|
|
177
379
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
]
|
|
380
|
+
// deck.gl 10 triangulates globe polygons in geocentric space. A single polygon spanning
|
|
381
|
+
// the whole sphere has no valid triangulation plane, even with viewport subdivision enabled.
|
|
382
|
+
function getGlobeBackgroundPatches(south: number, north: number): number[][][] {
|
|
383
|
+
const polygons: number[][][] = [];
|
|
384
|
+
for (let latitude = south; latitude < north; latitude += 10) {
|
|
385
|
+
const top = Math.min(latitude + 10, north);
|
|
386
|
+
for (let longitude = -180; longitude < 180; longitude += 10) {
|
|
387
|
+
polygons.push([
|
|
388
|
+
[longitude, top],
|
|
389
|
+
[longitude + 10, top],
|
|
390
|
+
[longitude + 10, latitude],
|
|
391
|
+
[longitude, latitude]
|
|
392
|
+
]);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return polygons;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const GLOBE_BACKGROUND_DATA = getGlobeBackgroundPatches(-90, 90);
|
|
399
|
+
const BACKGROUND_NORTH_POLE_DATA = getGlobeBackgroundPatches(85, 90);
|
|
188
400
|
|
|
189
401
|
const SUPPORTED_TYPES = new Set([
|
|
190
402
|
'background',
|
|
@@ -194,7 +406,9 @@ const SUPPORTED_TYPES = new Set([
|
|
|
194
406
|
'line',
|
|
195
407
|
'symbol',
|
|
196
408
|
'raster',
|
|
197
|
-
'hillshade'
|
|
409
|
+
'hillshade',
|
|
410
|
+
'heatmap',
|
|
411
|
+
'color-relief'
|
|
198
412
|
]);
|
|
199
413
|
const DEFAULT_CONFIG: BasemapLayerConfig = {atmosphere: false, basemap: true, labels: true};
|
|
200
414
|
const DEFAULT_TEXT_COLOR = [0, 0, 0, 1];
|
|
@@ -211,11 +425,17 @@ const DASH_EXTENSION = new PathStyleExtension({dash: true, dashMode: 'path'});
|
|
|
211
425
|
/** The dash array of a solid line in a dashed sublayer: no gaps. */
|
|
212
426
|
const SOLID_DASH_ARRAY: StyleAccessor<[number, number]> = {value: [0, 0]};
|
|
213
427
|
/** `line-offset` and `line-gap-width`, alone and with dashes; shared for the same reason. */
|
|
214
|
-
const OFFSET_EXTENSION = new
|
|
215
|
-
const DASH_OFFSET_EXTENSION = new
|
|
428
|
+
const OFFSET_EXTENSION = new GapCapOffsetExtension({offset: true});
|
|
429
|
+
const DASH_OFFSET_EXTENSION = new GapCapOffsetExtension({dash: true, dashMode: 'path', offset: true});
|
|
430
|
+
const LINE_DASH_EXTENSION = new LineDashExtension();
|
|
431
|
+
const LINE_SHAPE_EXTENSION = new LineShapeExtension();
|
|
216
432
|
/** `line-blur`, shared for the same reason: by layer, and per feature. */
|
|
217
433
|
const LINE_BLUR_EXTENSION = new LineBlurExtension();
|
|
218
434
|
const LINE_BLUR_PER_FEATURE_EXTENSION = new LineBlurExtension({perFeature: true});
|
|
435
|
+
/** `line-gradient`, shared by every line that draws one. */
|
|
436
|
+
const LINE_GRADIENT_EXTENSION = new LineGradientExtension();
|
|
437
|
+
const LINE_PATTERN_EXTENSION = new LinePatternExtension();
|
|
438
|
+
const warnedGradientLayers = new Set<string>();
|
|
219
439
|
/** A fill's outline, drawn as a line; shared for the same reason. */
|
|
220
440
|
const FILL_OUTLINE_EXTENSION = new FillOutlineExtension();
|
|
221
441
|
|
|
@@ -225,6 +445,8 @@ const FILL_TRANSLATE_EXTENSION = new FillTranslateExtension();
|
|
|
225
445
|
|
|
226
446
|
/** Applies the `raster-*` color adjustments, shared by every raster layer that sets them. */
|
|
227
447
|
const RASTER_COLOR_EXTENSION = new RasterColorExtension();
|
|
448
|
+
/** `raster-fade-duration`, shared by every raster tile. */
|
|
449
|
+
const RASTER_FADE_EXTENSION = new RasterFadeExtension();
|
|
228
450
|
|
|
229
451
|
/**
|
|
230
452
|
* The texture filters of `raster-resampling: nearest`. MapLibre magnifies with the nearest texel
|
|
@@ -234,7 +456,6 @@ const NEAREST_TEXTURE_PARAMETERS = {magFilter: 'nearest'} as const;
|
|
|
234
456
|
|
|
235
457
|
/** Extrusions are depth-tested against each other; flat layers draw in style order. */
|
|
236
458
|
const EXTRUSION_PARAMETERS = {
|
|
237
|
-
depthTest: true,
|
|
238
459
|
depthWriteEnabled: true,
|
|
239
460
|
depthCompare: 'less-equal',
|
|
240
461
|
cullMode: 'none'
|
|
@@ -415,6 +636,13 @@ function getTileFeatures(data: unknown): any[] {
|
|
|
415
636
|
|
|
416
637
|
/** The prop that records which style layer of its run a tile sublayer draws. */
|
|
417
638
|
const STYLE_LAYER_INDEX = 'styleLayerIndex';
|
|
639
|
+
/** The prop that records the ids of the style layers a tile sublayer draws, for picking. */
|
|
640
|
+
const STYLE_LAYER_IDS = 'styleLayerIds';
|
|
641
|
+
/**
|
|
642
|
+
* The prop that records, per feature of a sublayer that draws several style layers, the index of
|
|
643
|
+
* its style layer in `STYLE_LAYER_IDS`.
|
|
644
|
+
*/
|
|
645
|
+
const STYLE_LAYER_PARTS = 'styleLayerParts';
|
|
418
646
|
/** The view each label layer draws in, or `null` for every view (see `renderLabelLayers`). */
|
|
419
647
|
const labelLayerViews = new WeakMap<Layer, string | null>();
|
|
420
648
|
|
|
@@ -444,8 +672,21 @@ function getStyleSubLayerId(parentId: string, styleLayerId: string | string[]):
|
|
|
444
672
|
*/
|
|
445
673
|
const ZOOM_PAINT_CONTEXT = 'zoomPaintContext';
|
|
446
674
|
|
|
675
|
+
/**
|
|
676
|
+
* The prop that tells a tile's `renderSubLayers` that its tile layer draws on WebGPU, where
|
|
677
|
+
* zoom-dependent paint is not interpolated on the GPU.
|
|
678
|
+
*/
|
|
679
|
+
const WEBGPU_DEVICE = 'webgpuDevice';
|
|
680
|
+
|
|
447
681
|
/** Shared by every fill and line sublayer, so deck.gl does not see their extensions change. */
|
|
448
682
|
const ZOOM_PAINT_EXTENSION = new ZoomPaintExtension();
|
|
683
|
+
/** Shared by sublayers that blend two sets of composite paint attributes. */
|
|
684
|
+
const COMPOSITE_ZOOM_PAINT_EXTENSION = new ZoomPaintExtension({composite: true});
|
|
685
|
+
/** Shared by dashed sublayers that pack composite paint into one vertex input. */
|
|
686
|
+
const DASHED_COMPOSITE_ZOOM_PAINT_EXTENSION = new ZoomPaintExtension({
|
|
687
|
+
composite: true,
|
|
688
|
+
packedPath: true
|
|
689
|
+
});
|
|
449
690
|
|
|
450
691
|
/** The paint properties `getGeometryPaint` reads. */
|
|
451
692
|
const GEOMETRY_PAINT_PROPERTIES = [
|
|
@@ -468,15 +709,14 @@ const GEOMETRY_PAINT_PROPERTIES = [
|
|
|
468
709
|
function setZoomPaintColors(
|
|
469
710
|
values: ZoomPaintValues,
|
|
470
711
|
row: number,
|
|
471
|
-
colors:
|
|
712
|
+
colors: (number[] | undefined)[]
|
|
472
713
|
): void {
|
|
473
714
|
const isLayerConstant = colors.every(
|
|
474
|
-
(
|
|
475
|
-
typeof value !== 'function' && JSON.stringify(value) === JSON.stringify(colors[0].value)
|
|
715
|
+
color => color && colors[0] && color.every((channel, index) => channel === colors[0]?.[index])
|
|
476
716
|
);
|
|
477
|
-
colors.forEach((
|
|
717
|
+
colors.forEach((value, part) => {
|
|
478
718
|
// Per-feature colors keep the alpha of -1 that takes them from the attribute.
|
|
479
|
-
if (
|
|
719
|
+
if (value) {
|
|
480
720
|
const offset = getZoomPaintOffset(row, part);
|
|
481
721
|
for (let channel = 0; channel < 4; channel++) {
|
|
482
722
|
values[offset + channel] =
|
|
@@ -488,50 +728,75 @@ function setZoomPaintColors(
|
|
|
488
728
|
|
|
489
729
|
/** Rounds a 0-255 value as deck.gl stores it in an 8 bit color attribute. */
|
|
490
730
|
const unorm8 = new Uint8ClampedArray(1);
|
|
731
|
+
/** Rounds a channel to the value stored in an unsigned normalized byte. */
|
|
491
732
|
function toUnorm8(value: number): number {
|
|
492
733
|
unorm8[0] = value;
|
|
493
734
|
return unorm8[0];
|
|
494
735
|
}
|
|
495
736
|
|
|
737
|
+
/** Compiles the texture paint of one fill or line style layer. */
|
|
738
|
+
function compileGeometryZoomPaint(styleLayer: BasemapStyleLayer, mode: BasemapMode) {
|
|
739
|
+
const {lineWidth, lineColor, fillColor} = getGeometryPaintProperties(styleLayer, mode);
|
|
740
|
+
const antialias = getCompiledStyleProperty(styleLayer, 'fill-antialias');
|
|
741
|
+
return {
|
|
742
|
+
width: lineWidth ? compileZoomPaintProperty(styleLayer, lineWidth) : null,
|
|
743
|
+
lineColor: compileZoomPaintProperty(styleLayer, lineColor),
|
|
744
|
+
fillColor: compileZoomPaintProperty(styleLayer, fillColor),
|
|
745
|
+
outline: (bucket: number) => drawsFillOutline(styleLayer, mode, antialias?.evaluate(bucket)),
|
|
746
|
+
antialiasChangesWithZoom: antialias?.isZoomDependent
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/** Writes the layer-wide paint and the composite blend factors of one sublayer into texels. */
|
|
751
|
+
function evaluateZoomPaint(
|
|
752
|
+
paints: ReturnType<typeof compileGeometryZoomPaint>[],
|
|
753
|
+
zoom: number,
|
|
754
|
+
bucket: number
|
|
755
|
+
): ZoomPaintValues {
|
|
756
|
+
const values = createZoomPaintValues();
|
|
757
|
+
const lineColors: (number[] | undefined)[] = [];
|
|
758
|
+
const fillColors: (number[] | undefined)[] = [];
|
|
759
|
+
paints.forEach(({width, lineColor, fillColor, outline}, part) => {
|
|
760
|
+
values[getZoomPaintOffset(ZOOM_PAINT_WIDTH_ROW, part)] = width
|
|
761
|
+
? width.evaluate(zoom) ?? 1
|
|
762
|
+
: Number(outline(bucket));
|
|
763
|
+
lineColors.push(lineColor.evaluate(zoom));
|
|
764
|
+
fillColors.push(fillColor.evaluate(zoom));
|
|
765
|
+
const offset = getZoomPaintOffset(ZOOM_PAINT_INTERPOLATION_ROW, part);
|
|
766
|
+
const next = bucket + STYLE_ZOOM_STEP;
|
|
767
|
+
values[offset] = getZoomInterpolationFactor(width?.interpolation ?? null, zoom, bucket, next);
|
|
768
|
+
values[offset + 1] = getZoomInterpolationFactor(lineColor.interpolation, zoom, bucket, next);
|
|
769
|
+
values[offset + 2] = getZoomInterpolationFactor(fillColor.interpolation, zoom, bucket, next);
|
|
770
|
+
});
|
|
771
|
+
setZoomPaintColors(values, ZOOM_PAINT_LINE_COLOR_ROW, lineColors);
|
|
772
|
+
setZoomPaintColors(values, ZOOM_PAINT_FILL_COLOR_ROW, fillColors);
|
|
773
|
+
return values;
|
|
774
|
+
}
|
|
775
|
+
|
|
496
776
|
/**
|
|
497
777
|
* Evaluates the paint of style layers drawn by one sublayer for `ZoomPaintExtension`: a style
|
|
498
778
|
* layer's width, or 1 where it is per feature, and its colors in 0-1, or an alpha of -1 where they
|
|
499
|
-
* are per feature.
|
|
779
|
+
* are per feature. Layer-wide paint is evaluated at the supplied zoom, which also determines
|
|
780
|
+
* the blend factors for composite paint between the two enclosing style zoom steps.
|
|
500
781
|
*/
|
|
501
782
|
export function getZoomPaintValues(
|
|
502
783
|
styleLayers: BasemapStyleLayer[],
|
|
503
784
|
mode: BasemapMode,
|
|
504
785
|
zoom: number
|
|
505
786
|
): ZoomPaintValues {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
values[getZoomPaintOffset(ZOOM_PAINT_WIDTH_ROW, part)] = lineWidth.value;
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
setZoomPaintColors(
|
|
514
|
-
values,
|
|
515
|
-
ZOOM_PAINT_LINE_COLOR_ROW,
|
|
516
|
-
paints.map(paint => paint.lineColor)
|
|
517
|
-
);
|
|
518
|
-
setZoomPaintColors(
|
|
519
|
-
values,
|
|
520
|
-
ZOOM_PAINT_FILL_COLOR_ROW,
|
|
521
|
-
paints.map(paint => paint.fillColor)
|
|
787
|
+
return evaluateZoomPaint(
|
|
788
|
+
styleLayers.map(layer => compileGeometryZoomPaint(layer, mode)),
|
|
789
|
+
zoom,
|
|
790
|
+
getZoomBucket(zoom)
|
|
522
791
|
);
|
|
523
|
-
return values;
|
|
524
792
|
}
|
|
525
793
|
|
|
526
794
|
/**
|
|
527
|
-
* The paint of one tile layer's fill and line sublayers for `ZoomPaintExtension`:
|
|
528
|
-
*
|
|
529
|
-
*
|
|
795
|
+
* The paint of one tile layer's fill and line sublayers for `ZoomPaintExtension`: a `ZoomPaint`
|
|
796
|
+
* per sequence of style layers drawn by one sublayer, shared by all tiles. Kept in the tile
|
|
797
|
+
* layer's state.
|
|
530
798
|
*/
|
|
531
799
|
export class ZoomPaintContext {
|
|
532
|
-
/** The stepped zoom (see `getZoomBucket`) at which paint is evaluated. */
|
|
533
|
-
zoom = 0;
|
|
534
|
-
|
|
535
800
|
private zoomPaints = new Map<string, {styleLayers: BasemapStyleLayer[]; zoomPaint: ZoomPaint}>();
|
|
536
801
|
|
|
537
802
|
/** The style the zoom paints were made for (see `setStyle`). */
|
|
@@ -558,8 +823,9 @@ export class ZoomPaintContext {
|
|
|
558
823
|
}
|
|
559
824
|
|
|
560
825
|
/**
|
|
561
|
-
* The `ZoomPaint` of style layers drawn by one sublayer. Its values are evaluated
|
|
562
|
-
*
|
|
826
|
+
* The `ZoomPaint` of style layers drawn by one sublayer. Its zoom-dependent values are evaluated
|
|
827
|
+
* at the viewport zoom, with blend factors relative to the sublayer's attribute zoom. Values
|
|
828
|
+
* are shared across draws at the same zooms and evaluated again when a paint property is replaced.
|
|
563
829
|
*/
|
|
564
830
|
get(styleLayers: BasemapStyleLayer[], mode: BasemapMode): ZoomPaint {
|
|
565
831
|
const key = `${mode} ${JSON.stringify(styleLayers.map(layer => layer.id))}`;
|
|
@@ -592,14 +858,26 @@ export class ZoomPaintContext {
|
|
|
592
858
|
}
|
|
593
859
|
return changed;
|
|
594
860
|
};
|
|
595
|
-
let
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
861
|
+
let paints: ReturnType<typeof compileGeometryZoomPaint>[] = [];
|
|
862
|
+
let isZoomDependent = false;
|
|
863
|
+
let last: {zoom: number; bucket: number; values: ZoomPaintValues} | null = null;
|
|
864
|
+
const zoomPaint = new ZoomPaint((zoom, bucket) => {
|
|
865
|
+
if (inputsChanged() || !last) {
|
|
866
|
+
paints = styleLayers.map(layer => compileGeometryZoomPaint(layer, mode));
|
|
867
|
+
isZoomDependent = paints.some(
|
|
868
|
+
paint =>
|
|
869
|
+
paint.width?.isZoomDependent ||
|
|
870
|
+
paint.lineColor.isZoomDependent ||
|
|
871
|
+
paint.fillColor.isZoomDependent ||
|
|
872
|
+
paint.antialiasChangesWithZoom
|
|
873
|
+
);
|
|
874
|
+
last = null;
|
|
875
|
+
}
|
|
876
|
+
if (!last || (isZoomDependent && (last.zoom !== zoom || last.bucket !== bucket))) {
|
|
877
|
+
last = {zoom, bucket, values: evaluateZoomPaint(paints, zoom, bucket)};
|
|
600
878
|
}
|
|
601
879
|
return last.values;
|
|
602
|
-
});
|
|
880
|
+
}, styleLayers.length);
|
|
603
881
|
this.zoomPaints.set(key, {styleLayers: [...styleLayers], zoomPaint});
|
|
604
882
|
return zoomPaint;
|
|
605
883
|
}
|
|
@@ -642,10 +920,28 @@ function getSubLayerBaseProps(props: any) {
|
|
|
642
920
|
highlightedObjectIndex,
|
|
643
921
|
highlightColor,
|
|
644
922
|
parameters,
|
|
645
|
-
wrapLongitude
|
|
923
|
+
wrapLongitude,
|
|
924
|
+
...getExtensionProps(props)
|
|
646
925
|
};
|
|
647
926
|
}
|
|
648
927
|
|
|
928
|
+
/**
|
|
929
|
+
* The props of a tile layer's `extensions`, which the tile layer got from the `BasemapLayer`: an
|
|
930
|
+
* extension reads them from the layer it draws, such as the `maskId` of `MaskExtension`. They are
|
|
931
|
+
* the props that the extension declares in its `defaultProps`.
|
|
932
|
+
*/
|
|
933
|
+
function getExtensionProps(props: any): Record<string, unknown> {
|
|
934
|
+
const extensionProps: Record<string, unknown> = {};
|
|
935
|
+
for (const extension of props.extensions || []) {
|
|
936
|
+
for (const name in extension.constructor?.defaultProps) {
|
|
937
|
+
if (name in props) {
|
|
938
|
+
extensionProps[name] = props[name];
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
return extensionProps;
|
|
943
|
+
}
|
|
944
|
+
|
|
649
945
|
function getGlobeFillColor(color: [number, number, number, number], mode: BasemapMode) {
|
|
650
946
|
if (mode !== 'globe') {
|
|
651
947
|
return color;
|
|
@@ -658,35 +954,106 @@ function getConfig(globe?: {config?: BasemapGlobeConfig}): BasemapLayerConfig {
|
|
|
658
954
|
return {...DEFAULT_CONFIG, ...(globe?.config || {})};
|
|
659
955
|
}
|
|
660
956
|
|
|
957
|
+
/**
|
|
958
|
+
* The vertical offset, in repeats, that places a background pattern's rows as MapLibre GL JS
|
|
959
|
+
* places them: from the top of the world, in pixels at the integer zoom. deck.gl places the rows
|
|
960
|
+
* from the bottom of the world, which is a fraction of a repeat away unless the image height
|
|
961
|
+
* divides the world height.
|
|
962
|
+
*/
|
|
963
|
+
function getBackgroundPatternOffset(pattern: FillPatternGroup, zoom: number): [number, number] {
|
|
964
|
+
const name = pattern.getFillPattern as string;
|
|
965
|
+
const pixelRatio = pattern.getPixelRatio as number;
|
|
966
|
+
const repeats = (512 * 2 ** Math.floor(zoom) * pixelRatio) / pattern.atlas.mapping[name].height;
|
|
967
|
+
return [0, repeats - Math.floor(repeats)];
|
|
968
|
+
}
|
|
969
|
+
|
|
661
970
|
function createBackgroundLayer({
|
|
662
971
|
idPrefix,
|
|
663
972
|
layer,
|
|
664
973
|
zoom,
|
|
665
|
-
mode
|
|
974
|
+
mode,
|
|
975
|
+
projected,
|
|
976
|
+
firstPerson,
|
|
977
|
+
spriteAtlases
|
|
666
978
|
}: {
|
|
667
979
|
idPrefix: string;
|
|
668
980
|
layer: BasemapStyleLayer;
|
|
669
981
|
zoom: number;
|
|
670
982
|
mode: BasemapMode;
|
|
983
|
+
projected?: boolean;
|
|
984
|
+
firstPerson?: boolean;
|
|
985
|
+
spriteAtlases?: SpriteAtlas[] | null;
|
|
671
986
|
}) {
|
|
672
987
|
const paint = getPaint(layer, zoom);
|
|
988
|
+
const opacity = paint['background-opacity'] ?? 1;
|
|
989
|
+
const data = mode === 'globe' ? GLOBE_BACKGROUND_DATA : BACKGROUND_DATA;
|
|
990
|
+
// A `background-pattern` disables `background-color`: the image supplies the colors and
|
|
991
|
+
// `background-opacity` the opacity, as for a patterned fill. Without its image (sprites loading,
|
|
992
|
+
// or missing) the background draws nothing rather than its color or the default black.
|
|
993
|
+
const hasPattern = paint['background-pattern'] !== undefined;
|
|
994
|
+
const [pattern] = hasPattern
|
|
995
|
+
? getFillPatternGroups(data, layer, zoom, spriteAtlases, 'background-pattern')
|
|
996
|
+
: [];
|
|
997
|
+
const getFillColor = hasPattern
|
|
998
|
+
? pattern
|
|
999
|
+
? withOpacity([255, 255, 255, 1], opacity)
|
|
1000
|
+
: TRANSPARENT_COLOR
|
|
1001
|
+
: withOpacity(
|
|
1002
|
+
(paint['background-color'] ?? getStylePropertyDefault('background-color')) as number[],
|
|
1003
|
+
opacity
|
|
1004
|
+
);
|
|
1005
|
+
// deck.gl adds an extension's attributes only to a new layer: the pattern draws in its own
|
|
1006
|
+
// layer, made once the sprites have loaded.
|
|
1007
|
+
const id = `${idPrefix}-${layer.id}${pattern ? '-pattern' : firstPerson ? '-ground' : ''}`;
|
|
1008
|
+
const parameters = getBackgroundParameters(mode);
|
|
1009
|
+
|
|
1010
|
+
if (pattern) {
|
|
1011
|
+
// Placed in common space, so the pattern stays anchored to the map, and sized at the integer
|
|
1012
|
+
// zoom, as in MapLibre GL JS (see `getFillPatternProps`).
|
|
1013
|
+
const {getFillPatternScale, ...fillPatternProps} = getFillPatternProps(pattern, zoom);
|
|
1014
|
+
const patternProps = {
|
|
1015
|
+
extensions: [FILL_PATTERN_EXTENSION],
|
|
1016
|
+
...fillPatternProps,
|
|
1017
|
+
// `background-pattern` does not depend on feature data: its image, and so its scale, is one.
|
|
1018
|
+
getFillPatternScale: getFillPatternScale as number,
|
|
1019
|
+
getFillPatternOffset: getBackgroundPatternOffset(pattern, zoom),
|
|
1020
|
+
getFillColor: getFillColor as Color,
|
|
1021
|
+
parameters
|
|
1022
|
+
};
|
|
1023
|
+
if (mode === 'globe') {
|
|
1024
|
+
// A composite layer, so that on WebGPU, where the extension draws no pattern, the extension
|
|
1025
|
+
// makes its fill transparent rather than white.
|
|
1026
|
+
return new PolygonLayer({
|
|
1027
|
+
id,
|
|
1028
|
+
data,
|
|
1029
|
+
getPolygon: d => d,
|
|
1030
|
+
stroked: false,
|
|
1031
|
+
filled: true,
|
|
1032
|
+
...patternProps
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
// A square around the view rather than the whole world, whose far vertices would leave too
|
|
1036
|
+
// little precision to place the pattern at high zoom.
|
|
1037
|
+
return new ProjectedBackgroundLayer({id, geographic: !projected, ...patternProps});
|
|
1038
|
+
}
|
|
673
1039
|
|
|
1040
|
+
// A local ground polygon avoids clipping world-scale triangles against the view.
|
|
1041
|
+
if (projected || firstPerson) {
|
|
1042
|
+
return new ProjectedBackgroundLayer({
|
|
1043
|
+
id,
|
|
1044
|
+
geographic: firstPerson,
|
|
1045
|
+
getFillColor: getFillColor as Color,
|
|
1046
|
+
parameters
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
674
1049
|
return new SolidPolygonLayer({
|
|
675
|
-
id
|
|
676
|
-
data
|
|
1050
|
+
id,
|
|
1051
|
+
data,
|
|
677
1052
|
getPolygon: d => d,
|
|
678
1053
|
stroked: false,
|
|
679
1054
|
filled: true,
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
getFillColor:
|
|
683
|
-
paint['background-pattern'] !== undefined
|
|
684
|
-
? TRANSPARENT_COLOR
|
|
685
|
-
: withOpacity(
|
|
686
|
-
(paint['background-color'] ?? getStylePropertyDefault('background-color')) as number[],
|
|
687
|
-
paint['background-opacity'] ?? 1
|
|
688
|
-
),
|
|
689
|
-
parameters: getBackgroundParameters(mode)
|
|
1055
|
+
getFillColor,
|
|
1056
|
+
parameters
|
|
690
1057
|
});
|
|
691
1058
|
}
|
|
692
1059
|
|
|
@@ -736,17 +1103,47 @@ export function getTilePyramidProps(source: BasemapSource): {
|
|
|
736
1103
|
};
|
|
737
1104
|
}
|
|
738
1105
|
|
|
1106
|
+
const transformedOptions = new WeakMap<BasemapTransformRequest, WeakMap<object, NonNullable<BasemapLoadOptions>>>();
|
|
1107
|
+
const emptyLoadOptions = {};
|
|
1108
|
+
|
|
1109
|
+
/**
|
|
1110
|
+
* `loadOptions` with `transformRequest`, for the loaders that fetch with the basemap load options
|
|
1111
|
+
* themselves: raster-dem tiles, and raster tiles with `rejectRasterTile`.
|
|
1112
|
+
*/
|
|
1113
|
+
export function withTransformRequest(
|
|
1114
|
+
loadOptions: BasemapLoadOptions | undefined,
|
|
1115
|
+
transformRequest: BasemapTransformRequest | null | undefined
|
|
1116
|
+
): BasemapLoadOptions | undefined {
|
|
1117
|
+
if (!transformRequest) return loadOptions;
|
|
1118
|
+
let byOptions = transformedOptions.get(transformRequest);
|
|
1119
|
+
if (!byOptions) {
|
|
1120
|
+
byOptions = new WeakMap();
|
|
1121
|
+
transformedOptions.set(transformRequest, byOptions);
|
|
1122
|
+
}
|
|
1123
|
+
const key = loadOptions || emptyLoadOptions;
|
|
1124
|
+
let result = byOptions.get(key);
|
|
1125
|
+
if (!result) {
|
|
1126
|
+
result = {...loadOptions, transformRequest};
|
|
1127
|
+
byOptions.set(key, result);
|
|
1128
|
+
}
|
|
1129
|
+
return result;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
739
1132
|
/**
|
|
740
1133
|
* Creates the tileset of a `raster-dem` source: each tile is fetched and decoded once, and shared by
|
|
741
|
-
* every `hillshade` layer drawn from it. `BasemapLayer` creates and finalizes these itself. Direct
|
|
1134
|
+
* every `hillshade` and `color-relief` layer drawn from it. `BasemapLayer` creates and finalizes these itself. Direct
|
|
742
1135
|
* `getBasemapLayers` callers that call it on every render pass them in `tilesets`, keyed by source,
|
|
743
1136
|
* to keep the tiles across calls, and finalize them when done.
|
|
744
1137
|
*/
|
|
745
1138
|
export function createDemTileset(
|
|
746
1139
|
source: BasemapSource,
|
|
747
|
-
loadOptions?: BasemapLoadOptions
|
|
1140
|
+
loadOptions?: BasemapLoadOptions,
|
|
1141
|
+
projectedMaxStretch?: number
|
|
748
1142
|
): SharedTileset2D<DemTile | null> {
|
|
749
|
-
return createSharedDemTileset(source, loadOptions,
|
|
1143
|
+
return createSharedDemTileset(source, getTileLoadOptions(source, loadOptions), {
|
|
1144
|
+
...getTilePyramidProps(source),
|
|
1145
|
+
adapter: getBasemapTilesetAdapter(projectedMaxStretch, getSourceTileBounds(source))
|
|
1146
|
+
});
|
|
750
1147
|
}
|
|
751
1148
|
|
|
752
1149
|
function createRasterLayer({
|
|
@@ -755,15 +1152,27 @@ function createRasterLayer({
|
|
|
755
1152
|
source,
|
|
756
1153
|
zoom,
|
|
757
1154
|
mode,
|
|
758
|
-
|
|
1155
|
+
loadOptions,
|
|
1156
|
+
fetch,
|
|
1157
|
+
transformRequest,
|
|
1158
|
+
rejectRasterTile,
|
|
1159
|
+
onError,
|
|
1160
|
+
depthTested,
|
|
1161
|
+
projectedMaxStretch
|
|
759
1162
|
}: {
|
|
760
1163
|
idPrefix: string;
|
|
761
1164
|
layer: BasemapStyleLayer;
|
|
762
1165
|
source: BasemapSource;
|
|
763
1166
|
zoom: number;
|
|
764
1167
|
mode: BasemapMode;
|
|
1168
|
+
loadOptions?: BasemapLoadOptions;
|
|
1169
|
+
fetch?: LayerProps['fetch'];
|
|
1170
|
+
transformRequest?: BasemapTransformRequest | null;
|
|
1171
|
+
rejectRasterTile?: RejectRasterTile | null;
|
|
1172
|
+
onError?: BasemapLoadErrorHandler | null;
|
|
765
1173
|
/** Drawn after an extrusion, see `getTileParameters`. */
|
|
766
1174
|
depthTested?: boolean;
|
|
1175
|
+
projectedMaxStretch?: number;
|
|
767
1176
|
}) {
|
|
768
1177
|
const paint = getPaint(layer, zoom);
|
|
769
1178
|
const rasterColorAdjustments = getRasterColorAdjustments(paint);
|
|
@@ -774,11 +1183,36 @@ function createRasterLayer({
|
|
|
774
1183
|
const isNearest =
|
|
775
1184
|
getRasterPaintValue(paint, 'raster-resampling') === 'nearest' ||
|
|
776
1185
|
getRasterPaintValue(paint, 'resampling') === 'nearest';
|
|
1186
|
+
const tilePyramidProps = getTilePyramidProps(source);
|
|
1187
|
+
// The tiles of a PMTiles archive load with a `fetch` that reads them from the archive.
|
|
1188
|
+
const tileLoadOptions = getTileLoadOptions(source, withTransformRequest(loadOptions, transformRequest));
|
|
1189
|
+
|
|
1190
|
+
// MapLibre fades a raster tile in over `raster-fade-duration` once it loads.
|
|
1191
|
+
const fadeDuration = Math.max(0, Number(getRasterPaintValue(paint, 'raster-fade-duration')) || 0);
|
|
777
1192
|
|
|
778
|
-
|
|
1193
|
+
// Also selects tiles in a projected view.
|
|
1194
|
+
return new RasterFadeTileLayer({
|
|
779
1195
|
id: `${idPrefix}-${layer.id}`,
|
|
780
|
-
data: source
|
|
781
|
-
...
|
|
1196
|
+
data: getSourceTileTemplates(source),
|
|
1197
|
+
...(projectedMaxStretch === undefined ? {} : {maxStretch: projectedMaxStretch}),
|
|
1198
|
+
...tilePyramidProps,
|
|
1199
|
+
// Tiles outside the source's `bounds` are not requested.
|
|
1200
|
+
tileBounds: getSourceTileBounds(source),
|
|
1201
|
+
// Tiles use the basemap fetch and load options, and registered protocol handlers.
|
|
1202
|
+
fetch: getBasemapTileFetch(fetch || DEFAULT_LAYER_FETCH, 'image', transformRequest),
|
|
1203
|
+
...(tileLoadOptions ? {loadOptions: tileLoadOptions} : {}),
|
|
1204
|
+
// A tile without data is drawn from its nearest ancestor that has data.
|
|
1205
|
+
...(rejectRasterTile
|
|
1206
|
+
? {
|
|
1207
|
+
getTileData: getRasterTileLoader(source, {
|
|
1208
|
+
sourceId: layer.source || '',
|
|
1209
|
+
minZoom: tilePyramidProps.minZoom,
|
|
1210
|
+
rejectTile: rejectRasterTile,
|
|
1211
|
+
loadOptions: tileLoadOptions
|
|
1212
|
+
}).getTileData
|
|
1213
|
+
}
|
|
1214
|
+
: {}),
|
|
1215
|
+
updateTriggers: {getTileData: rejectRasterTile || null},
|
|
782
1216
|
tileSize: source.tileSize || 512,
|
|
783
1217
|
// deck.gl draws with `opacity ** (1 / 2.2)`. Undo that, so the alpha is `raster-opacity`, as
|
|
784
1218
|
// in MapLibre.
|
|
@@ -786,6 +1220,7 @@ function createRasterLayer({
|
|
|
786
1220
|
// The color adjustments and texture filter are passed down to each tile's bitmap layer.
|
|
787
1221
|
...(isColorAdjusted ? {extensions: [RASTER_COLOR_EXTENSION], rasterColorAdjustments} : {}),
|
|
788
1222
|
textureParameters: isNearest ? NEAREST_TEXTURE_PARAMETERS : null,
|
|
1223
|
+
rasterFadeDuration: fadeDuration,
|
|
789
1224
|
renderSubLayers: props => {
|
|
790
1225
|
const {west, south, east, north} = (props.tile?.bbox || {}) as {
|
|
791
1226
|
west: number;
|
|
@@ -798,11 +1233,15 @@ function createRasterLayer({
|
|
|
798
1233
|
const blendParameters = (props as {rasterColorBlendParameters?: object | null})
|
|
799
1234
|
.rasterColorBlendParameters;
|
|
800
1235
|
|
|
801
|
-
|
|
1236
|
+
// In a projected view, the image is drawn with a mesh that follows the projection.
|
|
1237
|
+
return new ProjectedBitmapLayer({
|
|
802
1238
|
...props,
|
|
803
1239
|
// A texture keeps the filter it was created with, so a filter change needs a new layer.
|
|
804
1240
|
id: isNearest ? `${props.id}-nearest` : props.id,
|
|
805
|
-
_imageCoordinateSystem:
|
|
1241
|
+
_imageCoordinateSystem: 'cartesian',
|
|
1242
|
+
...(fadeDuration > 0
|
|
1243
|
+
? {extensions: [...(props.extensions || []), RASTER_FADE_EXTENSION]}
|
|
1244
|
+
: {}),
|
|
806
1245
|
data: null,
|
|
807
1246
|
image: props.data,
|
|
808
1247
|
bounds: [west, south, east, north],
|
|
@@ -811,16 +1250,80 @@ function createRasterLayer({
|
|
|
811
1250
|
: getTileParameters(mode, depthTested)
|
|
812
1251
|
} as any);
|
|
813
1252
|
},
|
|
814
|
-
onTileError: error => {
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
sourceId: layer.source
|
|
1253
|
+
onTileError: (error, tile) => {
|
|
1254
|
+
reportTileError(onError, error, tile, {
|
|
1255
|
+
source,
|
|
1256
|
+
sourceId: layer.source,
|
|
1257
|
+
message: 'Raster tile failed to load',
|
|
1258
|
+
details: {layerId: layer.id, sourceId: layer.source}
|
|
818
1259
|
});
|
|
819
1260
|
},
|
|
820
1261
|
parameters: getTileParameters(mode, depthTested)
|
|
821
1262
|
});
|
|
822
1263
|
}
|
|
823
1264
|
|
|
1265
|
+
/**
|
|
1266
|
+
* A `raster` style layer over an `image` source: the source's image at its four corners, with the
|
|
1267
|
+
* raster paint properties of a raster tile layer. As in MapLibre, the image draws at every zoom.
|
|
1268
|
+
*/
|
|
1269
|
+
function createImageLayer({
|
|
1270
|
+
idPrefix,
|
|
1271
|
+
layer,
|
|
1272
|
+
source,
|
|
1273
|
+
zoom,
|
|
1274
|
+
mode,
|
|
1275
|
+
loadOptions,
|
|
1276
|
+
fetch,
|
|
1277
|
+
depthTested,
|
|
1278
|
+
onError
|
|
1279
|
+
}: {
|
|
1280
|
+
idPrefix: string;
|
|
1281
|
+
layer: BasemapStyleLayer;
|
|
1282
|
+
source: BasemapSource;
|
|
1283
|
+
onError?: BasemapLoadErrorHandler | null;
|
|
1284
|
+
zoom: number;
|
|
1285
|
+
mode: BasemapMode;
|
|
1286
|
+
loadOptions?: BasemapLoadOptions;
|
|
1287
|
+
fetch?: LayerProps['fetch'];
|
|
1288
|
+
/** Drawn after an extrusion, see `getTileParameters`. */
|
|
1289
|
+
depthTested?: boolean;
|
|
1290
|
+
}) {
|
|
1291
|
+
const paint = getPaint(layer, zoom);
|
|
1292
|
+
const rasterColorAdjustments = getRasterColorAdjustments(paint);
|
|
1293
|
+
const isColorAdjusted = hasRasterColorAdjustments(rasterColorAdjustments);
|
|
1294
|
+
const isNearest =
|
|
1295
|
+
getRasterPaintValue(paint, 'raster-resampling') === 'nearest' ||
|
|
1296
|
+
getRasterPaintValue(paint, 'resampling') === 'nearest';
|
|
1297
|
+
const corners = getImageSourceCorners(source) as ImageSourceCorners;
|
|
1298
|
+
return new ImageSourceLayer({
|
|
1299
|
+
id: `${idPrefix}-${layer.id}`,
|
|
1300
|
+
image: source.url as string,
|
|
1301
|
+
corners,
|
|
1302
|
+
...(fetch ? {fetch} : {}),
|
|
1303
|
+
...(loadOptions ? {loadOptions} : {}),
|
|
1304
|
+
// As for raster tiles: deck.gl draws with `opacity ** (1 / 2.2)`.
|
|
1305
|
+
opacity: getRasterPaintValue(paint, 'raster-opacity') ** 2.2,
|
|
1306
|
+
...(isColorAdjusted ? {extensions: [RASTER_COLOR_EXTENSION], rasterColorAdjustments} : {}),
|
|
1307
|
+
textureParameters: isNearest ? NEAREST_TEXTURE_PARAMETERS : null,
|
|
1308
|
+
onError: (error: Error) => {
|
|
1309
|
+
if (onError) {
|
|
1310
|
+
onError(
|
|
1311
|
+
getBasemapLoadError('image', error, {sourceId: layer.source, url: source.url as string})
|
|
1312
|
+
);
|
|
1313
|
+
} else {
|
|
1314
|
+
logBasemapRuntimeError('Image failed to load', error, {
|
|
1315
|
+
layerId: layer.id,
|
|
1316
|
+
sourceId: layer.source
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
},
|
|
1320
|
+
parameters:
|
|
1321
|
+
mode === 'globe' && hasFlippedWinding(corners)
|
|
1322
|
+
? {...getTileParameters(mode, depthTested), cullMode: 'front'}
|
|
1323
|
+
: getTileParameters(mode, depthTested)
|
|
1324
|
+
} as any);
|
|
1325
|
+
}
|
|
1326
|
+
|
|
824
1327
|
/**
|
|
825
1328
|
* A `hillshade` style layer over a `raster-dem` source. Its tiles are decoded on the main thread,
|
|
826
1329
|
* once for all of the source's hillshade layers, which share `tileset` (see `HillshadeTileLayer`).
|
|
@@ -834,10 +1337,12 @@ function createHillshadeLayer({
|
|
|
834
1337
|
source,
|
|
835
1338
|
zoom,
|
|
836
1339
|
mode,
|
|
837
|
-
depthTested
|
|
1340
|
+
depthTested,
|
|
1341
|
+
onError
|
|
838
1342
|
}: {
|
|
839
1343
|
idPrefix: string;
|
|
840
1344
|
layer: BasemapStyleLayer;
|
|
1345
|
+
onError?: BasemapLoadErrorHandler | null;
|
|
841
1346
|
/** The source's decoded tiles (see `createDemTileset`). */
|
|
842
1347
|
tileset: SharedTileset2D;
|
|
843
1348
|
/** Set when the layer shares a tileset that no `BasemapLayer` owns. */
|
|
@@ -865,10 +1370,74 @@ function createHillshadeLayer({
|
|
|
865
1370
|
textureParameters: {minFilter: filter, magFilter: filter, mipmapFilter: 'none'},
|
|
866
1371
|
parameters: getTileParameters(mode, depthTested)
|
|
867
1372
|
},
|
|
868
|
-
onTileError: error => {
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
sourceId: layer.source
|
|
1373
|
+
onTileError: (error, tile) => {
|
|
1374
|
+
reportTileError(onError, error, tile, {
|
|
1375
|
+
source,
|
|
1376
|
+
sourceId: layer.source,
|
|
1377
|
+
message: 'DEM tile failed to load',
|
|
1378
|
+
details: {layerId: layer.id, sourceId: layer.source}
|
|
1379
|
+
});
|
|
1380
|
+
},
|
|
1381
|
+
parameters: getTileParameters(mode, depthTested)
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
/**
|
|
1386
|
+
* A `color-relief` style layer over a `raster-dem` source, which shares the source's decoded tiles
|
|
1387
|
+
* with its other layers (see `createHillshadeLayer`). A ramp that is not an `interpolate`
|
|
1388
|
+
* expression is transparent, as in MapLibre, and draws nothing.
|
|
1389
|
+
*/
|
|
1390
|
+
function createColorReliefLayer({
|
|
1391
|
+
idPrefix,
|
|
1392
|
+
layer,
|
|
1393
|
+
tileset,
|
|
1394
|
+
demTilesetOwner,
|
|
1395
|
+
source,
|
|
1396
|
+
zoom,
|
|
1397
|
+
mode,
|
|
1398
|
+
depthTested,
|
|
1399
|
+
onError
|
|
1400
|
+
}: {
|
|
1401
|
+
idPrefix: string;
|
|
1402
|
+
layer: BasemapStyleLayer;
|
|
1403
|
+
/** The source's decoded tiles (see `createDemTileset`). */
|
|
1404
|
+
tileset: SharedTileset2D;
|
|
1405
|
+
/** Set when the layer shares a tileset that no `BasemapLayer` owns. */
|
|
1406
|
+
demTilesetOwner?: DemTilesetOwner;
|
|
1407
|
+
source: BasemapSource;
|
|
1408
|
+
onError?: BasemapLoadErrorHandler | null;
|
|
1409
|
+
zoom: number;
|
|
1410
|
+
mode: BasemapMode;
|
|
1411
|
+
/** Drawn after an extrusion, see `getTileParameters`. */
|
|
1412
|
+
depthTested?: boolean;
|
|
1413
|
+
}) {
|
|
1414
|
+
const paint = getPaint(layer, zoom);
|
|
1415
|
+
const opacity = (paint['color-relief-opacity'] as number | undefined) ?? 1;
|
|
1416
|
+
const colorReliefColor = layer.paint?.['color-relief-color'];
|
|
1417
|
+
const isNearest = getRasterPaintValue(paint, 'resampling') === 'nearest';
|
|
1418
|
+
const filter = isNearest ? 'nearest' : 'linear';
|
|
1419
|
+
|
|
1420
|
+
return new ColorReliefTileLayer({
|
|
1421
|
+
id: `${idPrefix}-${layer.id}`,
|
|
1422
|
+
data: tileset,
|
|
1423
|
+
demTilesetOwner,
|
|
1424
|
+
...getTilePyramidProps(source),
|
|
1425
|
+
tileSize: source.tileSize || 512,
|
|
1426
|
+
visible: opacity > 0 && isColorRampVisible(createColorRamp(colorReliefColor, Infinity)),
|
|
1427
|
+
colorReliefColor,
|
|
1428
|
+
colorReliefOpacity: opacity,
|
|
1429
|
+
colorReliefUnpack: getDemUnpackVector(source),
|
|
1430
|
+
colorReliefSubLayerProps: {
|
|
1431
|
+
// MapLibre samples the elevations without mipmaps.
|
|
1432
|
+
textureParameters: {minFilter: filter, magFilter: filter, mipmapFilter: 'none'},
|
|
1433
|
+
parameters: getTileParameters(mode, depthTested)
|
|
1434
|
+
},
|
|
1435
|
+
onTileError: (error, tile) => {
|
|
1436
|
+
reportTileError(onError, error, tile, {
|
|
1437
|
+
source,
|
|
1438
|
+
sourceId: layer.source,
|
|
1439
|
+
message: 'DEM tile failed to load',
|
|
1440
|
+
details: {layerId: layer.id, sourceId: layer.source}
|
|
872
1441
|
});
|
|
873
1442
|
},
|
|
874
1443
|
parameters: getTileParameters(mode, depthTested)
|
|
@@ -895,6 +1464,18 @@ const TILE_LABEL_FEATURES = 'tileLabelFeatures';
|
|
|
895
1464
|
/** The features of a symbol style layer without any in a tile. */
|
|
896
1465
|
const NO_FEATURES: any[] = [];
|
|
897
1466
|
|
|
1467
|
+
/** The prop that hands a tile's `renderSubLayers` the map to record its heatmap points in. */
|
|
1468
|
+
const TILE_HEATMAP_POINTS = 'tileHeatmapPoints';
|
|
1469
|
+
|
|
1470
|
+
/**
|
|
1471
|
+
* Builds the heatmap layers of a run from the points of its drawn tiles, by style layer index;
|
|
1472
|
+
* `getSubLayerProps` gives a heatmap layer the tile layer's props.
|
|
1473
|
+
*/
|
|
1474
|
+
type RenderHeatmapLayers = (
|
|
1475
|
+
pointsByStyleLayer: Map<number, HeatmapPoint[]>,
|
|
1476
|
+
getSubLayerProps: (id: string) => Record<string, any>
|
|
1477
|
+
) => Layer[];
|
|
1478
|
+
|
|
898
1479
|
/**
|
|
899
1480
|
* Builds the label layers of a run from the label features of its drawn tiles, by style layer
|
|
900
1481
|
* index; `getSubLayerProps` gives a label layer the tile layer's props.
|
|
@@ -916,6 +1497,20 @@ type SharedTile = {
|
|
|
916
1497
|
content?: unknown;
|
|
917
1498
|
};
|
|
918
1499
|
|
|
1500
|
+
/**
|
|
1501
|
+
* The id of the style layer a tile or label sublayer drew its feature `index` with: the sublayer's
|
|
1502
|
+
* one style layer, or, in a sublayer of several, the style layer of that feature.
|
|
1503
|
+
*/
|
|
1504
|
+
function getPickedStyleLayerId(
|
|
1505
|
+
props: Record<string, any> | undefined,
|
|
1506
|
+
index: number
|
|
1507
|
+
): string | undefined {
|
|
1508
|
+
const ids: string[] | undefined =
|
|
1509
|
+
props?.[STYLE_LAYER_IDS] ?? (props?.styleLayer ? [props.styleLayer.id] : undefined);
|
|
1510
|
+
const parts: ArrayLike<number> | null | undefined = props?.[STYLE_LAYER_PARTS];
|
|
1511
|
+
return ids?.[parts ? parts[index] : 0];
|
|
1512
|
+
}
|
|
1513
|
+
|
|
919
1514
|
class StyledMVTLayer extends SharedMVTLayer {
|
|
920
1515
|
declare state: SharedMVTLayer['state'] & {
|
|
921
1516
|
sourceTilesetOwner?: SourceTilesetOwner;
|
|
@@ -943,6 +1538,16 @@ class StyledMVTLayer extends SharedMVTLayer {
|
|
|
943
1538
|
/** The style layers `labelStyleLayers` indexes, and the tileset of their tiles. */
|
|
944
1539
|
labelStyle?: unknown;
|
|
945
1540
|
labelTileset?: unknown;
|
|
1541
|
+
/**
|
|
1542
|
+
* The points of each heatmap style layer in a tile, by tile id and the style layer's index in
|
|
1543
|
+
* its run, as `renderSubLayers` last recorded them (see `renderHeatmapLayers`).
|
|
1544
|
+
*/
|
|
1545
|
+
tileHeatmapPoints?: Map<string, Map<number, HeatmapPoint[]>>;
|
|
1546
|
+
/** The heatmap layers last rendered, with their props and points, by view. */
|
|
1547
|
+
heatmapLayers?: Map<
|
|
1548
|
+
string,
|
|
1549
|
+
{props: unknown; key: unknown[]; points: Map<number, HeatmapPoint[]>; layers: Layer[]}
|
|
1550
|
+
>;
|
|
946
1551
|
/** The label layers last rendered, and the props and tiles they were rendered for, by view. */
|
|
947
1552
|
labelLayers?: Map<
|
|
948
1553
|
string,
|
|
@@ -961,13 +1566,19 @@ class StyledMVTLayer extends SharedMVTLayer {
|
|
|
961
1566
|
owner?.consumers.add(this.state);
|
|
962
1567
|
this.state.sourceTilesetOwner = owner;
|
|
963
1568
|
}
|
|
964
|
-
const {geographic, tileset} = this.state;
|
|
1569
|
+
const {geographic, projectionMode, tileset} = this.state;
|
|
965
1570
|
super.updateState(params);
|
|
966
|
-
// A new tileset, or a switch between a map and a
|
|
967
|
-
|
|
1571
|
+
// A new tileset, or a switch between a map, a globe and a projected view, makes every kept
|
|
1572
|
+
// sublayer obsolete.
|
|
1573
|
+
if (
|
|
1574
|
+
this.state.geographic !== geographic ||
|
|
1575
|
+
this.state.projectionMode !== projectionMode ||
|
|
1576
|
+
this.state.tileset !== tileset
|
|
1577
|
+
) {
|
|
968
1578
|
this.state.keptTileLayers?.clear();
|
|
969
1579
|
this.state.staleTiles?.clear();
|
|
970
1580
|
this.state.tileLabelFeatures?.clear();
|
|
1581
|
+
this.state.tileHeatmapPoints?.clear();
|
|
971
1582
|
}
|
|
972
1583
|
}
|
|
973
1584
|
|
|
@@ -1022,7 +1633,71 @@ class StyledMVTLayer extends SharedMVTLayer {
|
|
|
1022
1633
|
if (!Array.isArray(layers)) {
|
|
1023
1634
|
return layers;
|
|
1024
1635
|
}
|
|
1025
|
-
return [
|
|
1636
|
+
return [
|
|
1637
|
+
...sortTileSubLayers(layers as (Layer[] | null)[]),
|
|
1638
|
+
...this.renderHeatmapLayers(tiles),
|
|
1639
|
+
...this.renderLabelLayers(tiles)
|
|
1640
|
+
];
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
/**
|
|
1644
|
+
* The heatmaps of all drawn tiles, one layer per heatmap style layer and view: MapLibre GL JS
|
|
1645
|
+
* sums the kernels of all tiles into one density before it colors it. A heatmap style layer has
|
|
1646
|
+
* a run of its own (see `getStyleLayerRuns`), so it draws in style order. Where a drawn tile's
|
|
1647
|
+
* ancestor is drawn too, as while the tile's siblings load, only the ancestor's points are
|
|
1648
|
+
* drawn, as in MapLibre, so that no point adds to the density twice.
|
|
1649
|
+
*/
|
|
1650
|
+
renderHeatmapLayers(tiles: SharedTile[]): Layer[] {
|
|
1651
|
+
const render = (this.props as {renderHeatmapLayers?: RenderHeatmapLayers}).renderHeatmapLayers;
|
|
1652
|
+
if (!render) {
|
|
1653
|
+
return [];
|
|
1654
|
+
}
|
|
1655
|
+
const views = this.state.tilesetViews;
|
|
1656
|
+
const entries: [string | null, (tile: SharedTile) => boolean][] =
|
|
1657
|
+
!views || views.size <= 1
|
|
1658
|
+
? [[null, tile => this.isTileShown(tile)]]
|
|
1659
|
+
: [...views].map(([viewKey, view]) => [viewKey, tile => view.isTileVisible(tile as any)]);
|
|
1660
|
+
this.state.heatmapLayers ||= new Map();
|
|
1661
|
+
const layers: Layer[] = [];
|
|
1662
|
+
for (const [viewKey, isShown] of entries) {
|
|
1663
|
+
const drawn = tiles.filter(
|
|
1664
|
+
tile => tile.content && isShown(tile) && this.state.tileHeatmapPoints?.has(tile.id)
|
|
1665
|
+
);
|
|
1666
|
+
const key: unknown[] = [];
|
|
1667
|
+
const pointsByStyleLayer = new Map<number, HeatmapPoint[][]>();
|
|
1668
|
+
for (const tile of getTilesWithoutDrawnAncestor(drawn)) {
|
|
1669
|
+
for (const [styleLayerIndex, points] of this.state.tileHeatmapPoints!.get(tile.id)!) {
|
|
1670
|
+
key.push(styleLayerIndex, points);
|
|
1671
|
+
let list = pointsByStyleLayer.get(styleLayerIndex);
|
|
1672
|
+
if (!list) {
|
|
1673
|
+
list = [];
|
|
1674
|
+
pointsByStyleLayer.set(styleLayerIndex, list);
|
|
1675
|
+
}
|
|
1676
|
+
list.push(points);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
// The same layers while the points and props do not change: new instances would be compared
|
|
1680
|
+
// and updated at every frame. New props keep the points, so the layers keep their attributes.
|
|
1681
|
+
const cacheKey = viewKey ?? '';
|
|
1682
|
+
const last = this.state.heatmapLayers.get(cacheKey);
|
|
1683
|
+
const isSamePoints = last && isSameList(last.key, key);
|
|
1684
|
+
if (isSamePoints && last.props === this.props) {
|
|
1685
|
+
layers.push(...last.layers);
|
|
1686
|
+
continue;
|
|
1687
|
+
}
|
|
1688
|
+
const points = isSamePoints
|
|
1689
|
+
? last.points
|
|
1690
|
+
: new Map([...pointsByStyleLayer].map(([index, lists]) => [index, lists.flat()]));
|
|
1691
|
+
const viewLayers = render(points, id =>
|
|
1692
|
+
this.getSubLayerProps({id: viewKey === null ? id : `${id}-view-${viewKey}`})
|
|
1693
|
+
);
|
|
1694
|
+
for (const layer of viewLayers) {
|
|
1695
|
+
labelLayerViews.set(layer, viewKey);
|
|
1696
|
+
}
|
|
1697
|
+
this.state.heatmapLayers.set(cacheKey, {props: this.props, key, points, layers: viewLayers});
|
|
1698
|
+
layers.push(...viewLayers);
|
|
1699
|
+
}
|
|
1700
|
+
return layers;
|
|
1026
1701
|
}
|
|
1027
1702
|
|
|
1028
1703
|
/**
|
|
@@ -1059,13 +1734,15 @@ class StyledMVTLayer extends SharedMVTLayer {
|
|
|
1059
1734
|
const previous = this.state.labelTiles.get(cacheKey) || new Map();
|
|
1060
1735
|
const next = new Map<number, {key: unknown[]; tiles: LabelTile[]}>();
|
|
1061
1736
|
const tileSize = (this.props as {tileSize?: number}).tileSize ?? 512;
|
|
1737
|
+
const {maxZoom} = this.props;
|
|
1738
|
+
const tileMaxZoom = maxZoom != null && Number.isFinite(maxZoom) ? maxZoom : null;
|
|
1062
1739
|
for (const tile of tiles) {
|
|
1063
1740
|
const byStyleLayer =
|
|
1064
1741
|
tile.content && isShown(tile) ? this.state.tileLabelFeatures?.get(tile.id) : null;
|
|
1065
1742
|
for (const [styleLayerIndex, features] of byStyleLayer || []) {
|
|
1066
1743
|
let entry = next.get(styleLayerIndex);
|
|
1067
1744
|
if (!entry) {
|
|
1068
|
-
entry = {key: [], tiles: []};
|
|
1745
|
+
entry = {key: [tileMaxZoom], tiles: []};
|
|
1069
1746
|
next.set(styleLayerIndex, entry);
|
|
1070
1747
|
}
|
|
1071
1748
|
entry.key.push(tile, features);
|
|
@@ -1074,6 +1751,7 @@ class StyledMVTLayer extends SharedMVTLayer {
|
|
|
1074
1751
|
features,
|
|
1075
1752
|
tileBoundingBox: (tile.bbox as LabelTile['tileBoundingBox']) ?? null,
|
|
1076
1753
|
tileZoom: tile.index?.z ?? null,
|
|
1754
|
+
tileMaxZoom,
|
|
1077
1755
|
tileSize,
|
|
1078
1756
|
tile
|
|
1079
1757
|
});
|
|
@@ -1189,6 +1867,13 @@ class StyledMVTLayer extends SharedMVTLayer {
|
|
|
1189
1867
|
filterSubLayer(context: any): boolean {
|
|
1190
1868
|
const {layer} = context;
|
|
1191
1869
|
if (layer.props.tile) {
|
|
1870
|
+
if (isProjectedViewport(context.viewport)) {
|
|
1871
|
+
// `SharedTile2DLayer` culls tiles outside the longitude/latitude box of the screen
|
|
1872
|
+
// corners. In a projected view a corner can lie outside the projection, and the tile
|
|
1873
|
+
// selection has tested each tile against the screen already.
|
|
1874
|
+
const view = this.state.tilesetViews?.get(context.viewport?.id || 'default');
|
|
1875
|
+
return Boolean(view?.isTileVisible(layer.props.tile));
|
|
1876
|
+
}
|
|
1192
1877
|
return super.filterSubLayer(context);
|
|
1193
1878
|
}
|
|
1194
1879
|
const viewKey = labelLayerViews.get(layer);
|
|
@@ -1201,18 +1886,35 @@ class StyledMVTLayer extends SharedMVTLayer {
|
|
|
1201
1886
|
*/
|
|
1202
1887
|
getPickingInfo(params: any): any {
|
|
1203
1888
|
const {sourceLayer} = params;
|
|
1889
|
+
// The index of the picked feature in the sublayer's data.
|
|
1890
|
+
const index: number = params.info.index;
|
|
1891
|
+
let info: any;
|
|
1204
1892
|
if (sourceLayer && !sourceLayer.props.tile) {
|
|
1205
|
-
const coordinateSystem =
|
|
1206
|
-
?
|
|
1207
|
-
:
|
|
1208
|
-
|
|
1893
|
+
const coordinateSystem = isGeographicViewport(this.context.viewport)
|
|
1894
|
+
? 'lnglat'
|
|
1895
|
+
: 'cartesian';
|
|
1896
|
+
info = super.getPickingInfo({
|
|
1209
1897
|
...params,
|
|
1210
1898
|
sourceLayer: {props: {tile: params.info.tile, coordinateSystem}}
|
|
1211
1899
|
});
|
|
1212
1900
|
info.sourceTileSubLayer = sourceLayer;
|
|
1213
|
-
|
|
1901
|
+
} else {
|
|
1902
|
+
info = super.getPickingInfo(params);
|
|
1214
1903
|
}
|
|
1215
|
-
|
|
1904
|
+
const styleLayerId = getPickedStyleLayerId(sourceLayer?.props, index);
|
|
1905
|
+
if (info.object && styleLayerId !== undefined) {
|
|
1906
|
+
const {styleSourceId, styleSource} = this.props as {
|
|
1907
|
+
styleSourceId?: string;
|
|
1908
|
+
styleSource?: BasemapSource;
|
|
1909
|
+
};
|
|
1910
|
+
info.basemapFeature = getPickedFeature(
|
|
1911
|
+
info.object,
|
|
1912
|
+
styleSourceId ?? '',
|
|
1913
|
+
styleSource,
|
|
1914
|
+
styleLayerId
|
|
1915
|
+
);
|
|
1916
|
+
}
|
|
1917
|
+
return info;
|
|
1216
1918
|
}
|
|
1217
1919
|
|
|
1218
1920
|
/**
|
|
@@ -1227,22 +1929,58 @@ class StyledMVTLayer extends SharedMVTLayer {
|
|
|
1227
1929
|
this.state.zoomPaintContext ||= new ZoomPaintContext();
|
|
1228
1930
|
const {zoomPaintContext} = this.state;
|
|
1229
1931
|
zoomPaintContext.setStyle((this.props as {paintStyle?: unknown}).paintStyle);
|
|
1230
|
-
zoomPaintContext.zoom = getZoomBucket((this.props as {styleZoom?: number}).styleZoom ?? 0);
|
|
1231
1932
|
// The tile's label features, recorded as `renderSubLayers` filters them.
|
|
1232
1933
|
const labelFeatures = new Map<number, any[]>();
|
|
1233
1934
|
this.state.tileLabelFeatures ||= new Map();
|
|
1234
1935
|
this.state.tileLabelFeatures.set(props.tile.id, labelFeatures);
|
|
1235
1936
|
(props as any)[TILE_LABEL_FEATURES] = labelFeatures;
|
|
1937
|
+
// The tile's heatmap points, recorded as `renderSubLayers` filters them.
|
|
1938
|
+
const heatmapPoints = new Map<number, HeatmapPoint[]>();
|
|
1939
|
+
this.state.tileHeatmapPoints ||= new Map();
|
|
1940
|
+
this.state.tileHeatmapPoints.set(props.tile.id, heatmapPoints);
|
|
1941
|
+
(props as any)[TILE_HEATMAP_POINTS] = heatmapPoints;
|
|
1236
1942
|
const previous = this.state.keptTileLayers?.get(props.tile.id);
|
|
1237
|
-
|
|
1238
|
-
return super.renderSubLayers({
|
|
1943
|
+
const styledProps = {
|
|
1239
1944
|
...props,
|
|
1240
1945
|
[ZOOM_PAINT_CONTEXT]: this.context.device?.type === 'webgpu' ? null : zoomPaintContext,
|
|
1946
|
+
[WEBGPU_DEVICE]: this.context.device?.type === 'webgpu',
|
|
1241
1947
|
[PREVIOUS_TILE_LAYERS]: previous
|
|
1242
1948
|
? new Map(previous.map((layer: Layer) => [layer.id, layer]))
|
|
1243
1949
|
: undefined,
|
|
1244
1950
|
[AUTO_HIGHLIGHT]: Boolean(this.props.autoHighlight)
|
|
1245
|
-
} as typeof props
|
|
1951
|
+
} as typeof props;
|
|
1952
|
+
if (isProjectedViewport(this.context.viewport)) {
|
|
1953
|
+
return this.renderProjectedSubLayers(styledProps);
|
|
1954
|
+
}
|
|
1955
|
+
// `SharedMVTLayer` turns `autoHighlight` off for the tile sublayers, which it highlights itself.
|
|
1956
|
+
return super.renderSubLayers(styledProps);
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
/**
|
|
1960
|
+
* A tile's sublayers in a projected view. `SharedMVTLayer` draws tile-local geometry, scaled to
|
|
1961
|
+
* the tile's square in Web Mercator space, except on a globe. In a view of another projection
|
|
1962
|
+
* a tile is not a square, so the geometry is drawn from longitude/latitude positions, as on a
|
|
1963
|
+
* globe: deck.gl converts each vertex to the view's coordinate reference system.
|
|
1964
|
+
*/
|
|
1965
|
+
private renderProjectedSubLayers(props: Parameters<SharedMVTLayer['renderSubLayers']>[0]) {
|
|
1966
|
+
if (!props.data) {
|
|
1967
|
+
return [];
|
|
1968
|
+
}
|
|
1969
|
+
return (
|
|
1970
|
+
SharedTile2DLayer.prototype.renderSubLayers.call(this, {
|
|
1971
|
+
...props,
|
|
1972
|
+
autoHighlight: false,
|
|
1973
|
+
data: getTileFeaturesInLngLat(props.data, props.tile.index),
|
|
1974
|
+
modelMatrix: new Matrix4(),
|
|
1975
|
+
coordinateOrigin: [0, 0, 0],
|
|
1976
|
+
coordinateSystem: 'lnglat'
|
|
1977
|
+
} as typeof props) ?? []
|
|
1978
|
+
);
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
/** Tile traversal that also selects tiles in a projected view (see `basemapTilesetAdapter`). */
|
|
1982
|
+
_getTilesetOptions(): ReturnType<SharedMVTLayer['_getTilesetOptions']> {
|
|
1983
|
+
return {...super._getTilesetOptions(), adapter: getBasemapTilesetAdapter()};
|
|
1246
1984
|
}
|
|
1247
1985
|
|
|
1248
1986
|
_onTileLoad(tile: any): void {
|
|
@@ -1285,6 +2023,7 @@ class StyledMVTLayer extends SharedMVTLayer {
|
|
|
1285
2023
|
this.state.keptTileLayers?.delete(tile.id);
|
|
1286
2024
|
this.state.staleTiles?.delete(tile.id);
|
|
1287
2025
|
this.state.tileLabelFeatures?.delete(tile.id);
|
|
2026
|
+
this.state.tileHeatmapPoints?.delete(tile.id);
|
|
1288
2027
|
}
|
|
1289
2028
|
|
|
1290
2029
|
/** Releases the shared tileset and the textures of `ZoomPaintExtension`. */
|
|
@@ -1307,7 +2046,8 @@ class StyledMVTLayer extends SharedMVTLayer {
|
|
|
1307
2046
|
static defaultProps = {
|
|
1308
2047
|
...SharedMVTLayer.defaultProps,
|
|
1309
2048
|
// A new function at each update, as `renderSubLayers`: compared, it would regenerate every tile.
|
|
1310
|
-
renderLabelLayers: {type: 'function', optional: true, value: null, compare: false}
|
|
2049
|
+
renderLabelLayers: {type: 'function', optional: true, value: null, compare: false},
|
|
2050
|
+
renderHeatmapLayers: {type: 'function', optional: true, value: null, compare: false}
|
|
1311
2051
|
} as any;
|
|
1312
2052
|
}
|
|
1313
2053
|
|
|
@@ -1317,7 +2057,11 @@ class StyledMVTLayer extends SharedMVTLayer {
|
|
|
1317
2057
|
* `drawsLineStrings: false` leaves out line strings, which a fill without an outline would draw
|
|
1318
2058
|
* zero pixels wide. Every sublayer left out would otherwise be updated and drawn at every frame.
|
|
1319
2059
|
*/
|
|
1320
|
-
class StyledGeoJsonLayer extends GeoJsonLayer<any,
|
|
2060
|
+
class StyledGeoJsonLayer extends GeoJsonLayer<any, ZoomPaintExtensionProps & {
|
|
2061
|
+
drawsLineStrings?: boolean;
|
|
2062
|
+
/** Whether to check the paint at draw and pick time before rendering retained geometry. */
|
|
2063
|
+
deferredZoomPaint?: boolean;
|
|
2064
|
+
}> {
|
|
1321
2065
|
static layerName = 'StyledGeoJsonLayer';
|
|
1322
2066
|
static defaultProps = {...GeoJsonLayer.defaultProps, drawsLineStrings: true};
|
|
1323
2067
|
|
|
@@ -1341,6 +2085,21 @@ class StyledGeoJsonLayer extends GeoJsonLayer<any, {drawsLineStrings?: boolean}>
|
|
|
1341
2085
|
return layer;
|
|
1342
2086
|
}
|
|
1343
2087
|
|
|
2088
|
+
/** Keeps the geometry resident while its layer-constant paint is invisible. */
|
|
2089
|
+
filterSubLayer(context: Parameters<GeoJsonLayer['filterSubLayer']>[0]): boolean {
|
|
2090
|
+
const {deferredZoomPaint, zoomPaint, zoomPaintGeneration, zoomPaintBucket, filled, stroked} = this.props;
|
|
2091
|
+
return (
|
|
2092
|
+
(!deferredZoomPaint ||
|
|
2093
|
+
Boolean(zoomPaint?.isVisible(
|
|
2094
|
+
getZoomPaintZoom(getStyleZoom(context.viewport), zoomPaintGeneration?.zoom),
|
|
2095
|
+
zoomPaintBucket ?? undefined,
|
|
2096
|
+
filled,
|
|
2097
|
+
stroked
|
|
2098
|
+
))) &&
|
|
2099
|
+
super.filterSubLayer(context)
|
|
2100
|
+
);
|
|
2101
|
+
}
|
|
2102
|
+
|
|
1344
2103
|
protected shouldRenderSubLayer(subLayerId: string, data: any): boolean {
|
|
1345
2104
|
if (
|
|
1346
2105
|
subLayerId.startsWith('points-') ||
|
|
@@ -1433,14 +2192,27 @@ export function isSameProps(
|
|
|
1433
2192
|
* rendered, which deck.gl then neither diffs nor updates; a new one would be created, cloned by
|
|
1434
2193
|
* `TileLayer`, matched and diffed, only to change nothing.
|
|
1435
2194
|
*/
|
|
1436
|
-
function getTileGeoJsonLayer(
|
|
2195
|
+
function getTileGeoJsonLayer(
|
|
2196
|
+
tileProps: any,
|
|
2197
|
+
props: Record<string, any>,
|
|
2198
|
+
zoomPaintGenerationZoom?: number
|
|
2199
|
+
): StyledGeoJsonLayer {
|
|
1437
2200
|
const previous = (tileProps[PREVIOUS_TILE_LAYERS] as Map<string, any> | undefined)?.get(props.id);
|
|
1438
2201
|
const inputs = previous && tileLayerInputs.get(previous);
|
|
1439
2202
|
if (inputs && isSameProps(props, inputs)) {
|
|
2203
|
+
const generation = previous.props.zoomPaintGeneration;
|
|
2204
|
+
if (generation && zoomPaintGenerationZoom !== undefined) {
|
|
2205
|
+
// The drawing layers share this value, so reusing them still updates their fallback zoom.
|
|
2206
|
+
generation.zoom = zoomPaintGenerationZoom;
|
|
2207
|
+
}
|
|
1440
2208
|
keptTileLayers.add(previous);
|
|
1441
2209
|
return previous;
|
|
1442
2210
|
}
|
|
1443
|
-
const layer = new StyledGeoJsonLayer(
|
|
2211
|
+
const layer = new StyledGeoJsonLayer(
|
|
2212
|
+
zoomPaintGenerationZoom === undefined
|
|
2213
|
+
? props
|
|
2214
|
+
: {...props, zoomPaintGeneration: {zoom: zoomPaintGenerationZoom}}
|
|
2215
|
+
);
|
|
1444
2216
|
tileLayerInputs.set(layer, props);
|
|
1445
2217
|
return layer;
|
|
1446
2218
|
}
|
|
@@ -1466,7 +2238,10 @@ function createStyledVectorSubLayer({
|
|
|
1466
2238
|
fontFamily,
|
|
1467
2239
|
glyphs,
|
|
1468
2240
|
labelPlacement,
|
|
1469
|
-
light
|
|
2241
|
+
light,
|
|
2242
|
+
featureState,
|
|
2243
|
+
lineMetrics,
|
|
2244
|
+
styleProps
|
|
1470
2245
|
}: {
|
|
1471
2246
|
idPrefix: string;
|
|
1472
2247
|
sourceId: string;
|
|
@@ -1488,6 +2263,12 @@ function createStyledVectorSubLayer({
|
|
|
1488
2263
|
labelPlacement?: LabelPlacement | null;
|
|
1489
2264
|
/** The style's `light`, which shades `fill-extrusion` layers. */
|
|
1490
2265
|
light?: FillExtrusionLight;
|
|
2266
|
+
/** The feature states the style layer's paint reads, if it reads any. */
|
|
2267
|
+
featureState?: FeatureStateLookup;
|
|
2268
|
+
/** Whether the source is a GeoJSON source with `lineMetrics`, which `line-gradient` needs. */
|
|
2269
|
+
lineMetrics?: boolean;
|
|
2270
|
+
/** Extra props that will be applied to the created sublayer. */
|
|
2271
|
+
styleProps?: StyleLayerSubLayerProps;
|
|
1491
2272
|
}) {
|
|
1492
2273
|
if (features.length === 0) {
|
|
1493
2274
|
return null;
|
|
@@ -1515,18 +2296,24 @@ function createStyledVectorSubLayer({
|
|
|
1515
2296
|
|
|
1516
2297
|
if (styleLayer.type === 'circle') {
|
|
1517
2298
|
return createCircleSubLayer({
|
|
1518
|
-
baseProps: getSubLayerBaseProps(props),
|
|
2299
|
+
baseProps: {...getSubLayerBaseProps(props), [STYLE_LAYER_IDS]: [styleLayer.id]},
|
|
1519
2300
|
id: getStyleSubLayerId(props.id, styleLayer.id),
|
|
1520
2301
|
styleLayer,
|
|
1521
2302
|
features,
|
|
1522
2303
|
zoom,
|
|
2304
|
+
featureState,
|
|
1523
2305
|
globe: mode === 'globe',
|
|
2306
|
+
webgpu: Boolean(props[WEBGPU_DEVICE]),
|
|
2307
|
+
styleProps,
|
|
2308
|
+
translate:
|
|
2309
|
+
styleLayer.paint?.['circle-translate'] === undefined
|
|
2310
|
+
? null
|
|
2311
|
+
: getTranslateProps(styleLayer, zoom, 'circle'),
|
|
1524
2312
|
// Depth-tested against the globe without writing depth: a circle's quad, blur and
|
|
1525
2313
|
// antialiased edge included, would otherwise cut holes in the circles drawn after it.
|
|
1526
2314
|
// Circles face the viewer, so back-face culling does not hide those on the far side.
|
|
1527
2315
|
parameters: {
|
|
1528
2316
|
...getTileParameters(mode),
|
|
1529
|
-
depthTest: true,
|
|
1530
2317
|
depthCompare: 'less-equal',
|
|
1531
2318
|
depthWriteEnabled: false
|
|
1532
2319
|
}
|
|
@@ -1534,11 +2321,21 @@ function createStyledVectorSubLayer({
|
|
|
1534
2321
|
}
|
|
1535
2322
|
|
|
1536
2323
|
if (styleLayer.type === 'fill-extrusion') {
|
|
1537
|
-
return createExtrusionSubLayer({props, styleLayer, features, zoom, light});
|
|
2324
|
+
return createExtrusionSubLayer({props, styleLayer, features, zoom, light, featureState});
|
|
1538
2325
|
}
|
|
1539
2326
|
|
|
1540
2327
|
if (styleLayer.type === 'line') {
|
|
1541
|
-
return createLineSubLayers({
|
|
2328
|
+
return createLineSubLayers({
|
|
2329
|
+
props,
|
|
2330
|
+
styleLayer,
|
|
2331
|
+
features,
|
|
2332
|
+
mode,
|
|
2333
|
+
zoom,
|
|
2334
|
+
depthTested,
|
|
2335
|
+
featureState,
|
|
2336
|
+
lineMetrics,
|
|
2337
|
+
spriteAtlases
|
|
2338
|
+
});
|
|
1542
2339
|
}
|
|
1543
2340
|
|
|
1544
2341
|
if (styleLayer.type === 'fill' && styleLayer.paint?.['fill-pattern'] !== undefined) {
|
|
@@ -1554,7 +2351,8 @@ function createStyledVectorSubLayer({
|
|
|
1554
2351
|
mode,
|
|
1555
2352
|
zoom,
|
|
1556
2353
|
depthTested,
|
|
1557
|
-
pattern
|
|
2354
|
+
pattern,
|
|
2355
|
+
featureState
|
|
1558
2356
|
})
|
|
1559
2357
|
],
|
|
1560
2358
|
mode,
|
|
@@ -1568,7 +2366,14 @@ function createStyledVectorSubLayer({
|
|
|
1568
2366
|
createGeometrySubLayer({
|
|
1569
2367
|
props,
|
|
1570
2368
|
styles: [
|
|
1571
|
-
getGeometryStyle({
|
|
2369
|
+
getGeometryStyle({
|
|
2370
|
+
styleLayer,
|
|
2371
|
+
features: unpatterned,
|
|
2372
|
+
mode,
|
|
2373
|
+
zoom,
|
|
2374
|
+
depthTested,
|
|
2375
|
+
featureState
|
|
2376
|
+
})
|
|
1572
2377
|
],
|
|
1573
2378
|
mode,
|
|
1574
2379
|
idSuffix: '-missing-pattern'
|
|
@@ -1581,7 +2386,7 @@ function createStyledVectorSubLayer({
|
|
|
1581
2386
|
|
|
1582
2387
|
return createGeometrySubLayer({
|
|
1583
2388
|
props,
|
|
1584
|
-
styles: [getGeometryStyle({styleLayer, features, mode, zoom, depthTested})],
|
|
2389
|
+
styles: [getGeometryStyle({styleLayer, features, mode, zoom, depthTested, featureState})],
|
|
1585
2390
|
mode
|
|
1586
2391
|
});
|
|
1587
2392
|
}
|
|
@@ -1604,11 +2409,16 @@ function createVectorLayerGroup({
|
|
|
1604
2409
|
spriteAtlases,
|
|
1605
2410
|
fontFamily,
|
|
1606
2411
|
glyphs,
|
|
1607
|
-
labelPlacement
|
|
2412
|
+
labelPlacement,
|
|
2413
|
+
styleLayerProps,
|
|
2414
|
+
onError,
|
|
2415
|
+
featureState,
|
|
2416
|
+
pickable
|
|
1608
2417
|
}: {
|
|
1609
2418
|
idPrefix: string;
|
|
1610
2419
|
id: string;
|
|
1611
2420
|
sourceId: string;
|
|
2421
|
+
onError?: BasemapLoadErrorHandler | null;
|
|
1612
2422
|
source: BasemapSource;
|
|
1613
2423
|
/** Shared with the source's other runs, if it has any. */
|
|
1614
2424
|
tileset?: SharedTileset2D | null;
|
|
@@ -1631,17 +2441,29 @@ function createVectorLayerGroup({
|
|
|
1631
2441
|
glyphs?: GlyphStore | null;
|
|
1632
2442
|
/** The label placement shared by the map's label layers (see `LabelPlacement`). */
|
|
1633
2443
|
labelPlacement?: LabelPlacement | null;
|
|
2444
|
+
/** Extra sublayer props by style layer; tiles regenerate when it changes. */
|
|
2445
|
+
styleLayerProps?: StyleLayerPropsMap | null;
|
|
2446
|
+
/** The states that `["feature-state", ...]` reads; tiles regenerate when those read change. */
|
|
2447
|
+
featureState?: BasemapFeatureState | null;
|
|
2448
|
+
/** Makes the features pickable (see `BasemapPickedFeature`). */
|
|
2449
|
+
pickable?: LayerProps['pickable'];
|
|
1634
2450
|
}) {
|
|
1635
2451
|
const filterSnapshots = new FilterSnapshots();
|
|
2452
|
+
// The feature states each style layer's paint reads, by style layer index.
|
|
2453
|
+
const featureStates = styleLayers.map(styleLayer =>
|
|
2454
|
+
getFeatureStateLookup(featureState, sourceId, source, styleLayer)
|
|
2455
|
+
);
|
|
1636
2456
|
|
|
1637
2457
|
return new StyledMVTLayer({
|
|
1638
2458
|
id: `${idPrefix}-${id}`,
|
|
1639
|
-
data: tileset || source
|
|
2459
|
+
data: tileset || getSourceTileTemplates(source),
|
|
1640
2460
|
...{sourceTilesetOwner},
|
|
2461
|
+
...(pickable ? {pickable} : {}),
|
|
2462
|
+
// Name the source of picked features (see `getPickingInfo`).
|
|
2463
|
+
styleSourceId: sourceId,
|
|
2464
|
+
styleSource: source,
|
|
1641
2465
|
// The tile pyramid's range; style layers are gated by their own range in renderSubLayers.
|
|
1642
2466
|
...getTilePyramidProps(source),
|
|
1643
|
-
// The zoom at which `renderSubLayers` evaluates paint, which `ZoomPaintExtension` also uses.
|
|
1644
|
-
styleZoom: zoom,
|
|
1645
2467
|
// The style layers whose paint `ZoomPaintExtension` draws (see `ZoomPaintContext.setStyle`).
|
|
1646
2468
|
paintStyle: styleDefinition?.layers,
|
|
1647
2469
|
tileSize: source.tileSize || 512,
|
|
@@ -1653,9 +2475,13 @@ function createVectorLayerGroup({
|
|
|
1653
2475
|
shape: 'geojson-table'
|
|
1654
2476
|
}
|
|
1655
2477
|
},
|
|
1656
|
-
onTileError: (error: unknown) => {
|
|
1657
|
-
|
|
1658
|
-
|
|
2478
|
+
onTileError: (error: unknown, tile?: {index?: unknown}) => {
|
|
2479
|
+
reportTileError(onError, error, tile, {
|
|
2480
|
+
source,
|
|
2481
|
+
sourceId,
|
|
2482
|
+
message: 'Vector tile layer failed',
|
|
2483
|
+
details: {sourceId},
|
|
2484
|
+
missingIsEmpty: true
|
|
1659
2485
|
});
|
|
1660
2486
|
},
|
|
1661
2487
|
onTileLoad: (tile: Parameters<NonNullable<SharedMVTLayer['props']['onTileLoad']>>[0]) => {
|
|
@@ -1681,7 +2507,10 @@ function createVectorLayerGroup({
|
|
|
1681
2507
|
spriteAtlases,
|
|
1682
2508
|
fontFamily,
|
|
1683
2509
|
glyphs,
|
|
1684
|
-
labelPlacement
|
|
2510
|
+
labelPlacement,
|
|
2511
|
+
styleLayerProps,
|
|
2512
|
+
// The states read by the run's paint: only the paint attributes that read them change.
|
|
2513
|
+
featureStates.map(lookup => lookup?.token ?? -1).join(',')
|
|
1685
2514
|
]
|
|
1686
2515
|
},
|
|
1687
2516
|
renderLabelLayers: ((tilesByStyleLayer, getSubLayerProps, hidden) =>
|
|
@@ -1691,7 +2520,7 @@ function createVectorLayerGroup({
|
|
|
1691
2520
|
if (!styleLayer) {
|
|
1692
2521
|
return [];
|
|
1693
2522
|
}
|
|
1694
|
-
|
|
2523
|
+
const labelLayer = createSymbolSubLayer({
|
|
1695
2524
|
props: {
|
|
1696
2525
|
...getSubLayerProps(`labels-${JSON.stringify(styleLayer.id)}`),
|
|
1697
2526
|
// A label layer kept without features (see `renderViewLabelLayers`) is not drawn.
|
|
@@ -1713,7 +2542,25 @@ function createVectorLayerGroup({
|
|
|
1713
2542
|
glyphs,
|
|
1714
2543
|
labelPlacement
|
|
1715
2544
|
});
|
|
2545
|
+
return withStyleLayerProps(labelLayer, styleLayerProps?.get(styleLayer));
|
|
1716
2546
|
})) as RenderLabelLayers,
|
|
2547
|
+
renderHeatmapLayers: ((pointsByStyleLayer, getSubLayerProps) =>
|
|
2548
|
+
[...pointsByStyleLayer].flatMap(([styleLayerIndex, points]) => {
|
|
2549
|
+
const styleLayer = styleLayers[styleLayerIndex];
|
|
2550
|
+
const layer =
|
|
2551
|
+
styleLayer?.type === 'heatmap'
|
|
2552
|
+
? createHeatmapSubLayer({
|
|
2553
|
+
props: {
|
|
2554
|
+
...getSubLayerProps(`heatmap-${JSON.stringify(styleLayer.id)}`),
|
|
2555
|
+
[STYLE_LAYER_INDEX]: styleLayerIndex
|
|
2556
|
+
},
|
|
2557
|
+
styleLayer,
|
|
2558
|
+
points,
|
|
2559
|
+
zoom
|
|
2560
|
+
})
|
|
2561
|
+
: null;
|
|
2562
|
+
return layer && styleLayer ? [withStyleLayerProps(layer, styleLayerProps?.get(styleLayer))] : [];
|
|
2563
|
+
})) as RenderHeatmapLayers,
|
|
1717
2564
|
renderSubLayers: (props: Parameters<SharedMVTLayer['renderSubLayers']>[0]) => {
|
|
1718
2565
|
const styleProps = props as typeof props & {
|
|
1719
2566
|
styleAutoHighlight?: boolean;
|
|
@@ -1724,6 +2571,10 @@ function createVectorLayerGroup({
|
|
|
1724
2571
|
const layers: any[] = [];
|
|
1725
2572
|
// Where the tile layer collects them, a tile's labels are drawn with the other tiles'.
|
|
1726
2573
|
const labelFeatures = (props as any)[TILE_LABEL_FEATURES] as Map<number, any[]> | undefined;
|
|
2574
|
+
// Where the tile layer collects them, a tile's heatmap points are drawn with the others'.
|
|
2575
|
+
const heatmapPoints = (props as any)[TILE_HEATMAP_POINTS] as
|
|
2576
|
+
| Map<number, HeatmapPoint[]>
|
|
2577
|
+
| undefined;
|
|
1727
2578
|
const highlights =
|
|
1728
2579
|
Boolean(styleProps[AUTO_HIGHLIGHT]) ||
|
|
1729
2580
|
(styleProps.highlightedFeatureId !== null && styleProps.highlightedFeatureId !== undefined);
|
|
@@ -1735,12 +2586,18 @@ function createVectorLayerGroup({
|
|
|
1735
2586
|
let batchIndex = 0;
|
|
1736
2587
|
const flush = () => {
|
|
1737
2588
|
if (batch.length > 0) {
|
|
2589
|
+
// A style layer with extra props draws alone (see below).
|
|
2590
|
+
const ownProps =
|
|
2591
|
+
batch.length === 1 ? styleLayerProps?.get(batch[0].styleLayer) : undefined;
|
|
1738
2592
|
layers.push(
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
2593
|
+
withStyleLayerProps(
|
|
2594
|
+
createGeometrySubLayer({
|
|
2595
|
+
props: {...props, [STYLE_LAYER_INDEX]: batchIndex},
|
|
2596
|
+
styles: batch,
|
|
2597
|
+
mode
|
|
2598
|
+
}),
|
|
2599
|
+
ownProps
|
|
2600
|
+
)
|
|
1744
2601
|
);
|
|
1745
2602
|
batch = [];
|
|
1746
2603
|
}
|
|
@@ -1782,22 +2639,35 @@ function createVectorLayerGroup({
|
|
|
1782
2639
|
styleLayer.type === 'line'
|
|
1783
2640
|
? sortFeaturesByKey(filteredData, styleLayer, 'line-sort-key', zoom)
|
|
1784
2641
|
: filteredData;
|
|
1785
|
-
const style = getBatchableGeometryStyle(
|
|
2642
|
+
const style = getBatchableGeometryStyle(
|
|
2643
|
+
styleLayer,
|
|
2644
|
+
layerFeatures,
|
|
2645
|
+
mode,
|
|
2646
|
+
zoom,
|
|
2647
|
+
depthTested,
|
|
2648
|
+
featureStates[styleLayerIndex]
|
|
2649
|
+
);
|
|
1786
2650
|
if (style) {
|
|
1787
2651
|
// A style layer that draws nothing in this tile does not separate its neighbours. A line
|
|
1788
2652
|
// that draws nothing only because its width is 0 at this zoom step, and takes its width
|
|
1789
2653
|
// from `ZoomPaintExtension`, is batched as at a step that gives it a width: its sublayer
|
|
1790
2654
|
// and batch stay the same across the step, and are not made again (see
|
|
1791
2655
|
// `createGeometrySubLayer`, which hides a sublayer that draws nothing).
|
|
1792
|
-
|
|
1793
|
-
|
|
2656
|
+
if (zoomPaintContext && takesZoomPaint(style)) {
|
|
2657
|
+
keepGeometryPaint(style, mode);
|
|
2658
|
+
}
|
|
2659
|
+
if (style.drawsFill || style.drawsLines || style.deferredPaint) {
|
|
1794
2660
|
// A batch draws all of its style layers in one tile before the next tile. On a map,
|
|
1795
2661
|
// tiles are clipped to their bounds, so that draws the same pixels as each style layer
|
|
1796
2662
|
// across all tiles in turn; on the globe, tiles are not clipped, and where their
|
|
1797
2663
|
// buffers overlap a tile's later style layer would draw under a neighbour's earlier one.
|
|
1798
2664
|
// A highlight colors one object of a sublayer: in a batch, a feature drawn by two
|
|
1799
2665
|
// style layers would be highlighted only under the second one's copy.
|
|
1800
|
-
|
|
2666
|
+
// A style layer with extra props draws in a sublayer of its own, which takes them.
|
|
2667
|
+
const key =
|
|
2668
|
+
mode === 'globe' || highlights || styleLayerProps?.has(styleLayer)
|
|
2669
|
+
? null
|
|
2670
|
+
: getBatchKey(style);
|
|
1801
2671
|
if (!canBatch(batch, style, key)) {
|
|
1802
2672
|
flush();
|
|
1803
2673
|
batchIndex = styleLayerIndex;
|
|
@@ -1815,27 +2685,40 @@ function createVectorLayerGroup({
|
|
|
1815
2685
|
labelFeatures.set(styleLayerIndex, filteredData);
|
|
1816
2686
|
return;
|
|
1817
2687
|
}
|
|
2688
|
+
if (styleLayer.type === 'heatmap') {
|
|
2689
|
+
// Drawn with the points of the other tiles (see `renderHeatmapLayers`). Tile-local
|
|
2690
|
+
// features are drawn in a Cartesian frame; on a globe and in a projected view they are
|
|
2691
|
+
// in longitude/latitude.
|
|
2692
|
+
heatmapPoints?.set(
|
|
2693
|
+
styleLayerIndex,
|
|
2694
|
+
getHeatmapPoints(filteredData, props.tile.index, props.coordinateSystem === 'lnglat')
|
|
2695
|
+
);
|
|
2696
|
+
return;
|
|
2697
|
+
}
|
|
1818
2698
|
flush();
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
2699
|
+
const extraProps = styleLayerProps?.get(styleLayer);
|
|
2700
|
+
const sublayers = createStyledVectorSubLayer({
|
|
2701
|
+
idPrefix,
|
|
2702
|
+
sourceId,
|
|
2703
|
+
styleLayer,
|
|
2704
|
+
features: layerFeatures,
|
|
2705
|
+
props: {...props, [STYLE_LAYER_INDEX]: styleLayerIndex},
|
|
2706
|
+
zoom,
|
|
2707
|
+
config,
|
|
2708
|
+
mode,
|
|
2709
|
+
depthTested,
|
|
2710
|
+
collisionPriorityRange: labelPriorityRanges?.get(styleLayer),
|
|
2711
|
+
spriteAtlases,
|
|
2712
|
+
loadOptions,
|
|
2713
|
+
fontFamily,
|
|
2714
|
+
glyphs,
|
|
2715
|
+
labelPlacement,
|
|
2716
|
+
light: getFillExtrusionLight(styleDefinition, zoom),
|
|
2717
|
+
featureState: featureStates[styleLayerIndex],
|
|
2718
|
+
lineMetrics: source.type === 'geojson' && Boolean(source.lineMetrics),
|
|
2719
|
+
styleProps: extraProps
|
|
2720
|
+
});
|
|
2721
|
+
layers.push(withStyleLayerProps(sublayers, extraProps));
|
|
1839
2722
|
});
|
|
1840
2723
|
flush();
|
|
1841
2724
|
|
|
@@ -1874,16 +2757,28 @@ export function getBasemapLayers({
|
|
|
1874
2757
|
styleDefinition,
|
|
1875
2758
|
zoom = 0,
|
|
1876
2759
|
loadOptions,
|
|
2760
|
+
fetch,
|
|
2761
|
+
transformRequest,
|
|
2762
|
+
rejectRasterTile,
|
|
2763
|
+
onError,
|
|
1877
2764
|
spriteAtlases,
|
|
1878
2765
|
fontFamily,
|
|
1879
2766
|
glyphs,
|
|
1880
2767
|
labelPlacement,
|
|
1881
|
-
|
|
2768
|
+
featureState,
|
|
2769
|
+
pickable,
|
|
2770
|
+
tilesets,
|
|
2771
|
+
projected,
|
|
2772
|
+
firstPerson,
|
|
2773
|
+
projectedMaxStretch,
|
|
2774
|
+
styleLayerProps,
|
|
2775
|
+
insertLayers
|
|
1882
2776
|
}: BasemapLayerGroup) {
|
|
1883
2777
|
const config = getConfig(globe);
|
|
1884
2778
|
const styleLayers = (styleDefinition.layers || []).filter(layer =>
|
|
1885
2779
|
SUPPORTED_TYPES.has(layer.type)
|
|
1886
2780
|
);
|
|
2781
|
+
const {insertions, topLayers} = getStyleInsertions(insertLayers, styleDefinition, styleLayers);
|
|
1887
2782
|
const layers: any[] = [];
|
|
1888
2783
|
logBasemapRuntimeEvent('Generating basemap layers', {
|
|
1889
2784
|
mode,
|
|
@@ -1902,49 +2797,101 @@ export function getBasemapLayers({
|
|
|
1902
2797
|
zoom,
|
|
1903
2798
|
config,
|
|
1904
2799
|
loadOptions,
|
|
2800
|
+
fetch,
|
|
2801
|
+
transformRequest,
|
|
2802
|
+
rejectRasterTile,
|
|
2803
|
+
onError,
|
|
1905
2804
|
mode,
|
|
1906
2805
|
spriteAtlases,
|
|
1907
2806
|
fontFamily,
|
|
1908
2807
|
glyphs,
|
|
1909
2808
|
labelPlacement,
|
|
1910
|
-
|
|
2809
|
+
featureState,
|
|
2810
|
+
pickable,
|
|
2811
|
+
tilesets,
|
|
2812
|
+
projected,
|
|
2813
|
+
firstPerson,
|
|
2814
|
+
projectedMaxStretch,
|
|
2815
|
+
styleLayerProps,
|
|
2816
|
+
insertions
|
|
1911
2817
|
})
|
|
1912
2818
|
);
|
|
2819
|
+
} else {
|
|
2820
|
+
layers.push(...insertions.map(insertion => insertion.layers));
|
|
1913
2821
|
}
|
|
1914
2822
|
|
|
1915
2823
|
layers.push(...getGlobePostLayers({idPrefix, mode, config, styleLayers, zoom}));
|
|
2824
|
+
layers.push(topLayers);
|
|
2825
|
+
|
|
2826
|
+
return (layers.flat(Infinity) as unknown[]).filter(layer => Boolean(layer)) as any[];
|
|
2827
|
+
}
|
|
1916
2828
|
|
|
1917
|
-
|
|
2829
|
+
/** The error of an insertion whose `beforeId` names no layer of the style. */
|
|
2830
|
+
export function getInsertionError(beforeId: string): Error {
|
|
2831
|
+
return new Error(`Cannot insert layers before non-existing style layer "${beforeId}"`);
|
|
2832
|
+
}
|
|
2833
|
+
|
|
2834
|
+
/** deck.gl layers to draw before the style layer at `index` of the drawn style layers. */
|
|
2835
|
+
type StyleInsertion = {index: number; layers: LayersList};
|
|
2836
|
+
|
|
2837
|
+
/**
|
|
2838
|
+
* Places each insertion of `insertLayers` in the style, as MapLibre GL JS's
|
|
2839
|
+
* `addLayer(layer, beforeId)`: before the first drawn style layer at or after `beforeId`, or after
|
|
2840
|
+
* the style's layers when none follows. Insertions without a `beforeId` draw over the whole basemap.
|
|
2841
|
+
* Throws for a `beforeId` that names no layer of the style, as `addLayer` reports an error.
|
|
2842
|
+
*/
|
|
2843
|
+
export function getStyleInsertions(
|
|
2844
|
+
insertLayers: BasemapInsertion[] | null | undefined,
|
|
2845
|
+
styleDefinition: ResolvedBasemapStyle,
|
|
2846
|
+
styleLayers: BasemapStyleLayer[]
|
|
2847
|
+
): {insertions: StyleInsertion[]; topLayers: LayersList} {
|
|
2848
|
+
const insertions: StyleInsertion[] = [];
|
|
2849
|
+
const topLayers: LayersList = [];
|
|
2850
|
+
if (!insertLayers?.length) {
|
|
2851
|
+
return {insertions, topLayers};
|
|
2852
|
+
}
|
|
2853
|
+
const allLayers = styleDefinition.layers || [];
|
|
2854
|
+
const drawnIndex = new Map(styleLayers.map((layer, index) => [layer, index]));
|
|
2855
|
+
for (const {beforeId, layers} of insertLayers) {
|
|
2856
|
+
if (beforeId === undefined || beforeId === null) {
|
|
2857
|
+
topLayers.push(layers);
|
|
2858
|
+
continue;
|
|
2859
|
+
}
|
|
2860
|
+
const position = allLayers.findIndex(layer => layer.id === beforeId);
|
|
2861
|
+
if (position < 0) {
|
|
2862
|
+
throw getInsertionError(beforeId);
|
|
2863
|
+
}
|
|
2864
|
+
let index = styleLayers.length;
|
|
2865
|
+
for (let i = position; i < allLayers.length; i++) {
|
|
2866
|
+
const drawn = drawnIndex.get(allLayers[i]);
|
|
2867
|
+
if (drawn !== undefined) {
|
|
2868
|
+
index = drawn;
|
|
2869
|
+
break;
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
insertions.push({index, layers});
|
|
2873
|
+
}
|
|
2874
|
+
// A stable sort: insertions before the same style layer keep their order in `insertLayers`.
|
|
2875
|
+
insertions.sort((a, b) => a.index - b.index);
|
|
2876
|
+
return {insertions, topLayers};
|
|
1918
2877
|
}
|
|
1919
2878
|
|
|
2879
|
+
/**
|
|
2880
|
+
* `getBasemapLayers` with `mode: 'globe'` and the id prefix `'globe-basemap'`.
|
|
2881
|
+
*
|
|
2882
|
+
* @deprecated Use `getBasemapLayers({...options, mode: 'globe'})`.
|
|
2883
|
+
*/
|
|
1920
2884
|
export function getGlobeBaseLayers({
|
|
1921
|
-
globe,
|
|
1922
|
-
styleDefinition,
|
|
1923
2885
|
idPrefix = 'globe-basemap',
|
|
1924
|
-
|
|
1925
|
-
loadOptions,
|
|
1926
|
-
spriteAtlases,
|
|
1927
|
-
fontFamily,
|
|
1928
|
-
glyphs,
|
|
1929
|
-
labelPlacement
|
|
2886
|
+
...options
|
|
1930
2887
|
}: Omit<BasemapLayerGroup, 'mode'>) {
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
mode: 'globe',
|
|
1934
|
-
globe,
|
|
1935
|
-
styleDefinition,
|
|
1936
|
-
zoom,
|
|
1937
|
-
loadOptions,
|
|
1938
|
-
spriteAtlases,
|
|
1939
|
-
fontFamily,
|
|
1940
|
-
glyphs,
|
|
1941
|
-
labelPlacement
|
|
1942
|
-
});
|
|
2888
|
+
log.deprecated('getGlobeBaseLayers', "getBasemapLayers({...options, mode: 'globe'})")();
|
|
2889
|
+
return getBasemapLayers({...options, idPrefix, mode: 'globe'});
|
|
1943
2890
|
}
|
|
1944
2891
|
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
return
|
|
2892
|
+
/** The layers drawn over the globe: the atmosphere, when `globe.config.atmosphere` is set. */
|
|
2893
|
+
export function getGlobeTopLayers({globe}: {globe?: {config?: BasemapGlobeConfig}} = {}) {
|
|
2894
|
+
return getConfig(globe).atmosphere ? [getGlobeAtmosphereLayer()] : [];
|
|
1948
2895
|
}
|
|
1949
2896
|
|
|
1950
2897
|
function createSymbolSubLayer({
|
|
@@ -1999,8 +2946,9 @@ function createSymbolSubLayer({
|
|
|
1999
2946
|
labelPlacement,
|
|
2000
2947
|
// Polygon labels outside the tile's own extent are left to the neighbouring tile.
|
|
2001
2948
|
tileBoundingBox: props.tile?.bbox ?? null,
|
|
2002
|
-
//
|
|
2949
|
+
// The source limit and tile zoom are both in tile-index zoom.
|
|
2003
2950
|
tileZoom: props.tile?.index?.z ?? null,
|
|
2951
|
+
tileMaxZoom: Number.isFinite(props.maxZoom) ? props.maxZoom : null,
|
|
2004
2952
|
tileSize: props.tileSize ?? null,
|
|
2005
2953
|
zoom: getZoomBucket(zoom),
|
|
2006
2954
|
// The style spec's default `text-color` is black.
|
|
@@ -2010,11 +2958,9 @@ function createSymbolSubLayer({
|
|
|
2010
2958
|
}
|
|
2011
2959
|
|
|
2012
2960
|
/**
|
|
2013
|
-
*
|
|
2014
|
-
*
|
|
2015
|
-
*
|
|
2016
|
-
* its dashes. In an odd-length pattern the last dash runs into the first, as in MapLibre. An empty
|
|
2017
|
-
* pattern, or one without gaps, draws a solid line.
|
|
2961
|
+
* Encodes a style `line-dasharray` as a period and a negative atlas row marker for WebGL.
|
|
2962
|
+
* Lengths double because deck.gl uses half line widths. An empty pattern or one without
|
|
2963
|
+
* gaps draws solid. Patterns beyond the atlas limits fall back to a single dash and gap.
|
|
2018
2964
|
*/
|
|
2019
2965
|
export function getDashArray(dasharray: unknown): [number, number] {
|
|
2020
2966
|
if (!Array.isArray(dasharray)) {
|
|
@@ -2022,15 +2968,22 @@ export function getDashArray(dasharray: unknown): [number, number] {
|
|
|
2022
2968
|
}
|
|
2023
2969
|
let dash = 0;
|
|
2024
2970
|
let gap = 0;
|
|
2025
|
-
|
|
2026
|
-
const
|
|
2971
|
+
const pattern = Array.from(dasharray, (value, index) => {
|
|
2972
|
+
const number = Number(value);
|
|
2973
|
+
const length = Number.isFinite(number) ? Math.max(0, number) : 0;
|
|
2027
2974
|
if (index % 2 === 0) {
|
|
2028
2975
|
dash += length;
|
|
2029
2976
|
} else {
|
|
2030
2977
|
gap += length;
|
|
2031
2978
|
}
|
|
2979
|
+
return length;
|
|
2032
2980
|
});
|
|
2033
|
-
|
|
2981
|
+
if (gap <= 0 || !Number.isFinite(Math.fround(2 * (dash + gap)))) {
|
|
2982
|
+
return [0, 0];
|
|
2983
|
+
}
|
|
2984
|
+
const row = getDashPatternRow(pattern);
|
|
2985
|
+
const registered = getDashPattern(row);
|
|
2986
|
+
return registered ? [registered.period, -(row + 1)] : [dash * 2, gap * 2];
|
|
2034
2987
|
}
|
|
2035
2988
|
|
|
2036
2989
|
/** The least distance, in pixels, of a gap's line from the gap's center: see getLineOffset. */
|
|
@@ -2070,9 +3023,9 @@ export function getLineOffset(
|
|
|
2070
3023
|
}
|
|
2071
3024
|
|
|
2072
3025
|
/**
|
|
2073
|
-
* Scales a blurred gap's
|
|
2074
|
-
*
|
|
2075
|
-
* `[offset, gap, width, blur]` accessor of `getLineOffset`.
|
|
3026
|
+
* Scales a blurred gap's dash lengths by `width / drawnWidth` so it keeps the pixel lengths
|
|
3027
|
+
* MapLibre gives it in `line-width`s. The negative atlas row marker stays fixed.
|
|
3028
|
+
* `shape` is the `[offset, gap, width, blur]` accessor of `getLineOffset`.
|
|
2076
3029
|
*/
|
|
2077
3030
|
export function getBlurredDashArray(
|
|
2078
3031
|
dashArray: StyleAccessor<[number, number]>,
|
|
@@ -2084,7 +3037,7 @@ export function getBlurredDashArray(
|
|
|
2084
3037
|
): [number, number] => {
|
|
2085
3038
|
const drawnWidth = getBlurredLineWidth(width, gapWidth, blur);
|
|
2086
3039
|
const ratio = drawnWidth > 0 ? width / drawnWidth : 1;
|
|
2087
|
-
return [dash * ratio, gap * ratio];
|
|
3040
|
+
return [dash * ratio, gap < 0 ? gap : gap * ratio];
|
|
2088
3041
|
};
|
|
2089
3042
|
const dashValue = dashArray.value;
|
|
2090
3043
|
const shapeValue = shape.value;
|
|
@@ -2108,6 +3061,8 @@ export function getBlurredDashArray(
|
|
|
2108
3061
|
/** deck.gl path props for a line's `line-cap`, `line-join` and `line-miter-limit`. */
|
|
2109
3062
|
export type LineShape = {
|
|
2110
3063
|
lineCapRounded: boolean;
|
|
3064
|
+
/** Whether WebGL extends the flat cap past each path endpoint. */
|
|
3065
|
+
lineCapSquare: boolean;
|
|
2111
3066
|
lineJointRounded: boolean;
|
|
2112
3067
|
lineMiterLimit: number;
|
|
2113
3068
|
};
|
|
@@ -2115,22 +3070,19 @@ export type LineShape = {
|
|
|
2115
3070
|
/**
|
|
2116
3071
|
* Converts `line-cap`, `line-join` and `line-miter-limit` into deck.gl path props.
|
|
2117
3072
|
*
|
|
2118
|
-
*
|
|
2119
|
-
*
|
|
2120
|
-
*
|
|
2121
|
-
* `miter` join in full while its tip is within `line-miter-limit` half widths of the vertex, so
|
|
2122
|
-
* passing `line-miter-limit - 1` draws the same joins in full. A sharper corner, which MapLibre
|
|
2123
|
-
* bevels, is cut flat at that distance instead.
|
|
2124
|
-
* - deck.gl has no bevel join. A `bevel` join is cut flat half the line width from the vertex,
|
|
2125
|
-
* which matches a bevel at shallow corners; at sharp corners a true bevel cuts closer.
|
|
3073
|
+
* LineShapeExtension extends square caps and bevels corners that exceed the miter limit.
|
|
3074
|
+
* deck.gl expresses that limit as `miterLimit + 1` half widths. MapLibre uses a limit of
|
|
3075
|
+
* 1.05 half widths for an explicit bevel, retaining the miter at shallow turns.
|
|
2126
3076
|
*/
|
|
2127
3077
|
export function getLineShape([cap, join, miterLimit]: unknown[]): LineShape {
|
|
2128
3078
|
const lineJoin = join ?? getStylePropertyDefault('line-join');
|
|
2129
3079
|
const limit = Number(miterLimit ?? getStylePropertyDefault('line-miter-limit'));
|
|
3080
|
+
const deckMiterLimit = lineJoin === 'miter' && Number.isFinite(limit) ? Math.max(0, limit - 1) : 0;
|
|
2130
3081
|
return {
|
|
2131
3082
|
lineCapRounded: (cap ?? getStylePropertyDefault('line-cap')) === 'round',
|
|
3083
|
+
lineCapSquare: cap === 'square',
|
|
2132
3084
|
lineJointRounded: lineJoin === 'round',
|
|
2133
|
-
lineMiterLimit: lineJoin === '
|
|
3085
|
+
lineMiterLimit: lineJoin === 'bevel' ? 0.05 : deckMiterLimit
|
|
2134
3086
|
};
|
|
2135
3087
|
}
|
|
2136
3088
|
|
|
@@ -2141,7 +3093,10 @@ function createLineSubLayers({
|
|
|
2141
3093
|
features,
|
|
2142
3094
|
mode,
|
|
2143
3095
|
zoom,
|
|
2144
|
-
depthTested
|
|
3096
|
+
depthTested,
|
|
3097
|
+
featureState,
|
|
3098
|
+
lineMetrics,
|
|
3099
|
+
spriteAtlases
|
|
2145
3100
|
}: {
|
|
2146
3101
|
props: any;
|
|
2147
3102
|
styleLayer: BasemapStyleLayer;
|
|
@@ -2149,42 +3104,54 @@ function createLineSubLayers({
|
|
|
2149
3104
|
mode: BasemapMode;
|
|
2150
3105
|
zoom: number;
|
|
2151
3106
|
depthTested?: boolean;
|
|
3107
|
+
featureState?: FeatureStateLookup;
|
|
3108
|
+
lineMetrics?: boolean;
|
|
3109
|
+
spriteAtlases?: SpriteAtlas[] | null;
|
|
2152
3110
|
}) {
|
|
2153
3111
|
const lineShape = getLineShapeAccessor(styleLayer, zoom);
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
3112
|
+
const draw = (lineFeatures: any[], pattern: FillPatternGroup | undefined, idSuffix: string) => {
|
|
3113
|
+
const getStyle = (styleFeatures: any[], shape: LineShape) =>
|
|
3114
|
+
getGeometryStyle({
|
|
3115
|
+
styleLayer,
|
|
3116
|
+
features: styleFeatures,
|
|
3117
|
+
mode,
|
|
3118
|
+
zoom,
|
|
3119
|
+
depthTested,
|
|
3120
|
+
lineShape: shape,
|
|
3121
|
+
lineMetrics,
|
|
3122
|
+
pattern,
|
|
3123
|
+
featureState
|
|
3124
|
+
});
|
|
3125
|
+
if (typeof lineShape.value !== 'function') {
|
|
3126
|
+
return createGeometrySubLayer({
|
|
3127
|
+
props,
|
|
3128
|
+
styles: [getStyle(lineFeatures, lineShape.value)],
|
|
3129
|
+
mode,
|
|
3130
|
+
idSuffix
|
|
3131
|
+
});
|
|
3132
|
+
}
|
|
3133
|
+
return getLineShapeGroups(lineFeatures, styleLayer, lineShape).map(group =>
|
|
3134
|
+
createGeometrySubLayer({
|
|
3135
|
+
props,
|
|
3136
|
+
styles: [getStyle(group.features, group.shape)],
|
|
3137
|
+
mode,
|
|
3138
|
+
idSuffix: `${idSuffix}-${group.key}`
|
|
3139
|
+
})
|
|
3140
|
+
);
|
|
3141
|
+
};
|
|
2170
3142
|
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
],
|
|
2184
|
-
mode,
|
|
2185
|
-
idSuffix: `-${group.key}`
|
|
2186
|
-
})
|
|
2187
|
-
);
|
|
3143
|
+
// A patterned line draws a sublayer per run of consecutive lines whose images are in one sprite
|
|
3144
|
+
// atlas, so that the runs keep the lines' order (`line-sort-key`) across atlases. Lines whose
|
|
3145
|
+
// image is in no loaded sprite draw nothing, as in MapLibre GL JS, and so do all of them while
|
|
3146
|
+
// the sprites load.
|
|
3147
|
+
if (styleLayer.paint?.['line-pattern'] !== undefined) {
|
|
3148
|
+
const groups = getFillPatternGroups(features, styleLayer, zoom, spriteAtlases, 'line-pattern');
|
|
3149
|
+
const runs = getPatternRuns(features, groups);
|
|
3150
|
+
return runs.flatMap(run =>
|
|
3151
|
+
draw(run.features, run.group, runs.length > 1 ? `-pattern-${run.key}` : '')
|
|
3152
|
+
);
|
|
3153
|
+
}
|
|
3154
|
+
return draw(features, undefined, '');
|
|
2188
3155
|
}
|
|
2189
3156
|
|
|
2190
3157
|
function getLineShapeAccessor(styleLayer: BasemapStyleLayer, zoom: number) {
|
|
@@ -2205,21 +3172,36 @@ function getBatchableGeometryStyle(
|
|
|
2205
3172
|
features: any[],
|
|
2206
3173
|
mode: BasemapMode,
|
|
2207
3174
|
zoom: number,
|
|
2208
|
-
depthTested: boolean
|
|
3175
|
+
depthTested: boolean,
|
|
3176
|
+
featureState?: FeatureStateLookup
|
|
2209
3177
|
): GeometryStyle | null {
|
|
2210
3178
|
if (styleLayer.type === 'fill') {
|
|
2211
3179
|
// A patterned fill draws a sublayer per sprite atlas of its images (see `getFillPatternGroups`).
|
|
2212
3180
|
return styleLayer.paint?.['fill-pattern'] !== undefined
|
|
2213
3181
|
? null
|
|
2214
|
-
: getGeometryStyle({styleLayer, features, mode, zoom, depthTested});
|
|
3182
|
+
: getGeometryStyle({styleLayer, features, mode, zoom, depthTested, featureState});
|
|
2215
3183
|
}
|
|
2216
|
-
|
|
3184
|
+
// A gradient takes its source's `lineMetrics`, which `createStyledVectorSubLayer` checks, and a
|
|
3185
|
+
// pattern its sprites.
|
|
3186
|
+
if (
|
|
3187
|
+
styleLayer.type !== 'line' ||
|
|
3188
|
+
styleLayer.paint?.['line-gradient'] !== undefined ||
|
|
3189
|
+
styleLayer.paint?.['line-pattern'] !== undefined
|
|
3190
|
+
) {
|
|
2217
3191
|
return null;
|
|
2218
3192
|
}
|
|
2219
3193
|
const lineShape = getLineShapeAccessor(styleLayer, zoom);
|
|
2220
3194
|
return typeof lineShape.value === 'function'
|
|
2221
3195
|
? null
|
|
2222
|
-
: getGeometryStyle({
|
|
3196
|
+
: getGeometryStyle({
|
|
3197
|
+
styleLayer,
|
|
3198
|
+
features,
|
|
3199
|
+
mode,
|
|
3200
|
+
zoom,
|
|
3201
|
+
depthTested,
|
|
3202
|
+
lineShape: lineShape.value,
|
|
3203
|
+
featureState
|
|
3204
|
+
});
|
|
2223
3205
|
}
|
|
2224
3206
|
|
|
2225
3207
|
type LineShapeGroup = {key: string; shape: LineShape; features: any[]};
|
|
@@ -2262,7 +3244,7 @@ function getLineShapeGroups(
|
|
|
2262
3244
|
const groups = new Map<string, LineShapeGroup>();
|
|
2263
3245
|
for (const feature of features) {
|
|
2264
3246
|
const shape = getShape(feature);
|
|
2265
|
-
const groupKey =
|
|
3247
|
+
const groupKey = getLineShapeKey(shape);
|
|
2266
3248
|
let group = groups.get(groupKey);
|
|
2267
3249
|
if (!group) {
|
|
2268
3250
|
group = {key: groupKey, shape, features: []};
|
|
@@ -2275,6 +3257,25 @@ function getLineShapeGroups(
|
|
|
2275
3257
|
return result;
|
|
2276
3258
|
}
|
|
2277
3259
|
|
|
3260
|
+
/**
|
|
3261
|
+
* The props of `FillTranslateExtension` from a style layer's `<prefix>-translate` and
|
|
3262
|
+
* `<prefix>-translate-anchor` (`fill`, `line`, `circle` or `fill-extrusion`), evaluated at the
|
|
3263
|
+
* stepped zoom: the style specification does not let them depend on feature data.
|
|
3264
|
+
*/
|
|
3265
|
+
function getTranslateProps(
|
|
3266
|
+
styleLayer: BasemapStyleLayer,
|
|
3267
|
+
zoom: number,
|
|
3268
|
+
prefix: 'fill' | 'line' | 'circle' | 'fill-extrusion'
|
|
3269
|
+
): {fillTranslate: [number, number]; fillTranslateAnchor: FillTranslateAnchor} {
|
|
3270
|
+
const paint = getPaint(styleLayer, zoom);
|
|
3271
|
+
const translate = `${prefix}-translate`;
|
|
3272
|
+
const anchor = `${prefix}-translate-anchor`;
|
|
3273
|
+
return {
|
|
3274
|
+
fillTranslate: paint[translate] ?? getStylePropertyDefault(translate),
|
|
3275
|
+
fillTranslateAnchor: paint[anchor] ?? getStylePropertyDefault(anchor)
|
|
3276
|
+
};
|
|
3277
|
+
}
|
|
3278
|
+
|
|
2278
3279
|
/**
|
|
2279
3280
|
* The extensions and props of `fill-pattern` (with the features' images) and `fill-translate`
|
|
2280
3281
|
* (when the layer sets it). `fill-translate` is evaluated at the stepped zoom; it cannot depend on
|
|
@@ -2290,7 +3291,6 @@ function getFillStyleProps(
|
|
|
2290
3291
|
if (!pattern && !hasTranslate) {
|
|
2291
3292
|
return {};
|
|
2292
3293
|
}
|
|
2293
|
-
const paint = getPaint(styleLayer, zoom);
|
|
2294
3294
|
return {
|
|
2295
3295
|
extensions: [
|
|
2296
3296
|
...(extensions || []),
|
|
@@ -2298,13 +3298,7 @@ function getFillStyleProps(
|
|
|
2298
3298
|
...(hasTranslate ? [FILL_TRANSLATE_EXTENSION] : [])
|
|
2299
3299
|
],
|
|
2300
3300
|
...(pattern ? getFillPatternProps(pattern, zoom) : {}),
|
|
2301
|
-
...(hasTranslate
|
|
2302
|
-
? {
|
|
2303
|
-
fillTranslate: paint['fill-translate'] ?? getStylePropertyDefault('fill-translate'),
|
|
2304
|
-
fillTranslateAnchor:
|
|
2305
|
-
paint['fill-translate-anchor'] ?? getStylePropertyDefault('fill-translate-anchor')
|
|
2306
|
-
}
|
|
2307
|
-
: {})
|
|
3301
|
+
...(hasTranslate ? getTranslateProps(styleLayer, zoom, 'fill') : {})
|
|
2308
3302
|
};
|
|
2309
3303
|
}
|
|
2310
3304
|
|
|
@@ -2319,10 +3313,12 @@ type GeometryStyle = {
|
|
|
2319
3313
|
drawsFill: boolean;
|
|
2320
3314
|
drawsLines: boolean;
|
|
2321
3315
|
/**
|
|
2322
|
-
*
|
|
2323
|
-
*
|
|
3316
|
+
* Fill or line geometry kept for paint that can become visible inside the step or for a line
|
|
3317
|
+
* that drew at the previous step. It keeps its place in its sublayer (see `renderSubLayers`).
|
|
2324
3318
|
*/
|
|
2325
|
-
|
|
3319
|
+
deferredPaint?: {fill: boolean; line: boolean} | null;
|
|
3320
|
+
/** The feature states the style layer's paint reads, if it reads any. */
|
|
3321
|
+
featureState?: FeatureStateLookup;
|
|
2326
3322
|
fillColor: StyleAccessor<number[]>;
|
|
2327
3323
|
lineColor: StyleAccessor<number[]>;
|
|
2328
3324
|
lineWidth: StyleAccessor<number>;
|
|
@@ -2336,9 +3332,20 @@ type GeometryStyle = {
|
|
|
2336
3332
|
isBlurredGap: boolean;
|
|
2337
3333
|
/** Whether the fill sets `fill-pattern` or `fill-translate`, which take their own extensions. */
|
|
2338
3334
|
hasFillStyle: boolean;
|
|
3335
|
+
/** Whether the line sets `line-translate`, which takes its own extension. */
|
|
3336
|
+
hasLineTranslate: boolean;
|
|
2339
3337
|
lineShape?: LineShape;
|
|
2340
3338
|
/** The features' `fill-pattern` images; without it, a patterned fill draws no fill. */
|
|
2341
3339
|
pattern?: FillPatternGroup;
|
|
3340
|
+
/** The line's `line-gradient` ramp, which replaces `line-color`. */
|
|
3341
|
+
lineGradient: LineGradientRamp | null;
|
|
3342
|
+
/** A gradient line's `line-color`, which it draws where the ramp shader does not run. */
|
|
3343
|
+
lineGradientFallbackColor: StyleAccessor<number[]> | null;
|
|
3344
|
+
/**
|
|
3345
|
+
* A patterned line's `line-width` at the integer zoom, which its image's height is drawn at
|
|
3346
|
+
* along the line, as in MapLibre GL JS.
|
|
3347
|
+
*/
|
|
3348
|
+
linePatternWidth: StyleAccessor<number> | null;
|
|
2342
3349
|
/** Whether the style layer draws after an extrusion (see `getTileParameters`). */
|
|
2343
3350
|
depthTested?: boolean;
|
|
2344
3351
|
};
|
|
@@ -2352,54 +3359,125 @@ type GeometryPaint = {
|
|
|
2352
3359
|
hasOutline: boolean;
|
|
2353
3360
|
};
|
|
2354
3361
|
|
|
3362
|
+
/** Whether a fill sets `fill-outline-color`: its outline then has a color of its own. */
|
|
3363
|
+
function hasOutlineColor(styleLayer: BasemapStyleLayer): boolean {
|
|
3364
|
+
return styleLayer.type === 'fill' && styleLayer.paint?.['fill-outline-color'] !== undefined;
|
|
3365
|
+
}
|
|
3366
|
+
|
|
3367
|
+
/** The fill color used when the style leaves it unset. */
|
|
3368
|
+
const DEFAULT_FILL_COLOR = getStylePropertyDefault('fill-color') as number[];
|
|
3369
|
+
|
|
3370
|
+
/** Describes the widths and colors shared by attributes and texture paint. */
|
|
3371
|
+
function getGeometryPaintProperties(styleLayer: BasemapStyleLayer, mode: BasemapMode) {
|
|
3372
|
+
const isLine = styleLayer.type === 'line';
|
|
3373
|
+
const ownOutline = hasOutlineColor(styleLayer);
|
|
3374
|
+
const lineWidth: PaintProperty<number> | null = isLine
|
|
3375
|
+
? {names: ['line-width'], combine: ([width]) => Math.max(0, Number(width ?? 1))}
|
|
3376
|
+
: null;
|
|
3377
|
+
const fillColor: PaintProperty<number[]> = {
|
|
3378
|
+
names: ['fill-color', 'fill-opacity'],
|
|
3379
|
+
combine: ([color, opacity]) =>
|
|
3380
|
+
getGlobeFillColor(withOpacity(color ?? DEFAULT_FILL_COLOR, opacity ?? 1), mode)
|
|
3381
|
+
};
|
|
3382
|
+
const lineColor: PaintProperty<number[]> = {
|
|
3383
|
+
names: isLine
|
|
3384
|
+
? ['line-color', 'line-opacity']
|
|
3385
|
+
: [ownOutline ? 'fill-outline-color' : 'fill-color', 'fill-opacity'],
|
|
3386
|
+
combine: ([color, opacity]) =>
|
|
3387
|
+
withOpacity(
|
|
3388
|
+
color ?? (isLine ? DEFAULT_COLOR : ownOutline ? undefined : DEFAULT_FILL_COLOR),
|
|
3389
|
+
opacity ?? 1
|
|
3390
|
+
)
|
|
3391
|
+
};
|
|
3392
|
+
return {lineWidth, lineColor, fillColor};
|
|
3393
|
+
}
|
|
3394
|
+
|
|
3395
|
+
/** Whether the fill draws an antialiasing outline at the evaluated style zoom. */
|
|
3396
|
+
function drawsFillOutline(styleLayer: BasemapStyleLayer, mode: BasemapMode, antialias: unknown) {
|
|
3397
|
+
return (
|
|
3398
|
+
styleLayer.type === 'fill' &&
|
|
3399
|
+
(hasOutlineColor(styleLayer) || (styleLayer.paint?.['fill-pattern'] === undefined && mode !== 'globe')) &&
|
|
3400
|
+
antialias !== false
|
|
3401
|
+
);
|
|
3402
|
+
}
|
|
3403
|
+
|
|
2355
3404
|
function getGeometryPaint(
|
|
2356
3405
|
styleLayer: BasemapStyleLayer,
|
|
2357
3406
|
mode: BasemapMode,
|
|
2358
3407
|
zoom: number,
|
|
2359
|
-
pattern?: FillPatternGroup
|
|
3408
|
+
pattern?: FillPatternGroup,
|
|
3409
|
+
featureState?: FeatureStateLookup
|
|
2360
3410
|
): GeometryPaint {
|
|
2361
|
-
const
|
|
2362
|
-
|
|
3411
|
+
const properties = getGeometryPaintProperties(styleLayer, mode);
|
|
3412
|
+
/** Builds the lower endpoint attribute for a width or color. */
|
|
3413
|
+
const accessor = <T>(property: PaintProperty<T>) =>
|
|
3414
|
+
getStyleAccessor(styleLayer, property.names, zoom, property.combine, featureState);
|
|
2363
3415
|
|
|
2364
3416
|
// A `fill-pattern` disables `fill-color`: the image supplies the colors and `fill-opacity` the
|
|
2365
3417
|
// opacity, also on a globe. Without its images (sprites loading, or missing) the fill draws
|
|
2366
3418
|
// nothing rather than its color or the default black.
|
|
2367
|
-
const hasFillPattern =
|
|
3419
|
+
const hasFillPattern = styleLayer.type === 'fill' && styleLayer.paint?.['fill-pattern'] !== undefined;
|
|
2368
3420
|
const fillColor = hasFillPattern
|
|
2369
3421
|
? pattern
|
|
2370
|
-
?
|
|
2371
|
-
|
|
2372
|
-
|
|
3422
|
+
? accessor({
|
|
3423
|
+
names: ['fill-opacity'],
|
|
3424
|
+
combine: ([opacity]) => withOpacity([255, 255, 255, 1], opacity ?? 1)
|
|
3425
|
+
})
|
|
2373
3426
|
: {value: TRANSPARENT_COLOR}
|
|
2374
|
-
:
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
3427
|
+
: accessor(properties.fillColor);
|
|
3428
|
+
// MapLibre draws a fill's outline only with `fill-antialias`, in `fill-outline-color` or, without
|
|
3429
|
+
// it, in `fill-color`. That outline is more than antialiasing: it closes the cracks between
|
|
3430
|
+
// polygons that meet at an edge, and it draws a polygon narrower than a pixel, such as a river at
|
|
3431
|
+
// a low zoom, as a line. A patterned fill's own outline draws the pattern, and a globe's fills
|
|
3432
|
+
// are opaque: both are left without it unless the style sets an explicit outline color.
|
|
3433
|
+
const antialias = getCompiledStyleProperty(styleLayer, 'fill-antialias')?.evaluate(getZoomBucket(zoom));
|
|
3434
|
+
const hasOutline = drawsFillOutline(styleLayer, mode, antialias);
|
|
3435
|
+
// A fill's outline is MapLibre's 1 pixel antialiasing line.
|
|
3436
|
+
return {
|
|
3437
|
+
fillColor,
|
|
3438
|
+
lineColor: accessor(properties.lineColor),
|
|
3439
|
+
lineWidth: properties.lineWidth ? accessor(properties.lineWidth) : {value: hasOutline ? 1 : 0},
|
|
3440
|
+
hasOutline
|
|
3441
|
+
};
|
|
3442
|
+
}
|
|
3443
|
+
|
|
3444
|
+
/** Builds attributes at the next style zoom for paint that depends on both features and zoom. */
|
|
3445
|
+
function getNextGeometryPaint(
|
|
3446
|
+
style: GeometryStyle,
|
|
3447
|
+
mode: BasemapMode
|
|
3448
|
+
): Partial<Pick<GeometryPaint, 'lineWidth' | 'lineColor' | 'fillColor'>> {
|
|
3449
|
+
const {styleLayer, zoom, featureState} = style;
|
|
3450
|
+
const properties = getGeometryPaintProperties(styleLayer, mode);
|
|
3451
|
+
/** Samples the upper endpoint when the combined paint depends on both feature and zoom. */
|
|
3452
|
+
const next = <T>(property: PaintProperty<T> | null, current: StyleAccessor<T>) => {
|
|
3453
|
+
if (!property) {
|
|
3454
|
+
return undefined;
|
|
3455
|
+
}
|
|
3456
|
+
const compiled = property.names.map(name => getCompiledStyleProperty(styleLayer, name));
|
|
3457
|
+
if (
|
|
3458
|
+
compiled.some(value => value?.isFeatureDependent) &&
|
|
3459
|
+
compiled.some(value => value?.isZoomDependent)
|
|
3460
|
+
) {
|
|
3461
|
+
const bucket = getZoomBucket(zoom);
|
|
3462
|
+
const {value} = getStyleAccessor(
|
|
2391
3463
|
styleLayer,
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
3464
|
+
property.names,
|
|
3465
|
+
bucket + STYLE_ZOOM_STEP,
|
|
3466
|
+
property.combine,
|
|
3467
|
+
featureState,
|
|
3468
|
+
{exactZoom: true, stepZoom: bucket}
|
|
2395
3469
|
);
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
:
|
|
2402
|
-
|
|
3470
|
+
return {value, updateTrigger: current.updateTrigger};
|
|
3471
|
+
}
|
|
3472
|
+
return undefined;
|
|
3473
|
+
};
|
|
3474
|
+
return {
|
|
3475
|
+
lineWidth: next(properties.lineWidth, style.lineWidth),
|
|
3476
|
+
lineColor: style.drawsLines || style.deferredPaint?.line
|
|
3477
|
+
? next(properties.lineColor, style.lineColor)
|
|
3478
|
+
: undefined,
|
|
3479
|
+
fillColor: style.isFill ? next(properties.fillColor, style.fillColor) : undefined
|
|
3480
|
+
};
|
|
2403
3481
|
}
|
|
2404
3482
|
|
|
2405
3483
|
function getGeometryStyle({
|
|
@@ -2409,7 +3487,9 @@ function getGeometryStyle({
|
|
|
2409
3487
|
zoom,
|
|
2410
3488
|
depthTested,
|
|
2411
3489
|
lineShape,
|
|
2412
|
-
pattern
|
|
3490
|
+
pattern,
|
|
3491
|
+
featureState,
|
|
3492
|
+
lineMetrics
|
|
2413
3493
|
}: {
|
|
2414
3494
|
styleLayer: BasemapStyleLayer;
|
|
2415
3495
|
features: any[];
|
|
@@ -2418,27 +3498,60 @@ function getGeometryStyle({
|
|
|
2418
3498
|
depthTested?: boolean;
|
|
2419
3499
|
lineShape?: LineShape;
|
|
2420
3500
|
pattern?: FillPatternGroup;
|
|
3501
|
+
/** The feature states the style layer's paint reads, if it reads any. */
|
|
3502
|
+
featureState?: FeatureStateLookup;
|
|
3503
|
+
lineMetrics?: boolean;
|
|
2421
3504
|
}): GeometryStyle {
|
|
2422
3505
|
const isLine = styleLayer.type === 'line';
|
|
2423
3506
|
const isFill = styleLayer.type === 'fill';
|
|
2424
3507
|
|
|
2425
|
-
const paint = getGeometryPaint(styleLayer, mode, zoom, pattern);
|
|
2426
|
-
const {fillColor,
|
|
2427
|
-
const hasDashArray = isLine && styleLayer.paint?.['line-dasharray'] !== undefined;
|
|
3508
|
+
const paint = getGeometryPaint(styleLayer, mode, zoom, pattern, featureState);
|
|
3509
|
+
const {fillColor, hasOutline} = paint;
|
|
2428
3510
|
const hasOffset =
|
|
2429
3511
|
isLine &&
|
|
2430
3512
|
(styleLayer.paint?.['line-offset'] !== undefined ||
|
|
2431
3513
|
styleLayer.paint?.['line-gap-width'] !== undefined);
|
|
3514
|
+
// As in MapLibre GL JS, a pattern replaces a gradient, and both replace `line-color`: the image
|
|
3515
|
+
// or the ramp gives the colors, `line-opacity` the opacity.
|
|
3516
|
+
const linePattern = isLine ? pattern : undefined;
|
|
3517
|
+
const lineGradient =
|
|
3518
|
+
isLine && !linePattern ? getLineGradient(styleLayer, lineMetrics) : null;
|
|
3519
|
+
const lineColor =
|
|
3520
|
+
lineGradient || linePattern
|
|
3521
|
+
? getStyleAccessor(
|
|
3522
|
+
styleLayer,
|
|
3523
|
+
['line-opacity'],
|
|
3524
|
+
zoom,
|
|
3525
|
+
([opacity]) => withOpacity([255, 255, 255, 1], opacity ?? 1),
|
|
3526
|
+
featureState
|
|
3527
|
+
)
|
|
3528
|
+
: paint.lineColor;
|
|
3529
|
+
// Dashes, offsets, a gradient, a pattern and a per-feature blur each take vertex attributes, of
|
|
3530
|
+
// which WebGL2 guarantees room for three besides PathLayer's own (see
|
|
3531
|
+
// `createSegmentAttributeUpdate`): dashes and a pattern take two, the others one. A gradient
|
|
3532
|
+
// with an offset draws without dashes. A pattern draws without dashes, as in MapLibre.
|
|
3533
|
+
const hasDashArray =
|
|
3534
|
+
isLine &&
|
|
3535
|
+
styleLayer.paint?.['line-dasharray'] !== undefined &&
|
|
3536
|
+
!linePattern &&
|
|
3537
|
+
!(lineGradient && hasOffset);
|
|
2432
3538
|
const styleBlur =
|
|
2433
3539
|
isLine && styleLayer.paint?.['line-blur'] !== undefined
|
|
2434
|
-
? getStyleAccessor(
|
|
2435
|
-
|
|
3540
|
+
? getStyleAccessor(
|
|
3541
|
+
styleLayer,
|
|
3542
|
+
['line-blur'],
|
|
3543
|
+
zoom,
|
|
3544
|
+
([blur]) => Math.max(0, Number(blur) || 0),
|
|
3545
|
+
featureState
|
|
2436
3546
|
)
|
|
2437
3547
|
: null;
|
|
2438
|
-
// A per-feature blur takes a vertex attribute, which a path with dashes and
|
|
2439
|
-
// for (see LineBlurExtension): such lines
|
|
3548
|
+
// A per-feature blur takes a vertex attribute, which a path with dashes and an offset or a
|
|
3549
|
+
// gradient, or with a pattern and an offset, has no room for (see LineBlurExtension): such lines
|
|
3550
|
+
// draw sharp.
|
|
2440
3551
|
const lineBlur =
|
|
2441
|
-
styleBlur &&
|
|
3552
|
+
styleBlur &&
|
|
3553
|
+
(typeof styleBlur.value !== 'function' ||
|
|
3554
|
+
!((hasDashArray && (hasOffset || lineGradient)) || (linePattern && hasOffset)))
|
|
2442
3555
|
? styleBlur
|
|
2443
3556
|
: null;
|
|
2444
3557
|
const hasBlur = lineBlur !== null;
|
|
@@ -2454,13 +3567,18 @@ function getGeometryStyle({
|
|
|
2454
3567
|
Math.max(0, Number(width ?? 1)),
|
|
2455
3568
|
Number(gap ?? 0),
|
|
2456
3569
|
Math.max(0, Number(blur) || 0)
|
|
2457
|
-
)
|
|
3570
|
+
),
|
|
3571
|
+
featureState
|
|
2458
3572
|
)
|
|
2459
3573
|
: paint.lineWidth;
|
|
2460
3574
|
// The style spec evaluates zoom in `line-dasharray` at integer zooms only.
|
|
2461
3575
|
const dashArray: StyleAccessor<[number, number]> | null = hasDashArray
|
|
2462
|
-
? getStyleAccessor(
|
|
2463
|
-
|
|
3576
|
+
? getStyleAccessor(
|
|
3577
|
+
styleLayer,
|
|
3578
|
+
['line-dasharray'],
|
|
3579
|
+
Math.floor(zoom),
|
|
3580
|
+
([dasharray]) => getDashArray(dasharray),
|
|
3581
|
+
featureState
|
|
2464
3582
|
)
|
|
2465
3583
|
: null;
|
|
2466
3584
|
const lineOffset = hasOffset
|
|
@@ -2473,39 +3591,40 @@ function getGeometryStyle({
|
|
|
2473
3591
|
Math.max(0, Number(gap ?? 0)),
|
|
2474
3592
|
Math.max(0, Number(width ?? 1)),
|
|
2475
3593
|
hasBlur ? Math.max(0, Number(blur) || 0) : 0
|
|
2476
|
-
]
|
|
3594
|
+
],
|
|
3595
|
+
featureState
|
|
2477
3596
|
)
|
|
2478
3597
|
: null;
|
|
2479
3598
|
// Where a wide blur makes a gap's two lines overlap, each draws only its side of the gap's
|
|
2480
3599
|
// center. That takes the center's `line-offset` for the whole layer.
|
|
2481
3600
|
const gapOffset = isBlurredGap
|
|
2482
|
-
? getStyleAccessor(
|
|
3601
|
+
? getStyleAccessor(
|
|
3602
|
+
styleLayer,
|
|
3603
|
+
['line-offset'],
|
|
3604
|
+
zoom,
|
|
3605
|
+
([offset]) => Number(offset ?? 0),
|
|
3606
|
+
featureState
|
|
3607
|
+
)
|
|
2483
3608
|
: null;
|
|
2484
3609
|
const gapWidth = hasOffset
|
|
2485
|
-
? getStyleAccessor(
|
|
3610
|
+
? getStyleAccessor(
|
|
3611
|
+
styleLayer,
|
|
3612
|
+
['line-gap-width'],
|
|
3613
|
+
zoom,
|
|
3614
|
+
([gap]) => Number(gap ?? 0),
|
|
3615
|
+
featureState
|
|
3616
|
+
)
|
|
2486
3617
|
: null;
|
|
2487
3618
|
const hasFillStyle =
|
|
2488
3619
|
isFill &&
|
|
2489
3620
|
(styleLayer.paint?.['fill-pattern'] !== undefined ||
|
|
2490
3621
|
styleLayer.paint?.['fill-translate'] !== undefined);
|
|
3622
|
+
const hasLineTranslate = isLine && styleLayer.paint?.['line-translate'] !== undefined;
|
|
2491
3623
|
|
|
2492
|
-
// A constant transparent color or zero width draws nothing, so its sublayers are left out
|
|
3624
|
+
// A constant transparent color or zero width draws nothing, so its sublayers are left out
|
|
3625
|
+
// unless their geometry is kept for continuous zoom paint or batch stability.
|
|
2493
3626
|
const drawsFill = isFill && !isTransparent(fillColor);
|
|
2494
3627
|
const drawsLines = (isLine || hasOutline) && !isTransparent(lineColor) && lineWidth.value !== 0;
|
|
2495
|
-
// A line whose width is 0 at this zoom step, and which draws at the next step or the previous
|
|
2496
|
-
// one, is kept for that step (see `renderSubLayers`). One that draws at neither, as many lines
|
|
2497
|
-
// do below the zoom where their width starts, or that stays transparent, is left out. Its color
|
|
2498
|
-
// at this step does not matter: at width 0 it draws nothing. Lines with an offset or a blur take
|
|
2499
|
-
// their width in attributes, not from `ZoomPaintExtension`.
|
|
2500
|
-
const isZeroWidth =
|
|
2501
|
-
isLine &&
|
|
2502
|
-
lineWidth.value === 0 &&
|
|
2503
|
-
!hasOffset &&
|
|
2504
|
-
!hasBlur &&
|
|
2505
|
-
[zoom - STYLE_ZOOM_STEP, zoom + STYLE_ZOOM_STEP].some(stepZoom => {
|
|
2506
|
-
const stepPaint = getGeometryPaint(styleLayer, mode, stepZoom);
|
|
2507
|
-
return stepPaint.lineWidth.value !== 0 && !isTransparent(stepPaint.lineColor);
|
|
2508
|
-
});
|
|
2509
3628
|
|
|
2510
3629
|
return {
|
|
2511
3630
|
styleLayer,
|
|
@@ -2515,7 +3634,7 @@ function getGeometryStyle({
|
|
|
2515
3634
|
isFill,
|
|
2516
3635
|
drawsFill,
|
|
2517
3636
|
drawsLines,
|
|
2518
|
-
|
|
3637
|
+
featureState,
|
|
2519
3638
|
fillColor,
|
|
2520
3639
|
lineColor,
|
|
2521
3640
|
lineWidth,
|
|
@@ -2526,28 +3645,134 @@ function getGeometryStyle({
|
|
|
2526
3645
|
gapOffset,
|
|
2527
3646
|
isBlurredGap,
|
|
2528
3647
|
hasFillStyle,
|
|
3648
|
+
hasLineTranslate,
|
|
2529
3649
|
lineShape,
|
|
2530
3650
|
pattern,
|
|
3651
|
+
lineGradient,
|
|
3652
|
+
lineGradientFallbackColor: lineGradient ? paint.lineColor : null,
|
|
3653
|
+
linePatternWidth: linePattern
|
|
3654
|
+
? getStyleAccessor(
|
|
3655
|
+
styleLayer,
|
|
3656
|
+
['line-width'],
|
|
3657
|
+
Math.floor(zoom),
|
|
3658
|
+
([width]) => Math.max(0, Number(width ?? 1)),
|
|
3659
|
+
featureState
|
|
3660
|
+
)
|
|
3661
|
+
: null,
|
|
2531
3662
|
depthTested
|
|
2532
3663
|
};
|
|
2533
3664
|
}
|
|
2534
3665
|
|
|
3666
|
+
/**
|
|
3667
|
+
* The ramp of a line's `line-gradient`, or null without one. As in MapLibre GL JS, a gradient
|
|
3668
|
+
* needs a GeoJSON source with `lineMetrics`: MapLibre rejects the style otherwise, and here the
|
|
3669
|
+
* line draws in its `line-color`, with a warning.
|
|
3670
|
+
*/
|
|
3671
|
+
function getLineGradient(
|
|
3672
|
+
styleLayer: BasemapStyleLayer,
|
|
3673
|
+
lineMetrics: boolean | undefined
|
|
3674
|
+
): LineGradientRamp | null {
|
|
3675
|
+
if (styleLayer.paint?.['line-gradient'] === undefined) {
|
|
3676
|
+
return null;
|
|
3677
|
+
}
|
|
3678
|
+
if (!lineMetrics) {
|
|
3679
|
+
if (!warnedGradientLayers.has(styleLayer.id)) {
|
|
3680
|
+
warnedGradientLayers.add(styleLayer.id);
|
|
3681
|
+
log.warn(
|
|
3682
|
+
`[BasemapLayer] layer "${styleLayer.id}" sets line-gradient, which needs a GeoJSON ` +
|
|
3683
|
+
'source with lineMetrics; drawn in line-color'
|
|
3684
|
+
)();
|
|
3685
|
+
}
|
|
3686
|
+
return null;
|
|
3687
|
+
}
|
|
3688
|
+
return getLineGradientRamp(styleLayer);
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3691
|
+
/** Whether a geometry style can use paint from the texture. */
|
|
3692
|
+
function takesZoomPaint(style: GeometryStyle): boolean {
|
|
3693
|
+
const paint = style.styleLayer.paint;
|
|
3694
|
+
return !(
|
|
3695
|
+
style.lineOffset ||
|
|
3696
|
+
style.hasFillStyle ||
|
|
3697
|
+
paint?.['line-blur'] !== undefined ||
|
|
3698
|
+
paint?.['line-gradient'] !== undefined ||
|
|
3699
|
+
paint?.['line-pattern'] !== undefined
|
|
3700
|
+
);
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
/**
|
|
3704
|
+
* Keeps otherwise invisible geometry if its paint can appear before the next step. A line whose
|
|
3705
|
+
* width is 0 at this zoom step, and which draws at the next step or the previous one, is kept for
|
|
3706
|
+
* that step (see `renderSubLayers`). One that draws at neither, as many lines do below the zoom
|
|
3707
|
+
* where their width starts, is left out. Lines with an offset or a blur take their width in
|
|
3708
|
+
* attributes and do not need this test.
|
|
3709
|
+
*/
|
|
3710
|
+
function keepGeometryPaint(style: GeometryStyle, mode: BasemapMode): void {
|
|
3711
|
+
if (style.deferredPaint !== undefined) {
|
|
3712
|
+
return;
|
|
3713
|
+
}
|
|
3714
|
+
style.deferredPaint = null;
|
|
3715
|
+
const testFill = style.isFill && !style.drawsFill;
|
|
3716
|
+
const testLine = !style.drawsLines && (style.isLine || style.lineWidth.value === 1);
|
|
3717
|
+
if (!testFill && !testLine) {
|
|
3718
|
+
return;
|
|
3719
|
+
}
|
|
3720
|
+
/** Evaluates an adjacent step with the same style and feature state as this one. */
|
|
3721
|
+
const paintAt = (step: number) =>
|
|
3722
|
+
getGeometryPaint(style.styleLayer, mode, step, undefined, style.featureState);
|
|
3723
|
+
const bucket = getZoomBucket(style.zoom);
|
|
3724
|
+
const next = paintAt(bucket + STYLE_ZOOM_STEP);
|
|
3725
|
+
const fill = testFill && !isTransparent(next.fillColor);
|
|
3726
|
+
let line =
|
|
3727
|
+
testLine &&
|
|
3728
|
+
(style.lineWidth.value !== 0 || next.lineWidth.value !== 0) &&
|
|
3729
|
+
(!isTransparent(style.lineColor) || !isTransparent(next.lineColor));
|
|
3730
|
+
if (!line && style.isLine && style.lineWidth.value === 0) {
|
|
3731
|
+
// The previous width keeps the batch stable. Only the current and next paint affect visibility.
|
|
3732
|
+
const previous = paintAt(bucket - STYLE_ZOOM_STEP);
|
|
3733
|
+
line = previous.lineWidth.value !== 0 && !isTransparent(previous.lineColor);
|
|
3734
|
+
}
|
|
3735
|
+
if (fill || line) {
|
|
3736
|
+
style.deferredPaint = {fill, line};
|
|
3737
|
+
}
|
|
3738
|
+
}
|
|
3739
|
+
|
|
2535
3740
|
/**
|
|
2536
3741
|
* The key under which consecutive style layers can draw as one sublayer, or null when this one
|
|
2537
3742
|
* draws alone. Style layers share a sublayer when everything deck.gl applies to a whole layer is
|
|
2538
|
-
* the same: a fill without an outline, or a line's cap, join and miter limit.
|
|
3743
|
+
* the same: a fill without an outline, or a line's cap, join and miter limit. A fill with an
|
|
3744
|
+
* outline draws alone, its fill and then its outline: a batch would draw all of its fills before
|
|
3745
|
+
* or after all of its outlines, and then hide a later layer's outline below an earlier layer's fill,
|
|
3746
|
+
* or draw an earlier layer's outline over a later layer's fill. Solid and dashed
|
|
2539
3747
|
* lines share a sublayer: the solid ones draw with a dash array without gaps. Lines with an
|
|
2540
3748
|
* offset, a gap or a blur, and fills with a pattern or a translation, draw alone.
|
|
2541
3749
|
*/
|
|
2542
3750
|
function getBatchKey(style: GeometryStyle): string | null {
|
|
2543
3751
|
if (style.isFill) {
|
|
2544
|
-
return style.drawsLines || style.hasFillStyle ? null : 'fill';
|
|
3752
|
+
return style.drawsLines || style.deferredPaint?.line || style.hasFillStyle ? null : 'fill';
|
|
2545
3753
|
}
|
|
2546
|
-
if (
|
|
3754
|
+
if (
|
|
3755
|
+
style.lineOffset ||
|
|
3756
|
+
style.lineBlur ||
|
|
3757
|
+
style.lineGradient ||
|
|
3758
|
+
style.pattern ||
|
|
3759
|
+
style.hasLineTranslate ||
|
|
3760
|
+
!style.lineShape
|
|
3761
|
+
) {
|
|
2547
3762
|
return null;
|
|
2548
3763
|
}
|
|
2549
|
-
|
|
2550
|
-
|
|
3764
|
+
return `line-${getLineShapeKey(style.lineShape)}`;
|
|
3765
|
+
}
|
|
3766
|
+
|
|
3767
|
+
function getLineShapeKey({
|
|
3768
|
+
lineCapRounded,
|
|
3769
|
+
lineCapSquare,
|
|
3770
|
+
lineJointRounded,
|
|
3771
|
+
lineMiterLimit
|
|
3772
|
+
}: LineShape): string {
|
|
3773
|
+
// Keep the existing sublayer ID suffixes for butt and round caps.
|
|
3774
|
+
const cap = lineCapSquare ? 'square' : lineCapRounded;
|
|
3775
|
+
return `${cap}-${lineJointRounded}-${lineMiterLimit}`;
|
|
2551
3776
|
}
|
|
2552
3777
|
|
|
2553
3778
|
/** Whether features include polygons and lines, per tile content and style layer. */
|
|
@@ -2679,31 +3904,34 @@ function createGeometrySubLayer({
|
|
|
2679
3904
|
idSuffix?: string;
|
|
2680
3905
|
}) {
|
|
2681
3906
|
// Paint that is the same for all features of a style layer is taken from a texture (see
|
|
2682
|
-
// `ZoomPaintExtension`)
|
|
2683
|
-
// with
|
|
2684
|
-
//
|
|
3907
|
+
// `ZoomPaintExtension`). Composite paint blends two attributes using factors from that texture.
|
|
3908
|
+
// Lines with an offset compute it from the width on the CPU. They keep their paint in attributes,
|
|
3909
|
+
// as do blurred, gradient and patterned lines and patterned or translated fills.
|
|
2685
3910
|
const zoomPaintContext = props[ZOOM_PAINT_CONTEXT] as ZoomPaintContext | null | undefined;
|
|
2686
|
-
const
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
//
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
? allStyles
|
|
2697
|
-
: allStyles.filter(style => style.drawsFill || style.drawsLines);
|
|
3911
|
+
const useZoomPaint = Boolean(
|
|
3912
|
+
zoomPaintContext && allStyles.length <= MAX_ZOOM_PAINT_PARTS && takesZoomPaint(allStyles[0])
|
|
3913
|
+
);
|
|
3914
|
+
if (useZoomPaint) {
|
|
3915
|
+
allStyles.forEach(style => keepGeometryPaint(style, mode));
|
|
3916
|
+
}
|
|
3917
|
+
// Without the texture, style layers that draw nothing at the bucket zoom are left out.
|
|
3918
|
+
const styles = allStyles.filter(
|
|
3919
|
+
style => style.drawsFill || style.drawsLines || (useZoomPaint && style.deferredPaint)
|
|
3920
|
+
);
|
|
2698
3921
|
if (styles.length === 0) {
|
|
2699
3922
|
return null;
|
|
2700
3923
|
}
|
|
2701
3924
|
const [first] = styles;
|
|
2702
3925
|
// A batch draws lines when any of its style layers does, or keeps lines at width 0. A sublayer
|
|
2703
|
-
//
|
|
2704
|
-
const drawsFill = styles.some(
|
|
2705
|
-
|
|
2706
|
-
|
|
3926
|
+
// kept only for deferred paint is hidden while its paint draws nothing at the viewport zoom.
|
|
3927
|
+
const drawsFill = styles.some(
|
|
3928
|
+
style => style.drawsFill || (useZoomPaint && style.deferredPaint?.fill)
|
|
3929
|
+
);
|
|
3930
|
+
const drawsLines = styles.some(
|
|
3931
|
+
style => style.drawsLines || (useZoomPaint && style.deferredPaint?.line)
|
|
3932
|
+
);
|
|
3933
|
+
const deferredZoomPaint =
|
|
3934
|
+
useZoomPaint && !styles.some(style => style.drawsFill || style.drawsLines);
|
|
2707
3935
|
const {
|
|
2708
3936
|
isFill,
|
|
2709
3937
|
lineShape,
|
|
@@ -2714,9 +3942,14 @@ function createGeometrySubLayer({
|
|
|
2714
3942
|
gapOffset,
|
|
2715
3943
|
isBlurredGap,
|
|
2716
3944
|
hasFillStyle,
|
|
3945
|
+
hasLineTranslate,
|
|
2717
3946
|
pattern,
|
|
3947
|
+
lineGradient,
|
|
3948
|
+
lineGradientFallbackColor,
|
|
3949
|
+
linePatternWidth,
|
|
2718
3950
|
zoom
|
|
2719
3951
|
} = first;
|
|
3952
|
+
const linePattern = isFill ? undefined : pattern;
|
|
2720
3953
|
if (!drawsFill && !drawsLines) {
|
|
2721
3954
|
return null;
|
|
2722
3955
|
}
|
|
@@ -2736,7 +3969,7 @@ function createGeometrySubLayer({
|
|
|
2736
3969
|
const merge = <T>(get: (style: GeometryStyle) => StyleAccessor<T>) =>
|
|
2737
3970
|
mergeStyleAccessors(styles.map(get), partIndices);
|
|
2738
3971
|
const zoomPaint =
|
|
2739
|
-
zoomPaintContext &&
|
|
3972
|
+
zoomPaintContext && useZoomPaint
|
|
2740
3973
|
? zoomPaintContext.get(
|
|
2741
3974
|
styles.map(style => style.styleLayer),
|
|
2742
3975
|
mode
|
|
@@ -2749,17 +3982,68 @@ function createGeometrySubLayer({
|
|
|
2749
3982
|
// The width attribute scales the texture's width of its style layer, which is 1 where it is per
|
|
2750
3983
|
// feature.
|
|
2751
3984
|
const lineWidth = merge(style => perFeature(style.lineWidth, 1));
|
|
3985
|
+
const nextPaint = zoomPaint
|
|
3986
|
+
? styles.map(style => getNextGeometryPaint(style, mode))
|
|
3987
|
+
: [];
|
|
3988
|
+
const hasComposite = nextPaint.some(paint => paint.lineWidth || paint.lineColor || paint.fillColor);
|
|
3989
|
+
/** Merges upper endpoint attributes with the current value for parts that do not blend. */
|
|
3990
|
+
const mergeNext = <T>(
|
|
3991
|
+
next: (paint: (typeof nextPaint)[number]) => StyleAccessor<T> | undefined,
|
|
3992
|
+
current: (style: GeometryStyle) => StyleAccessor<T>,
|
|
3993
|
+
constant: T
|
|
3994
|
+
) =>
|
|
3995
|
+
mergeStyleAccessors(
|
|
3996
|
+
styles.map((style, index) => next(nextPaint[index]) ?? perFeature(current(style), constant)),
|
|
3997
|
+
partIndices
|
|
3998
|
+
);
|
|
3999
|
+
const nextLineWidth = hasComposite
|
|
4000
|
+
? mergeNext(paint => paint.lineWidth, style => style.lineWidth, 1)
|
|
4001
|
+
: undefined;
|
|
4002
|
+
const nextLineColor = hasComposite
|
|
4003
|
+
? mergeNext(paint => paint.lineColor, style => style.lineColor, TRANSPARENT_COLOR)
|
|
4004
|
+
: undefined;
|
|
4005
|
+
const nextFillColor = hasComposite && isFill
|
|
4006
|
+
? mergeNext(paint => paint.fillColor, style => style.fillColor, TRANSPARENT_COLOR)
|
|
4007
|
+
: undefined;
|
|
2752
4008
|
// A dash array without gaps draws a solid line.
|
|
2753
4009
|
const dashArray = styles.some(style => style.dashArray)
|
|
2754
4010
|
? merge(style => style.dashArray ?? SOLID_DASH_ARRAY)
|
|
2755
4011
|
: null;
|
|
2756
4012
|
|
|
4013
|
+
const packPath = Boolean(dashArray && hasComposite);
|
|
4014
|
+
const zoomPaintExtension = packPath
|
|
4015
|
+
? DASHED_COMPOSITE_ZOOM_PAINT_EXTENSION
|
|
4016
|
+
: hasComposite
|
|
4017
|
+
? COMPOSITE_ZOOM_PAINT_EXTENSION
|
|
4018
|
+
: ZOOM_PAINT_EXTENSION;
|
|
4019
|
+
/** Packs each dashed feature's style part, upper width and upper color into one attribute. */
|
|
4020
|
+
const getNextDashedPaint = packPath && nextLineWidth && nextLineColor
|
|
4021
|
+
? (feature: any, info: {index: number}) => {
|
|
4022
|
+
const width = nextLineWidth.value;
|
|
4023
|
+
const color = nextLineColor.value;
|
|
4024
|
+
return [
|
|
4025
|
+
partIndices[info.index] ?? 0,
|
|
4026
|
+
typeof width === 'function' ? width(feature, info) : width,
|
|
4027
|
+
...packZoomPaintColor(typeof color === 'function' ? color(feature, info) : color)
|
|
4028
|
+
];
|
|
4029
|
+
}
|
|
4030
|
+
: undefined;
|
|
4031
|
+
|
|
2757
4032
|
const offsetValue = lineOffset?.value;
|
|
4033
|
+
const drawsGap = gapWidth && (typeof gapWidth.value === 'function' || gapWidth.value > 0);
|
|
4034
|
+
const takesSquareGapCap = drawsGap && lineShape?.lineCapSquare;
|
|
4035
|
+
const getOffsetValues = (feature: any) =>
|
|
4036
|
+
typeof offsetValue === 'function' ? offsetValue(feature) : offsetValue!;
|
|
2758
4037
|
const getOffset = (side: number) => (feature: any) => {
|
|
2759
|
-
const [offset, gap, width, blur] =
|
|
2760
|
-
typeof offsetValue === 'function' ? offsetValue(feature) : offsetValue!;
|
|
4038
|
+
const [offset, gap, width, blur] = getOffsetValues(feature);
|
|
2761
4039
|
return getLineOffset(offset, gap, width, side, blur);
|
|
2762
4040
|
};
|
|
4041
|
+
const getSquareGapCap = (feature: any) => {
|
|
4042
|
+
const [, gap, width] = getOffsetValues(feature);
|
|
4043
|
+
return gap > 0 && width > 0 ? gap / 2 + width : 0;
|
|
4044
|
+
};
|
|
4045
|
+
const offsetTrigger =
|
|
4046
|
+
typeof offsetValue === 'function' ? lineOffset?.updateTrigger : offsetValue;
|
|
2763
4047
|
const getBlurGap = (side: number) =>
|
|
2764
4048
|
gapOffset && typeof gapOffset.value !== 'function'
|
|
2765
4049
|
? {blurGapSide: side, blurGapOffset: gapOffset.value}
|
|
@@ -2777,14 +4061,24 @@ function createGeometrySubLayer({
|
|
|
2777
4061
|
// deck.gl draws lines without antialiasing and cut to a line's pixels by `FillOutlineExtension`.
|
|
2778
4062
|
const fadesLines = drawsLines && !isFill;
|
|
2779
4063
|
const drawsOutline = drawsLines && isFill;
|
|
4064
|
+
// `line-translate` takes the extension of `fill-translate`, which moves any vertex.
|
|
4065
|
+
const translatesLine = !isFill && hasLineTranslate;
|
|
4066
|
+
// Offset joins keep PathLayer's cut. The default miter limit is reachable, so sharp turns
|
|
4067
|
+
// still need the shape shader to change that cut to a flip bevel.
|
|
4068
|
+
const needsLineShape =
|
|
4069
|
+
fadesLines && lineShape &&
|
|
4070
|
+
(lineShape.lineCapSquare ||
|
|
4071
|
+
(!lineOffset && !lineShape.lineJointRounded && lineShape.lineMiterLimit + 1 < MAX_LINE_SHAPE_MITER_RATIO));
|
|
2780
4072
|
const geometryExtensions =
|
|
2781
|
-
dashArray || lineOffset || fadesLines || drawsOutline || zoomPaint
|
|
4073
|
+
dashArray || lineOffset || fadesLines || drawsOutline || zoomPaint || translatesLine
|
|
2782
4074
|
? [
|
|
2783
4075
|
...(baseProps.extensions || []),
|
|
2784
|
-
...(dashArray
|
|
4076
|
+
...(dashArray
|
|
4077
|
+
? [lineOffset ? DASH_OFFSET_EXTENSION : DASH_EXTENSION, LINE_DASH_EXTENSION]
|
|
4078
|
+
: []),
|
|
2785
4079
|
...(!dashArray && lineOffset ? [OFFSET_EXTENSION] : []),
|
|
2786
4080
|
// Before the fade, which widens the stroke once its width is final.
|
|
2787
|
-
...(zoomPaint ? [
|
|
4081
|
+
...(zoomPaint ? [zoomPaintExtension] : []),
|
|
2788
4082
|
...(fadesLines
|
|
2789
4083
|
? [
|
|
2790
4084
|
typeof lineBlur?.value === 'function'
|
|
@@ -2792,7 +4086,11 @@ function createGeometrySubLayer({
|
|
|
2792
4086
|
: LINE_BLUR_EXTENSION
|
|
2793
4087
|
]
|
|
2794
4088
|
: []),
|
|
2795
|
-
...(drawsOutline ? [FILL_OUTLINE_EXTENSION] : [])
|
|
4089
|
+
...(drawsOutline ? [FILL_OUTLINE_EXTENSION] : []),
|
|
4090
|
+
...(needsLineShape ? [LINE_SHAPE_EXTENSION] : []),
|
|
4091
|
+
...(lineGradient ? [LINE_GRADIENT_EXTENSION] : []),
|
|
4092
|
+
...(linePattern ? [LINE_PATTERN_EXTENSION] : []),
|
|
4093
|
+
...(translatesLine ? [FILL_TRANSLATE_EXTENSION] : [])
|
|
2796
4094
|
]
|
|
2797
4095
|
: null;
|
|
2798
4096
|
// `fill-pattern` and `fill-translate` add their extensions to these, so an outlined fill keeps
|
|
@@ -2809,9 +4107,9 @@ function createGeometrySubLayer({
|
|
|
2809
4107
|
|
|
2810
4108
|
const layerProps = {
|
|
2811
4109
|
...baseProps,
|
|
2812
|
-
// Not drawn, picked or highlighted while all of its lines are kept at width 0.
|
|
2813
|
-
...(isHidden ? {visible: false, pickable: false} : {}),
|
|
2814
4110
|
id: `${getStyleSubLayerId(props.id, styleLayerIds)}${idSuffix}`,
|
|
4111
|
+
[STYLE_LAYER_IDS]: styles.map(style => style.styleLayer.id),
|
|
4112
|
+
[STYLE_LAYER_PARTS]: styles.length === 1 ? null : partIndices,
|
|
2815
4113
|
data,
|
|
2816
4114
|
stroked: drawsLines,
|
|
2817
4115
|
filled: drawsFill,
|
|
@@ -2824,6 +4122,17 @@ function createGeometrySubLayer({
|
|
|
2824
4122
|
...(zoomPaint
|
|
2825
4123
|
? {
|
|
2826
4124
|
zoomPaint,
|
|
4125
|
+
// Invisible retained paint is skipped in drawing, picking and highlighting.
|
|
4126
|
+
...(deferredZoomPaint ? {deferredZoomPaint} : {}),
|
|
4127
|
+
...(hasComposite
|
|
4128
|
+
? {
|
|
4129
|
+
zoomPaintBucket: getZoomBucket(zoom),
|
|
4130
|
+
getNextLineWidth: nextLineWidth?.value,
|
|
4131
|
+
getNextLineColor: nextLineColor?.value,
|
|
4132
|
+
...(nextFillColor ? {getNextFillColor: nextFillColor.value} : {}),
|
|
4133
|
+
...(getNextDashedPaint ? {getNextDashedPaint} : {})
|
|
4134
|
+
}
|
|
4135
|
+
: {}),
|
|
2827
4136
|
getStylePart:
|
|
2828
4137
|
styles.length === 1
|
|
2829
4138
|
? 0
|
|
@@ -2834,7 +4143,23 @@ function createGeometrySubLayer({
|
|
|
2834
4143
|
...(fadesLines ? {getBlur: lineBlur ? lineBlur.value : 0} : {}),
|
|
2835
4144
|
...getBlurGap(1),
|
|
2836
4145
|
...fillStyleProps,
|
|
4146
|
+
...(lineGradient
|
|
4147
|
+
? {
|
|
4148
|
+
lineGradientImage: lineGradient.image,
|
|
4149
|
+
textureParameters: lineGradient.textureParameters,
|
|
4150
|
+
getLineClip,
|
|
4151
|
+
getLineGradientFallbackColor: lineGradientFallbackColor?.value
|
|
4152
|
+
}
|
|
4153
|
+
: {}),
|
|
4154
|
+
...(linePattern && linePatternWidth
|
|
4155
|
+
? {
|
|
4156
|
+
...getLinePatternProps(linePattern, zoom),
|
|
4157
|
+
getLinePatternWidth: linePatternWidth.value
|
|
4158
|
+
}
|
|
4159
|
+
: {}),
|
|
4160
|
+
...(translatesLine ? getTranslateProps(first.styleLayer, zoom, 'line') : {}),
|
|
2837
4161
|
...(offsetValue ? {getOffset: getOffset(1)} : {}),
|
|
4162
|
+
...(takesSquareGapCap ? {getSquareGapCap} : {}),
|
|
2838
4163
|
...(lineDashArray
|
|
2839
4164
|
? {
|
|
2840
4165
|
getDashArray: lineDashArray.value as any,
|
|
@@ -2847,9 +4172,33 @@ function createGeometrySubLayer({
|
|
|
2847
4172
|
getFillPatternScale: pattern ? Math.floor(zoom) : undefined,
|
|
2848
4173
|
getLineColor: lineColor.updateTrigger,
|
|
2849
4174
|
getLineWidth: lineWidth.updateTrigger,
|
|
4175
|
+
...(hasComposite
|
|
4176
|
+
? {
|
|
4177
|
+
getNextLineWidth: nextLineWidth?.updateTrigger,
|
|
4178
|
+
getNextLineColor: nextLineColor?.updateTrigger,
|
|
4179
|
+
getNextFillColor: nextFillColor?.updateTrigger,
|
|
4180
|
+
...(packPath
|
|
4181
|
+
? {
|
|
4182
|
+
getNextDashedPaint: [
|
|
4183
|
+
nextLineWidth?.updateTrigger,
|
|
4184
|
+
nextLineColor?.updateTrigger,
|
|
4185
|
+
...styles.flatMap(({styleLayer: {paint}}) => [
|
|
4186
|
+
paint?.['line-width'],
|
|
4187
|
+
paint?.['line-color'],
|
|
4188
|
+
paint?.['line-opacity']
|
|
4189
|
+
])
|
|
4190
|
+
]
|
|
4191
|
+
}
|
|
4192
|
+
: {})
|
|
4193
|
+
}
|
|
4194
|
+
: {}),
|
|
2850
4195
|
getDashArray: lineDashArray?.updateTrigger,
|
|
2851
|
-
getOffset:
|
|
2852
|
-
|
|
4196
|
+
getOffset: offsetTrigger,
|
|
4197
|
+
getSquareGapCap: takesSquareGapCap ? offsetTrigger : undefined,
|
|
4198
|
+
getBlur: lineBlur?.updateTrigger,
|
|
4199
|
+
getLinePattern: linePattern ? Math.floor(zoom) : undefined,
|
|
4200
|
+
getLinePatternWidth: linePatternWidth?.updateTrigger,
|
|
4201
|
+
getLineGradientFallbackColor: lineGradientFallbackColor?.updateTrigger
|
|
2853
4202
|
},
|
|
2854
4203
|
lineWidthUnits: 'pixels',
|
|
2855
4204
|
lineWidthMinPixels: 0,
|
|
@@ -2860,8 +4209,8 @@ function createGeometrySubLayer({
|
|
|
2860
4209
|
pointRadiusMinPixels: 0,
|
|
2861
4210
|
parameters: getTileParameters(mode, depthTested)
|
|
2862
4211
|
};
|
|
2863
|
-
const layer = getTileGeoJsonLayer(props, layerProps);
|
|
2864
|
-
if (!
|
|
4212
|
+
const layer = getTileGeoJsonLayer(props, layerProps, zoomPaint ? zoom : undefined);
|
|
4213
|
+
if (!drawsGap) {
|
|
2865
4214
|
return layer;
|
|
2866
4215
|
}
|
|
2867
4216
|
|
|
@@ -2975,23 +4324,31 @@ function createExtrusionSubLayer({
|
|
|
2975
4324
|
styleLayer,
|
|
2976
4325
|
features,
|
|
2977
4326
|
zoom,
|
|
2978
|
-
light = DEFAULT_FILL_EXTRUSION_LIGHT
|
|
4327
|
+
light = DEFAULT_FILL_EXTRUSION_LIGHT,
|
|
4328
|
+
featureState
|
|
2979
4329
|
}: {
|
|
2980
4330
|
props: any;
|
|
2981
4331
|
styleLayer: BasemapStyleLayer;
|
|
2982
4332
|
features: any[];
|
|
2983
4333
|
zoom: number;
|
|
2984
4334
|
light?: FillExtrusionLight;
|
|
4335
|
+
/** The feature states the style layer's paint reads, if it reads any. */
|
|
4336
|
+
featureState?: FeatureStateLookup;
|
|
2985
4337
|
}) {
|
|
2986
4338
|
const paint = getPaint(styleLayer, zoom);
|
|
2987
|
-
const color = getStyleAccessor(
|
|
2988
|
-
|
|
4339
|
+
const color = getStyleAccessor(
|
|
4340
|
+
styleLayer,
|
|
4341
|
+
['fill-extrusion-color'],
|
|
4342
|
+
zoom,
|
|
4343
|
+
([value]) => withOpacity([...(value ?? DEFAULT_COLOR).slice(0, 3), 1]),
|
|
4344
|
+
featureState
|
|
2989
4345
|
);
|
|
2990
4346
|
const base = getStyleAccessor(
|
|
2991
4347
|
styleLayer,
|
|
2992
4348
|
['fill-extrusion-height', 'fill-extrusion-base'],
|
|
2993
4349
|
zoom,
|
|
2994
|
-
([height, baseValue]) => getExtrusionBounds(height, baseValue)[0]
|
|
4350
|
+
([height, baseValue]) => getExtrusionBounds(height, baseValue)[0],
|
|
4351
|
+
featureState
|
|
2995
4352
|
);
|
|
2996
4353
|
const elevation = getStyleAccessor(
|
|
2997
4354
|
styleLayer,
|
|
@@ -3000,13 +4357,17 @@ function createExtrusionSubLayer({
|
|
|
3000
4357
|
([height, baseValue]) => {
|
|
3001
4358
|
const [bottom, top] = getExtrusionBounds(height, baseValue);
|
|
3002
4359
|
return top - bottom;
|
|
3003
|
-
}
|
|
4360
|
+
},
|
|
4361
|
+
featureState
|
|
3004
4362
|
);
|
|
3005
4363
|
const baseProps = getSubLayerBaseProps(props);
|
|
4364
|
+
// `fill-extrusion-translate` moves the whole extrusion, walls and roof, on the ground.
|
|
4365
|
+
const translates = styleLayer.paint?.['fill-extrusion-translate'] !== undefined;
|
|
3006
4366
|
|
|
3007
4367
|
return getTileGeoJsonLayer(props, {
|
|
3008
4368
|
...baseProps,
|
|
3009
4369
|
id: getStyleSubLayerId(props.id, styleLayer.id),
|
|
4370
|
+
[STYLE_LAYER_IDS]: [styleLayer.id],
|
|
3010
4371
|
data: getRaisedFeatures(features, styleLayer, base),
|
|
3011
4372
|
opacity: (baseProps.opacity ?? 1) * (paint['fill-extrusion-opacity'] ?? 1),
|
|
3012
4373
|
extruded: true,
|
|
@@ -3023,7 +4384,12 @@ function createExtrusionSubLayer({
|
|
|
3023
4384
|
getPointRadius: 0,
|
|
3024
4385
|
pointRadiusMinPixels: 0,
|
|
3025
4386
|
parameters: EXTRUSION_PARAMETERS,
|
|
3026
|
-
extensions: [
|
|
4387
|
+
extensions: [
|
|
4388
|
+
...(baseProps.extensions || []),
|
|
4389
|
+
FILL_EXTRUSION_LIGHTING_EXTENSION,
|
|
4390
|
+
...(translates ? [FILL_TRANSLATE_EXTENSION] : [])
|
|
4391
|
+
],
|
|
4392
|
+
...(translates ? getTranslateProps(styleLayer, zoom, 'fill-extrusion') : {}),
|
|
3027
4393
|
fillExtrusionLight: light,
|
|
3028
4394
|
fillExtrusionVerticalGradient: paint['fill-extrusion-vertical-gradient'] ?? true
|
|
3029
4395
|
});
|
|
@@ -3095,13 +4461,30 @@ function getLabelPriorityRanges(
|
|
|
3095
4461
|
}
|
|
3096
4462
|
|
|
3097
4463
|
/** Whether a style layer is drawn from vector tiles: a `symbol` layer only with labels on. */
|
|
4464
|
+
/**
|
|
4465
|
+
* Whether `getBasemapLayers` draws a style layer with these globe toggles: a supported type, with
|
|
4466
|
+
* the basemap on, and labels on for a symbol layer. Style visibility and zoom are not checked.
|
|
4467
|
+
*/
|
|
4468
|
+
export function isDrawnStyleLayer(
|
|
4469
|
+
layer: BasemapStyleLayer,
|
|
4470
|
+
globe?: {config?: BasemapGlobeConfig}
|
|
4471
|
+
): boolean {
|
|
4472
|
+
const config = getConfig(globe);
|
|
4473
|
+
return (
|
|
4474
|
+
config.basemap &&
|
|
4475
|
+
SUPPORTED_TYPES.has(layer.type) &&
|
|
4476
|
+
(layer.type !== 'symbol' || config.labels)
|
|
4477
|
+
);
|
|
4478
|
+
}
|
|
4479
|
+
|
|
3098
4480
|
function isVectorStyleLayer(layer: BasemapStyleLayer, config: BasemapLayerConfig): boolean {
|
|
3099
4481
|
return layer.type === 'symbol'
|
|
3100
4482
|
? config.labels
|
|
3101
4483
|
: layer.type === 'fill' ||
|
|
3102
4484
|
layer.type === 'fill-extrusion' ||
|
|
3103
4485
|
layer.type === 'line' ||
|
|
3104
|
-
layer.type === 'circle'
|
|
4486
|
+
layer.type === 'circle' ||
|
|
4487
|
+
layer.type === 'heatmap';
|
|
3105
4488
|
}
|
|
3106
4489
|
|
|
3107
4490
|
/**
|
|
@@ -3117,14 +4500,16 @@ export function isVectorTileSource(source: BasemapSource | undefined): boolean {
|
|
|
3117
4500
|
/**
|
|
3118
4501
|
* The `getTileData` of a vector tile source's tileset: `loader` fetches and decodes a vector
|
|
3119
4502
|
* source's tiles, and a GeoJSON source's tiles are cut from its data, in the same tile-local
|
|
3120
|
-
* coordinates.
|
|
4503
|
+
* coordinates. `geoJson` says how: a view that shows latitudes past the edges of Web Mercator
|
|
4504
|
+
* tiles, projected or a globe, cuts GeoJSON at them (see `GeoJsonTileOptions`).
|
|
3121
4505
|
*/
|
|
3122
4506
|
export function getVectorTileLoader(
|
|
3123
4507
|
source: BasemapSource,
|
|
3124
|
-
loader: SharedMVTLayer
|
|
4508
|
+
loader: SharedMVTLayer,
|
|
4509
|
+
geoJson?: GeoJsonTileOptions
|
|
3125
4510
|
): (tile: Parameters<SharedMVTLayer['getTileData']>[0]) => Promise<any> {
|
|
3126
4511
|
return source.type === 'geojson'
|
|
3127
|
-
? tile => getGeoJsonTileFeatures(source, tile.index)
|
|
4512
|
+
? tile => getGeoJsonTileFeatures(source, tile.index, geoJson)
|
|
3128
4513
|
: tile => loader.getTileData(tile);
|
|
3129
4514
|
}
|
|
3130
4515
|
|
|
@@ -3184,21 +4569,27 @@ export function getSourceLoadOptions(
|
|
|
3184
4569
|
}
|
|
3185
4570
|
|
|
3186
4571
|
/**
|
|
3187
|
-
* Splits the style into runs that draw in style order, as in MapLibre: each background, raster
|
|
3188
|
-
* and
|
|
4572
|
+
* Splits the style into runs that draw in style order, as in MapLibre: each background, raster,
|
|
4573
|
+
* hillshade and color-relief layer on its own, and consecutive layers of one vector source together, so that a
|
|
3189
4574
|
* raster layer between two vector layers draws between them. Layers that cannot draw (a source
|
|
3190
4575
|
* without tiles, labels turned off) do not split a run. Runs do not depend on zoom, so the tile
|
|
3191
|
-
* layers keep their ids and tiles when a layer leaves its zoom range. Background, raster
|
|
3192
|
-
* hillshade runs have their style layer's id. The first run of a source has the
|
|
3193
|
-
* id
|
|
4576
|
+
* layers keep their ids and tiles when a layer leaves its zoom range. Background, raster,
|
|
4577
|
+
* hillshade and color-relief runs have their style layer's id. The first run of a source has the
|
|
4578
|
+
* source id as its id, unless such a run already has that id; later runs, and a first run whose source id is
|
|
3194
4579
|
* taken, add the quoted id of their first style layer.
|
|
4580
|
+
*
|
|
4581
|
+
* A style layer in `cutBefore` starts a new run, so that deck.gl layers can draw between it and the
|
|
4582
|
+
* layers before it (see `BasemapLayerProps.insertLayers`). A cut at a layer that draws nothing
|
|
4583
|
+
* applies to the next layer that draws.
|
|
3195
4584
|
*/
|
|
3196
4585
|
export function getStyleLayerRuns(
|
|
3197
4586
|
styleLayers: BasemapStyleLayer[],
|
|
3198
4587
|
styleDefinition: ResolvedBasemapStyle,
|
|
3199
|
-
config: BasemapLayerConfig = DEFAULT_CONFIG
|
|
4588
|
+
config: BasemapLayerConfig = DEFAULT_CONFIG,
|
|
4589
|
+
cutBefore: ReadonlySet<BasemapStyleLayer> = new Set()
|
|
3200
4590
|
): StyleLayerRun[] {
|
|
3201
4591
|
const runs: StyleLayerRun[] = [];
|
|
4592
|
+
let cut = false;
|
|
3202
4593
|
const sourceIds = new Set<string>();
|
|
3203
4594
|
const reservedIds = new Set([
|
|
3204
4595
|
...Object.keys(styleDefinition.sources || {}),
|
|
@@ -3212,29 +4603,40 @@ export function getStyleLayerRuns(
|
|
|
3212
4603
|
.filter(
|
|
3213
4604
|
layer =>
|
|
3214
4605
|
layer.type === 'background' ||
|
|
3215
|
-
((layer.type === 'raster' ||
|
|
4606
|
+
((layer.type === 'raster' ||
|
|
4607
|
+
layer.type === 'hillshade' ||
|
|
4608
|
+
layer.type === 'color-relief') &&
|
|
4609
|
+
getSource(layer)?.tiles) ||
|
|
4610
|
+
(layer.type === 'raster' && isDrawableImageSource(getSource(layer)))
|
|
3216
4611
|
)
|
|
3217
4612
|
.map(layer => layer.id)
|
|
3218
4613
|
);
|
|
3219
4614
|
for (const layer of styleLayers) {
|
|
3220
4615
|
const sourceId = layer.source as string | undefined;
|
|
3221
4616
|
const source = getSource(layer);
|
|
4617
|
+
const runCount = runs.length;
|
|
4618
|
+
cut ||= cutBefore.has(layer);
|
|
3222
4619
|
if (layer.type === 'background') {
|
|
3223
4620
|
runs.push({type: 'background', id: layer.id, styleLayers: [layer]});
|
|
3224
4621
|
} else if (layer.type === 'raster') {
|
|
3225
|
-
if (source?.tiles) {
|
|
4622
|
+
if (source?.tiles || isDrawableImageSource(source)) {
|
|
3226
4623
|
runs.push({type: 'raster', id: layer.id, sourceId, source, styleLayers: [layer]});
|
|
4624
|
+
} else if (source?.type === 'image') {
|
|
4625
|
+
// Logged once per message: the runs are built again on each update.
|
|
4626
|
+
log.warn(
|
|
4627
|
+
`[BasemapLayer] Skipping raster layer "${layer.id}": image source "${sourceId}" needs a url and four [longitude, latitude] coordinates within the Web Mercator world`
|
|
4628
|
+
)();
|
|
3227
4629
|
} else {
|
|
3228
4630
|
logBasemapRuntimeEvent('Skipping style layer without resolved tiles', {
|
|
3229
4631
|
layerId: layer.id,
|
|
3230
4632
|
sourceId
|
|
3231
4633
|
});
|
|
3232
4634
|
}
|
|
3233
|
-
} else if (layer.type === 'hillshade') {
|
|
4635
|
+
} else if (layer.type === 'hillshade' || layer.type === 'color-relief') {
|
|
3234
4636
|
if (source?.tiles && source.type === 'raster-dem') {
|
|
3235
|
-
runs.push({type:
|
|
4637
|
+
runs.push({type: layer.type, id: layer.id, sourceId, source, styleLayers: [layer]});
|
|
3236
4638
|
} else {
|
|
3237
|
-
logBasemapRuntimeEvent(
|
|
4639
|
+
logBasemapRuntimeEvent(`Skipping ${layer.type} layer without a raster-dem source`, {
|
|
3238
4640
|
layerId: layer.id,
|
|
3239
4641
|
sourceId
|
|
3240
4642
|
});
|
|
@@ -3245,7 +4647,18 @@ export function getStyleLayerRuns(
|
|
|
3245
4647
|
const followsLabel =
|
|
3246
4648
|
layer.type !== 'symbol' &&
|
|
3247
4649
|
last?.styleLayers.some(styleLayer => styleLayer.type === 'symbol');
|
|
3248
|
-
|
|
4650
|
+
// A heatmap draws all of its tiles' points at once (see `renderHeatmapLayers`), so it has a
|
|
4651
|
+
// run of its own.
|
|
4652
|
+
const isHeatmapRun =
|
|
4653
|
+
layer.type === 'heatmap' ||
|
|
4654
|
+
last?.styleLayers.some(styleLayer => styleLayer.type === 'heatmap');
|
|
4655
|
+
if (
|
|
4656
|
+
last?.type === 'vector' &&
|
|
4657
|
+
last.sourceId === sourceId &&
|
|
4658
|
+
!followsLabel &&
|
|
4659
|
+
!isHeatmapRun &&
|
|
4660
|
+
!cut
|
|
4661
|
+
) {
|
|
3249
4662
|
last.styleLayers.push(layer);
|
|
3250
4663
|
} else {
|
|
3251
4664
|
let id = sourceId;
|
|
@@ -3264,6 +4677,10 @@ export function getStyleLayerRuns(
|
|
|
3264
4677
|
sourceIds.add(sourceId);
|
|
3265
4678
|
}
|
|
3266
4679
|
}
|
|
4680
|
+
// The layer that the cut applies to starts a run.
|
|
4681
|
+
if (runs.length !== runCount) {
|
|
4682
|
+
cut = false;
|
|
4683
|
+
}
|
|
3267
4684
|
}
|
|
3268
4685
|
return runs;
|
|
3269
4686
|
}
|
|
@@ -3281,19 +4698,42 @@ function getStyleLayers({
|
|
|
3281
4698
|
zoom,
|
|
3282
4699
|
config,
|
|
3283
4700
|
loadOptions,
|
|
4701
|
+
fetch,
|
|
4702
|
+
transformRequest,
|
|
4703
|
+
rejectRasterTile,
|
|
4704
|
+
onError,
|
|
3284
4705
|
mode,
|
|
3285
4706
|
spriteAtlases,
|
|
3286
4707
|
fontFamily,
|
|
3287
4708
|
glyphs,
|
|
3288
4709
|
labelPlacement,
|
|
3289
|
-
|
|
4710
|
+
featureState,
|
|
4711
|
+
pickable,
|
|
4712
|
+
tilesets,
|
|
4713
|
+
projected,
|
|
4714
|
+
firstPerson,
|
|
4715
|
+
projectedMaxStretch,
|
|
4716
|
+
styleLayerProps,
|
|
4717
|
+
insertions = []
|
|
3290
4718
|
}: {
|
|
4719
|
+
featureState?: BasemapFeatureState | null;
|
|
4720
|
+
pickable?: LayerProps['pickable'];
|
|
4721
|
+
projected?: boolean;
|
|
4722
|
+
firstPerson?: boolean;
|
|
4723
|
+
projectedMaxStretch?: number;
|
|
4724
|
+
styleLayerProps?: StyleLayerPropsMap | null;
|
|
4725
|
+
/** deck.gl layers to draw between the runs, sorted by index (see `getStyleInsertions`). */
|
|
4726
|
+
insertions?: StyleInsertion[];
|
|
3291
4727
|
idPrefix: string;
|
|
3292
4728
|
styleLayers: BasemapStyleLayer[];
|
|
3293
4729
|
styleDefinition: ResolvedBasemapStyle;
|
|
3294
4730
|
zoom: number;
|
|
3295
4731
|
config: BasemapLayerConfig;
|
|
3296
4732
|
loadOptions?: BasemapLoadOptions;
|
|
4733
|
+
fetch?: LayerProps['fetch'];
|
|
4734
|
+
transformRequest?: BasemapTransformRequest | null;
|
|
4735
|
+
rejectRasterTile?: RejectRasterTile | null;
|
|
4736
|
+
onError?: BasemapLoadErrorHandler | null;
|
|
3297
4737
|
mode: BasemapMode;
|
|
3298
4738
|
spriteAtlases?: SpriteAtlas[] | null;
|
|
3299
4739
|
fontFamily?: LabelFontFamily | null;
|
|
@@ -3306,10 +4746,14 @@ function getStyleLayers({
|
|
|
3306
4746
|
const labelPriorityRanges = getLabelPriorityRanges(
|
|
3307
4747
|
styleLayers.filter(layer => isVectorStyleLayer(layer, config))
|
|
3308
4748
|
);
|
|
3309
|
-
const
|
|
4749
|
+
const cutBefore = new Set(
|
|
4750
|
+
insertions.map(insertion => styleLayers[insertion.index]).filter(layer => Boolean(layer))
|
|
4751
|
+
);
|
|
4752
|
+
const allRuns = getStyleLayerRuns(styleLayers, styleDefinition, config, cutBefore);
|
|
3310
4753
|
const runs = allRuns.filter(run =>
|
|
3311
4754
|
run.styleLayers.some(layer => isStyleLayerVisibleAtZoom(layer, zoom))
|
|
3312
4755
|
);
|
|
4756
|
+
const styleLayerIndex = new Map(styleLayers.map((layer, index) => [layer, index]));
|
|
3313
4757
|
|
|
3314
4758
|
// On a globe, flat layers drawn after an extrusion are depth-tested against the buildings.
|
|
3315
4759
|
const extrusionIndex =
|
|
@@ -3323,10 +4767,23 @@ function getStyleLayers({
|
|
|
3323
4767
|
const ownedTilesets = new Map<BasemapSource, SourceTilesetOwner>();
|
|
3324
4768
|
const ownedDemTilesets = new Map<BasemapSource, DemTilesetOwner>();
|
|
3325
4769
|
let sourceLayers: Map<BasemapSource, string[] | null> | undefined;
|
|
3326
|
-
|
|
4770
|
+
const createRunLayer = (run: StyleLayerRun) => {
|
|
3327
4771
|
const [layer] = run.styleLayers;
|
|
3328
4772
|
if (run.type === 'background') {
|
|
3329
|
-
return createBackgroundLayer({idPrefix, layer, zoom, mode});
|
|
4773
|
+
return createBackgroundLayer({idPrefix, layer, zoom, mode, projected, firstPerson, spriteAtlases});
|
|
4774
|
+
}
|
|
4775
|
+
if (run.type === 'raster' && run.source?.type === 'image') {
|
|
4776
|
+
return createImageLayer({
|
|
4777
|
+
idPrefix,
|
|
4778
|
+
layer,
|
|
4779
|
+
source: run.source,
|
|
4780
|
+
zoom,
|
|
4781
|
+
mode,
|
|
4782
|
+
loadOptions,
|
|
4783
|
+
fetch,
|
|
4784
|
+
onError,
|
|
4785
|
+
depthTested: depthTested.has(layer)
|
|
4786
|
+
});
|
|
3330
4787
|
}
|
|
3331
4788
|
if (run.type === 'raster') {
|
|
3332
4789
|
return createRasterLayer({
|
|
@@ -3335,25 +4792,35 @@ function getStyleLayers({
|
|
|
3335
4792
|
source: run.source!,
|
|
3336
4793
|
zoom,
|
|
3337
4794
|
mode,
|
|
3338
|
-
|
|
4795
|
+
loadOptions,
|
|
4796
|
+
fetch,
|
|
4797
|
+
transformRequest,
|
|
4798
|
+
rejectRasterTile,
|
|
4799
|
+
onError,
|
|
4800
|
+
depthTested: depthTested.has(layer),
|
|
4801
|
+
projectedMaxStretch
|
|
3339
4802
|
});
|
|
3340
4803
|
}
|
|
3341
|
-
if (run.type === 'hillshade') {
|
|
3342
|
-
// One tileset per raster-dem source, shared by its hillshade layers.
|
|
4804
|
+
if (run.type === 'hillshade' || run.type === 'color-relief') {
|
|
4805
|
+
// One tileset per raster-dem source, shared by its hillshade and color-relief layers.
|
|
3343
4806
|
let owner: DemTilesetOwner | undefined;
|
|
3344
4807
|
let tileset = tilesets?.get(run.source!);
|
|
3345
4808
|
if (!tileset) {
|
|
3346
4809
|
owner = ownedDemTilesets.get(run.source!);
|
|
3347
4810
|
if (!owner) {
|
|
3348
4811
|
owner = {
|
|
3349
|
-
tileset: createDemTileset(
|
|
4812
|
+
tileset: createDemTileset(
|
|
4813
|
+
run.source!,
|
|
4814
|
+
withTransformRequest(loadOptions, transformRequest),
|
|
4815
|
+
projectedMaxStretch
|
|
4816
|
+
),
|
|
3350
4817
|
consumers: new Set()
|
|
3351
4818
|
};
|
|
3352
4819
|
ownedDemTilesets.set(run.source!, owner);
|
|
3353
4820
|
}
|
|
3354
4821
|
tileset = owner.tileset;
|
|
3355
4822
|
}
|
|
3356
|
-
return createHillshadeLayer({
|
|
4823
|
+
return (run.type === 'hillshade' ? createHillshadeLayer : createColorReliefLayer)({
|
|
3357
4824
|
idPrefix,
|
|
3358
4825
|
layer,
|
|
3359
4826
|
tileset,
|
|
@@ -3361,7 +4828,8 @@ function getStyleLayers({
|
|
|
3361
4828
|
source: run.source!,
|
|
3362
4829
|
zoom,
|
|
3363
4830
|
mode,
|
|
3364
|
-
depthTested: depthTested.has(layer)
|
|
4831
|
+
depthTested: depthTested.has(layer),
|
|
4832
|
+
onError
|
|
3365
4833
|
});
|
|
3366
4834
|
}
|
|
3367
4835
|
let tileset = tilesets?.get(run.source!);
|
|
@@ -3372,17 +4840,24 @@ function getStyleLayers({
|
|
|
3372
4840
|
// Tiles decode the source layers of all of the source's runs, at every zoom.
|
|
3373
4841
|
sourceLayers ??= getRunSourceLayers(allRuns);
|
|
3374
4842
|
const loader = new SharedMVTLayer({
|
|
3375
|
-
data: run.source
|
|
3376
|
-
|
|
4843
|
+
data: getSourceTileTemplates(run.source!)!,
|
|
4844
|
+
fetch: getBasemapTileFetch(DEFAULT_MVT_FETCH, 'arrayBuffer', transformRequest),
|
|
4845
|
+
loadOptions: getTileLoadOptions(
|
|
4846
|
+
run.source!,
|
|
4847
|
+
getSourceLoadOptions(withTransformRequest(loadOptions, transformRequest), sourceLayers.get(run.source!))
|
|
4848
|
+
)
|
|
3377
4849
|
});
|
|
3378
|
-
|
|
4850
|
+
const ownedTileset: SharedTileset2D = new SharedTileset2D({
|
|
3379
4851
|
...loader._getTilesetOptions(),
|
|
4852
|
+
adapter: getBasemapTilesetAdapter(projectedMaxStretch, getSourceTileBounds(run.source!)),
|
|
3380
4853
|
...getTilePyramidProps(run.source!),
|
|
3381
4854
|
tileSize: run.source!.tileSize || 512,
|
|
3382
4855
|
zoomOffset: VECTOR_TILE_ZOOM_OFFSET,
|
|
3383
|
-
getTileData: getVectorTileLoader(run.source!, loader
|
|
4856
|
+
getTileData: getVectorTileLoader(run.source!, loader, {
|
|
4857
|
+
clipToMercatorRange: mode === 'globe' || Boolean(projected)
|
|
4858
|
+
})
|
|
3384
4859
|
});
|
|
3385
|
-
owner = {tileset, consumers: new Set()};
|
|
4860
|
+
owner = {tileset: ownedTileset, consumers: new Set()};
|
|
3386
4861
|
ownedTilesets.set(run.source!, owner);
|
|
3387
4862
|
}
|
|
3388
4863
|
tileset = owner.tileset;
|
|
@@ -3405,9 +4880,33 @@ function getStyleLayers({
|
|
|
3405
4880
|
spriteAtlases,
|
|
3406
4881
|
fontFamily,
|
|
3407
4882
|
glyphs,
|
|
3408
|
-
labelPlacement
|
|
4883
|
+
labelPlacement,
|
|
4884
|
+
styleLayerProps,
|
|
4885
|
+
onError,
|
|
4886
|
+
featureState,
|
|
4887
|
+
pickable
|
|
3409
4888
|
});
|
|
3410
|
-
}
|
|
4889
|
+
};
|
|
4890
|
+
|
|
4891
|
+
const layers: LayersList = [];
|
|
4892
|
+
let nextInsertion = 0;
|
|
4893
|
+
for (const run of runs) {
|
|
4894
|
+
// No run spans an insertion: runs are cut at each insertion's style layer.
|
|
4895
|
+
const runIndex = styleLayerIndex.get(run.styleLayers[0])!;
|
|
4896
|
+
while (nextInsertion < insertions.length && insertions[nextInsertion].index <= runIndex) {
|
|
4897
|
+
layers.push(insertions[nextInsertion++].layers);
|
|
4898
|
+
}
|
|
4899
|
+
layers.push(
|
|
4900
|
+
withStyleLayerProps(
|
|
4901
|
+
createRunLayer(run),
|
|
4902
|
+
run.type === 'vector' ? undefined : styleLayerProps?.get(run.styleLayers[0])
|
|
4903
|
+
)
|
|
4904
|
+
);
|
|
4905
|
+
}
|
|
4906
|
+
for (const insertion of insertions.slice(nextInsertion)) {
|
|
4907
|
+
layers.push(insertion.layers);
|
|
4908
|
+
}
|
|
4909
|
+
return layers;
|
|
3411
4910
|
}
|
|
3412
4911
|
|
|
3413
4912
|
function getGlobePreLayers({
|
|
@@ -3437,7 +4936,7 @@ function getGlobePreLayers({
|
|
|
3437
4936
|
layers.push(
|
|
3438
4937
|
new SolidPolygonLayer({
|
|
3439
4938
|
id: `${idPrefix}-background-fallback`,
|
|
3440
|
-
data:
|
|
4939
|
+
data: GLOBE_BACKGROUND_DATA,
|
|
3441
4940
|
getPolygon: d => d,
|
|
3442
4941
|
stroked: false,
|
|
3443
4942
|
filled: true,
|