@tangram.gl/basemap-layers 0.0.0 → 10.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {LayerExtension, project32} from '@deck.gl/core';
|
|
6
|
-
import type {Layer} from '@deck.gl/core';
|
|
6
|
+
import type {FirstPersonViewport, Layer} from '@deck.gl/core';
|
|
7
|
+
import type {ShaderPlugin} from '@luma.gl/shaders';
|
|
8
|
+
import {isGeographicFirstPersonViewport} from './projected-background-layer';
|
|
9
|
+
import {createShaderInjectionPlugin} from './shader-injection-plugin';
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* Turns a billboard drawn along a line on a globe from the line's direction at the anchor (the
|
|
@@ -24,8 +27,8 @@ import type {Layer} from '@deck.gl/core';
|
|
|
24
27
|
* The instance angle and pixel offset are only declared in the layer's own shader source, after the
|
|
25
28
|
* hook functions, so they are copied into globals at the start of `main`.
|
|
26
29
|
*/
|
|
27
|
-
const getGlobeLineAngleModule = (keepUpright: boolean, pixelOffset?: string) => ({
|
|
28
|
-
name:
|
|
30
|
+
const getGlobeLineAngleModule = (keepUpright: boolean, pixelOffset?: string, mercator = false) => createShaderInjectionPlugin({
|
|
31
|
+
name: `${mercator ? 'mercator' : 'globe'}LineAngle${keepUpright ? 'Upright' : ''}${pixelOffset ? `_${pixelOffset}` : ''}`,
|
|
29
32
|
dependencies: [project32],
|
|
30
33
|
inject: {
|
|
31
34
|
'vs:#decl': /* glsl */ `
|
|
@@ -38,7 +41,11 @@ vec2 globeLineAngle_pixelOffset;
|
|
|
38
41
|
globeLineAngle_pixelOffset = ${pixelOffset ? `vec2(${pixelOffset}.x, -${pixelOffset}.y)` : 'vec2(0.0)'};
|
|
39
42
|
`,
|
|
40
43
|
'vs:DECKGL_FILTER_SIZE': /* glsl */ `
|
|
41
|
-
if (project.projectionMode == PROJECTION_MODE_GLOBE) {
|
|
44
|
+
if (${mercator ? 'true' : 'project.projectionMode == PROJECTION_MODE_GLOBE'}) {
|
|
45
|
+
${mercator ? `
|
|
46
|
+
vec3 globeLineAngle_tangent = vec3(cos(globeLineAngle_angle), sin(globeLineAngle_angle), 0.0);
|
|
47
|
+
vec4 globeLineAngle_clip = project_common_position_to_clipspace(geometry.position);
|
|
48
|
+
` : `
|
|
42
49
|
float globeLineAngle_lambda = radians(geometry.worldPosition.x);
|
|
43
50
|
float globeLineAngle_phi = radians(geometry.worldPosition.y);
|
|
44
51
|
vec3 globeLineAngle_east = vec3(cos(globeLineAngle_lambda), sin(globeLineAngle_lambda), 0.0);
|
|
@@ -52,6 +59,7 @@ vec2 globeLineAngle_pixelOffset;
|
|
|
52
59
|
vec4 globeLineAngle_clip = project_common_position_to_clipspace(
|
|
53
60
|
vec4(project_position(geometry.worldPosition), 1.0)
|
|
54
61
|
);
|
|
62
|
+
`}
|
|
55
63
|
vec4 globeLineAngle_clipTangent = project.viewProjectionMatrix * vec4(globeLineAngle_tangent, 0.0);
|
|
56
64
|
// The derivative of the anchor's normalized device coordinates, times w squared, in pixels.
|
|
57
65
|
vec2 globeLineAngle_screen = (globeLineAngle_clipTangent.xy * globeLineAngle_clip.w -
|
|
@@ -85,13 +93,67 @@ const GLOBE_LINE_ANGLE_MODULES = {
|
|
|
85
93
|
instancePixelOffsets: getGlobeLineAngleModule(true, 'instancePixelOffsets')
|
|
86
94
|
};
|
|
87
95
|
|
|
96
|
+
/** Apply the same screen-space rotation to Mercator billboards on WebGPU. */
|
|
97
|
+
function getMercatorLineAnglePluginWGSL(pixelOffset: string, keepUpright: boolean): ShaderPlugin {
|
|
98
|
+
// Glyphs and text backgrounds both expose these attributes in their vertex entry point.
|
|
99
|
+
const input = pixelOffset === 'instancePixelOffsets' ? 'attributes' : 'inp';
|
|
100
|
+
return {
|
|
101
|
+
name: `mercatorLineAngle${keepUpright ? 'Upright' : ''}_${pixelOffset}`,
|
|
102
|
+
injections: [
|
|
103
|
+
{stage: 'vertex', target: '#decl', wgsl: `
|
|
104
|
+
var<private> mercatorLineAngle: f32;
|
|
105
|
+
var<private> mercatorLinePixelOffset: vec2<f32>;
|
|
106
|
+
`},
|
|
107
|
+
{stage: 'vertex', target: '#main-start', wgsl: `
|
|
108
|
+
mercatorLineAngle = radians(${input}.instanceAngles);
|
|
109
|
+
${keepUpright ? `mercatorLinePixelOffset = vec2<f32>(${input}.${pixelOffset}.x, -${input}.${pixelOffset}.y);` : ''}
|
|
110
|
+
`},
|
|
111
|
+
{
|
|
112
|
+
stage: 'vertex',
|
|
113
|
+
target: 'DECKGL_FILTER_SIZE',
|
|
114
|
+
wgsl: /* wgsl */ `
|
|
115
|
+
{
|
|
116
|
+
let angle = mercatorLineAngle;
|
|
117
|
+
let direction = vec2<f32>(cos(angle), sin(angle));
|
|
118
|
+
let clip = project_common_position_to_clipspace(geometry.position);
|
|
119
|
+
let tangent = project.viewProjectionMatrix * vec4<f32>(direction, 0.0, 0.0);
|
|
120
|
+
let screen = (tangent.xy * clip.w - clip.xy * tangent.w) * project.viewportSize;
|
|
121
|
+
let turn = atan2(screen.y, screen.x) - angle;
|
|
122
|
+
var offset = (*size).xy;
|
|
123
|
+
${keepUpright ? `
|
|
124
|
+
if (screen.x < 0.0) {
|
|
125
|
+
offset = 2.0 * mercatorLinePixelOffset - offset;
|
|
126
|
+
}
|
|
127
|
+
` : ''}
|
|
128
|
+
let rotation = mat2x2<f32>(cos(turn), sin(turn), -sin(turn), cos(turn));
|
|
129
|
+
*size = vec3<f32>(rotation * offset, (*size).z);
|
|
130
|
+
}
|
|
131
|
+
`
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const MERCATOR_LINE_ANGLE_MODULES = {
|
|
138
|
+
free: getGlobeLineAngleModule(false, undefined, true),
|
|
139
|
+
instancePixelOffset: getGlobeLineAngleModule(true, 'instancePixelOffset', true),
|
|
140
|
+
instancePixelOffsets: getGlobeLineAngleModule(true, 'instancePixelOffsets', true)
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const MERCATOR_LINE_ANGLE_WGSL = {
|
|
144
|
+
instancePixelOffset: {
|
|
145
|
+
free: getMercatorLineAnglePluginWGSL('instancePixelOffset', false),
|
|
146
|
+
upright: getMercatorLineAnglePluginWGSL('instancePixelOffset', true)
|
|
147
|
+
},
|
|
148
|
+
instancePixelOffsets: {
|
|
149
|
+
free: getMercatorLineAnglePluginWGSL('instancePixelOffsets', false),
|
|
150
|
+
upright: getMercatorLineAnglePluginWGSL('instancePixelOffsets', true)
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
88
154
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* north up, and the shader turns them as the view draws the line, upright with `keepUpright`. In
|
|
92
|
-
* other views it does nothing. Add it only to billboards (the shader would also turn the offset of
|
|
93
|
-
* a layer drawn in the map plane) whose angle is a direction on the map. WebGL only: on WebGPU the
|
|
94
|
-
* extension adds no shader code, and they stay as they are drawn from north up.
|
|
155
|
+
* Turns camera-facing labels along the projected line, upright with `keepUpright`. The globe
|
|
156
|
+
* uses this on WebGL. With `mercator`, viewport-pitched road text uses it on both backends.
|
|
95
157
|
*
|
|
96
158
|
* Added to a composite layer such as `TextLayer`, it reaches the character and background
|
|
97
159
|
* sublayers. With `keepOffsetSide`, text kept upright is turned around without its pixel offset,
|
|
@@ -100,32 +162,130 @@ const GLOBE_LINE_ANGLE_MODULES = {
|
|
|
100
162
|
export class GlobeLineAngleExtension extends LayerExtension<{
|
|
101
163
|
keepUpright: boolean;
|
|
102
164
|
keepOffsetSide?: boolean;
|
|
165
|
+
mercator?: boolean;
|
|
103
166
|
}> {
|
|
104
167
|
static extensionName = 'GlobeLineAngleExtension';
|
|
105
168
|
|
|
106
|
-
constructor(opts: {keepUpright: boolean; keepOffsetSide?: boolean}) {
|
|
169
|
+
constructor(opts: {keepUpright: boolean; keepOffsetSide?: boolean; mercator?: boolean}) {
|
|
107
170
|
super(opts);
|
|
108
171
|
}
|
|
109
172
|
|
|
110
173
|
getShaders(this: Layer, extension: GlobeLineAngleExtension) {
|
|
174
|
+
const {keepUpright, keepOffsetSide, mercator} = extension.opts;
|
|
175
|
+
// `TextLayer`'s backgrounds name the attribute in the plural.
|
|
176
|
+
const attributes = (this.getAttributeManager() as any)?.attributes || {};
|
|
177
|
+
const pixelOffset = attributes.instancePixelOffsets ? 'instancePixelOffsets' : 'instancePixelOffset';
|
|
178
|
+
if (mercator) {
|
|
179
|
+
const plugin = this.context.device.type === 'webgpu'
|
|
180
|
+
? MERCATOR_LINE_ANGLE_WGSL[pixelOffset][keepUpright ? 'upright' : 'free']
|
|
181
|
+
: MERCATOR_LINE_ANGLE_MODULES[keepUpright ? pixelOffset : 'free'];
|
|
182
|
+
return {plugins: [plugin]};
|
|
183
|
+
}
|
|
111
184
|
if (this.context.device.type === 'webgpu') {
|
|
112
185
|
return {};
|
|
113
186
|
}
|
|
114
|
-
const {keepUpright, keepOffsetSide} = extension.opts;
|
|
115
187
|
if (!keepUpright) {
|
|
116
|
-
return {
|
|
188
|
+
return {plugins: [GLOBE_LINE_ANGLE_MODULES.free]};
|
|
117
189
|
}
|
|
118
190
|
if (!keepOffsetSide) {
|
|
119
|
-
return {
|
|
191
|
+
return {plugins: [GLOBE_LINE_ANGLE_MODULES.upright]};
|
|
120
192
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
193
|
+
return {plugins: [GLOBE_LINE_ANGLE_MODULES[pixelOffset]]};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Forward distance to the ground at the view center, limited to the far plane at the horizon. */
|
|
198
|
+
export function getFirstPersonLabelReferenceDepth(viewport: FirstPersonViewport): number {
|
|
199
|
+
const {cameraPosition, viewMatrixInverse, projectionMatrix} = viewport;
|
|
200
|
+
const groundDepth = cameraPosition[2] / viewMatrixInverse[10];
|
|
201
|
+
const farDepth = projectionMatrix[14] / (projectionMatrix[10] + 1);
|
|
202
|
+
const hasFarDepth = Number.isFinite(farDepth) && farDepth > 0;
|
|
203
|
+
if (Number.isFinite(groundDepth) && groundDepth > 0) {
|
|
204
|
+
return hasFarDepth ? Math.min(groundDepth, farDepth) : groundDepth;
|
|
205
|
+
}
|
|
206
|
+
return hasFarDepth ? farDepth : 0;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** MapLibre's viewport-pitched symbol size, shared with placement. */
|
|
210
|
+
export function getFirstPersonLabelPerspective(referenceDepth: number, anchorDepth: number): number {
|
|
211
|
+
return referenceDepth > 0 && anchorDepth > 0
|
|
212
|
+
? Math.min(4, 0.5 + 0.5 * referenceDepth / anchorDepth)
|
|
213
|
+
: 1;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const firstPersonLabelSizeUniforms = {referenceDepth: 'f32'} as const;
|
|
217
|
+
|
|
218
|
+
const firstPersonLabelSizeGLSL = createShaderInjectionPlugin({
|
|
219
|
+
name: 'firstPersonLabelSize',
|
|
220
|
+
dependencies: [project32],
|
|
221
|
+
vs: /* glsl */ `
|
|
222
|
+
layout(std140) uniform firstPersonLabelSizeUniforms {
|
|
223
|
+
float referenceDepth;
|
|
224
|
+
} firstPersonLabelSize;
|
|
225
|
+
`,
|
|
226
|
+
uniformTypes: firstPersonLabelSizeUniforms,
|
|
227
|
+
inject: {
|
|
228
|
+
'vs:DECKGL_FILTER_SIZE': {
|
|
229
|
+
order: 1,
|
|
230
|
+
injection: `
|
|
231
|
+
float referenceDepth = firstPersonLabelSize.referenceDepth;
|
|
232
|
+
if (referenceDepth > 0.0) {
|
|
233
|
+
float anchorDepth = project_common_position_to_clipspace(geometry.position).w;
|
|
234
|
+
float perspective = anchorDepth > 0.0 ? min(4.0, 0.5 + 0.5 * referenceDepth / anchorDepth) : 1.0;
|
|
235
|
+
size.xy *= perspective * max(0.0, anchorDepth) / project.focalDistance;
|
|
236
|
+
}
|
|
237
|
+
`
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const firstPersonLabelSizeWGSL: ShaderPlugin = {
|
|
243
|
+
name: 'firstPersonLabelSize',
|
|
244
|
+
module: {
|
|
245
|
+
name: 'firstPersonLabelSize',
|
|
246
|
+
source: /* wgsl */ `
|
|
247
|
+
struct FirstPersonLabelSizeUniforms {
|
|
248
|
+
referenceDepth: f32,
|
|
249
|
+
};
|
|
250
|
+
@group(1) @binding(auto) var<uniform> firstPersonLabelSize: FirstPersonLabelSizeUniforms;
|
|
251
|
+
`,
|
|
252
|
+
uniformTypes: firstPersonLabelSizeUniforms
|
|
253
|
+
},
|
|
254
|
+
injections: [{
|
|
255
|
+
stage: 'vertex',
|
|
256
|
+
target: 'DECKGL_FILTER_SIZE',
|
|
257
|
+
order: 1,
|
|
258
|
+
wgsl: `
|
|
259
|
+
let referenceDepth = firstPersonLabelSize.referenceDepth;
|
|
260
|
+
if (referenceDepth > 0.0) {
|
|
261
|
+
let anchorDepth = project_common_position_to_clipspace(geometry.position).w;
|
|
262
|
+
var perspective = 1.0;
|
|
263
|
+
if (anchorDepth > 0.0) {
|
|
264
|
+
perspective = min(4.0, 0.5 + 0.5 * referenceDepth / anchorDepth);
|
|
265
|
+
}
|
|
266
|
+
let firstPersonLabelScale = perspective * max(0.0, anchorDepth) / project.focalDistance;
|
|
267
|
+
*size = vec3<f32>((*size).xy * firstPersonLabelScale, (*size).z);
|
|
268
|
+
}
|
|
269
|
+
`
|
|
270
|
+
}]
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/** Size first-person billboard symbols in screen pixels with MapLibre's distance falloff. */
|
|
274
|
+
export class FirstPersonLabelSizeExtension extends LayerExtension {
|
|
275
|
+
static extensionName = 'FirstPersonLabelSizeExtension';
|
|
276
|
+
|
|
277
|
+
getShaders(this: Layer) {
|
|
278
|
+
return {plugins: [this.context.device.type === 'webgpu' ? firstPersonLabelSizeWGSL : firstPersonLabelSizeGLSL]};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
draw(this: Layer) {
|
|
282
|
+
const {viewport} = this.context;
|
|
283
|
+
this.setShaderModuleProps({
|
|
284
|
+
firstPersonLabelSize: {
|
|
285
|
+
referenceDepth: isGeographicFirstPersonViewport(viewport)
|
|
286
|
+
? getFirstPersonLabelReferenceDepth(viewport)
|
|
287
|
+
: 0
|
|
288
|
+
}
|
|
289
|
+
});
|
|
130
290
|
}
|
|
131
291
|
}
|
package/src/glyph-store.ts
CHANGED
|
@@ -6,8 +6,14 @@
|
|
|
6
6
|
// SPDX-License-Identifier: MIT
|
|
7
7
|
// Copyright (c) vis.gl contributors
|
|
8
8
|
|
|
9
|
+
import {getBasemapResourceFetch, type BasemapTransformRequest} from './basemap-request';
|
|
9
10
|
import {GLYPH_RANGE_SIZE, parseGlyphRange} from './glyph-pbf';
|
|
10
11
|
import type {Glyph} from './glyph-pbf';
|
|
12
|
+
import {
|
|
13
|
+
BasemapFetchError,
|
|
14
|
+
getBasemapLoadError,
|
|
15
|
+
type BasemapLoadErrorHandler
|
|
16
|
+
} from './basemap-error';
|
|
11
17
|
|
|
12
18
|
/** Options for a {@link GlyphStore}. */
|
|
13
19
|
export type GlyphStoreOptions = {
|
|
@@ -17,6 +23,10 @@ export type GlyphStoreOptions = {
|
|
|
17
23
|
baseUrl?: string;
|
|
18
24
|
fetch?: typeof fetch;
|
|
19
25
|
fetchOptions?: RequestInit;
|
|
26
|
+
/** Called for each range that fails to load, in place of the warning logged without it. */
|
|
27
|
+
onError?: BasemapLoadErrorHandler;
|
|
28
|
+
/** Changes each glyph range request before it is sent (see `BasemapTransformRequest`). */
|
|
29
|
+
transformRequest?: BasemapTransformRequest | null;
|
|
20
30
|
};
|
|
21
31
|
|
|
22
32
|
/** The highest code point of a glyph range, as in MapLibre GL JS. */
|
|
@@ -66,8 +76,11 @@ export class GlyphStore {
|
|
|
66
76
|
*/
|
|
67
77
|
readonly id = ++lastStoreId;
|
|
68
78
|
readonly url: string;
|
|
79
|
+
/** Whether a glyph range failed to load. Such a range holds no glyphs, and is not loaded again. */
|
|
80
|
+
failed = false;
|
|
69
81
|
private readonly fetch: typeof fetch;
|
|
70
82
|
private readonly fetchOptions?: RequestInit;
|
|
83
|
+
private readonly onError?: BasemapLoadErrorHandler;
|
|
71
84
|
private readonly stacks = new Map<string, StackEntry>();
|
|
72
85
|
/** The font stacks each consumer retains (see `retain`). */
|
|
73
86
|
private readonly retained = new Map<object, Set<string>>();
|
|
@@ -76,10 +89,11 @@ export class GlyphStore {
|
|
|
76
89
|
/** Called once when a consumer next gives back a font stack (see `onRetainedFreed`). */
|
|
77
90
|
private readonly freedListeners = new Map<object, () => void>();
|
|
78
91
|
|
|
79
|
-
constructor({url, baseUrl, fetch: fetchFn, fetchOptions}: GlyphStoreOptions) {
|
|
92
|
+
constructor({url, baseUrl, fetch: fetchFn, fetchOptions, transformRequest, onError}: GlyphStoreOptions) {
|
|
80
93
|
this.url = resolveGlyphsUrl(url, baseUrl);
|
|
81
|
-
this.fetch =
|
|
94
|
+
this.fetch = getBasemapResourceFetch('Glyphs', 'arrayBuffer', {fetch: fetchFn, transformRequest});
|
|
82
95
|
this.fetchOptions = fetchOptions;
|
|
96
|
+
this.onError = onError;
|
|
83
97
|
}
|
|
84
98
|
|
|
85
99
|
/**
|
|
@@ -242,9 +256,10 @@ export class GlyphStore {
|
|
|
242
256
|
private async loadRange(fontStack: string, range: number): Promise<Map<number, Glyph>> {
|
|
243
257
|
const glyphs = new Map<number, Glyph>();
|
|
244
258
|
try {
|
|
245
|
-
const
|
|
259
|
+
const url = this.getRangeUrl(fontStack, range);
|
|
260
|
+
const response = await this.fetch(url, this.fetchOptions);
|
|
246
261
|
if (!response.ok) {
|
|
247
|
-
throw new
|
|
262
|
+
throw new BasemapFetchError(`HTTP ${response.status}`, url, response.status);
|
|
248
263
|
}
|
|
249
264
|
for (const glyph of parseGlyphRange(await response.arrayBuffer())) {
|
|
250
265
|
if (getGlyphRange(glyph.id) === range) {
|
|
@@ -252,8 +267,15 @@ export class GlyphStore {
|
|
|
252
267
|
}
|
|
253
268
|
}
|
|
254
269
|
} catch (error) {
|
|
255
|
-
|
|
256
|
-
|
|
270
|
+
this.failed = true;
|
|
271
|
+
if (this.onError) {
|
|
272
|
+
this.onError(
|
|
273
|
+
getBasemapLoadError('glyphs', error, {url: this.getRangeUrl(fontStack, range)})
|
|
274
|
+
);
|
|
275
|
+
} else {
|
|
276
|
+
// biome-ignore lint/suspicious/noConsole: a missing range leaves its characters undrawn.
|
|
277
|
+
console.warn(`Failed to load glyphs ${this.getRangeUrl(fontStack, range)}`, error);
|
|
278
|
+
}
|
|
257
279
|
}
|
|
258
280
|
return glyphs;
|
|
259
281
|
}
|