@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/circle-layer.ts
CHANGED
|
@@ -6,12 +6,29 @@
|
|
|
6
6
|
// SPDX-License-Identifier: MIT
|
|
7
7
|
// Copyright (c) vis.gl contributors
|
|
8
8
|
|
|
9
|
-
import {LayerExtension} from '@deck.gl/core';
|
|
10
|
-
import type {Layer} from '@deck.gl/core';
|
|
11
|
-
import {ScatterplotLayer} from '@deck.gl/layers';
|
|
9
|
+
import {LayerExtension, project} from '@deck.gl/core';
|
|
10
|
+
import type {Accessor, DefaultProps, Layer, UpdateParameters} from '@deck.gl/core';
|
|
11
|
+
import {ScatterplotLayer, type ScatterplotLayerProps} from '@deck.gl/layers';
|
|
12
|
+
import type {ShaderPlugin} from '@luma.gl/shaders';
|
|
13
|
+
import {
|
|
14
|
+
FillTranslateExtension,
|
|
15
|
+
type FillTranslateExtensionProps,
|
|
16
|
+
fillTranslateModuleWGSL
|
|
17
|
+
} from './fill-style-extensions';
|
|
18
|
+
import {createShaderInjectionPlugin} from './shader-injection-plugin';
|
|
12
19
|
import {sortFeaturesByKey} from './sort-key';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
20
|
+
import type {FeatureStateLookup} from './feature-state';
|
|
21
|
+
import {getStyleZoom} from './projected-viewport';
|
|
22
|
+
import {
|
|
23
|
+
type PaintProperty,
|
|
24
|
+
STYLE_ZOOM_STEP,
|
|
25
|
+
compileZoomPaintProperty,
|
|
26
|
+
getStyleAccessor,
|
|
27
|
+
getZoomBucket,
|
|
28
|
+
getZoomPaintZoom,
|
|
29
|
+
withOpacity
|
|
30
|
+
} from './style-accessor';
|
|
31
|
+
import {getStylePropertyDefault, getZoomInterpolationFactor} from './style-expression';
|
|
15
32
|
import type {ResolvedBasemapStyleLayer as BasemapStyleLayer} from './style-resolver';
|
|
16
33
|
|
|
17
34
|
const DEFAULT_RADIUS = getStylePropertyDefault('circle-radius') as number;
|
|
@@ -22,19 +39,279 @@ const DEFAULT_STROKE_COLOR = getStylePropertyDefault('circle-stroke-color') as n
|
|
|
22
39
|
const DEFAULT_STROKE_OPACITY = getStylePropertyDefault('circle-stroke-opacity') as number;
|
|
23
40
|
const DEFAULT_BLUR = getStylePropertyDefault('circle-blur') as number;
|
|
24
41
|
|
|
42
|
+
/** The inner radius of the circle, in pixels. */
|
|
43
|
+
const CIRCLE_RADIUS: PaintProperty<number> = {
|
|
44
|
+
names: ['circle-radius'],
|
|
45
|
+
combine: ([radius]) => Math.max(0, Number(radius ?? DEFAULT_RADIUS))
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** The width of the stroke drawn outside the circle. */
|
|
49
|
+
const CIRCLE_STROKE_WIDTH: PaintProperty<number> = {
|
|
50
|
+
names: ['circle-stroke-width'],
|
|
51
|
+
combine: ([width]) => Math.max(0, Number(width ?? DEFAULT_STROKE_WIDTH))
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** The fill color with its opacity applied. */
|
|
55
|
+
const CIRCLE_FILL_COLOR: PaintProperty<number[]> = {
|
|
56
|
+
names: ['circle-color', 'circle-opacity'],
|
|
57
|
+
combine: ([color, opacity]) => withOpacity(color ?? DEFAULT_COLOR, opacity ?? DEFAULT_OPACITY)
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** The stroke color with its opacity applied. */
|
|
61
|
+
const CIRCLE_STROKE_COLOR: PaintProperty<number[]> = {
|
|
62
|
+
names: ['circle-stroke-color', 'circle-stroke-opacity'],
|
|
63
|
+
combine: ([color, opacity]) =>
|
|
64
|
+
withOpacity(color ?? DEFAULT_STROKE_COLOR, opacity ?? DEFAULT_STROKE_OPACITY)
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** Explicit paint accessors and column data bypass the style's circle paint attributes. */
|
|
68
|
+
const CIRCLE_PAINT_OVERRIDES = [
|
|
69
|
+
'getRadius', 'getLineWidth', 'getFillColor', 'getLineColor', 'getColor',
|
|
70
|
+
'positions', 'radii', 'lineWidths', 'fillColors', 'lineColors'
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
/** Uniforms of the circle paint at the viewport zoom. */
|
|
74
|
+
type CircleZoomPaint = {
|
|
75
|
+
/** Inner radius and stroke width, each negative when it comes from an attribute. */
|
|
76
|
+
size: number[];
|
|
77
|
+
/** RGBA fill, with a negative alpha when it comes from an attribute. */
|
|
78
|
+
fillColor: number[];
|
|
79
|
+
/** RGBA stroke, with a negative alpha when it comes from an attribute. */
|
|
80
|
+
lineColor: number[];
|
|
81
|
+
/** Blend factors for the radius, stroke width, fill and stroke color, in that order. */
|
|
82
|
+
blend: number[];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** Circle paint supplied to the WebGL shader. */
|
|
86
|
+
type CircleZoomPaintProps = {
|
|
87
|
+
/** The uniform values at the current zoom, or null for ordinary stepped attributes. */
|
|
88
|
+
circleZoomPaint?: ((zoom: number) => CircleZoomPaint) | null;
|
|
89
|
+
/** Inner radius and stroke width at the next style zoom step. */
|
|
90
|
+
getNextCircleSize?: Accessor<any, [number, number]>;
|
|
91
|
+
/** Fill RGBA at the next style zoom step. */
|
|
92
|
+
getNextCircleFillColor?: Accessor<any, number[]>;
|
|
93
|
+
/** Stroke RGBA at the next style zoom step. */
|
|
94
|
+
getNextCircleLineColor?: Accessor<any, number[]>;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Substitutes paint before the vertex shader clamps its radius and stroke width and computes
|
|
99
|
+
* the padded quad and the stroke's inner edge. The size hook receives the vertex offset after
|
|
100
|
+
* those calculations, including any pixel offset.
|
|
101
|
+
*/
|
|
102
|
+
const circleZoomPaintPlugin = createShaderInjectionPlugin({
|
|
103
|
+
name: 'circleZoomPaint',
|
|
104
|
+
vs: /* glsl */ `
|
|
105
|
+
layout(std140) uniform circleZoomPaintUniforms {
|
|
106
|
+
vec2 size;
|
|
107
|
+
vec4 fillColor;
|
|
108
|
+
vec4 lineColor;
|
|
109
|
+
vec4 blend;
|
|
110
|
+
} circleZoomPaint;
|
|
111
|
+
`,
|
|
112
|
+
uniformTypes: {
|
|
113
|
+
size: 'vec2<f32>',
|
|
114
|
+
fillColor: 'vec4<f32>',
|
|
115
|
+
lineColor: 'vec4<f32>',
|
|
116
|
+
blend: 'vec4<f32>'
|
|
117
|
+
},
|
|
118
|
+
inject: {
|
|
119
|
+
'vs:#decl': /* glsl */ `
|
|
120
|
+
in vec2 instanceNextCircleSize;
|
|
121
|
+
in vec4 instanceNextCircleFillColors;
|
|
122
|
+
in vec4 instanceNextCircleLineColors;
|
|
123
|
+
|
|
124
|
+
vec4 circleZoomPaint_color(vec4 currentColor, vec4 nextColor, vec4 uniformColor, float blend) {
|
|
125
|
+
return uniformColor.a < 0.0 ? mix(currentColor, nextColor, blend) : uniformColor;
|
|
126
|
+
}
|
|
127
|
+
`,
|
|
128
|
+
'vs:#main-start': /* glsl */ `
|
|
129
|
+
// Locals shadow the input attributes for the rest of main. The size is in pixels.
|
|
130
|
+
vec2 circleZoomPaint_size = mix(
|
|
131
|
+
vec2(instanceRadius, instanceLineWidths), instanceNextCircleSize, circleZoomPaint.blend.xy
|
|
132
|
+
);
|
|
133
|
+
vec4 circleZoomPaint_fill = circleZoomPaint_color(
|
|
134
|
+
instanceFillColors, instanceNextCircleFillColors, circleZoomPaint.fillColor, circleZoomPaint.blend.z
|
|
135
|
+
);
|
|
136
|
+
vec4 circleZoomPaint_line = circleZoomPaint_color(
|
|
137
|
+
instanceLineColors, instanceNextCircleLineColors, circleZoomPaint.lineColor, circleZoomPaint.blend.w
|
|
138
|
+
);
|
|
139
|
+
vec2 resolvedSize = mix(circleZoomPaint_size, circleZoomPaint.size, greaterThanEqual(circleZoomPaint.size, vec2(0.0)));
|
|
140
|
+
float instanceLineWidths = resolvedSize.y;
|
|
141
|
+
float instanceRadius = resolvedSize.x + instanceLineWidths / 2.0;
|
|
142
|
+
vec4 instanceFillColors = circleZoomPaint_fill;
|
|
143
|
+
vec4 instanceLineColors = circleZoomPaint_line;
|
|
144
|
+
`,
|
|
145
|
+
'vs:#main-end': /* glsl */ `
|
|
146
|
+
if (outerRadiusPixels <= 0.0) {
|
|
147
|
+
gl_Position = vec4(0.0, 0.0, 2.0, 1.0);
|
|
148
|
+
} else if (instanceLineWidths == 0.0 && scatterplot.lineWidthMinPixels == 0.0) {
|
|
149
|
+
// A zoom-dependent stroke can have width zero while the layer is still marked stroked.
|
|
150
|
+
// Move its inner edge beyond the antialiasing padding so only the fill draws.
|
|
151
|
+
innerUnitRadius = 1.0 + 2.0 * SMOOTH_EDGE_RADIUS / outerRadiusPixels;
|
|
152
|
+
}
|
|
153
|
+
`
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
/** The upper zoom endpoints read by the circle paint shader. */
|
|
158
|
+
const CIRCLE_ZOOM_ATTRIBUTES = {
|
|
159
|
+
instanceNextCircleSize: {size: 2, accessor: 'getNextCircleSize'},
|
|
160
|
+
instanceNextCircleFillColors: {size: 4, type: 'unorm8', accessor: 'getNextCircleFillColor'},
|
|
161
|
+
instanceNextCircleLineColors: {size: 4, type: 'unorm8', accessor: 'getNextCircleLineColor'}
|
|
162
|
+
} as const;
|
|
163
|
+
|
|
164
|
+
/** Draws the installed scatterplot shader with continuous paint when the style needs it. */
|
|
165
|
+
class ZoomPaintScatterplotLayer extends ScatterplotLayer<any, CircleZoomPaintProps> {
|
|
166
|
+
static layerName = 'ZoomPaintScatterplotLayer';
|
|
167
|
+
static defaultProps: DefaultProps<ScatterplotLayerProps & CircleZoomPaintProps> = {
|
|
168
|
+
...ScatterplotLayer.defaultProps,
|
|
169
|
+
circleZoomPaint: {type: 'function', value: null, optional: true, ignore: false},
|
|
170
|
+
getNextCircleSize: {type: 'accessor', value: [0, 0]},
|
|
171
|
+
getNextCircleFillColor: {type: 'accessor', value: [0, 0, 0, 0]},
|
|
172
|
+
getNextCircleLineColor: {type: 'accessor', value: [0, 0, 0, 0]}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** Adds the paint plugin alongside all of the inherited extension shaders. */
|
|
176
|
+
getShaders() {
|
|
177
|
+
const shaders = super.getShaders();
|
|
178
|
+
if (this.props.circleZoomPaint && this.context.device.type !== 'webgpu') {
|
|
179
|
+
shaders.plugins = [...(shaders.plugins || []), circleZoomPaintPlugin];
|
|
180
|
+
}
|
|
181
|
+
return shaders;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Updates the attribute layout before a style edit switches the model's shader. */
|
|
185
|
+
updateState(params: UpdateParameters<this>): void {
|
|
186
|
+
const enabled = Boolean(params.props.circleZoomPaint) && this.context.device.type !== 'webgpu';
|
|
187
|
+
const manager = this.getAttributeManager();
|
|
188
|
+
const hadAttributes = Boolean(manager?.getAttributes().instanceNextCircleSize);
|
|
189
|
+
if (enabled !== hadAttributes) {
|
|
190
|
+
if (enabled) {
|
|
191
|
+
manager?.addInstanced(CIRCLE_ZOOM_ATTRIBUTES);
|
|
192
|
+
} else {
|
|
193
|
+
manager?.remove(Object.keys(CIRCLE_ZOOM_ATTRIBUTES));
|
|
194
|
+
}
|
|
195
|
+
params = {...params, changeFlags: {...params.changeFlags, extensionsChanged: true}};
|
|
196
|
+
}
|
|
197
|
+
super.updateState(params);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Evaluates layer-wide paint and composite factors for the viewport being drawn. */
|
|
201
|
+
draw(options: Parameters<ScatterplotLayer['draw']>[0]): void {
|
|
202
|
+
if (this.props.circleZoomPaint && this.context.device.type !== 'webgpu') {
|
|
203
|
+
this.setShaderModuleProps({
|
|
204
|
+
circleZoomPaint: this.props.circleZoomPaint(getStyleZoom(this.context.viewport))
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
super.draw(options);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Compiles the draw-time values and upper endpoint accessors of one circle style layer. */
|
|
212
|
+
function getCircleZoomPaint(
|
|
213
|
+
styleLayer: BasemapStyleLayer,
|
|
214
|
+
zoom: number,
|
|
215
|
+
featureState?: FeatureStateLookup
|
|
216
|
+
) {
|
|
217
|
+
const radius = compileZoomPaintProperty(styleLayer, CIRCLE_RADIUS);
|
|
218
|
+
const width = compileZoomPaintProperty(styleLayer, CIRCLE_STROKE_WIDTH);
|
|
219
|
+
const fill = compileZoomPaintProperty(styleLayer, CIRCLE_FILL_COLOR);
|
|
220
|
+
const line = compileZoomPaintProperty(styleLayer, CIRCLE_STROKE_COLOR);
|
|
221
|
+
const properties = [radius, width, fill, line];
|
|
222
|
+
if (properties.every(property => !property.isZoomDependent)) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const bucket = getZoomBucket(zoom);
|
|
227
|
+
const upper = bucket + STYLE_ZOOM_STEP;
|
|
228
|
+
/** Converts an evaluated color to normalized RGBA, or selects the attributes. */
|
|
229
|
+
const normalize = (color?: number[]) => color?.map(channel => channel / 255) ?? [0, 0, 0, -1];
|
|
230
|
+
/** Only composite values need another attribute sample. */
|
|
231
|
+
const composite = (property: (typeof properties)[number]) =>
|
|
232
|
+
property.isZoomDependent && property.isFeatureDependent;
|
|
233
|
+
/** Unchanged paint stays in its original attribute. */
|
|
234
|
+
const atZoom = <T>(property: ReturnType<typeof compileZoomPaintProperty<T>>, viewportZoom: number) =>
|
|
235
|
+
property.isZoomDependent ? property.evaluate(viewportZoom) : undefined;
|
|
236
|
+
/** Evaluates the paint uniforms at the viewport zoom, relative to this sublayer's attributes. */
|
|
237
|
+
// The color, picking and highlight passes of a frame draw at the same zoom: evaluate once.
|
|
238
|
+
let last: {zoom: number; paint: CircleZoomPaint} | null = null;
|
|
239
|
+
const evaluate = (viewportZoom: number): CircleZoomPaint => {
|
|
240
|
+
const paintZoom = getZoomPaintZoom(viewportZoom, zoom);
|
|
241
|
+
if (last?.zoom !== paintZoom) {
|
|
242
|
+
last = {
|
|
243
|
+
zoom: paintZoom,
|
|
244
|
+
paint: {
|
|
245
|
+
size: [atZoom(radius, paintZoom) ?? -1, atZoom(width, paintZoom) ?? -1],
|
|
246
|
+
fillColor: normalize(atZoom(fill, paintZoom)),
|
|
247
|
+
lineColor: normalize(atZoom(line, paintZoom)),
|
|
248
|
+
blend: properties.map(property =>
|
|
249
|
+
getZoomInterpolationFactor(property.interpolation, paintZoom, bucket, upper)
|
|
250
|
+
)
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
return last.paint;
|
|
255
|
+
};
|
|
256
|
+
/** Builds a per-feature accessor at the upper endpoint. */
|
|
257
|
+
const next = <T>(property: PaintProperty<T>) =>
|
|
258
|
+
getStyleAccessor(styleLayer, property.names, upper, property.combine, featureState, {
|
|
259
|
+
exactZoom: true,
|
|
260
|
+
stepZoom: bucket
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
evaluate,
|
|
265
|
+
widthChangesWithZoom: width.isZoomDependent,
|
|
266
|
+
size: composite(radius) || composite(width)
|
|
267
|
+
? next({
|
|
268
|
+
names: [...CIRCLE_RADIUS.names, ...CIRCLE_STROKE_WIDTH.names],
|
|
269
|
+
combine: ([r, w]): [number, number] =>
|
|
270
|
+
[CIRCLE_RADIUS.combine([r]), CIRCLE_STROKE_WIDTH.combine([w])]
|
|
271
|
+
})
|
|
272
|
+
: null,
|
|
273
|
+
fill: composite(fill) ? next(CIRCLE_FILL_COLOR) : null,
|
|
274
|
+
line: composite(line) ? next(CIRCLE_STROKE_COLOR) : null
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* The WGSL of `CircleBlurExtension`: the same fade as its GLSL, with the blur passed from the
|
|
280
|
+
* vertex to the fragment stage by luma.gl's shader plugin interface.
|
|
281
|
+
*/
|
|
282
|
+
const circleBlurPluginWGSL: ShaderPlugin = {
|
|
283
|
+
name: 'circleBlur',
|
|
284
|
+
vertexInputs: {instanceCircleBlur: 'f32'},
|
|
285
|
+
interStageVariables: {circleBlur_blur: {type: 'f32', interpolation: 'flat'}},
|
|
286
|
+
injections: [
|
|
287
|
+
{
|
|
288
|
+
stage: 'vertex',
|
|
289
|
+
target: 'DECKGL_FILTER_GL_POSITION',
|
|
290
|
+
wgsl: /* wgsl */ `
|
|
291
|
+
circleBlur_blur = instanceCircleBlur;
|
|
292
|
+
`
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
stage: 'fragment',
|
|
296
|
+
target: 'DECKGL_FILTER_COLOR',
|
|
297
|
+
wgsl: /* wgsl */ `
|
|
298
|
+
if (circleBlur_blur > 0.0) {
|
|
299
|
+
(*color).a *= 1.0 - smoothstep(1.0 - circleBlur_blur, 1.0, length(geometry.uv));
|
|
300
|
+
}
|
|
301
|
+
`
|
|
302
|
+
}
|
|
303
|
+
]
|
|
304
|
+
};
|
|
305
|
+
|
|
25
306
|
/**
|
|
26
307
|
* Adds `getBlur` to a `ScatterplotLayer`: per circle, the outer fraction of the circle (stroke
|
|
27
|
-
* included) that fades out, as MapLibre GL JS draws `circle-blur
|
|
28
|
-
* draw without blur.
|
|
308
|
+
* included) that fades out, as MapLibre GL JS draws `circle-blur`, on WebGL and WebGPU.
|
|
29
309
|
*/
|
|
30
310
|
export class CircleBlurExtension extends LayerExtension {
|
|
31
311
|
static extensionName = 'CircleBlurExtension';
|
|
32
312
|
static defaultProps = {getBlur: {type: 'accessor', value: 0}};
|
|
33
313
|
|
|
34
314
|
initializeState(this: Layer) {
|
|
35
|
-
if (this.context.device.type === 'webgpu') {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
315
|
this.getAttributeManager()?.addInstanced({
|
|
39
316
|
instanceCircleBlur: {size: 1, accessor: 'getBlur', defaultValue: 0}
|
|
40
317
|
});
|
|
@@ -42,7 +319,7 @@ export class CircleBlurExtension extends LayerExtension {
|
|
|
42
319
|
|
|
43
320
|
getShaders(this: Layer) {
|
|
44
321
|
if (this.context.device.type === 'webgpu') {
|
|
45
|
-
return {};
|
|
322
|
+
return {plugins: [circleBlurPluginWGSL]};
|
|
46
323
|
}
|
|
47
324
|
// deck.gl appends these to the layer's and other extensions' code for the same hooks.
|
|
48
325
|
return {
|
|
@@ -63,6 +340,94 @@ export class CircleBlurExtension extends LayerExtension {
|
|
|
63
340
|
/** Shared by every blurred circle sublayer, so deck.gl does not see their extensions change. */
|
|
64
341
|
const CIRCLE_BLUR_EXTENSION = new CircleBlurExtension();
|
|
65
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Checks globe visibility and applies deck.gl's billboard depth adjustment at the translated
|
|
345
|
+
* center. ScatterplotLayer still checks visibility at the original center.
|
|
346
|
+
*/
|
|
347
|
+
const circleTranslateGlobeModule = createShaderInjectionPlugin({
|
|
348
|
+
name: 'circleTranslateGlobe',
|
|
349
|
+
dependencies: [project],
|
|
350
|
+
inject: {
|
|
351
|
+
'vs:DECKGL_FILTER_GL_POSITION': /* glsl */ `
|
|
352
|
+
if (fillTranslate.offset != vec2(0.0) && scatterplot.billboard) {
|
|
353
|
+
vec4 moved = fillTranslate_getPosition(geometry.position);
|
|
354
|
+
if (project_globe_is_occluded(moved.xyz)) {
|
|
355
|
+
position = vec4(0.0, 0.0, 2.0, 1.0);
|
|
356
|
+
} else {
|
|
357
|
+
position = project_globe_billboard_clipspace(position, moved.xyz);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
`
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
/** Translates the billboard center while preserving ScatterplotLayer's clip-space corner offset. */
|
|
365
|
+
const circleTranslatePluginWGSL: ShaderPlugin = {
|
|
366
|
+
name: 'circleTranslate',
|
|
367
|
+
module: {
|
|
368
|
+
name: 'circleTranslate',
|
|
369
|
+
dependencies: [fillTranslateModuleWGSL],
|
|
370
|
+
source: /* wgsl */ `
|
|
371
|
+
var<private> circleTranslate_center: vec4<f32>;
|
|
372
|
+
`
|
|
373
|
+
},
|
|
374
|
+
injections: [
|
|
375
|
+
{
|
|
376
|
+
stage: 'vertex',
|
|
377
|
+
target: 'DECKGL_FILTER_SIZE',
|
|
378
|
+
wgsl: /* wgsl */ `
|
|
379
|
+
// Scatterplot's billboard geometry still holds the center at this hook.
|
|
380
|
+
circleTranslate_center = geometry.position;
|
|
381
|
+
`
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
stage: 'vertex',
|
|
385
|
+
target: 'DECKGL_FILTER_GL_POSITION',
|
|
386
|
+
order: -1,
|
|
387
|
+
wgsl: /* wgsl */ `
|
|
388
|
+
if (any(fillTranslate.offset != vec2<f32>(0.0))) {
|
|
389
|
+
if (scatterplot.billboard == 0) {
|
|
390
|
+
*position = project_common_position_to_clipspace(fillTranslate_getPosition(geometry.position));
|
|
391
|
+
} else if (!project_globe_is_occluded(circleTranslate_center.xyz)) {
|
|
392
|
+
let center = circleTranslate_center;
|
|
393
|
+
let moved = fillTranslate_getPosition(center);
|
|
394
|
+
if (project_globe_is_occluded(moved.xyz)) {
|
|
395
|
+
*position = vec4<f32>(0.0, 0.0, 2.0, 1.0);
|
|
396
|
+
} else {
|
|
397
|
+
let centerClip = project_globe_billboard_clipspace(
|
|
398
|
+
project_common_position_to_clipspace(center), center.xyz
|
|
399
|
+
);
|
|
400
|
+
let corner = *position - centerClip;
|
|
401
|
+
*position = project_globe_billboard_clipspace(
|
|
402
|
+
project_common_position_to_clipspace(moved), moved.xyz
|
|
403
|
+
) + corner;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
`
|
|
408
|
+
}
|
|
409
|
+
]
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* `circle-translate` and `circle-translate-anchor` for a `ScatterplotLayer`: the offset of
|
|
414
|
+
* `FillTranslateExtension`, which moves a circle's center on the ground, turned with the map or
|
|
415
|
+
* with the viewport, as MapLibre GL JS moves it in tile units, on WebGL and WebGPU.
|
|
416
|
+
*/
|
|
417
|
+
export class CircleTranslateExtension extends FillTranslateExtension {
|
|
418
|
+
static extensionName = 'CircleTranslateExtension';
|
|
419
|
+
|
|
420
|
+
getShaders(this: Layer) {
|
|
421
|
+
if (this.context.device.type === 'webgpu') {
|
|
422
|
+
return {plugins: [circleTranslatePluginWGSL]};
|
|
423
|
+
}
|
|
424
|
+
const {plugins} = FillTranslateExtension.prototype.getShaders.call(this);
|
|
425
|
+
return {plugins: [...plugins, circleTranslateGlobeModule]};
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const CIRCLE_TRANSLATE_EXTENSION = new CircleTranslateExtension();
|
|
430
|
+
|
|
66
431
|
const pointFeatureCache = new WeakMap<any[], any[]>();
|
|
67
432
|
|
|
68
433
|
function getPointFeatures(features: any[]): any[] {
|
|
@@ -89,8 +454,8 @@ function getPointFeatures(features: any[]): any[] {
|
|
|
89
454
|
* Draws a `circle` style layer's points (and each point of a multipoint) with MapLibre's circle
|
|
90
455
|
* paint: the stroke is drawn outside `circle-radius`. Under pitch, circles shrink with distance,
|
|
91
456
|
* as with the default `circle-pitch-scale` of `map`; `viewport` is not applied.
|
|
92
|
-
* `circle-translate
|
|
93
|
-
*
|
|
457
|
+
* `circle-translate` moves the circles on the ground, as in MapLibre, turned with the map, or with
|
|
458
|
+
* the viewport for a `circle-translate-anchor` of `viewport`.
|
|
94
459
|
*/
|
|
95
460
|
export function createCircleSubLayer({
|
|
96
461
|
baseProps,
|
|
@@ -98,7 +463,11 @@ export function createCircleSubLayer({
|
|
|
98
463
|
styleLayer,
|
|
99
464
|
features,
|
|
100
465
|
zoom,
|
|
466
|
+
featureState,
|
|
101
467
|
globe,
|
|
468
|
+
webgpu = false,
|
|
469
|
+
styleProps,
|
|
470
|
+
translate = null,
|
|
102
471
|
parameters
|
|
103
472
|
}: {
|
|
104
473
|
baseProps: any;
|
|
@@ -106,59 +475,55 @@ export function createCircleSubLayer({
|
|
|
106
475
|
styleLayer: BasemapStyleLayer;
|
|
107
476
|
features: any[];
|
|
108
477
|
zoom: number;
|
|
478
|
+
/** The feature states the style layer's paint reads, if it reads any. */
|
|
479
|
+
featureState?: FeatureStateLookup;
|
|
109
480
|
/**
|
|
110
481
|
* On a globe, circles always face the viewer: `circle-pitch-alignment: map` is not verified
|
|
111
482
|
* there.
|
|
112
483
|
*/
|
|
113
484
|
globe: boolean;
|
|
485
|
+
/** Whether the circles draw on WebGPU, where zoom-dependent paint is not interpolated on the GPU. */
|
|
486
|
+
webgpu?: boolean;
|
|
487
|
+
/** Extra sublayer props that may supply their own paint accessors or columns. */
|
|
488
|
+
styleProps?: Record<string, unknown>;
|
|
489
|
+
/** `circle-translate` and its anchor, when the layer sets them, as `FillTranslateExtension` takes them. */
|
|
490
|
+
translate?: FillTranslateExtensionProps | null;
|
|
114
491
|
parameters: any;
|
|
115
492
|
}) {
|
|
116
493
|
const points = getPointFeatures(features);
|
|
117
494
|
if (points.length === 0) {
|
|
118
495
|
return null;
|
|
119
496
|
}
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
);
|
|
137
|
-
const
|
|
138
|
-
styleLayer,
|
|
139
|
-
['circle-stroke-color', 'circle-stroke-opacity'],
|
|
140
|
-
zoom,
|
|
141
|
-
([color, opacity]) =>
|
|
142
|
-
withOpacity(color ?? DEFAULT_STROKE_COLOR, opacity ?? DEFAULT_STROKE_OPACITY)
|
|
143
|
-
);
|
|
144
|
-
const blur = getStyleAccessor(styleLayer, ['circle-blur'], zoom, ([value]) =>
|
|
145
|
-
Math.min(1, Math.max(0, Number(value ?? DEFAULT_BLUR) || 0))
|
|
146
|
-
);
|
|
147
|
-
const pixelOffset = getStyleAccessor<[number, number]>(
|
|
497
|
+
const hasPaintOverrides = CIRCLE_PAINT_OVERRIDES.some(name => styleProps?.[name] != null);
|
|
498
|
+
const zoomPaint =
|
|
499
|
+
webgpu || hasPaintOverrides ? null : getCircleZoomPaint(styleLayer, zoom, featureState);
|
|
500
|
+
/** Evaluates a circle paint attribute at the lower endpoint. */
|
|
501
|
+
const accessor = <T>(property: PaintProperty<T>) =>
|
|
502
|
+
getStyleAccessor(styleLayer, property.names, zoom, property.combine, featureState);
|
|
503
|
+
// The scatterplot shader adds the other half of the stroke to put the full stroke outside
|
|
504
|
+
// the circle. With continuous paint the first half is also added in the shader.
|
|
505
|
+
const radius = zoomPaint
|
|
506
|
+
? accessor(CIRCLE_RADIUS)
|
|
507
|
+
: accessor({
|
|
508
|
+
names: [...CIRCLE_RADIUS.names, ...CIRCLE_STROKE_WIDTH.names],
|
|
509
|
+
combine: ([r, w]) => CIRCLE_RADIUS.combine([r]) + CIRCLE_STROKE_WIDTH.combine([w]) / 2
|
|
510
|
+
});
|
|
511
|
+
const lineWidth = accessor(CIRCLE_STROKE_WIDTH);
|
|
512
|
+
const fillColor = accessor(CIRCLE_FILL_COLOR);
|
|
513
|
+
const lineColor = accessor(CIRCLE_STROKE_COLOR);
|
|
514
|
+
const blur = getStyleAccessor(
|
|
148
515
|
styleLayer,
|
|
149
|
-
['circle-
|
|
516
|
+
['circle-blur'],
|
|
150
517
|
zoom,
|
|
151
|
-
([value]) =>
|
|
152
|
-
|
|
153
|
-
// Scatterplot adds offsets in clip space (billboard) or common space (map), both y-up.
|
|
154
|
-
return [x, y === 0 ? 0 : -y];
|
|
155
|
-
}
|
|
518
|
+
([value]) => Math.min(1, Math.max(0, Number(value ?? DEFAULT_BLUR) || 0)),
|
|
519
|
+
featureState
|
|
156
520
|
);
|
|
157
521
|
const alignment = getStyleAccessor(styleLayer, ['circle-pitch-alignment'], zoom, ([v]) => v);
|
|
522
|
+
const billboard = globe || alignment.value !== 'map';
|
|
158
523
|
|
|
159
524
|
const hasBlur = styleLayer.paint?.['circle-blur'] !== undefined;
|
|
160
525
|
|
|
161
|
-
return new
|
|
526
|
+
return new ZoomPaintScatterplotLayer({
|
|
162
527
|
...baseProps,
|
|
163
528
|
id,
|
|
164
529
|
data: sortFeaturesByKey(points, styleLayer, 'circle-sort-key', zoom),
|
|
@@ -167,18 +532,29 @@ export function createCircleSubLayer({
|
|
|
167
532
|
getLineWidth: lineWidth.value,
|
|
168
533
|
getFillColor: fillColor.value,
|
|
169
534
|
getLineColor: lineColor.value,
|
|
170
|
-
|
|
535
|
+
circleZoomPaint: zoomPaint?.evaluate ?? null,
|
|
536
|
+
...(zoomPaint?.size ? {getNextCircleSize: zoomPaint.size.value} : {}),
|
|
537
|
+
...(zoomPaint?.fill ? {getNextCircleFillColor: zoomPaint.fill.value} : {}),
|
|
538
|
+
...(zoomPaint?.line ? {getNextCircleLineColor: zoomPaint.line.value} : {}),
|
|
539
|
+
extensions: [
|
|
540
|
+
...(baseProps.extensions || []),
|
|
541
|
+
...(hasBlur ? [CIRCLE_BLUR_EXTENSION] : []),
|
|
542
|
+
...(translate ? [CIRCLE_TRANSLATE_EXTENSION] : [])
|
|
543
|
+
],
|
|
171
544
|
...(hasBlur ? {getBlur: blur.value} : {}),
|
|
172
|
-
|
|
173
|
-
billboard
|
|
174
|
-
stroked: styleLayer.paint?.['circle-stroke-width'] !== undefined &&
|
|
545
|
+
...translate,
|
|
546
|
+
billboard,
|
|
547
|
+
stroked: styleLayer.paint?.['circle-stroke-width'] !== undefined &&
|
|
548
|
+
(lineWidth.value !== 0 || Boolean(zoomPaint?.widthChangesWithZoom)),
|
|
175
549
|
updateTriggers: {
|
|
176
550
|
getRadius: radius.updateTrigger,
|
|
177
551
|
getLineWidth: lineWidth.updateTrigger,
|
|
178
552
|
getFillColor: fillColor.updateTrigger,
|
|
179
553
|
getLineColor: lineColor.updateTrigger,
|
|
180
|
-
|
|
181
|
-
|
|
554
|
+
getNextCircleSize: zoomPaint?.size?.updateTrigger,
|
|
555
|
+
getNextCircleFillColor: zoomPaint?.fill?.updateTrigger,
|
|
556
|
+
getNextCircleLineColor: zoomPaint?.line?.updateTrigger,
|
|
557
|
+
getBlur: hasBlur ? blur.updateTrigger : undefined
|
|
182
558
|
},
|
|
183
559
|
radiusUnits: 'pixels',
|
|
184
560
|
lineWidthUnits: 'pixels',
|