@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
package/src/polylabel.ts DELETED
@@ -1,312 +0,0 @@
1
- // tangram-layers
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- // deck.gl-community
6
- // SPDX-License-Identifier: MIT
7
- // Copyright (c) vis.gl contributors
8
-
9
- // Point labels on polygons sit at the polygon's pole of inaccessibility: the interior point
10
- // farthest from the outline. MapLibre places them there too. This file finds that point with the
11
- // grid refinement of Garcia-Castellanos and Lombardo, "Poles of inaccessibility: a calculation
12
- // algorithm for the remotest places on Earth" (Scottish Geographical Journal 123(3), 2007),
13
- // in its best-first form: candidate squares wait in a priority queue, ordered by the largest
14
- // distance any point in them could have, and a square is split into four only while it could
15
- // still beat the best point found by more than the precision.
16
- //
17
- // Tile geometry is untrusted input, so the search is bounded by the work it does. Scoring one
18
- // candidate costs one point-to-segment distance test per polygon vertex. The search counts those
19
- // tests against a budget, and returns the best point found when the budget runs out. A caller
20
- // can share one budget across all polygons of a tile, so a tile with many large polygons cannot
21
- // hold the main thread either. The first grid also has at most MAX_GRID_CELLS_PER_AXIS squares
22
- // along the longer side, and the precision has a floor relative to the polygon's size.
23
-
24
- const MAX_GRID_CELLS_PER_AXIS = 64;
25
- const MIN_RELATIVE_PRECISION = 1e-6;
26
- /** Default budget for one search: point-to-segment distance tests. */
27
- export const DEFAULT_POLE_SEARCH_SEGMENT_TESTS = 5e6;
28
-
29
- /** Remaining work, in point-to-segment distance tests, shared by the searches that use it. */
30
- export type PoleSearchBudget = {
31
- segmentTests: number;
32
- };
33
-
34
- /**
35
- * Returns the point inside a polygon farthest from its outline, to within `precision` in the
36
- * polygon's units. `polygon` is GeoJSON-style: an outer ring followed by hole rings. Coordinates
37
- * must be planar.
38
- *
39
- * The search spends at most `budget.segmentTests` point-to-segment distance tests and deducts
40
- * what it spends, so one budget can bound several searches. When the budget runs out the best
41
- * point found so far is returned. Returns null for a polygon without vertices, with a non-finite
42
- * coordinate, or when the budget cannot pay for the first scored point.
43
- */
44
- export function getPoleOfInaccessibility(
45
- polygon: number[][][],
46
- precision: number,
47
- budget: PoleSearchBudget = {segmentTests: DEFAULT_POLE_SEARCH_SEGMENT_TESTS}
48
- ): [number, number] | null {
49
- const outline = polygon[0];
50
- if (!outline || outline.length === 0) {
51
- return null;
52
- }
53
- const vertexCount = countFiniteVertices(polygon);
54
- if (vertexCount < 0) {
55
- return null;
56
- }
57
-
58
- const box = getRingBox(outline);
59
- const width = box.right - box.left;
60
- const height = box.top - box.bottom;
61
- if (width === 0 || height === 0) {
62
- return [box.left, box.bottom];
63
- }
64
- const longSide = Math.max(width, height);
65
- const tolerance = Math.max(
66
- Number.isFinite(precision) && precision > 0 ? precision : 0,
67
- longSide * MIN_RELATIVE_PRECISION
68
- );
69
-
70
- const search = new PoleSearch(polygon, vertexCount, budget);
71
-
72
- // Two cheap first guesses: the area centroid, which is inside most convex-ish shapes, and the
73
- // middle of the bounding box.
74
- const [centroidX, centroidY] = getAreaCentroid(polygon[0]);
75
- if (!search.score(centroidX, centroidY, 0)) {
76
- return null;
77
- }
78
- if (!search.score(box.left + width / 2, box.bottom + height / 2, 0)) {
79
- return search.bestPoint();
80
- }
81
-
82
- // The first grid uses squares as wide as the polygon's short side, so a long, thin polygon is
83
- // covered by squares that fit it. The cap keeps a sliver from starting with millions of them.
84
- const side = Math.max(Math.min(width, height), longSide / MAX_GRID_CELLS_PER_AXIS);
85
- const columns = Math.ceil(width / side);
86
- const rows = Math.ceil(height / side);
87
- for (let column = 0; column < columns; column++) {
88
- for (let row = 0; row < rows; row++) {
89
- const x = box.left + (column + 0.5) * side;
90
- const y = box.bottom + (row + 0.5) * side;
91
- if (!search.score(x, y, side / 2)) {
92
- return search.bestPoint();
93
- }
94
- }
95
- }
96
-
97
- search.refine(tolerance);
98
- return search.bestPoint();
99
- }
100
-
101
- /** Returns the number of vertices in all rings, or -1 if any coordinate is not finite. */
102
- function countFiniteVertices(polygon: number[][][]): number {
103
- let count = 0;
104
- for (const ring of polygon) {
105
- for (const point of ring) {
106
- if (!Number.isFinite(point[0]) || !Number.isFinite(point[1])) {
107
- return -1;
108
- }
109
- }
110
- count += ring.length;
111
- }
112
- return count;
113
- }
114
-
115
- function getRingBox(ring: number[][]): {left: number; bottom: number; right: number; top: number} {
116
- let left = Infinity;
117
- let bottom = Infinity;
118
- let right = -Infinity;
119
- let top = -Infinity;
120
- for (const point of ring) {
121
- left = Math.min(left, point[0]);
122
- right = Math.max(right, point[0]);
123
- bottom = Math.min(bottom, point[1]);
124
- top = Math.max(top, point[1]);
125
- }
126
- return {left, bottom, right, top};
127
- }
128
-
129
- /** The centroid of the area a ring encloses, or its first vertex when that area is zero. */
130
- function getAreaCentroid(ring: number[][]): [number, number] {
131
- let twiceArea = 0;
132
- let sumX = 0;
133
- let sumY = 0;
134
- let previous = ring[ring.length - 1];
135
- for (const current of ring) {
136
- const cross = previous[0] * current[1] - current[0] * previous[1];
137
- twiceArea += cross;
138
- sumX += (previous[0] + current[0]) * cross;
139
- sumY += (previous[1] + current[1]) * cross;
140
- previous = current;
141
- }
142
- if (twiceArea === 0) {
143
- return [ring[0][0], ring[0][1]];
144
- }
145
- return [sumX / (3 * twiceArea), sumY / (3 * twiceArea)];
146
- }
147
-
148
- /**
149
- * The state of one search: the best point so far and a max-heap of candidate squares. The
150
- * squares are kept in parallel arrays, and the heap holds their indices, ordered by `reach`.
151
- */
152
- class PoleSearch {
153
- private readonly polygon: number[][][];
154
- private readonly vertexCount: number;
155
- private readonly budget: PoleSearchBudget;
156
-
157
- private readonly centerX: number[] = [];
158
- private readonly centerY: number[] = [];
159
- private readonly halfSide: number[] = [];
160
- /** The largest distance to the outline that any point of the square can have. */
161
- private readonly reach: number[] = [];
162
- private readonly heap: number[] = [];
163
-
164
- private bestX = NaN;
165
- private bestY = NaN;
166
- private bestDistance = -Infinity;
167
-
168
- constructor(polygon: number[][][], vertexCount: number, budget: PoleSearchBudget) {
169
- this.polygon = polygon;
170
- this.vertexCount = vertexCount;
171
- this.budget = budget;
172
- }
173
-
174
- bestPoint(): [number, number] {
175
- return [this.bestX, this.bestY];
176
- }
177
-
178
- /**
179
- * Scores the square centered at (x, y), keeps its center if it is the best so far, and queues
180
- * the square if it has area. Returns false, without scoring, when the budget cannot pay.
181
- */
182
- score(x: number, y: number, half: number): boolean {
183
- if (this.budget.segmentTests < this.vertexCount) {
184
- return false;
185
- }
186
- this.budget.segmentTests -= this.vertexCount;
187
- const distance = getSignedOutlineDistance(this.polygon, x, y);
188
- if (distance > this.bestDistance) {
189
- this.bestX = x;
190
- this.bestY = y;
191
- this.bestDistance = distance;
192
- }
193
- if (half > 0) {
194
- // No point in the square is farther from the center than half its diagonal.
195
- this.enqueue(x, y, half, distance + half * Math.SQRT2);
196
- }
197
- return true;
198
- }
199
-
200
- /** Splits the most promising squares until none can beat the best point by `tolerance`. */
201
- refine(tolerance: number): void {
202
- while (this.heap.length > 0) {
203
- const index = this.dequeue();
204
- if (this.reach[index] - this.bestDistance <= tolerance) {
205
- // The heap is ordered by reach, so no remaining square can do better either.
206
- return;
207
- }
208
- const quarter = this.halfSide[index] / 2;
209
- const x = this.centerX[index];
210
- const y = this.centerY[index];
211
- if (
212
- !this.score(x - quarter, y - quarter, quarter) ||
213
- !this.score(x + quarter, y - quarter, quarter) ||
214
- !this.score(x - quarter, y + quarter, quarter) ||
215
- !this.score(x + quarter, y + quarter, quarter)
216
- ) {
217
- return;
218
- }
219
- }
220
- }
221
-
222
- private enqueue(x: number, y: number, half: number, reach: number): void {
223
- const index = this.reach.length;
224
- this.centerX.push(x);
225
- this.centerY.push(y);
226
- this.halfSide.push(half);
227
- this.reach.push(reach);
228
-
229
- const {heap} = this;
230
- let slot = heap.length;
231
- heap.push(index);
232
- while (slot > 0) {
233
- const parentSlot = (slot - 1) >> 1;
234
- if (this.reach[heap[parentSlot]] >= reach) {
235
- break;
236
- }
237
- heap[slot] = heap[parentSlot];
238
- slot = parentSlot;
239
- }
240
- heap[slot] = index;
241
- }
242
-
243
- private dequeue(): number {
244
- const {heap, reach} = this;
245
- const top = heap[0];
246
- const moved = heap.pop() as number;
247
- const size = heap.length;
248
- if (size === 0) {
249
- return top;
250
- }
251
- let slot = 0;
252
- for (;;) {
253
- let next = slot * 2 + 1;
254
- if (next >= size) {
255
- break;
256
- }
257
- if (next + 1 < size && reach[heap[next + 1]] > reach[heap[next]]) {
258
- next += 1;
259
- }
260
- if (reach[heap[next]] <= reach[moved]) {
261
- break;
262
- }
263
- heap[slot] = heap[next];
264
- slot = next;
265
- }
266
- heap[slot] = moved;
267
- return top;
268
- }
269
- }
270
-
271
- /**
272
- * Distance from (x, y) to the nearest edge of any ring: positive inside the polygon, negative
273
- * outside, and 0 on an edge. Inside is decided by the even-odd rule, so holes count as outside.
274
- */
275
- function getSignedOutlineDistance(polygon: number[][][], x: number, y: number): number {
276
- let nearestSquared = Infinity;
277
- let crossings = 0;
278
- for (const ring of polygon) {
279
- let start = ring[ring.length - 1];
280
- for (const end of ring) {
281
- // Count edges that cross the horizontal ray from (x, y) toward +x.
282
- if (start[1] <= y !== end[1] <= y) {
283
- const t = (y - start[1]) / (end[1] - start[1]);
284
- if (start[0] + t * (end[0] - start[0]) > x) {
285
- crossings++;
286
- }
287
- }
288
- nearestSquared = Math.min(nearestSquared, getSquaredSegmentDistance(x, y, start, end));
289
- start = end;
290
- }
291
- }
292
- if (nearestSquared === 0) {
293
- return 0;
294
- }
295
- const distance = Math.sqrt(nearestSquared);
296
- return crossings % 2 === 1 ? distance : -distance;
297
- }
298
-
299
- /** Squared distance from (x, y) to the segment from `start` to `end`. */
300
- function getSquaredSegmentDistance(x: number, y: number, start: number[], end: number[]): number {
301
- const edgeX = end[0] - start[0];
302
- const edgeY = end[1] - start[1];
303
- const lengthSquared = edgeX * edgeX + edgeY * edgeY;
304
- // Where the perpendicular from (x, y) meets the edge's line, as a fraction of the edge.
305
- const along =
306
- lengthSquared === 0
307
- ? 0
308
- : Math.max(0, Math.min(1, ((x - start[0]) * edgeX + (y - start[1]) * edgeY) / lengthSquared));
309
- const offsetX = start[0] + along * edgeX - x;
310
- const offsetY = start[1] + along * edgeY - y;
311
- return offsetX * offsetX + offsetY * offsetY;
312
- }