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

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 (87) hide show
  1. package/dist/dist.dev.js +821 -680
  2. package/dist/dist.min.js +1 -1
  3. package/dist/index.cjs +795 -656
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +6 -5
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -1
  8. package/dist/lib/get-schemas-from-tilejson.d.ts +4 -0
  9. package/dist/lib/get-schemas-from-tilejson.d.ts.map +1 -0
  10. package/dist/lib/get-schemas-from-tilejson.js +55 -0
  11. package/dist/lib/parse-tilejson.d.ts +9 -4
  12. package/dist/lib/parse-tilejson.d.ts.map +1 -1
  13. package/dist/lib/parse-tilejson.js +6 -6
  14. package/dist/lib/types.d.ts +39 -1
  15. package/dist/lib/types.d.ts.map +1 -1
  16. package/dist/lib/types.js +1 -1
  17. package/dist/lib/utils/geometry-utils.js +1 -1
  18. package/dist/lib/vector-tiler/{clip.d.ts → features/clip-features.d.ts} +4 -4
  19. package/dist/lib/vector-tiler/features/clip-features.d.ts.map +1 -0
  20. package/dist/lib/vector-tiler/{clip.js → features/clip-features.js} +4 -4
  21. package/dist/lib/vector-tiler/{convert.d.ts → features/convert-feature.d.ts} +7 -7
  22. package/dist/lib/vector-tiler/features/convert-feature.d.ts.map +1 -0
  23. package/dist/lib/vector-tiler/features/convert-feature.js +140 -0
  24. package/dist/lib/vector-tiler/features/proto-feature.d.ts +30 -0
  25. package/dist/lib/vector-tiler/features/proto-feature.d.ts.map +1 -0
  26. package/dist/lib/vector-tiler/features/proto-feature.js +52 -0
  27. package/dist/lib/vector-tiler/{simplify.d.ts → features/simplify-path.d.ts} +2 -2
  28. package/dist/lib/vector-tiler/features/simplify-path.d.ts.map +1 -0
  29. package/dist/lib/vector-tiler/{simplify.js → features/simplify-path.js} +3 -3
  30. package/dist/lib/vector-tiler/{wrap.d.ts → features/wrap-features.d.ts} +5 -5
  31. package/dist/lib/vector-tiler/features/wrap-features.d.ts.map +1 -0
  32. package/dist/lib/vector-tiler/{wrap.js → features/wrap-features.js} +33 -26
  33. package/dist/lib/vector-tiler/proto-tile.d.ts +40 -0
  34. package/dist/lib/vector-tiler/proto-tile.d.ts.map +1 -0
  35. package/dist/lib/vector-tiler/proto-tile.js +138 -0
  36. package/dist/lib/vector-tiler/tile-to-geojson.d.ts +12 -0
  37. package/dist/lib/vector-tiler/tile-to-geojson.d.ts.map +1 -0
  38. package/dist/lib/vector-tiler/tile-to-geojson.js +81 -0
  39. package/dist/lib/vector-tiler/transform-tile.d.ts +7 -0
  40. package/dist/lib/vector-tiler/transform-tile.d.ts.map +1 -0
  41. package/dist/lib/vector-tiler/transform-tile.js +41 -0
  42. package/dist/mvt-loader.d.ts +2 -0
  43. package/dist/mvt-loader.d.ts.map +1 -1
  44. package/dist/mvt-loader.js +1 -1
  45. package/dist/mvt-source.d.ts +31 -14
  46. package/dist/mvt-source.d.ts.map +1 -1
  47. package/dist/mvt-source.js +26 -6
  48. package/dist/mvt-worker.js +4 -4
  49. package/dist/table-tile-source.d.ts +66 -36
  50. package/dist/table-tile-source.d.ts.map +1 -1
  51. package/dist/table-tile-source.js +167 -117
  52. package/dist/tilejson-loader.js +1 -1
  53. package/package.json +9 -6
  54. package/src/index.ts +13 -6
  55. package/src/lib/get-schemas-from-tilejson.ts +64 -0
  56. package/src/lib/parse-tilejson.ts +19 -12
  57. package/src/lib/types.ts +40 -2
  58. package/src/lib/utils/geometry-utils.ts +1 -1
  59. package/src/lib/vector-tiler/{clip.ts → features/clip-features.ts} +8 -8
  60. package/src/lib/vector-tiler/{convert.ts → features/convert-feature.ts} +91 -70
  61. package/src/lib/vector-tiler/features/proto-feature.ts +104 -0
  62. package/src/lib/vector-tiler/{simplify.ts → features/simplify-path.ts} +8 -3
  63. package/src/lib/vector-tiler/{wrap.ts → features/wrap-features.ts} +44 -29
  64. package/src/lib/vector-tiler/proto-tile.ts +217 -0
  65. package/src/lib/vector-tiler/tile-to-geojson.ts +105 -0
  66. package/src/lib/vector-tiler/transform-tile.ts +57 -0
  67. package/src/mvt-loader.ts +2 -0
  68. package/src/mvt-source.ts +42 -18
  69. package/src/table-tile-source.ts +130 -85
  70. package/src/tilejson-loader.ts +2 -2
  71. package/dist/lib/vector-tiler/clip.d.ts.map +0 -1
  72. package/dist/lib/vector-tiler/convert.d.ts.map +0 -1
  73. package/dist/lib/vector-tiler/convert.js +0 -139
  74. package/dist/lib/vector-tiler/feature.d.ts +0 -3
  75. package/dist/lib/vector-tiler/feature.d.ts.map +0 -1
  76. package/dist/lib/vector-tiler/feature.js +0 -44
  77. package/dist/lib/vector-tiler/simplify.d.ts.map +0 -1
  78. package/dist/lib/vector-tiler/tile.d.ts +0 -38
  79. package/dist/lib/vector-tiler/tile.d.ts.map +0 -1
  80. package/dist/lib/vector-tiler/tile.js +0 -123
  81. package/dist/lib/vector-tiler/transform.d.ts +0 -7
  82. package/dist/lib/vector-tiler/transform.d.ts.map +0 -1
  83. package/dist/lib/vector-tiler/transform.js +0 -41
  84. package/dist/lib/vector-tiler/wrap.d.ts.map +0 -1
  85. package/src/lib/vector-tiler/feature.ts +0 -47
  86. package/src/lib/vector-tiler/tile.ts +0 -187
  87. package/src/lib/vector-tiler/transform.ts +0 -57
@@ -3,49 +3,99 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
  // Based on https://github.com/mapbox/geojson-vt under compatible ISC license
5
5
 
6
+ import {Source} from '@loaders.gl/loader-utils';
6
7
  import type {
7
8
  VectorTileSourceProps,
8
9
  GetTileDataParameters,
9
- GetTileParameters
10
+ GetTileParameters,
11
+ LoaderWithParser
10
12
  } from '@loaders.gl/loader-utils';
11
- import {VectorTileSource, log} from '@loaders.gl/loader-utils';
13
+ import {VectorTileSource, TileSourceMetadata, log} from '@loaders.gl/loader-utils';
12
14
  import {Schema, GeoJSONTable, Feature, BinaryFeatureCollection} from '@loaders.gl/schema';
13
15
  import {deduceTableSchema} from '@loaders.gl/schema';
14
16
  import {Stats, Stat} from '@probe.gl/stats';
15
17
 
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
18
+ import type {ProtoFeature} from './lib/vector-tiler/features/proto-feature';
19
+ import type {ProtoTile} from './lib/vector-tiler/proto-tile';
20
+ import {createProtoTile} from './lib/vector-tiler/proto-tile';
21
+ import {transformTile} from './lib/vector-tiler/transform-tile'; // coordinate transformation
22
+ import {convertTileToGeoJSON} from './lib/vector-tiler/tile-to-geojson'; // tile clipping and wrapping
23
+ import {convertFeaturesToProtoFeature} from './lib/vector-tiler/features/convert-feature';
24
+ import {clipFeatures} from './lib/vector-tiler/features/clip-features'; // stripe clipping algorithm
25
+ import {wrapFeatures} from './lib/vector-tiler/features/wrap-features'; // date line processing
22
26
 
23
- import {projectToLngLat} from './lib/utils/geometry-utils';
24
- import {convertToLocalCoordinates} from './lib/utils/geometry-utils';
27
+ /** Options to configure tiling */
28
+ export const TableTileSource = {
29
+ name: 'TableTiler',
30
+ id: 'table-tiler',
31
+ version: '0.0.0',
32
+ extensions: ['mvt'],
33
+ mimeTypes: ['application/octet-stream'],
34
+ options: {
35
+ table: {
36
+ coordinates: 'local',
37
+ promoteId: undefined!,
38
+ maxZoom: 14,
39
+ indexMaxZoom: 5,
40
+ maxPointsPerTile: 10000,
41
+ tolerance: 3,
42
+ extent: 4096,
43
+ buffer: 64,
44
+ generateId: undefined
45
+ }
46
+ },
47
+ type: 'table',
48
+ testURL: (url: string): boolean => url.endsWith('.geojson'),
49
+ createDataSource(
50
+ url: string | Blob | GeoJSONTable | Promise<GeoJSONTable>,
51
+ options: DynamicVectorTileSourceProps
52
+ ): DynamicVectorTileSource {
53
+ const needsLoading = typeof url === 'string' || url instanceof Blob;
54
+ const loader = options?.table?.loaders?.[0]!;
55
+ const tablePromise = needsLoading ? loadTable(url, loader) : url;
56
+ return new DynamicVectorTileSource(tablePromise, options);
57
+ }
58
+ // @ts-expect-error
59
+ } as const satisfies Source<DynamicVectorTileSource, DynamicVectorTileSourceProps>;
60
+
61
+ async function loadTable(url: string | Blob, loader: LoaderWithParser): Promise<GeoJSONTable> {
62
+ if (typeof url === 'string') {
63
+ const response = await fetch(url);
64
+ const data = await response.arrayBuffer();
65
+ return (await loader.parse(data)) as GeoJSONTable;
66
+ }
67
+
68
+ const data = await url.arrayBuffer();
69
+ return (await loader.parse(data)) as GeoJSONTable; // options.loaders, options.loadOptions)
70
+ }
25
71
 
26
72
  /** 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;
73
+ export type DynamicVectorTileSourceProps = VectorTileSourceProps & {
74
+ table: {
75
+ coordinates: 'local' | 'wgs84' | 'EPSG:4326';
76
+ /** max zoom to preserve detail on */
77
+ maxZoom?: number;
78
+ /** max zoom in the tile index */
79
+ indexMaxZoom?: number;
80
+ /** max number of points per tile in the tile index */
81
+ maxPointsPerTile?: number;
82
+ /** simplification tolerance (higher means simpler) */
83
+ tolerance?: number;
84
+ /** tile extent */
85
+ extent?: number;
86
+ /** tile buffer on each side */
87
+ buffer?: number;
88
+ /** name of a feature property to be promoted to feature.id */
89
+ promoteId?: string;
90
+ /** whether to generate feature ids. Cannot be used with promoteId */
91
+ generateId?: boolean;
92
+ /** logging level (0, 1 or 2) */
93
+ debug?: number;
94
+ /** whether to calculate line metrics */
95
+ lineMetrics?: boolean;
96
+ /** table loders */
97
+ loaders?: LoaderWithParser[];
98
+ };
49
99
  };
50
100
 
51
101
  /**
@@ -63,29 +113,16 @@ export type TableTileSourceProps = VectorTileSourceProps & {
63
113
  * @todo - generate binary output tables
64
114
  * @todo - how does TileSourceLayer specify coordinates / decided which layer to render with
65
115
  */
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 */
116
+ export class DynamicVectorTileSource
117
+ implements VectorTileSource<DynamicVectorTileSourceProps, TileSourceMetadata>
118
+ {
119
+ /** Global stats for all DynamicVectorTileSources */
83
120
  static stats = new Stats({
84
121
  id: 'table-tile-source-all',
85
122
  stats: [new Stat('count', 'tiles'), new Stat('count', 'features')]
86
123
  });
87
124
 
88
- /** Stats for this TableTileSource */
125
+ /** Stats for this DynamicVectorTileSource */
89
126
  stats = new Stats({
90
127
  id: 'table-tile-source',
91
128
  stats: [new Stat('tiles', 'count'), new Stat('features', 'count')]
@@ -96,13 +133,14 @@ export class TableTileSource implements VectorTileSource<any> {
96
133
  readonly localCoordinates = true;
97
134
 
98
135
  /** The props that this tile source was created with */
99
- props: Required<TableTileSourceProps>;
136
+ // @ts-expect-error
137
+ props: Required<DynamicVectorTileSourceProps['table']>;
100
138
 
101
139
  /* Schema of the data */
102
140
  schema: Schema | null = null;
103
141
 
104
142
  /** Map of generated tiles, indexed by stringified tile coordinates */
105
- tiles: Record<string, TableTile> = {};
143
+ tiles: Record<string, ProtoTile> = {};
106
144
  /** Array of tile coordinates */
107
145
  tileCoords: {x: number; y: number; z: number}[] = [];
108
146
 
@@ -111,8 +149,9 @@ export class TableTileSource implements VectorTileSource<any> {
111
149
  /** Metadata for the tile source (generated TileJSON/tilestats */
112
150
  metadata: Promise<unknown>;
113
151
 
114
- constructor(table: GeoJSONTable | Promise<GeoJSONTable>, props?: TableTileSourceProps) {
115
- this.props = {...TableTileSource.defaultProps, ...props};
152
+ constructor(table: GeoJSONTable | Promise<GeoJSONTable>, props?: DynamicVectorTileSourceProps) {
153
+ // @ts-expect-error
154
+ this.props = {...TableTileSource.options.table, ...props?.table};
116
155
  this.getTileData = this.getTileData.bind(this);
117
156
  this.ready = this.initializeTilesAsync(table);
118
157
  this.metadata = this.getMetadata();
@@ -124,7 +163,7 @@ export class TableTileSource implements VectorTileSource<any> {
124
163
  this.createRootTiles(table);
125
164
  }
126
165
 
127
- async getMetadata(): Promise<unknown> {
166
+ async getMetadata(): Promise<TileSourceMetadata & {schema: Schema | null}> {
128
167
  await this.ready;
129
168
  return {schema: this.schema, minZoom: 0, maxZoom: this.props.maxZoom};
130
169
  }
@@ -166,12 +205,12 @@ export class TableTileSource implements VectorTileSource<any> {
166
205
  * @note Application must await `source.ready` before calling sync methods.
167
206
  */
168
207
  getTileSync(tileIndex: {z: number; x: number; y: number}): GeoJSONTable | null {
169
- const rawTile = this.getRawTile(tileIndex);
170
- if (!rawTile) {
208
+ const protoTile = this.getProtoTile(tileIndex);
209
+ if (!protoTile) {
171
210
  return null;
172
211
  }
173
212
 
174
- return convertToGeoJSONTable(rawTile, {
213
+ return convertTileToGeoJSON(protoTile, {
175
214
  coordinates: this.props.coordinates,
176
215
  tileIndex,
177
216
  extent: this.props.extent
@@ -190,21 +229,21 @@ export class TableTileSource implements VectorTileSource<any> {
190
229
  throw new Error('promoteId and generateId cannot be used together.');
191
230
  }
192
231
 
193
- log.log(1, 'TableTileSource creating root tiles', this.props)();
232
+ log.log(1, 'DynamicVectorTileSource creating root tiles', this.props)();
194
233
 
195
234
  // projects and adds simplification info
196
235
  log.time(1, 'preprocess table')();
197
- let features = convert(table, this.props);
236
+ let features = convertFeaturesToProtoFeature(table, this.props);
198
237
  log.timeEnd(1, 'preprocess table')();
199
238
 
200
239
  // wraps features (ie extreme west and extreme east)
201
240
  log.time(1, 'generate tiles')();
202
241
 
203
- features = wrap(features, this.props);
242
+ features = wrapFeatures(features, this.props);
204
243
 
205
244
  // start slicing from the top tile down
206
245
  if (features.length === 0) {
207
- log.log(1, 'TableTileSource: no features generated')();
246
+ log.log(1, 'DynamicVectorTileSource: no features generated')();
208
247
  return;
209
248
  }
210
249
 
@@ -214,7 +253,11 @@ export class TableTileSource implements VectorTileSource<any> {
214
253
  log.log(1, `root tile features: ${rootTile.numFeatures}, points: ${rootTile.numPoints}`)();
215
254
 
216
255
  log.timeEnd(1, 'generate tiles')();
217
- log.log(1, `TableTileSource: tiles generated: ${this.stats.get('total').count}`, this.stats)();
256
+ log.log(
257
+ 1,
258
+ `DynamicVectorTileSource: tiles generated: ${this.stats.get('total').count}`,
259
+ this.stats
260
+ )();
218
261
  }
219
262
 
220
263
  /**
@@ -222,7 +265,7 @@ export class TableTileSource implements VectorTileSource<any> {
222
265
  * @note Application must await `source.ready` before calling sync methods.
223
266
  */
224
267
  // eslint-disable-next-line complexity, max-statements
225
- getRawTile(tileIndex: {z: number; x: number; y: number}): TableTile | null {
268
+ getProtoTile(tileIndex: {z: number; x: number; y: number}): ProtoTile | null {
226
269
  const {z, y} = tileIndex;
227
270
  let {x} = tileIndex;
228
271
  // z = +z;
@@ -236,7 +279,7 @@ export class TableTileSource implements VectorTileSource<any> {
236
279
  }
237
280
 
238
281
  const z2 = 1 << z;
239
- x = (x + z2) & (z2 - 1); // wrap tile x coordinate
282
+ x = (x + z2) & (z2 - 1); // wrapFeatures tile x coordinate
240
283
 
241
284
  const id = toID(z, x, y);
242
285
  if (this.tiles[id]) {
@@ -257,7 +300,7 @@ export class TableTileSource implements VectorTileSource<any> {
257
300
  parent = this.tiles[toID(z0, x0, y0)];
258
301
  }
259
302
 
260
- if (!parent || !parent.source) {
303
+ if (!parent || !parent.sourceFeatures) {
261
304
  return null;
262
305
  }
263
306
 
@@ -265,7 +308,7 @@ export class TableTileSource implements VectorTileSource<any> {
265
308
  log.log(1, 'found parent tile z%d-%d-%d', z0, x0, y0)();
266
309
  log.time(1, 'drilling down')();
267
310
 
268
- this.splitTile(parent.source, z0, x0, y0, z, x, y);
311
+ this.splitTile(parent.sourceFeatures, z0, x0, y0, z, x, y);
269
312
 
270
313
  log.timeEnd(1, 'drilling down')();
271
314
 
@@ -282,7 +325,7 @@ export class TableTileSource implements VectorTileSource<any> {
282
325
  */
283
326
  // eslint-disable-next-line max-params, max-statements, complexity
284
327
  splitTile(
285
- features: TableTileFeature[],
328
+ features: ProtoFeature[],
286
329
  z: number,
287
330
  x: number,
288
331
  y: number,
@@ -306,7 +349,7 @@ export class TableTileSource implements VectorTileSource<any> {
306
349
  if (!tile) {
307
350
  log.time(2, 'tile creation')();
308
351
 
309
- tile = this.tiles[id] = createTile(features, z, x, y, this.props);
352
+ tile = this.tiles[id] = createProtoTile(features, z, x, y, this.props);
310
353
  this.tileCoords.push({z, x, y});
311
354
 
312
355
  const key = `z${z}`;
@@ -316,10 +359,10 @@ export class TableTileSource implements VectorTileSource<any> {
316
359
  stat = this.stats.get('total');
317
360
  stat.incrementCount();
318
361
 
319
- stat = TableTileSource.stats.get(key, 'count');
362
+ stat = DynamicVectorTileSource.stats.get(key, 'count');
320
363
  stat.incrementCount();
321
364
 
322
- stat = TableTileSource.stats.get('total');
365
+ stat = DynamicVectorTileSource.stats.get('total');
323
366
  stat.incrementCount();
324
367
 
325
368
  log.log(
@@ -336,9 +379,9 @@ export class TableTileSource implements VectorTileSource<any> {
336
379
  }
337
380
 
338
381
  // save reference to original geometry in tile so that we can drill down later if we stop now
339
- tile.source = features;
382
+ tile.sourceFeatures = features;
340
383
 
341
- /** eslint-disable no-continue */
384
+ /* eslint-disable no-continue */
342
385
 
343
386
  // if it's the first-pass tiling
344
387
  if (cz === undefined) {
@@ -360,7 +403,7 @@ export class TableTileSource implements VectorTileSource<any> {
360
403
  }
361
404
 
362
405
  // if we slice further down, no need to keep source geometry
363
- tile.source = null;
406
+ tile.sourceFeatures = null;
364
407
 
365
408
  if (features.length === 0) continue;
366
409
 
@@ -372,26 +415,26 @@ export class TableTileSource implements VectorTileSource<any> {
372
415
  const k3 = 0.5 + k1;
373
416
  const k4 = 1 + k1;
374
417
 
375
- let tl: TableTileFeature[] | null = null;
376
- let bl: TableTileFeature[] | null = null;
377
- let tr: TableTileFeature[] | null = null;
378
- let br: TableTileFeature[] | null = null;
418
+ let tl: ProtoFeature[] | null = null;
419
+ let bl: ProtoFeature[] | null = null;
420
+ let tr: ProtoFeature[] | null = null;
421
+ let br: ProtoFeature[] | null = null;
379
422
 
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);
423
+ let left = clipFeatures(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, this.props);
424
+ let right = clipFeatures(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, this.props);
382
425
 
383
426
  // @ts-expect-error - unclear why this is needed?
384
427
  features = null;
385
428
 
386
429
  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);
430
+ tl = clipFeatures(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
431
+ bl = clipFeatures(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
389
432
  left = null;
390
433
  }
391
434
 
392
435
  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);
436
+ tr = clipFeatures(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, this.props);
437
+ br = clipFeatures(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, this.props);
395
438
  right = null;
396
439
  }
397
440
 
@@ -408,10 +451,11 @@ export class TableTileSource implements VectorTileSource<any> {
408
451
  function toID(z, x, y): number {
409
452
  return ((1 << z) * y + x) * 32 + z;
410
453
  }
454
+ /*
411
455
 
412
456
  // eslint-disable-next-line max-statements, complexity
413
457
  function convertToGeoJSONTable(
414
- vtTile: TableTile,
458
+ vtTile: ProtoTile,
415
459
  props: {
416
460
  coordinates: 'local' | 'wgs84' | 'EPSG:4326';
417
461
  tileIndex: {x: number; y: number; z: number};
@@ -506,3 +550,4 @@ function convertToGeoJSONTable(
506
550
 
507
551
  return table;
508
552
  }
553
+ */
@@ -38,13 +38,13 @@ export const TileJSONLoader = {
38
38
  maxValues: undefined
39
39
  }
40
40
  },
41
- parse: async (arrayBuffer, options?: TileJSONLoaderOptions) => {
41
+ parse: async (arrayBuffer: ArrayBuffer, options?: TileJSONLoaderOptions) => {
42
42
  const jsonString = new TextDecoder().decode(arrayBuffer);
43
43
  const json = JSON.parse(jsonString);
44
44
  const tilejsonOptions = {...TileJSONLoader.options.tilejson, ...options?.tilejson};
45
45
  return parseTileJSON(json, tilejsonOptions) as TileJSON;
46
46
  },
47
- parseTextSync: (text, options) => {
47
+ parseTextSync: (text: string, options?: TileJSONLoaderOptions) => {
48
48
  const json = JSON.parse(text);
49
49
  const tilejsonOptions = {...TileJSONLoader.options.tilejson, ...options?.tilejson};
50
50
  return parseTileJSON(json, tilejsonOptions) as TileJSON;
@@ -1 +0,0 @@
1
- {"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/clip.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,gBAAgB,EAAC,kBAAe;AAK7C;;;;;;;;;;GAUG;AAEH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,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,gBAAgB,EAAE,GAAG,IAAI,CA4E3B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/convert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAC,gBAAgB,EAAC,kBAAe;AAK7C;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,iBAAiB,EAAE,OAAO,KAAA,GAAG,gBAAgB,EAAE,CActF;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC"}
@@ -1,139 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
5
- import { simplify } from "./simplify.js";
6
- import { createFeature } from "./feature.js";
7
- /**
8
- * converts a GeoJSON feature into an intermediate projected JSON vector format
9
- * with simplification data
10
- */
11
- export function convert(data, options) {
12
- const features = [];
13
- if (data.type === 'FeatureCollection') {
14
- for (let i = 0; i < data.features.length; i++) {
15
- convertFeature(features, data.features[i], options, i);
16
- }
17
- }
18
- else if (data.type === 'Feature') {
19
- convertFeature(features, data, options);
20
- }
21
- else {
22
- // single geometry or a geometry collection
23
- convertFeature(features, { geometry: data }, options);
24
- }
25
- return features;
26
- }
27
- /**
28
- * converts a GeoJSON feature into an intermediate projected JSON vector format
29
- * with simplification data
30
- */
31
- function convertFeature(features, geojson, options, index) {
32
- if (!geojson.geometry) {
33
- return;
34
- }
35
- const coords = geojson.geometry.coordinates;
36
- const type = geojson.geometry.type;
37
- const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
38
- let geometry = [];
39
- let id = geojson.id;
40
- if (options.promoteId) {
41
- id = geojson.properties[options.promoteId];
42
- }
43
- else if (options.generateId) {
44
- id = index || 0;
45
- }
46
- if (type === 'Point') {
47
- convertPoint(coords, geometry);
48
- }
49
- else if (type === 'MultiPoint') {
50
- for (const p of coords) {
51
- convertPoint(p, geometry);
52
- }
53
- }
54
- else if (type === 'LineString') {
55
- convertLine(coords, geometry, tolerance, false);
56
- }
57
- else if (type === 'MultiLineString') {
58
- if (options.lineMetrics) {
59
- // explode into linestrings to be able to track metrics
60
- for (const line of coords) {
61
- geometry = [];
62
- convertLine(line, geometry, tolerance, false);
63
- features.push(createFeature(id, 'LineString', geometry, geojson.properties));
64
- }
65
- return;
66
- }
67
- else {
68
- convertLines(coords, geometry, tolerance, false);
69
- }
70
- }
71
- else if (type === 'Polygon') {
72
- convertLines(coords, geometry, tolerance, true);
73
- }
74
- else if (type === 'MultiPolygon') {
75
- for (const polygon of coords) {
76
- const newPolygon = [];
77
- convertLines(polygon, newPolygon, tolerance, true);
78
- geometry.push(newPolygon);
79
- }
80
- }
81
- else if (type === 'GeometryCollection') {
82
- for (const singleGeometry of geojson.geometry.geometries) {
83
- convertFeature(features, {
84
- id,
85
- geometry: singleGeometry,
86
- properties: geojson.properties
87
- }, options, index);
88
- }
89
- return;
90
- }
91
- else {
92
- throw new Error('Input data is not a valid GeoJSON object.');
93
- }
94
- features.push(createFeature(id, type, geometry, geojson.properties));
95
- }
96
- function convertPoint(coords, out) {
97
- out.push(projectX(coords[0]), projectY(coords[1]), 0);
98
- }
99
- function convertLine(ring, out, tolerance, isPolygon) {
100
- let x0, y0;
101
- let size = 0;
102
- for (let j = 0; j < ring.length; j++) {
103
- const x = projectX(ring[j][0]);
104
- const y = projectY(ring[j][1]);
105
- out.push(x, y, 0);
106
- if (j > 0) {
107
- if (isPolygon) {
108
- size += (x0 * y - x * y0) / 2; // area
109
- }
110
- else {
111
- size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2)); // length
112
- }
113
- }
114
- x0 = x;
115
- y0 = y;
116
- }
117
- const last = out.length - 3;
118
- out[2] = 1;
119
- simplify(out, 0, last, tolerance);
120
- out[last + 2] = 1;
121
- out.size = Math.abs(size);
122
- out.start = 0;
123
- out.end = out.size;
124
- }
125
- function convertLines(rings, out, tolerance, isPolygon) {
126
- for (let i = 0; i < rings.length; i++) {
127
- const geom = [];
128
- convertLine(rings[i], geom, tolerance, isPolygon);
129
- out.push(geom);
130
- }
131
- }
132
- function projectX(x) {
133
- return x / 360 + 0.5;
134
- }
135
- function projectY(y) {
136
- const sin = Math.sin((y * Math.PI) / 180);
137
- const y2 = 0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI;
138
- return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
139
- }
@@ -1,3 +0,0 @@
1
- import { TableTileFeature } from "./tile.js";
2
- export declare function createFeature(id: any, type: any, geom: any, tags: any): TableTileFeature;
3
- //# sourceMappingURL=feature.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/feature.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,gBAAgB,EAAC,kBAAe;AAExC,wBAAgB,aAAa,CAAC,EAAE,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,EAAE,IAAI,KAAA,GAAG,gBAAgB,CA8BpE"}
@@ -1,44 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- // Forked from https://github.com/mapbox/geojson-vt under compatible ISC license
5
- export function createFeature(id, type, geom, tags) {
6
- const feature = {
7
- // eslint-disable-next-line
8
- id: id == null ? null : id,
9
- type,
10
- geometry: geom,
11
- tags,
12
- minX: Infinity,
13
- minY: Infinity,
14
- maxX: -Infinity,
15
- maxY: -Infinity
16
- };
17
- if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
18
- calcLineBBox(feature, geom);
19
- }
20
- else if (type === 'Polygon') {
21
- // the outer ring (ie [0]) contains all inner rings
22
- calcLineBBox(feature, geom[0]);
23
- }
24
- else if (type === 'MultiLineString') {
25
- for (const line of geom) {
26
- calcLineBBox(feature, line);
27
- }
28
- }
29
- else if (type === 'MultiPolygon') {
30
- for (const polygon of geom) {
31
- // the outer ring (ie [0]) contains all inner rings
32
- calcLineBBox(feature, polygon[0]);
33
- }
34
- }
35
- return feature;
36
- }
37
- function calcLineBBox(feature, geom) {
38
- for (let i = 0; i < geom.length; i += 3) {
39
- feature.minX = Math.min(feature.minX, geom[i]);
40
- feature.minY = Math.min(feature.minY, geom[i + 1]);
41
- feature.maxX = Math.max(feature.maxX, geom[i]);
42
- feature.maxY = Math.max(feature.maxY, geom[i + 1]);
43
- }
44
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"simplify.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/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,38 +0,0 @@
1
- export type TableTileFeature = {
2
- type: any;
3
- geometry: any;
4
- id?: string;
5
- tags?: string[];
6
- minX: number;
7
- maxX: number;
8
- minY: number;
9
- maxY: number;
10
- };
11
- export type TableTile = {
12
- features: TableTileFeature[];
13
- type?: number;
14
- tags?: Record<string, string>;
15
- x: number;
16
- y: number;
17
- z: number;
18
- minX: number;
19
- maxX: number;
20
- minY: number;
21
- maxY: number;
22
- transformed: boolean;
23
- numPoints: number;
24
- numSimplified: number;
25
- numFeatures: number;
26
- source: any | null;
27
- };
28
- export type CreateTileOptions = {
29
- maxZoom?: number;
30
- tolerance: number;
31
- extent: number;
32
- lineMetrics: boolean;
33
- };
34
- /**
35
- * Create a tile from features and tile index
36
- */
37
- export declare function createTile(features: any[], z: any, tx: any, ty: any, options: CreateTileOptions): TableTile;
38
- //# sourceMappingURL=tile.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../../../src/lib/vector-tiler/tile.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,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,SAAS,GAAG;IACtB,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,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,SAAS,CAqB5F"}