@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.
Files changed (139) hide show
  1. package/README.md +12 -7
  2. package/THIRD-PARTY-NOTICES.md +7 -5
  3. package/dist/geojson-task-worker.js +3166 -0
  4. package/dist/geojson-task-worker.js.map +6 -0
  5. package/dist/geojson-worker.js +1089 -7
  6. package/dist/geojson-worker.js.map +3 -3
  7. package/dist/index.cjs +9588 -2093
  8. package/dist/index.cjs.map +3 -3
  9. package/dist/index.js +9599 -2090
  10. package/dist/index.js.map +3 -3
  11. package/dist/map-style.cjs +456 -20
  12. package/dist/map-style.cjs.map +3 -3
  13. package/dist/map-style.js +456 -19
  14. package/dist/map-style.js.map +2 -2
  15. package/dist/types/basemap-error.d.ts +52 -0
  16. package/dist/types/basemap-layer.d.ts +378 -25
  17. package/dist/types/basemap-protocol.d.ts +91 -0
  18. package/dist/types/basemap-request.d.ts +73 -0
  19. package/dist/types/circle-layer.d.ts +65 -8
  20. package/dist/types/color-relief-layer.d.ts +184 -0
  21. package/dist/types/dem-pixels.d.ts +40 -0
  22. package/dist/types/feature-state.d.ts +55 -0
  23. package/dist/types/fill-extrusion-lighting-extension.d.ts +1 -2
  24. package/dist/types/fill-outline-extension.d.ts +2 -3
  25. package/dist/types/fill-pattern.d.ts +35 -3
  26. package/dist/types/fill-style-extensions.d.ts +11 -59
  27. package/dist/types/geojson-resource.d.ts +18 -0
  28. package/dist/types/geojson-source.d.ts +13 -2
  29. package/dist/types/geojson-task-handler.d.ts +2 -0
  30. package/dist/types/geojson-task.d.ts +26 -0
  31. package/dist/types/geojson-tiler.d.ts +29 -2
  32. package/dist/types/geojson-worker.d.ts +5 -1
  33. package/dist/types/globe-horizon-extension.d.ts +2 -45
  34. package/dist/types/globe-layers.d.ts +141 -45
  35. package/dist/types/globe-line-angle-extension.d.ts +20 -17
  36. package/dist/types/glyph-store.d.ts +10 -1
  37. package/dist/types/heatmap-layer.d.ts +99 -0
  38. package/dist/types/hillshade-layer.d.ts +159 -27
  39. package/dist/types/icon-text-fit.d.ts +92 -0
  40. package/dist/types/image-source-layer.d.ts +142 -0
  41. package/dist/types/index.d.ts +25 -1
  42. package/dist/types/line-blur-extension.d.ts +3 -11
  43. package/dist/types/line-dash-extension.d.ts +53 -0
  44. package/dist/types/line-gradient-extension.d.ts +69 -0
  45. package/dist/types/line-metrics.d.ts +24 -0
  46. package/dist/types/line-pattern-extension.d.ts +50 -0
  47. package/dist/types/line-shape-extension.d.ts +76 -0
  48. package/dist/types/map-style-loader.d.ts +1 -1
  49. package/dist/types/map-style.d.ts +2 -2
  50. package/dist/types/mvt-label-layer.d.ts +111 -20
  51. package/dist/types/pmtiles-source.d.ts +38 -0
  52. package/dist/types/projected-background-layer.d.ts +63 -0
  53. package/dist/types/projected-bitmap-layer.d.ts +58 -0
  54. package/dist/types/projected-tile-data.d.ts +16 -0
  55. package/dist/types/projected-tile-selection.d.ts +72 -0
  56. package/dist/types/projected-tileset.d.ts +92 -0
  57. package/dist/types/projected-viewport.d.ts +76 -0
  58. package/dist/types/raster-color-extension.d.ts +4 -7
  59. package/dist/types/raster-fade.d.ts +155 -0
  60. package/dist/types/raster-tile-fingerprint.d.ts +11 -0
  61. package/dist/types/raster-tile-loader.d.ts +80 -0
  62. package/dist/types/shader-injection-plugin.d.ts +8 -0
  63. package/dist/types/source-features.d.ts +58 -0
  64. package/dist/types/source-tiles.d.ts +32 -0
  65. package/dist/types/sprite.d.ts +37 -3
  66. package/dist/types/stretch-icon-layer.d.ts +28 -0
  67. package/dist/types/style-accessor.d.ts +50 -12
  68. package/dist/types/style-expression.d.ts +22 -2
  69. package/dist/types/style-resolver.d.ts +47 -2
  70. package/dist/types/terrain-query.d.ts +39 -0
  71. package/dist/types/zoom-load-gate.d.ts +22 -0
  72. package/dist/types/zoom-paint-extension.d.ts +80 -11
  73. package/package.json +24 -21
  74. package/src/basemap-error.ts +82 -0
  75. package/src/basemap-layer.ts +1289 -101
  76. package/src/basemap-protocol.ts +353 -0
  77. package/src/basemap-request.ts +212 -0
  78. package/src/circle-layer.ts +430 -54
  79. package/src/color-relief-layer.ts +572 -0
  80. package/src/dem-pixels.ts +174 -0
  81. package/src/feature-state.ts +164 -0
  82. package/src/fill-extrusion-lighting-extension.ts +126 -9
  83. package/src/fill-outline-extension.ts +4 -4
  84. package/src/fill-pattern.ts +87 -9
  85. package/src/fill-style-extensions.ts +114 -44
  86. package/src/geojson-resource.ts +58 -0
  87. package/src/geojson-source.ts +106 -85
  88. package/src/geojson-task-handler.ts +11 -0
  89. package/src/geojson-task-worker.ts +8 -0
  90. package/src/geojson-task.ts +34 -0
  91. package/src/geojson-tiler.ts +270 -4
  92. package/src/geojson-worker.ts +36 -6
  93. package/src/globe-horizon-extension.ts +14 -4
  94. package/src/globe-layers.ts +1905 -406
  95. package/src/globe-line-angle-extension.ts +183 -23
  96. package/src/glyph-store.ts +28 -6
  97. package/src/heatmap-layer.ts +591 -0
  98. package/src/hillshade-layer.ts +309 -88
  99. package/src/icon-text-fit.ts +358 -0
  100. package/src/image-source-layer.ts +380 -0
  101. package/src/index.ts +58 -1
  102. package/src/line-blur-extension.ts +14 -12
  103. package/src/line-dash-extension.ts +303 -0
  104. package/src/line-gradient-extension.ts +191 -0
  105. package/src/line-metrics.ts +90 -0
  106. package/src/line-pattern-extension.ts +173 -0
  107. package/src/line-shape-extension.ts +272 -0
  108. package/src/map-style-loader.ts +5 -4
  109. package/src/map-style.ts +2 -1
  110. package/src/mvt-label-layer.ts +568 -144
  111. package/src/pmtiles-source.ts +276 -0
  112. package/src/projected-background-layer.ts +202 -0
  113. package/src/projected-bitmap-layer.ts +262 -0
  114. package/src/projected-tile-data.ts +132 -0
  115. package/src/projected-tile-selection.ts +605 -0
  116. package/src/projected-tileset.ts +183 -0
  117. package/src/projected-viewport.ts +254 -0
  118. package/src/raster-color-extension.ts +43 -18
  119. package/src/raster-fade.ts +319 -0
  120. package/src/raster-tile-fingerprint.ts +31 -0
  121. package/src/raster-tile-loader.ts +211 -0
  122. package/src/shader-injection-plugin.ts +25 -0
  123. package/src/source-features.ts +170 -0
  124. package/src/source-tiles.ts +102 -0
  125. package/src/sprite.ts +122 -15
  126. package/src/stretch-icon-layer.ts +87 -0
  127. package/src/style-accessor.ts +105 -17
  128. package/src/style-expression.ts +80 -3
  129. package/src/style-resolver.ts +200 -22
  130. package/src/terrain-query.ts +86 -0
  131. package/src/text-layout.ts +2 -3
  132. package/src/zoom-load-gate.ts +57 -0
  133. package/src/zoom-paint-extension.ts +245 -47
  134. package/dist/types/arabic-shaping.d.ts +0 -7
  135. package/dist/types/bidi.d.ts +0 -8
  136. package/dist/types/polylabel.d.ts +0 -17
  137. package/src/arabic-shaping.ts +0 -366
  138. package/src/bidi.ts +0 -199
  139. package/src/polylabel.ts +0 -312
@@ -0,0 +1,86 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Viewport} from '@deck.gl/core';
6
+ import {Matrix4} from '@math.gl/core/matrix';
7
+ import {unprojectScreenRay} from '@math.gl/geometry/culling';
8
+ import {containsScreenPixel} from '@tangram.gl/map-utils/screen-ray';
9
+
10
+ /** Structural loaders.gl-compatible hit, separating displayed geometry from source elevation. */
11
+ export type TerrainSurfaceHit = {
12
+ /** Displayed content position, in the same units as the query ray. */
13
+ readonly position: readonly [number, number, number];
14
+ /** Longitude/latitude degrees and physical, unexaggerated source elevation meters. */
15
+ readonly coordinate: readonly [number, number, number];
16
+ /** Distance in content units, independent of direction length. */
17
+ readonly distance: number;
18
+ /** Unit normal following displayed triangle winding. */
19
+ readonly normal: readonly [number, number, number];
20
+ /** Original triangle identity, not a GPU feature index. */
21
+ readonly triangleIndex: number;
22
+ /** Weights in original vertex order. */
23
+ readonly barycentric: readonly [number, number, number];
24
+ };
25
+
26
+ /**
27
+ * Borrowed displayed terrain query owner. Structurally compatible with loaders.gl 5
28
+ * and Tangram without requiring either renderer or an alpha dependency upgrade.
29
+ */
30
+ export type TerrainSurface = {
31
+ /** Mercator XYZ meters or host-defined center-relative globe common units. */
32
+ readonly projection: 'web-mercator' | 'globe';
33
+ /** Nearest loaded hit inside the inclusive distance; a miss does not certify coverage. */
34
+ intersectRay(
35
+ ray: {
36
+ /** Absolute content origin, before camera and room-placement transforms. */
37
+ readonly origin: readonly [number, number, number];
38
+ /** Nonzero finite direction, not necessarily normalized. */
39
+ readonly direction: readonly [number, number, number];
40
+ },
41
+ maxDistance?: number
42
+ ): TerrainSurfaceHit | null;
43
+ };
44
+
45
+ /**
46
+ * Route an absolute top-origin CSS pixel through one actual deck viewport/eye.
47
+ * commonToSurface must be a finite affine transform from that viewport's common
48
+ * coordinates to the provider's content coordinates, including units and offsets.
49
+ * No geographic projection, globe radius, exaggeration or datum conversion is guessed.
50
+ * The provider remains responsible for matching the currently displayed generation.
51
+ */
52
+ export function pickTerrainSurface(
53
+ viewport: Pick<Viewport, 'x' | 'y' | 'width' | 'height' | 'viewProjectionMatrix'>,
54
+ pixel: readonly [number, number],
55
+ surface: TerrainSurface,
56
+ commonToSurface: Readonly<ArrayLike<number>>
57
+ ): TerrainSurfaceHit | null {
58
+ if (
59
+ commonToSurface.length !== 16 ||
60
+ !Array.from(commonToSurface).every(Number.isFinite) ||
61
+ commonToSurface[3] !== 0 ||
62
+ commonToSurface[7] !== 0 ||
63
+ commonToSurface[11] !== 0 ||
64
+ commonToSurface[15] !== 1
65
+ ) {
66
+ throw new RangeError('Terrain queries require a finite affine common-to-surface matrix');
67
+ }
68
+ // deck viewports require an explicit origin; the shared helper also accepts omitted origins.
69
+ if (!Number.isFinite(viewport.x) || !Number.isFinite(viewport.y) ||
70
+ !containsScreenPixel(viewport, pixel)) return null;
71
+ const conversion = new Matrix4(Array.from(commonToSurface));
72
+ if (!Number.isFinite(conversion.determinant()) || conversion.determinant() === 0) {
73
+ throw new RangeError('Terrain common-to-surface matrix must be invertible');
74
+ }
75
+ if (
76
+ viewport.viewProjectionMatrix.length !== 16 ||
77
+ !Array.from(viewport.viewProjectionMatrix).every(Number.isFinite)
78
+ )
79
+ return null;
80
+ const projection = new Matrix4(viewport.viewProjectionMatrix);
81
+ if (!Number.isFinite(projection.determinant()) || projection.determinant() === 0) return null;
82
+ const transform = conversion.multiplyRight(projection.invert());
83
+ const segment = unprojectScreenRay(transform, viewport, pixel);
84
+ if (!segment) return null;
85
+ return surface.intersectRay(segment, Math.hypot(...segment.direction));
86
+ }
@@ -7,8 +7,7 @@
7
7
  // Copyright (c) vis.gl contributors
8
8
 
9
9
  // Line breaking follows MapLibre GL JS's src/symbol/shaping.ts (BSD-3-Clause).
10
- import {applyArabicShaping} from './arabic-shaping';
11
- import {containsRightToLeftText, processBidirectionalText} from './bidi';
10
+ import {applyArabicShaping, containsRightToLeftText, orderVisualText} from '@tangram.gl/map-utils/text/explicit';
12
11
 
13
12
  const WHITESPACE = new Set([0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x20]);
14
13
  const BREAKABLE = new Set([
@@ -304,7 +303,7 @@ function layOutLines(text: string, breaks: number[] | null): string {
304
303
  codeUnitBreaks.push(codeUnit);
305
304
  }
306
305
  }
307
- return processBidirectionalText(text, codeUnitBreaks)
306
+ return orderVisualText({order: 'logical', text}, codeUnitBreaks).lines
308
307
  .map(line => trimLine(Array.from(line)))
309
308
  .join('\n');
310
309
  }
@@ -0,0 +1,57 @@
1
+ // tangram-layers
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /**
6
+ * Holds the vector tile loads of a `BasemapLayer` while its views zoom. In a zoom gesture the
7
+ * tile selection passes through several tile zooms, each shown for a fraction of a second, and
8
+ * each tile loaded at one of them is decoded and triangulated on the main thread. A load that
9
+ * the caller holds waits until no view's zoom has changed for `delay` milliseconds. A pan does not
10
+ * change the zoom, and its loads do not wait.
11
+ */
12
+ export class ZoomLoadGate {
13
+ /** Milliseconds a load waits after the last zoom change; 0 loads at once. */
14
+ delay = 0;
15
+ private zooms = new Map<string, number>();
16
+ private lastChange = -Infinity;
17
+
18
+ /** Records the zoom of a view at a tile selection. The first zoom of a view is not a change. */
19
+ noteZoom(viewId: string, zoom: number, now = performance.now()): void {
20
+ const last = this.zooms.get(viewId);
21
+ if (last !== zoom) {
22
+ if (last !== undefined) {
23
+ this.lastChange = now;
24
+ }
25
+ this.zooms.set(viewId, zoom);
26
+ }
27
+ }
28
+
29
+ /** Milliseconds until a load may start: 0 when no view has zoomed for `delay`. */
30
+ getRemainingDelay(now = performance.now()): number {
31
+ return Math.max(0, this.lastChange + this.delay - now);
32
+ }
33
+
34
+ /**
35
+ * Resolves when no view has zoomed for `delay` milliseconds, when `signal` aborts, or when
36
+ * `isHeld` returns false. Returns whether the load was held at all.
37
+ */
38
+ async wait(signal?: AbortSignal | null, isHeld: () => boolean = () => true): Promise<boolean> {
39
+ let held = false;
40
+ for (let remaining = this.getRemainingDelay(); remaining > 0; remaining = this.getRemainingDelay()) {
41
+ if (signal?.aborted || !isHeld()) {
42
+ return held;
43
+ }
44
+ held = true;
45
+ await new Promise<void>(resolve => {
46
+ const timer = setTimeout(done, remaining);
47
+ signal?.addEventListener('abort', done, {once: true});
48
+ function done() {
49
+ clearTimeout(timer);
50
+ signal?.removeEventListener('abort', done);
51
+ resolve();
52
+ }
53
+ });
54
+ }
55
+ return held;
56
+ }
57
+ }
@@ -3,8 +3,11 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {LayerExtension} from '@deck.gl/core';
6
- import type {Accessor, Layer, LayerContext} from '@deck.gl/core';
6
+ import type {Accessor, AttributeManager, Layer, LayerContext, UpdateParameters} from '@deck.gl/core';
7
7
  import type {Device, Texture} from '@luma.gl/core';
8
+ import {getStyleZoom} from './projected-viewport';
9
+ import {getZoomBucket, getZoomPaintZoom} from './style-accessor';
10
+ import {createShaderInjectionPlugin} from './shader-injection-plugin';
8
11
 
9
12
  /** The most style layers whose paint one layer can take from `ZoomPaintExtension`. */
10
13
  export const MAX_ZOOM_PAINT_PARTS = 64;
@@ -13,17 +16,21 @@ export const MAX_ZOOM_PAINT_PARTS = 64;
13
16
  export const ZOOM_PAINT_WIDTH_ROW = 0;
14
17
  export const ZOOM_PAINT_LINE_COLOR_ROW = 1;
15
18
  export const ZOOM_PAINT_FILL_COLOR_ROW = 2;
16
- const ZOOM_PAINT_ROWS = 3;
19
+ /** The row of blend factors for composite width, line color and fill color. */
20
+ export const ZOOM_PAINT_INTERPOLATION_ROW = 3;
21
+ /** The number of rows in the paint texture. */
22
+ const ZOOM_PAINT_ROWS = 4;
17
23
 
18
24
  /**
19
25
  * The paint of each style layer drawn by a layer, at one zoom: an RGBA texel per style layer
20
- * (column) and value (row), `MAX_ZOOM_PAINT_PARTS` by 3. Column `i` is the style layer that
26
+ * (column) and value (row), `MAX_ZOOM_PAINT_PARTS` by 4. Column `i` is the style layer that
21
27
  * `getStylePart` returns `i` for.
22
28
  *
23
29
  * - `ZOOM_PAINT_WIDTH_ROW`: in red, a factor of the layer's width attribute.
24
30
  * - `ZOOM_PAINT_LINE_COLOR_ROW`, `ZOOM_PAINT_FILL_COLOR_ROW`: a color in 0-1, which replaces the
25
31
  * layer's color attribute unless its alpha is negative: the attribute then holds the style
26
32
  * layer's per-feature colors.
33
+ * - `ZOOM_PAINT_INTERPOLATION_ROW`: blend factors for width, line color and fill color in RGB.
27
34
  */
28
35
  export type ZoomPaintValues = Float32Array;
29
36
 
@@ -51,11 +58,41 @@ export class ZoomPaint {
51
58
  private texture: Texture | null = null;
52
59
  private written: ZoomPaintValues | null = null;
53
60
 
54
- /** `getValues` returns the values at the current zoom, the same array while they are unchanged. */
55
- constructor(readonly getValues: () => ZoomPaintValues) {}
61
+ /**
62
+ * `evaluate` returns the values at the viewport zoom and attribute bucket, the same array
63
+ * while they are unchanged. `partCount` is the number of style layers using the texture.
64
+ */
65
+ constructor(
66
+ private readonly evaluate: (zoom: number, bucket: number) => ZoomPaintValues,
67
+ private readonly partCount: number
68
+ ) {}
56
69
 
57
- /** The texture of the current values, created on first use. */
58
- getTexture(device: Device): Texture {
70
+ /** The values at a zoom, using the bucket at which the layer's attributes were generated. */
71
+ getValues(zoom: number, bucket = getZoomBucket(zoom)): ZoomPaintValues {
72
+ return this.evaluate(zoom, bucket);
73
+ }
74
+
75
+ /** Whether a fill or line in this batch can draw at the current viewport zoom. */
76
+ isVisible(zoom: number, bucket: number | undefined, filled: boolean, stroked: boolean): boolean {
77
+ const values = this.getValues(zoom, bucket);
78
+ for (let part = 0; part < this.partCount; part++) {
79
+ if (
80
+ (filled && values[getZoomPaintOffset(ZOOM_PAINT_FILL_COLOR_ROW, part) + 3] !== 0) ||
81
+ (stroked &&
82
+ values[getZoomPaintOffset(ZOOM_PAINT_WIDTH_ROW, part)] > 0 &&
83
+ values[getZoomPaintOffset(ZOOM_PAINT_LINE_COLOR_ROW, part) + 3] !== 0)
84
+ ) {
85
+ return true;
86
+ }
87
+ }
88
+ return false;
89
+ }
90
+
91
+ /**
92
+ * The texture of the current values, created on first use. The viewport zoom gives the
93
+ * layer-wide values, and the attributes' bucket gives the lower endpoint of each blend.
94
+ */
95
+ getTexture(device: Device, zoom: number, bucket?: number): Texture {
59
96
  if (this.texture?.device !== device) {
60
97
  this.destroy();
61
98
  this.texture = device.createTexture({
@@ -68,7 +105,7 @@ export class ZoomPaint {
68
105
  });
69
106
  }
70
107
  // Layers that share the texture share the values, so it is written once per change.
71
- const values = this.getValues();
108
+ const values = this.getValues(zoom, bucket);
72
109
  if (this.written !== values) {
73
110
  this.texture.writeData(values);
74
111
  this.written = values;
@@ -86,22 +123,32 @@ export class ZoomPaint {
86
123
  export type ZoomPaintExtensionProps = {
87
124
  /** The paint to apply; the layer draws its attributes as they are without it. */
88
125
  zoomPaint?: ZoomPaint | null;
126
+ /** The zoom option used to build this sublayer, shared with its drawing layers. */
127
+ zoomPaintGeneration?: {zoom: number} | null;
128
+ /** The lower endpoint of the composite paint attributes. */
129
+ zoomPaintBucket?: number;
89
130
  /** Which of `zoomPaint`'s style layers each object belongs to. */
90
131
  getStylePart?: Accessor<any, number>;
132
+ /** Width at the upper endpoint of the composite paint interval. */
133
+ getNextLineWidth?: Accessor<any, number>;
134
+ /** Line color at the upper endpoint of the composite paint interval. */
135
+ getNextLineColor?: Accessor<any, number[]>;
136
+ /** Fill color at the upper endpoint of the composite paint interval. */
137
+ getNextFillColor?: Accessor<any, number[]>;
138
+ /** Style part, next width and packed RGBA for a dashed path. */
139
+ getNextDashedPaint?: Accessor<any, number[]>;
91
140
  };
92
141
 
142
+ /** Declares the sampler shared by the path and polygon shader variants. */
93
143
  const zoomPaintModule = {
94
144
  name: 'zoomPaint',
95
- vs: /* glsl */ `\
96
- uniform highp sampler2D zoomPaintTexture;
97
- `
145
+ vs: /* glsl */ `uniform highp sampler2D zoomPaintTexture;`
98
146
  } as const;
99
147
 
148
+ /** Reads the texels belonging to the current object's style layer. */
100
149
  const DECLARATIONS = /* glsl */ `
101
- in float instanceStyleParts;
102
-
103
150
  vec4 zoomPaint_get(int row) {
104
- return texelFetch(zoomPaintTexture, ivec2(int(instanceStyleParts + 0.5), row), 0);
151
+ return texelFetch(zoomPaintTexture, ivec2(int(ZOOM_PAINT_PART + 0.5), row), 0);
105
152
  }
106
153
 
107
154
  vec4 zoomPaint_color(vec4 color, int row) {
@@ -110,24 +157,114 @@ vec4 zoomPaint_color(vec4 color, int row) {
110
157
  }
111
158
  `;
112
159
 
113
- /** `PathLayer`: widths and line colors. */
114
- const PATH_INJECTION = {
115
- 'vs:#decl': DECLARATIONS,
116
- 'vs:DECKGL_FILTER_SIZE': /* glsl */ `
160
+ /** Reads the style part from its own vertex input. */
161
+ const STYLE_PART = /* glsl */ `
162
+ in float instanceStyleParts;
163
+ #define ZOOM_PAINT_PART instanceStyleParts
164
+ `;
165
+ /** Declares the upper endpoint attributes for a composite path. */
166
+ const PATH_NEXT = /* glsl */ `
167
+ in float instanceNextLineWidths;
168
+ in vec4 instanceNextLineColors;
169
+ #define ZOOM_PAINT_NEXT_WIDTH instanceNextLineWidths
170
+ #define ZOOM_PAINT_NEXT_COLOR instanceNextLineColors
171
+ `;
172
+ /** Unpacks the style part, width and RGBA of a dashed path from one vertex input. */
173
+ const PACKED_PATH_NEXT = /* glsl */ `
174
+ in vec4 instanceNextDashedPaint;
175
+ #define ZOOM_PAINT_PART instanceNextDashedPaint.x
176
+ #define ZOOM_PAINT_NEXT_WIDTH instanceNextDashedPaint.y
177
+ #define ZOOM_PAINT_NEXT_COLOR zoomPaint_unpackColor(instanceNextDashedPaint.zw)
178
+
179
+ vec4 zoomPaint_unpackColor(vec2 packedColor) {
180
+ vec2 highBytes = floor(packedColor / 256.0);
181
+ vec2 lowBytes = packedColor - highBytes * 256.0;
182
+ return vec4(highBytes.x, lowBytes.x, highBytes.y, lowBytes.y) / 255.0;
183
+ }
184
+ `;
185
+
186
+ /**
187
+ * A dashed path can already use all sixteen guaranteed vertex inputs. Store the two pairs of
188
+ * color bytes as exact integers alongside the width and part in its existing paint input.
189
+ */
190
+ const colorBytes = new Uint8ClampedArray(4);
191
+ /** Packs two unorm8 color channels into each of two floats for a dashed path. */
192
+ export function packZoomPaintColor(color: number[]): [number, number] {
193
+ colorBytes.set(color);
194
+ return [256 * colorBytes[0] + colorBytes[1], 256 * colorBytes[2] + colorBytes[3]];
195
+ }
196
+
197
+ /** Applies per-part widths and colors to a path or flat polygon. */
198
+ function createPaintPlugin(path: boolean, composite = false, packed = false) {
199
+ const colorRow = path ? ZOOM_PAINT_LINE_COLOR_ROW : ZOOM_PAINT_FILL_COLOR_ROW;
200
+ const nextColor = path ? 'ZOOM_PAINT_NEXT_COLOR' : 'nextFillColors';
201
+ const colorFactor = path ? 'g' : 'b';
202
+ return createShaderInjectionPlugin({
203
+ ...zoomPaintModule,
204
+ inject: {
205
+ 'vs:#decl':
206
+ (packed ? PACKED_PATH_NEXT : STYLE_PART) +
207
+ DECLARATIONS +
208
+ (path && composite ? 'float zoomPaint_currentWidth;\n' : '') +
209
+ (composite && !packed ? (path ? PATH_NEXT : 'in vec4 nextFillColors;') : ''),
210
+ // The size hook is declared before the path shader's own vertex inputs.
211
+ ...(path && composite
212
+ ? {'vs:#main-start': 'zoomPaint_currentWidth = instanceStrokeWidths;'}
213
+ : {}),
214
+ ...(path
215
+ ? {
216
+ 'vs:DECKGL_FILTER_SIZE': {
217
+ order: -1,
218
+ injection: (composite
219
+ ? /* glsl */ `
220
+ float currentWidth = zoomPaint_currentWidth;
221
+ float widthFactor = zoomPaint_get(${ZOOM_PAINT_INTERPOLATION_ROW}).r;
222
+ if (widthFactor > 0.0) {
223
+ float width = mix(currentWidth, ZOOM_PAINT_NEXT_WIDTH, widthFactor);
224
+ if (currentWidth > 0.0) {
225
+ size *= width / currentWidth;
226
+ } else {
227
+ vec2 halfWidth = vec2(project_size_to_pixel(width * path.widthScale, path.widthUnits) / 2.0);
228
+ size.xy = path.billboard ? halfWidth : project_pixel_size(halfWidth);
229
+ }
230
+ }
231
+ `
232
+ : '') + /* glsl */ `
117
233
  size *= zoomPaint_get(${ZOOM_PAINT_WIDTH_ROW}).r;
234
+ `
235
+ }
236
+ }
237
+ : {}),
238
+ 'vs:DECKGL_FILTER_COLOR': (composite
239
+ ? /* glsl */ `
240
+ vec4 nextColor = ${nextColor};
241
+ nextColor.a *= layer.opacity;
242
+ color = mix(color, nextColor, zoomPaint_get(${ZOOM_PAINT_INTERPOLATION_ROW}).${colorFactor});
243
+ `
244
+ : '') + /* glsl */ `
245
+ color = zoomPaint_color(color, ${colorRow});
118
246
  `,
119
- 'vs:DECKGL_FILTER_COLOR': /* glsl */ `
120
- color = zoomPaint_color(color, ${ZOOM_PAINT_LINE_COLOR_ROW});
247
+ // A transparent part can share a batch with visible parts. Clip it in both color and
248
+ // picking passes, so that it writes neither depth nor a picking color.
249
+ 'vs:#main-end': /* glsl */ `
250
+ if (zoomPaint_get(${colorRow}).a == 0.0) {
251
+ gl_Position = vec4(0.0, 0.0, 2.0, 1.0);
252
+ }
121
253
  `
122
- };
254
+ }
255
+ });
256
+ }
123
257
 
258
+ /** `PathLayer`: widths and line colors. */
259
+ const PATH_PLUGIN = createPaintPlugin(true);
260
+ /** The path variant that also blends upper endpoint widths and colors. */
261
+ const COMPOSITE_PATH_PLUGIN = createPaintPlugin(true, true);
262
+ /** The composite variant that uses one vertex input for dashed path paint. */
263
+ const PACKED_PATH_PLUGIN = createPaintPlugin(true, true, true);
124
264
  /** `SolidPolygonLayer`: fill colors. Not for extruded polygons, whose colors are lit. */
125
- const POLYGON_INJECTION = {
126
- 'vs:#decl': DECLARATIONS,
127
- 'vs:DECKGL_FILTER_COLOR': /* glsl */ `
128
- color = zoomPaint_color(color, ${ZOOM_PAINT_FILL_COLOR_ROW});
129
- `
130
- };
265
+ const POLYGON_PLUGIN = createPaintPlugin(false);
266
+ /** The polygon variant that also blends upper endpoint fill colors. */
267
+ const COMPOSITE_POLYGON_PLUGIN = createPaintPlugin(false, true);
131
268
 
132
269
  function getLayerType(layer: Layer): 'path' | 'polygon' | null {
133
270
  const state = layer.state as Record<string, unknown> | undefined;
@@ -146,21 +283,34 @@ const boundTextures = new WeakMap<object, Texture>();
146
283
  /**
147
284
  * Takes the zoom-dependent paint of the style layers a `PathLayer` or flat `SolidPolygonLayer`
148
285
  * draws from a texture instead of attributes: per style layer, its line width and, when they are
149
- * the same for all of its features, its colors. The values are read when the layer draws, so a
150
- * zoom step changes a small texture, shared by every layer with the same `zoomPaint`: the layers'
151
- * props, and so their attributes, stay the same. Each object's style layer is an attribute, which
286
+ * the same for all of its features, its colors. It also uses the texture's blend factors to
287
+ * interpolate per-feature paint between attributes evaluated at the enclosing zoom steps.
288
+ * The values are read when the layer draws, so zooming within a step changes a small texture,
289
+ * shared by every layer with the same `zoomPaint`. The layers' props, and so their attributes,
290
+ * stay the same. Each object's style layer is an attribute, which
152
291
  * changes only with the data.
153
292
  *
154
293
  * The width factor applies after `widthMinPixels` and `widthMaxPixels`, which must not clamp.
155
294
  * The owner of a `ZoomPaint` destroys its texture. WebGL only.
156
295
  */
157
- export class ZoomPaintExtension extends LayerExtension {
296
+ export class ZoomPaintExtension extends LayerExtension<{composite: boolean; packedPath: boolean}> {
158
297
  static extensionName = 'ZoomPaintExtension';
159
298
  static defaultProps = {
160
299
  zoomPaint: {type: 'object', value: null},
161
- getStylePart: {type: 'accessor', value: 0}
300
+ zoomPaintGeneration: {type: 'object', value: null},
301
+ zoomPaintBucket: {type: 'number', value: null, optional: true},
302
+ getStylePart: {type: 'accessor', value: 0},
303
+ getNextLineWidth: {type: 'accessor', value: 1},
304
+ getNextLineColor: {type: 'accessor', value: [0, 0, 0, 0]},
305
+ getNextFillColor: {type: 'accessor', value: [0, 0, 0, 0]},
306
+ getNextDashedPaint: {type: 'accessor', value: [0, 1, 0, 0]}
162
307
  };
163
308
 
309
+ /** Selects the shader variant and the attributes it needs for the upper zoom endpoint. */
310
+ constructor({composite = false, packedPath = false} = {}) {
311
+ super({composite, packedPath});
312
+ }
313
+
164
314
  isEnabled(layer: Layer): boolean {
165
315
  return getLayerType(layer) !== null;
166
316
  }
@@ -170,32 +320,80 @@ export class ZoomPaintExtension extends LayerExtension {
170
320
  if (!type) {
171
321
  return null;
172
322
  }
173
- return {
174
- modules: [zoomPaintModule],
175
- inject: type === 'path' ? PATH_INJECTION : POLYGON_INJECTION
176
- };
323
+ const {composite, packedPath} = extension.opts;
324
+ const pathPlugin = packedPath ? PACKED_PATH_PLUGIN : COMPOSITE_PATH_PLUGIN;
325
+ const compositePlugin = type === 'path' ? pathPlugin : COMPOSITE_POLYGON_PLUGIN;
326
+ const basePlugin = type === 'path' ? PATH_PLUGIN : POLYGON_PLUGIN;
327
+ return {plugins: [composite ? compositePlugin : basePlugin]};
177
328
  }
178
329
 
179
- initializeState(this: Layer<ZoomPaintExtensionProps>, context: LayerContext, extension: this) {
180
- if (!extension.isEnabled(this)) {
330
+ /** Matches the layer's paint attributes to the selected shader variant. */
331
+ private synchronizeAttributes(layer: Layer): void {
332
+ const type = getLayerType(layer);
333
+ const manager = layer.getAttributeManager();
334
+ if (!type || !manager) {
181
335
  return;
182
336
  }
183
- this.getAttributeManager()?.add({
184
- instanceStyleParts: {
185
- size: 1,
186
- stepMode: 'dynamic',
187
- accessor: 'getStylePart',
188
- defaultValue: 0
337
+
338
+ const {composite, packedPath} = this.opts;
339
+ const packed = composite && type === 'path' && packedPath;
340
+ const desired: Parameters<AttributeManager['add']>[0] = packed
341
+ ? {
342
+ instanceNextDashedPaint: {size: 4, stepMode: 'instance', accessor: 'getNextDashedPaint'}
343
+ }
344
+ : {
345
+ instanceStyleParts: {size: 1, stepMode: 'dynamic', accessor: 'getStylePart', defaultValue: 0}
346
+ };
347
+ if (composite && !packed) {
348
+ if (type === 'path') {
349
+ desired.instanceNextLineWidths = {size: 1, stepMode: 'instance', accessor: 'getNextLineWidth'};
350
+ desired.instanceNextLineColors = {size: 4, type: 'unorm8', stepMode: 'instance', accessor: 'getNextLineColor'};
351
+ } else {
352
+ desired.nextFillColors = {size: 4, type: 'unorm8', stepMode: 'dynamic', accessor: 'getNextFillColor'};
353
+ }
354
+ }
355
+ const attributes = manager.getAttributes();
356
+ const removed = [
357
+ 'instanceNextDashedPaint', 'instanceStyleParts', 'instanceNextLineWidths',
358
+ 'instanceNextLineColors', 'nextFillColors'
359
+ ].filter(name => attributes[name] && !desired[name]);
360
+ const added = Object.entries(desired).filter(([name]) => !attributes[name]);
361
+ if (removed.length || added.length) {
362
+ manager.remove(removed);
363
+ manager.add(Object.fromEntries(added));
364
+ manager.invalidateAll();
365
+ // A style edit can switch shader variants on a layer whose model has already been created.
366
+ for (const model of layer.getModels()) {
367
+ model.setBufferLayout(manager.getBufferLayouts(model));
189
368
  }
190
- });
369
+ }
370
+ }
371
+
372
+ initializeState(this: Layer<ZoomPaintExtensionProps>, context: LayerContext, extension: this) {
373
+ extension.synchronizeAttributes(this);
374
+ }
375
+
376
+ /** Updates the paint attributes when the layer switches shader variants. */
377
+ updateState(
378
+ this: Layer<ZoomPaintExtensionProps>,
379
+ params: UpdateParameters<Layer<ZoomPaintExtensionProps>>,
380
+ extension: this
381
+ ) {
382
+ if (params.changeFlags.extensionsChanged) {
383
+ extension.synchronizeAttributes(this);
384
+ }
191
385
  }
192
386
 
193
387
  draw(this: Layer<ZoomPaintExtensionProps>, params: any, extension: this) {
194
- const {zoomPaint} = this.props;
388
+ const {zoomPaint, zoomPaintGeneration, zoomPaintBucket} = this.props;
195
389
  if (!zoomPaint || !extension.isEnabled(this)) {
196
390
  return;
197
391
  }
198
- const texture = zoomPaint.getTexture(this.context.device);
392
+ const texture = zoomPaint.getTexture(
393
+ this.context.device,
394
+ getZoomPaintZoom(getStyleZoom(this.context.viewport), zoomPaintGeneration?.zoom),
395
+ zoomPaintBucket ?? undefined
396
+ );
199
397
  const models = this.getModels();
200
398
  if (models.some(model => boundTextures.get(model) !== texture)) {
201
399
  this.setShaderModuleProps({zoomPaint: {zoomPaintTexture: texture}} as any);
@@ -1,7 +0,0 @@
1
- /**
2
- * Rewrites Arabic letters as the shape they take in their word, named by their Arabic
3
- * Presentation Forms code points (U+FB50–FDFF, U+FE70–FEFF), with lam-alef ligatures, as MapLibre
4
- * GL JS does: glyphs are drawn one code point at a time, so the contextual shape has to be chosen
5
- * before glyphs are looked up. Text with no Arabic in it is returned unchanged.
6
- */
7
- export declare function applyArabicShaping(text: string): string;
@@ -1,8 +0,0 @@
1
- /** Whether `text` has right-to-left characters, so that it needs {@link processBidirectionalText}. */
2
- export declare function containsRightToLeftText(text: string): boolean;
3
- /**
4
- * Puts text into the order it is drawn, broken into lines, as MapLibre GL JS does: the embedding
5
- * levels are found for the whole label, then each line is reordered on its own. A label is broken
6
- * at `lineBreakPoints` (UTF-16 code unit offsets) and wherever a paragraph ends.
7
- */
8
- export declare function processBidirectionalText(text: string, lineBreakPoints: number[]): string[];
@@ -1,17 +0,0 @@
1
- /** Default budget for one search: point-to-segment distance tests. */
2
- export declare const DEFAULT_POLE_SEARCH_SEGMENT_TESTS = 5000000;
3
- /** Remaining work, in point-to-segment distance tests, shared by the searches that use it. */
4
- export type PoleSearchBudget = {
5
- segmentTests: number;
6
- };
7
- /**
8
- * Returns the point inside a polygon farthest from its outline, to within `precision` in the
9
- * polygon's units. `polygon` is GeoJSON-style: an outer ring followed by hole rings. Coordinates
10
- * must be planar.
11
- *
12
- * The search spends at most `budget.segmentTests` point-to-segment distance tests and deducts
13
- * what it spends, so one budget can bound several searches. When the budget runs out the best
14
- * point found so far is returned. Returns null for a polygon without vertices, with a non-finite
15
- * coordinate, or when the budget cannot pay for the first scored point.
16
- */
17
- export declare function getPoleOfInaccessibility(polygon: number[][][], precision: number, budget?: PoleSearchBudget): [number, number] | null;