@loaders.gl/mvt 4.3.0-alpha.1 → 4.3.0-alpha.2

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 (77) hide show
  1. package/dist/dist.dev.js +568 -175
  2. package/dist/dist.min.js +1 -1
  3. package/dist/index.cjs +226 -163
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lib/parse-mvt.d.ts +1 -1
  9. package/dist/lib/parse-mvt.js +2 -30
  10. package/dist/lib/parse-tilejson.d.ts +4 -4
  11. package/dist/lib/parse-tilejson.d.ts.map +1 -1
  12. package/dist/lib/utils/geometry-utils.d.ts +38 -1
  13. package/dist/lib/utils/geometry-utils.d.ts.map +1 -1
  14. package/dist/lib/utils/geometry-utils.js +65 -6
  15. package/dist/lib/vector-tile/vector-tile-feature.d.ts +28 -9
  16. package/dist/lib/vector-tile/vector-tile-feature.d.ts.map +1 -1
  17. package/dist/lib/vector-tile/vector-tile-feature.js +47 -50
  18. package/dist/lib/{geojsonvt → vector-tiler}/clip.d.ts +3 -3
  19. package/dist/lib/vector-tiler/clip.d.ts.map +1 -0
  20. package/dist/lib/vector-tiler/convert.d.ts +18 -0
  21. package/dist/lib/vector-tiler/convert.d.ts.map +1 -0
  22. package/dist/lib/{geojsonvt → vector-tiler}/convert.js +8 -1
  23. package/dist/lib/vector-tiler/feature.d.ts +3 -0
  24. package/dist/lib/vector-tiler/feature.d.ts.map +1 -0
  25. package/dist/lib/vector-tiler/simplify.d.ts.map +1 -0
  26. package/dist/lib/{geojsonvt → vector-tiler}/tile.d.ts +4 -4
  27. package/dist/lib/vector-tiler/tile.d.ts.map +1 -0
  28. package/dist/lib/vector-tiler/transform.d.ts +7 -0
  29. package/dist/lib/vector-tiler/transform.d.ts.map +1 -0
  30. package/dist/lib/{geojsonvt → vector-tiler}/wrap.d.ts +2 -2
  31. package/dist/lib/vector-tiler/wrap.d.ts.map +1 -0
  32. package/dist/mvt-loader.d.ts +1 -1
  33. package/dist/mvt-loader.js +1 -1
  34. package/dist/mvt-source.d.ts +4 -4
  35. package/dist/mvt-source.d.ts.map +1 -1
  36. package/dist/mvt-source.js +4 -4
  37. package/dist/mvt-worker.js +101 -56
  38. package/dist/table-tile-source.d.ts +118 -0
  39. package/dist/table-tile-source.d.ts.map +1 -0
  40. package/dist/{geojson-tile-source.js → table-tile-source.js} +154 -103
  41. package/dist/tilejson-loader.js +1 -1
  42. package/package.json +7 -6
  43. package/src/index.ts +3 -3
  44. package/src/lib/parse-mvt.ts +4 -33
  45. package/src/lib/parse-tilejson.ts +5 -5
  46. package/src/lib/utils/geometry-utils.ts +66 -1
  47. package/src/lib/vector-tile/vector-tile-feature.ts +65 -56
  48. package/src/lib/{geojsonvt → vector-tiler}/clip.ts +4 -4
  49. package/src/lib/{geojsonvt → vector-tiler}/convert.ts +18 -8
  50. package/src/lib/{geojsonvt → vector-tiler}/feature.ts +3 -3
  51. package/src/lib/{geojsonvt → vector-tiler}/tile.ts +8 -8
  52. package/src/lib/{geojsonvt → vector-tiler}/transform.ts +2 -2
  53. package/src/lib/{geojsonvt → vector-tiler}/wrap.ts +5 -5
  54. package/src/mvt-source.ts +6 -7
  55. package/src/table-tile-source.ts +508 -0
  56. package/dist/geojson-tile-source.d.ts +0 -79
  57. package/dist/geojson-tile-source.d.ts.map +0 -1
  58. package/dist/lib/geojsonvt/clip.d.ts.map +0 -1
  59. package/dist/lib/geojsonvt/convert.d.ts +0 -10
  60. package/dist/lib/geojsonvt/convert.d.ts.map +0 -1
  61. package/dist/lib/geojsonvt/feature.d.ts +0 -3
  62. package/dist/lib/geojsonvt/feature.d.ts.map +0 -1
  63. package/dist/lib/geojsonvt/simplify.d.ts.map +0 -1
  64. package/dist/lib/geojsonvt/tile.d.ts.map +0 -1
  65. package/dist/lib/geojsonvt/transform.d.ts +0 -7
  66. package/dist/lib/geojsonvt/transform.d.ts.map +0 -1
  67. package/dist/lib/geojsonvt/wrap.d.ts.map +0 -1
  68. package/src/geojson-tile-source.ts +0 -422
  69. /package/dist/lib/{geojsonvt → vector-tiler}/clip.js +0 -0
  70. /package/dist/lib/{geojsonvt → vector-tiler}/feature.js +0 -0
  71. /package/dist/lib/{geojsonvt → vector-tiler}/simplify.d.ts +0 -0
  72. /package/dist/lib/{geojsonvt → vector-tiler}/simplify.js +0 -0
  73. /package/dist/lib/{geojsonvt → vector-tiler}/tile.js +0 -0
  74. /package/dist/lib/{geojsonvt → vector-tiler}/transform.js +0 -0
  75. /package/dist/lib/{geojsonvt → vector-tiler}/wrap.js +0 -0
  76. /package/src/lib/{geojsonvt → vector-tiler}/LICENSE +0 -0
  77. /package/src/lib/{geojsonvt → vector-tiler}/simplify.ts +0 -0
@@ -0,0 +1,508 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT AND ISC
3
+ // Copyright (c) vis.gl contributors
4
+ // Based on https://github.com/mapbox/geojson-vt under compatible ISC license
5
+
6
+ import type {
7
+ VectorTileSourceProps,
8
+ GetTileDataParameters,
9
+ GetTileParameters
10
+ } from '@loaders.gl/loader-utils';
11
+ import {VectorTileSource, log} from '@loaders.gl/loader-utils';
12
+ import {Schema, GeoJSONTable, Feature, BinaryFeatureCollection} from '@loaders.gl/schema';
13
+ import {deduceTableSchema} from '@loaders.gl/schema';
14
+ import {Stats, Stat} from '@probe.gl/stats';
15
+
16
+ import type {TableTile, TableTileFeature} from './lib/vector-tiler/tile';
17
+ import {convert} from './lib/vector-tiler/convert'; // GeoJSON conversion and preprocessing
18
+ import {clip} from './lib/vector-tiler/clip'; // stripe clipping algorithm
19
+ import {wrap} from './lib/vector-tiler/wrap'; // date line processing
20
+ import {transformTile} from './lib/vector-tiler/transform'; // coordinate transformation
21
+ import {createTile} from './lib/vector-tiler/tile'; // final simplified tile generation
22
+
23
+ import {projectToLngLat} from './lib/utils/geometry-utils';
24
+ import {convertToLocalCoordinates} from './lib/utils/geometry-utils';
25
+
26
+ /** Options to configure tiling */
27
+ export type TableTileSourceProps = VectorTileSourceProps & {
28
+ coordinates: 'local' | 'wgs84' | 'EPSG:4326';
29
+ /** max zoom to preserve detail on */
30
+ maxZoom?: number;
31
+ /** max zoom in the tile index */
32
+ indexMaxZoom?: number;
33
+ /** max number of points per tile in the tile index */
34
+ maxPointsPerTile?: number;
35
+ /** simplification tolerance (higher means simpler) */
36
+ tolerance?: number;
37
+ /** tile extent */
38
+ extent?: number;
39
+ /** tile buffer on each side */
40
+ buffer?: number;
41
+ /** name of a feature property to be promoted to feature.id */
42
+ promoteId?: string;
43
+ /** whether to generate feature ids. Cannot be used with promoteId */
44
+ generateId?: boolean;
45
+ /** logging level (0, 1 or 2) */
46
+ debug?: number;
47
+ /** whether to calculate line metrics */
48
+ lineMetrics?: boolean;
49
+ };
50
+
51
+ /**
52
+ * Dynamically vector tiles a table (the table needs a geometry column)
53
+ * - Tiles are generated when requested.
54
+ * - Each tile contains a tables of clipped features.
55
+ *
56
+ * @note - Currently only accepts `GeoJSONTable` tables
57
+ * @note - Currently only outputs `GeoJSONTable`
58
+ * @note - (can be initialized with a promise that resolves to GeoJSONTable).
59
+ *
60
+ * @todo - metadata should scan all rows to determine schema
61
+ * @todo - metadata scan all rows to determine tilestats (field values[] etc).
62
+ * @todo - handle binary input tables
63
+ * @todo - generate binary output tables
64
+ * @todo - how does TileSourceLayer specify coordinates / decided which layer to render with
65
+ */
66
+ export class TableTileSource implements VectorTileSource<any> {
67
+ static defaultProps: Required<TableTileSourceProps> = {
68
+ coordinates: 'wgs84', // coordinates in tile coordinates or lng/lat
69
+ maxZoom: 14, // max zoom to preserve detail on
70
+ indexMaxZoom: 5, // max zoom in the tile index
71
+ maxPointsPerTile: 100000, // max number of points per tile in the tile index
72
+ tolerance: 3, // simplification tolerance (higher means simpler)
73
+ extent: 4096, // tile extent
74
+ buffer: 64, // tile buffer on each side
75
+ lineMetrics: false, // whether to calculate line metrics
76
+ // @ts-expect-error
77
+ promoteId: undefined, // name of a feature property to be promoted to feature.id
78
+ generateId: false, // whether to generate feature ids. Cannot be used with promoteId
79
+ debug: 0 // logging level (0, 1 or 2)
80
+ };
81
+
82
+ /** Global stats for all TableTileSources */
83
+ static stats = new Stats({
84
+ id: 'table-tile-source-all',
85
+ stats: [new Stat('count', 'tiles'), new Stat('count', 'features')]
86
+ });
87
+
88
+ /** Stats for this TableTileSource */
89
+ stats = new Stats({
90
+ id: 'table-tile-source',
91
+ stats: [new Stat('tiles', 'count'), new Stat('features', 'count')]
92
+ });
93
+
94
+ /** MIME type of the tiles emitted by this tile source */
95
+ readonly mimeType = 'application/vnd.mapbox-vector-tile';
96
+ readonly localCoordinates = true;
97
+
98
+ /** The props that this tile source was created with */
99
+ props: Required<TableTileSourceProps>;
100
+
101
+ /* Schema of the data */
102
+ schema: Schema | null = null;
103
+
104
+ /** Map of generated tiles, indexed by stringified tile coordinates */
105
+ tiles: Record<string, TableTile> = {};
106
+ /** Array of tile coordinates */
107
+ tileCoords: {x: number; y: number; z: number}[] = [];
108
+
109
+ /** Input data has loaded, initial top-level tiling is done, sync methods can now be called */
110
+ ready: Promise<void>;
111
+ /** Metadata for the tile source (generated TileJSON/tilestats */
112
+ metadata: Promise<unknown>;
113
+
114
+ constructor(table: GeoJSONTable | Promise<GeoJSONTable>, props?: TableTileSourceProps) {
115
+ this.props = {...TableTileSource.defaultProps, ...props};
116
+ this.getTileData = this.getTileData.bind(this);
117
+ this.ready = this.initializeTilesAsync(table);
118
+ this.metadata = this.getMetadata();
119
+ }
120
+
121
+ async initializeTilesAsync(tablePromise: GeoJSONTable | Promise<GeoJSONTable>): Promise<void> {
122
+ const table = await tablePromise;
123
+ this.schema = deduceTableSchema(table);
124
+ this.createRootTiles(table);
125
+ }
126
+
127
+ async getMetadata(): Promise<unknown> {
128
+ await this.ready;
129
+ return {schema: this.schema, minZoom: 0, maxZoom: this.props.maxZoom};
130
+ }
131
+
132
+ async getSchema(): Promise<Schema> {
133
+ await this.ready;
134
+ return this.schema!;
135
+ }
136
+
137
+ /**
138
+ * Get a tile at the specified index
139
+ * @param tileIndex z, x, y of tile
140
+ * @returns
141
+ */
142
+ async getVectorTile(tileIndex: GetTileParameters): Promise<GeoJSONTable | null> {
143
+ await this.ready;
144
+ const table = this.getTileSync(tileIndex);
145
+ log.info(2, 'getVectorTile', tileIndex, table)();
146
+ return table;
147
+ }
148
+
149
+ async getTile(tileIndex: {z: number; x: number; y: number}): Promise<GeoJSONTable | null> {
150
+ await this.ready;
151
+ return this.getTileSync(tileIndex);
152
+ }
153
+
154
+ async getTileData(
155
+ tileParams: GetTileDataParameters
156
+ ): Promise<Feature[] | BinaryFeatureCollection> {
157
+ const {x, y, z} = tileParams.index;
158
+ const tile = await this.getVectorTile({x, y, z});
159
+ return tile?.features || [];
160
+ }
161
+
162
+ // Implementation
163
+
164
+ /**
165
+ * Synchronously request a tile
166
+ * @note Application must await `source.ready` before calling sync methods.
167
+ */
168
+ getTileSync(tileIndex: {z: number; x: number; y: number}): GeoJSONTable | null {
169
+ const rawTile = this.getRawTile(tileIndex);
170
+ if (!rawTile) {
171
+ return null;
172
+ }
173
+
174
+ return convertToGeoJSONTable(rawTile, {
175
+ coordinates: this.props.coordinates,
176
+ tileIndex,
177
+ extent: this.props.extent
178
+ });
179
+ }
180
+
181
+ /**
182
+ * Create the initial tiles
183
+ * @note the tiles stores all the features together with additional data
184
+ */
185
+ createRootTiles(table: GeoJSONTable): void {
186
+ if (this.props.maxZoom < 0 || this.props.maxZoom > 24) {
187
+ throw new Error('maxZoom should be in the 0-24 range');
188
+ }
189
+ if (this.props.promoteId && this.props.generateId) {
190
+ throw new Error('promoteId and generateId cannot be used together.');
191
+ }
192
+
193
+ log.log(1, 'TableTileSource creating root tiles', this.props)();
194
+
195
+ // projects and adds simplification info
196
+ log.time(1, 'preprocess table')();
197
+ let features = convert(table, this.props);
198
+ log.timeEnd(1, 'preprocess table')();
199
+
200
+ // wraps features (ie extreme west and extreme east)
201
+ log.time(1, 'generate tiles')();
202
+
203
+ features = wrap(features, this.props);
204
+
205
+ // start slicing from the top tile down
206
+ if (features.length === 0) {
207
+ log.log(1, 'TableTileSource: no features generated')();
208
+ return;
209
+ }
210
+
211
+ this.splitTile(features, 0, 0, 0);
212
+
213
+ const rootTile = this.tiles[0];
214
+ log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
215
+
216
+ log.timeEnd(1, 'generate tiles')();
217
+ log.log(1, `TableTileSource: tiles generated: ${this.stats.get('total').count}`, this.stats)();
218
+ }
219
+
220
+ /**
221
+ * Return geojsonvt-style "half formed" vector tile
222
+ * @note Application must await `source.ready` before calling sync methods.
223
+ */
224
+ // eslint-disable-next-line complexity, max-statements
225
+ getRawTile(tileIndex: {z: number; x: number; y: number}): TableTile | null {
226
+ const {z, y} = tileIndex;
227
+ let {x} = tileIndex;
228
+ // z = +z;
229
+ // x = +x;
230
+ // y = +y;
231
+
232
+ const {extent} = this.props;
233
+
234
+ if (z < 0 || z > 24) {
235
+ return null;
236
+ }
237
+
238
+ const z2 = 1 << z;
239
+ x = (x + z2) & (z2 - 1); // wrap tile x coordinate
240
+
241
+ const id = toID(z, x, y);
242
+ if (this.tiles[id]) {
243
+ return transformTile(this.tiles[id], extent);
244
+ }
245
+
246
+ log.log(log, 'drilling down to z%d-%d-%d', z, x, y)();
247
+
248
+ let z0 = z;
249
+ let x0 = x;
250
+ let y0 = y;
251
+ let parent;
252
+
253
+ while (!parent && z0 > 0) {
254
+ z0--;
255
+ x0 = x0 >> 1;
256
+ y0 = y0 >> 1;
257
+ parent = this.tiles[toID(z0, x0, y0)];
258
+ }
259
+
260
+ if (!parent || !parent.source) {
261
+ return null;
262
+ }
263
+
264
+ // if we found a parent tile containing the original geometry, we can drill down from it
265
+ log.log(1, 'found parent tile z%d-%d-%d', z0, x0, y0)();
266
+ log.time(1, 'drilling down')();
267
+
268
+ this.splitTile(parent.source, z0, x0, y0, z, x, y);
269
+
270
+ log.timeEnd(1, 'drilling down')();
271
+
272
+ return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
273
+ }
274
+
275
+ /**
276
+ * splits features from a parent tile to sub-tiles.
277
+ * @param z, x, and y are the coordinates of the parent tile
278
+ * @param cz, cx, and cy are the coordinates of the target tile
279
+ *
280
+ * If no target tile is specified, splitting stops when we reach the maximum
281
+ * zoom or the number of points is low as specified in the props.
282
+ */
283
+ // eslint-disable-next-line max-params, max-statements, complexity
284
+ splitTile(
285
+ features: TableTileFeature[],
286
+ z: number,
287
+ x: number,
288
+ y: number,
289
+ cz?: number,
290
+ cx?: number,
291
+ cy?: number
292
+ ): void {
293
+ const stack: any[] = [features, z, x, y];
294
+
295
+ // avoid recursion by using a processing queue
296
+ while (stack.length) {
297
+ y = stack.pop();
298
+ x = stack.pop();
299
+ z = stack.pop();
300
+ features = stack.pop();
301
+
302
+ const z2 = 1 << z;
303
+ const id = toID(z, x, y);
304
+ let tile = this.tiles[id];
305
+
306
+ if (!tile) {
307
+ log.time(2, 'tile creation')();
308
+
309
+ tile = this.tiles[id] = createTile(features, z, x, y, this.props);
310
+ this.tileCoords.push({z, x, y});
311
+
312
+ const key = `z${z}`;
313
+ let stat = this.stats.get(key, 'count');
314
+ stat.incrementCount();
315
+
316
+ stat = this.stats.get('total');
317
+ stat.incrementCount();
318
+
319
+ stat = TableTileSource.stats.get(key, 'count');
320
+ stat.incrementCount();
321
+
322
+ stat = TableTileSource.stats.get('total');
323
+ stat.incrementCount();
324
+
325
+ log.log(
326
+ 2,
327
+ 'tile z%d-%d-%d (features: %d, points: %d, simplified: %d)',
328
+ z,
329
+ x,
330
+ y,
331
+ tile.numFeatures,
332
+ tile.numPoints,
333
+ tile.numSimplified
334
+ )();
335
+ log.timeEnd(2, 'tile creation')();
336
+ }
337
+
338
+ // save reference to original geometry in tile so that we can drill down later if we stop now
339
+ tile.source = features;
340
+
341
+ /** eslint-disable no-continue */
342
+
343
+ // if it's the first-pass tiling
344
+ if (cz === undefined) {
345
+ // stop tiling if we reached max zoom, or if the tile is too simple
346
+ if (z === this.props.indexMaxZoom || tile.numPoints <= this.props.maxPointsPerTile) {
347
+ continue;
348
+ }
349
+ // if a drilldown to a specific tile
350
+ } else if (z === this.props.maxZoom || z === cz) {
351
+ // stop tiling if we reached base zoom or our target tile zoom
352
+ continue;
353
+ } else if (cz !== undefined) {
354
+ // stop tiling if it's not an ancestor of the target tile
355
+ const zoomSteps = cz - z;
356
+ // @ts-expect-error TODO fix the types of cx cy
357
+ if (x !== cx >> zoomSteps || y !== cy >> zoomSteps) {
358
+ continue;
359
+ }
360
+ }
361
+
362
+ // if we slice further down, no need to keep source geometry
363
+ tile.source = null;
364
+
365
+ if (features.length === 0) continue;
366
+
367
+ log.time(2, 'clipping tile')();
368
+
369
+ // values we'll use for clipping
370
+ const k1 = (0.5 * this.props.buffer) / this.props.extent;
371
+ const k2 = 0.5 - k1;
372
+ const k3 = 0.5 + k1;
373
+ const k4 = 1 + k1;
374
+
375
+ let tl: TableTileFeature[] | null = null;
376
+ let bl: TableTileFeature[] | null = null;
377
+ let tr: TableTileFeature[] | null = null;
378
+ let br: TableTileFeature[] | null = null;
379
+
380
+ let left = clip(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
381
+ let right = clip(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
382
+
383
+ // @ts-expect-error - unclear why this is needed?
384
+ features = null;
385
+
386
+ if (left) {
387
+ tl = clip(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
388
+ bl = clip(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
389
+ left = null;
390
+ }
391
+
392
+ if (right) {
393
+ tr = clip(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
394
+ br = clip(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
395
+ right = null;
396
+ }
397
+
398
+ log.timeEnd(2, 'clipping tile')();
399
+
400
+ stack.push(tl || [], z + 1, x * 2, y * 2);
401
+ stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
402
+ stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
403
+ stack.push(br || [], z + 1, x * 2 + 1, y * 2 + 1);
404
+ }
405
+ }
406
+ }
407
+
408
+ function toID(z, x, y): number {
409
+ return ((1 << z) * y + x) * 32 + z;
410
+ }
411
+
412
+ // eslint-disable-next-line max-statements, complexity
413
+ function convertToGeoJSONTable(
414
+ vtTile: TableTile,
415
+ props: {
416
+ coordinates: 'local' | 'wgs84' | 'EPSG:4326';
417
+ tileIndex: {x: number; y: number; z: number};
418
+ extent: number;
419
+ }
420
+ ): GeoJSONTable | null {
421
+ const features: Feature[] = [];
422
+ for (const rawFeature of vtTile.features) {
423
+ if (!rawFeature || !rawFeature.geometry) {
424
+ continue;
425
+ }
426
+
427
+ let type:
428
+ | 'Point'
429
+ | 'MultiPoint'
430
+ | 'LineString'
431
+ | 'MultiLineString'
432
+ | 'Polygon'
433
+ | 'MultiPolygon';
434
+
435
+ let coordinates: any;
436
+
437
+ // raw geometry
438
+ switch (rawFeature.type) {
439
+ case 1:
440
+ if (rawFeature.geometry.length === 1) {
441
+ type = 'Point';
442
+ coordinates = rawFeature.geometry[0];
443
+ } else {
444
+ type = 'MultiPoint';
445
+ coordinates = rawFeature.geometry;
446
+ }
447
+ break;
448
+ case 2:
449
+ if (rawFeature.geometry.length === 1) {
450
+ type = 'LineString';
451
+ coordinates = rawFeature.geometry[0];
452
+ } else {
453
+ type = 'MultiLineString';
454
+ coordinates = rawFeature.geometry;
455
+ }
456
+ break;
457
+ case 3:
458
+ if (rawFeature.geometry.length > 1) {
459
+ type = 'MultiPolygon';
460
+ coordinates = [rawFeature.geometry];
461
+ } else {
462
+ type = 'Polygon';
463
+ coordinates = rawFeature.geometry;
464
+ }
465
+ break;
466
+ default:
467
+ continue;
468
+ }
469
+
470
+ switch (props.coordinates) {
471
+ case 'EPSG:4326':
472
+ case 'wgs84':
473
+ projectToLngLat(coordinates, props.tileIndex, props.extent);
474
+ break;
475
+
476
+ case 'local':
477
+ convertToLocalCoordinates(coordinates, props.extent);
478
+ break;
479
+
480
+ default:
481
+ throw new Error(`Unsupported CRS ${props.coordinates}`);
482
+ }
483
+
484
+ const feature: Feature = {
485
+ type: 'Feature',
486
+ geometry: {
487
+ type,
488
+ coordinates
489
+ },
490
+ properties: rawFeature.tags || {},
491
+ id: rawFeature.id
492
+ };
493
+
494
+ features.push(feature);
495
+ }
496
+
497
+ if (features.length === 0) {
498
+ return null;
499
+ }
500
+
501
+ const table: GeoJSONTable = {
502
+ shape: 'geojson-table',
503
+ type: 'FeatureCollection',
504
+ features
505
+ };
506
+
507
+ return table;
508
+ }
@@ -1,79 +0,0 @@
1
- import { VectorTileSource, VectorTileSourceProps, TileLoadParameters } from '@loaders.gl/loader-utils';
2
- import { GeoJSONTable } from '@loaders.gl/schema';
3
- import type { GeoJSONTile, GeoJSONTileFeature } from "./lib/geojsonvt/tile.js";
4
- /** Options to configure tiling */
5
- export type GeoJSONTileSourceOptions = VectorTileSourceProps & {
6
- maxZoom?: number /** max zoom to preserve detail on */;
7
- indexMaxZoom?: number /** max zoom in the tile index */;
8
- indexMaxPoints?: number /** max number of points per tile in the tile index */;
9
- tolerance?: number /** simplification tolerance (higher means simpler) */;
10
- extent?: number /** tile extent */;
11
- buffer?: number /** tile buffer on each side */;
12
- lineMetrics?: boolean /** whether to calculate line metrics */;
13
- promoteId?: string /** name of a feature property to be promoted to feature.id */;
14
- generateId?: boolean /** whether to generate feature ids. Cannot be used with promoteId */;
15
- debug?: number /** logging level (0, 1 or 2) */;
16
- };
17
- export declare class GeoJSONTileSource implements VectorTileSource<any> {
18
- static defaultOptions: Required<GeoJSONTileSourceOptions>;
19
- mimeType: string;
20
- options: Required<GeoJSONTileSourceOptions>;
21
- tiles: Record<string, GeoJSONTile>;
22
- tileCoords: {
23
- x: number;
24
- y: number;
25
- z: number;
26
- }[];
27
- stats: Record<string, number>;
28
- total: number;
29
- /** Sync methods can be called: the input data promise has been resolved and initial top-level tiling is done */
30
- ready: Promise<void>;
31
- constructor(data: GeoJSONTable | Promise<GeoJSONTable>, options?: GeoJSONTileSourceOptions);
32
- initializeTilesAsync(dataPromise: GeoJSONTable | Promise<GeoJSONTable>): Promise<void>;
33
- initializeTilesSync(data: GeoJSONTable): void;
34
- getMetadata(): Promise<unknown>;
35
- /**
36
- * Get a tile at the specified index
37
- * @param tileIndex z, x, y of tile
38
- * @returns
39
- */
40
- getVectorTile(tileIndex: {
41
- z: number;
42
- x: number;
43
- y: number;
44
- }): Promise<GeoJSONTable | null>;
45
- getTile(tileIndex: {
46
- z: number;
47
- x: number;
48
- y: number;
49
- }): Promise<GeoJSONTable | null>;
50
- getTileData(tileParams: TileLoadParameters): Promise<unknown | null>;
51
- /**
52
- * Synchronously request a tile
53
- * @note Application must await `source.ready` before calling sync methods.
54
- */
55
- getTileSync(tileIndex: {
56
- z: number;
57
- x: number;
58
- y: number;
59
- }): GeoJSONTable | null;
60
- /**
61
- * Return geojsonvt-style "half formed" vector tile
62
- * @note Application must await `source.ready` before calling sync methods.
63
- */
64
- getRawTile(tileIndex: {
65
- z: number;
66
- x: number;
67
- y: number;
68
- }): GeoJSONTile | null;
69
- /**
70
- * splits features from a parent tile to sub-tiles.
71
- * @param z, x, and y are the coordinates of the parent tile
72
- * @param cz, cx, and cy are the coordinates of the target tile
73
- *
74
- * If no target tile is specified, splitting stops when we reach the maximum
75
- * zoom or the number of points is low as specified in the options.
76
- */
77
- splitTile(features: GeoJSONTileFeature[], z: number, x: number, y: number, cz?: number, cx?: number, cy?: number): void;
78
- }
79
- //# sourceMappingURL=geojson-tile-source.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"geojson-tile-source.d.ts","sourceRoot":"","sources":["../src/geojson-tile-source.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAU,YA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,CAAC,EAAE,MAAM,GACV,IAAI;CAyGR"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/clip.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAK/C;;;;;;;;;;GAUG;AAEH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,kBAAkB,EAAE,EAC9B,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,IAAI,KAAA,EACJ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAC,WAAW,EAAE,OAAO,CAAA;CAAC,GAC9B,kBAAkB,EAAE,GAAG,IAAI,CA4E7B"}
@@ -1,10 +0,0 @@
1
- import type { Feature, FeatureCollection } from '@loaders.gl/schema';
2
- import type { GeoJSONTileFeature } from "./tile.js";
3
- export declare function convert(data: Feature | FeatureCollection, options: any): GeoJSONTileFeature[];
4
- export type ConvertFeatureOptions = {
5
- maxZoom?: number;
6
- tolerance: number;
7
- extent: number;
8
- lineMetrics: boolean;
9
- };
10
- //# sourceMappingURL=convert.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/convert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAO/C,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,iBAAiB,EAAE,OAAO,KAAA,GAAG,kBAAkB,EAAE,CAcxF;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC"}
@@ -1,3 +0,0 @@
1
- import { GeoJSONTileFeature } from "./tile.js";
2
- export declare function createFeature(id: any, type: any, geom: any, tags: any): GeoJSONTileFeature;
3
- //# sourceMappingURL=feature.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/feature.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,kBAAkB,EAAC,kBAAe;AAE1C,wBAAgB,aAAa,CAAC,EAAE,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,GAAG,kBAAkB,CA8BtE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"simplify.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/simplify.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAkCjG"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/tile.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,GAAG,CAAC;IACV,QAAQ,EAAE,GAAG,CAAC;IAGd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAGhB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,kBAAkB,EAAE,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAG9B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IAGV,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAEb,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC,KAAA,EAAE,EAAE,KAAA,EAAE,EAAE,KAAA,EAAE,OAAO,EAAE,iBAAiB,GAAG,WAAW,CAqB9F"}
@@ -1,7 +0,0 @@
1
- import type { GeoJSONTile } from "./tile.js";
2
- /**
3
- * Transforms the coordinates of each feature in the given tile from
4
- * mercator-projected space into (extent x extent) tile space.
5
- */
6
- export declare function transformTile(tile: GeoJSONTile, extent: number): GeoJSONTile;
7
- //# sourceMappingURL=transform.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/transform.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,WAAW,EAAC,kBAAe;AAExC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAiC5E"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../../src/lib/geojsonvt/wrap.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,kBAAkB,EAAC,kBAAe;AAI/C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC,8CAA8C,CAAC;IAC9D,MAAM,EAAE,MAAM,CAAC,0BAA0B,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,WAAW,wBAkBxE"}