@loaders.gl/mvt 4.2.0-alpha.6 → 4.2.0-beta.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 (59) hide show
  1. package/dist/dist.dev.js +15 -9
  2. package/dist/dist.min.js +1 -1
  3. package/dist/helpers/binary-util-functions.d.ts +3 -3
  4. package/dist/helpers/binary-util-functions.d.ts.map +1 -1
  5. package/dist/helpers/binary-util-functions.js +3 -0
  6. package/dist/helpers/mapbox-util-functions.d.ts +1 -1
  7. package/dist/helpers/mapbox-util-functions.d.ts.map +1 -1
  8. package/dist/helpers/mapbox-util-functions.js +3 -0
  9. package/dist/index.cjs +15 -11
  10. package/dist/index.cjs.map +3 -3
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +1 -1
  14. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
  15. package/dist/lib/binary-vector-tile/vector-tile-feature.js +4 -2
  16. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +5 -5
  17. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
  18. package/dist/lib/binary-vector-tile/vector-tile-layer.js +8 -5
  19. package/dist/lib/binary-vector-tile/vector-tile.d.ts +3 -3
  20. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -1
  21. package/dist/lib/binary-vector-tile/vector-tile.js +6 -3
  22. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +1 -1
  23. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -1
  24. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +4 -1
  25. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +2 -2
  26. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -1
  27. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +5 -4
  28. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +2 -2
  29. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -1
  30. package/dist/lib/mapbox-vector-tile/vector-tile.js +5 -2
  31. package/dist/lib/parse-mvt.d.ts +2 -2
  32. package/dist/lib/parse-mvt.d.ts.map +1 -1
  33. package/dist/lib/parse-mvt.js +7 -4
  34. package/dist/lib/types.d.ts +0 -10
  35. package/dist/lib/types.d.ts.map +1 -1
  36. package/dist/lib/types.js +3 -0
  37. package/dist/mvt-loader.d.ts +63 -6
  38. package/dist/mvt-loader.d.ts.map +1 -1
  39. package/dist/mvt-loader.js +7 -9
  40. package/dist/mvt-worker.js +12 -10
  41. package/dist/tilejson-loader.d.ts +2 -3
  42. package/dist/tilejson-loader.d.ts.map +1 -1
  43. package/dist/tilejson-loader.js +3 -1
  44. package/dist/workers/mvt-worker.js +3 -0
  45. package/package.json +6 -6
  46. package/src/helpers/binary-util-functions.ts +7 -3
  47. package/src/helpers/mapbox-util-functions.ts +5 -1
  48. package/src/index.ts +1 -1
  49. package/src/lib/binary-vector-tile/vector-tile-feature.ts +5 -1
  50. package/src/lib/binary-vector-tile/vector-tile-layer.ts +11 -7
  51. package/src/lib/binary-vector-tile/vector-tile.ts +13 -5
  52. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +5 -1
  53. package/src/lib/mapbox-vector-tile/vector-tile-layer.ts +6 -2
  54. package/src/lib/mapbox-vector-tile/vector-tile.ts +6 -2
  55. package/src/lib/parse-mvt.ts +13 -8
  56. package/src/lib/types.ts +3 -11
  57. package/src/mvt-loader.ts +35 -22
  58. package/src/tilejson-loader.ts +5 -2
  59. package/src/workers/mvt-worker.ts +4 -0
@@ -1,7 +1,11 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+
1
5
  import Protobuf from 'pbf';
2
6
  import {getPolygonSignedArea} from '@math.gl/polygon';
3
7
  import {FlatIndexedGeometry, FlatPolygon} from '@loaders.gl/schema';
4
- import VectorTileFeature from '../lib/binary-vector-tile/vector-tile-feature';
8
+ import {BinaryVectorTileFeature} from '../lib/binary-vector-tile/vector-tile-feature';
5
9
 
6
10
  /**
7
11
  * Classifies an array of rings into polygons with outer rings and holes
@@ -97,7 +101,7 @@ export function project(data: number[], x0: number, y0: number, size: number): v
97
101
  * @param feature
98
102
  * @param pbf
99
103
  */
100
- export function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Protobuf): void {
104
+ export function readFeature(tag: number, feature?: BinaryVectorTileFeature, pbf?: Protobuf): void {
101
105
  if (feature && pbf) {
102
106
  if (tag === 1) feature.id = pbf.readVarint();
103
107
  else if (tag === 2) readTag(pbf, feature);
@@ -110,7 +114,7 @@ export function readFeature(tag: number, feature?: VectorTileFeature, pbf?: Prot
110
114
  * @param pbf
111
115
  * @param feature
112
116
  */
113
- export function readTag(pbf: Protobuf, feature: VectorTileFeature): void {
117
+ export function readTag(pbf: Protobuf, feature: BinaryVectorTileFeature): void {
114
118
  const end = pbf.readVarint() + pbf.pos;
115
119
 
116
120
  while (pbf.pos < end) {
@@ -1,6 +1,10 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+
1
5
  import Protobuf from 'pbf';
2
6
  import {MVTMapboxGeometry} from '../lib/types';
3
- import VectorTileFeature from '../lib/mapbox-vector-tile/vector-tile-feature';
7
+ import {VectorTileFeature} from '../lib/mapbox-vector-tile/vector-tile-feature';
4
8
 
5
9
  /**
6
10
  * Classifies an array of rings into polygons with outer rings and holes
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- export type {MVTLoaderOptions} from './lib/types';
5
+ export type {MVTLoaderOptions} from './mvt-loader';
6
6
  export {MVTLoader, MVTWorkerLoader} from './mvt-loader';
7
7
 
8
8
  export type {TileJSON} from './lib/parse-tilejson';
@@ -1,3 +1,7 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+
1
5
  // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
2
6
 
3
7
  import Protobuf from 'pbf';
@@ -17,7 +21,7 @@ export const TEST_EXPORTS = {
17
21
  classifyRings
18
22
  };
19
23
 
20
- export default class VectorTileFeature {
24
+ export class BinaryVectorTileFeature {
21
25
  properties: {[x: string]: string | number | boolean | null};
22
26
  extent: any;
23
27
  type: number;
@@ -1,11 +1,15 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+
1
5
  /* eslint-disable indent */
2
6
  // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
3
7
 
4
- import VectorTileFeature from './vector-tile-feature';
8
+ import {BinaryVectorTileFeature} from './vector-tile-feature';
5
9
  import Protobuf from 'pbf';
6
10
  import {GeojsonGeometryInfo} from '@loaders.gl/schema';
7
11
 
8
- export default class VectorTileLayer {
12
+ export class BinaryVectorTileLayer {
9
13
  version: number;
10
14
  name: string;
11
15
  extent: number;
@@ -33,13 +37,13 @@ export default class VectorTileLayer {
33
37
  }
34
38
 
35
39
  /**
36
- * return feature `i` from this layer as a `VectorTileFeature`
40
+ * return feature `i` from this layer as a `BinaryVectorTileFeature`
37
41
  *
38
42
  * @param index
39
43
  * @param geometryInfo
40
- * @returns {VectorTileFeature}
44
+ * @returns {BinaryVectorTileFeature}
41
45
  */
42
- feature(i: number, geometryInfo: GeojsonGeometryInfo): VectorTileFeature {
46
+ feature(i: number, geometryInfo: GeojsonGeometryInfo): BinaryVectorTileFeature {
43
47
  if (i < 0 || i >= this._features.length) {
44
48
  throw new Error('feature index out of bounds');
45
49
  }
@@ -47,7 +51,7 @@ export default class VectorTileLayer {
47
51
  this._pbf.pos = this._features[i];
48
52
 
49
53
  const end = this._pbf.readVarint() + this._pbf.pos;
50
- return new VectorTileFeature(
54
+ return new BinaryVectorTileFeature(
51
55
  this._pbf,
52
56
  end,
53
57
  this.extent,
@@ -64,7 +68,7 @@ export default class VectorTileLayer {
64
68
  * @param layer
65
69
  * @param pbf
66
70
  */
67
- function readLayer(tag: number, layer?: VectorTileLayer, pbf?: Protobuf): void {
71
+ function readLayer(tag: number, layer?: BinaryVectorTileLayer, pbf?: Protobuf): void {
68
72
  if (layer && pbf) {
69
73
  if (tag === 15) layer.version = pbf.readVarint();
70
74
  else if (tag === 1) layer.name = pbf.readString();
@@ -1,10 +1,14 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+
1
5
  // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
2
6
 
3
- import VectorTileLayer from './vector-tile-layer';
7
+ import {BinaryVectorTileLayer} from './vector-tile-layer';
4
8
  import Protobuf from 'pbf';
5
9
 
6
- export default class VectorTile {
7
- layers: {[x: string]: VectorTileLayer};
10
+ export class BinaryVectorTile {
11
+ layers: {[x: string]: BinaryVectorTileLayer};
8
12
  constructor(pbf: Protobuf, end?: number) {
9
13
  this.layers = pbf.readFields(readTile, {}, end);
10
14
  }
@@ -16,10 +20,14 @@ export default class VectorTile {
16
20
  * @param layers
17
21
  * @param pbf
18
22
  */
19
- function readTile(tag: number, layers?: {[x: string]: VectorTileLayer}, pbf?: Protobuf): void {
23
+ function readTile(
24
+ tag: number,
25
+ layers?: {[x: string]: BinaryVectorTileLayer},
26
+ pbf?: Protobuf
27
+ ): void {
20
28
  if (tag === 3) {
21
29
  if (pbf) {
22
- const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
30
+ const layer = new BinaryVectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
23
31
  if (layer.length && layers) {
24
32
  layers[layer.name] = layer;
25
33
  }
@@ -1,9 +1,13 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+
1
5
  // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
2
6
  import Protobuf from 'pbf';
3
7
  import {MVTMapboxCoordinates, MVTMapboxGeometry} from '../types';
4
8
  import {readFeature, classifyRings} from '../../helpers/mapbox-util-functions';
5
9
 
6
- export default class VectorTileFeature {
10
+ export class VectorTileFeature {
7
11
  properties: {[x: string]: string | number | boolean | null};
8
12
  extent: any;
9
13
  type: number;
@@ -1,10 +1,14 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+
1
5
  /* eslint-disable indent */
2
6
  // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
3
7
 
4
8
  import Protobuf from 'pbf';
5
- import VectorTileFeature from './vector-tile-feature';
9
+ import {VectorTileFeature} from './vector-tile-feature';
6
10
 
7
- export default class VectorTileLayer {
11
+ export class VectorTileLayer {
8
12
  version: number;
9
13
  name: string;
10
14
  extent: number;
@@ -1,9 +1,13 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+
1
5
  // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
2
6
 
3
- import VectorTileLayer from './vector-tile-layer';
7
+ import {VectorTileLayer} from './vector-tile-layer';
4
8
  import Protobuf from 'pbf';
5
9
 
6
- export default class VectorTile {
10
+ export class VectorTile {
7
11
  layers: {[x: string]: VectorTileLayer};
8
12
  constructor(pbf: Protobuf, end?: number) {
9
13
  this.layers = pbf.readFields(readTile, {}, end);
@@ -1,3 +1,7 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+
1
5
  import {flatGeojsonToBinary} from '@loaders.gl/gis';
2
6
  import type {
3
7
  FlatFeature,
@@ -8,12 +12,13 @@ import type {
8
12
  } from '@loaders.gl/schema';
9
13
  import Protobuf from 'pbf';
10
14
 
11
- import type {MVTMapboxCoordinates, MVTOptions, MVTLoaderOptions} from '../lib/types';
15
+ import type {MVTMapboxCoordinates, MVTOptions} from '../lib/types';
16
+ import type {MVTLoaderOptions} from '../mvt-loader';
12
17
 
13
- import VectorTile from './mapbox-vector-tile/vector-tile';
14
- import BinaryVectorTile from './binary-vector-tile/vector-tile';
15
- import VectorTileFeatureBinary from './binary-vector-tile/vector-tile-feature';
16
- import VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';
18
+ import {VectorTile} from './mapbox-vector-tile/vector-tile';
19
+ import {BinaryVectorTile} from './binary-vector-tile/vector-tile';
20
+ import {BinaryVectorTileFeature} from './binary-vector-tile/vector-tile-feature';
21
+ import {VectorTileFeature as VectorTileFeatureMapBox} from './mapbox-vector-tile/vector-tile-feature';
17
22
 
18
23
  /**
19
24
  * Parse MVT arrayBuffer and return GeoJSON.
@@ -22,7 +27,7 @@ import VectorTileFeatureMapBox from './mapbox-vector-tile/vector-tile-feature';
22
27
  * @param options
23
28
  * @returns A GeoJSON geometry object or a binary representation
24
29
  */
25
- export default function parseMVT(arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions) {
30
+ export function parseMVT(arrayBuffer: ArrayBuffer, options?: MVTLoaderOptions) {
26
31
  const mvtOptions = normalizeOptions(options);
27
32
 
28
33
  const shape: string | undefined =
@@ -179,12 +184,12 @@ function getDecodedFeature(
179
184
  * @returns decoded binary feature
180
185
  */
181
186
  function getDecodedFeatureBinary(
182
- feature: VectorTileFeatureBinary,
187
+ feature: BinaryVectorTileFeature,
183
188
  options: MVTOptions,
184
189
  layerName: string
185
190
  ): FlatFeature {
186
191
  const decodedFeature = feature.toBinaryCoordinates(
187
- // @ts-expect-error What is going on here?
192
+ // @ts-expect-error
188
193
  options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary
189
194
  );
190
195
 
package/src/lib/types.ts CHANGED
@@ -1,4 +1,6 @@
1
- import type {LoaderOptions} from '@loaders.gl/loader-utils';
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
2
4
 
3
5
  /** For local coordinates, the tileIndex is not required */
4
6
  type MVTLocalCoordinatesOptions = {
@@ -55,13 +57,3 @@ export type MVTMapboxCoordinates = {
55
57
  properties: {[x: string]: string | number | boolean | null};
56
58
  id?: number;
57
59
  };
58
-
59
- export type MVTLoaderOptions = LoaderOptions & {
60
- mvt?: MVTOptions;
61
- gis?: {
62
- /** `true`: parser will output the data in binary format. Equivalent to loading the data as GeoJSON and then applying geojsonToBinary */
63
- binary?: boolean;
64
- /** @deprecated. Use options.mvt.shape */
65
- format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
66
- };
67
- };
package/src/mvt-loader.ts CHANGED
@@ -1,26 +1,35 @@
1
- import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';
2
- import type {MVTLoaderOptions} from './lib/types';
3
- // import type {
4
- // Feature,
5
- // BinaryFeatureCollection,
6
- // GeoJSONTable,
7
- // Geometry,
8
- // GeoJsonProperties
9
- // } from '@loaders.gl/schema';
10
- import parseMVT from './lib/parse-mvt';
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+
5
+ import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
6
+ import {parseMVT} from './lib/parse-mvt';
7
+ import type {MVTOptions} from './lib/types';
11
8
 
12
9
  // __VERSION__ is injected by babel-plugin-version-inline
13
10
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
14
11
  const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
15
12
 
13
+ export type MVTLoaderOptions = LoaderOptions & {
14
+ mvt?: MVTOptions & {
15
+ /** Override the URL to the worker bundle (by default loads from unpkg.com) */
16
+ workerUrl?: string;
17
+ };
18
+ gis?: {
19
+ /** `true`: parser will output the data in binary format. Equivalent to loading the data as GeoJSON and then applying geojsonToBinary */
20
+ binary?: boolean;
21
+ /** @deprecated. Use options.mvt.shape */
22
+ format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
23
+ };
24
+ };
25
+
16
26
  /**
17
27
  * Worker loader for the Mapbox Vector Tile format
18
28
  */
19
- export const MVTWorkerLoader: Loader<
20
- any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,
21
- never,
22
- MVTLoaderOptions
23
- > = {
29
+ export const MVTWorkerLoader = {
30
+ dataType: null as any,
31
+ batchType: null as never,
32
+
24
33
  name: 'Mapbox Vector Tile',
25
34
  id: 'mvt',
26
35
  module: 'mvt',
@@ -44,18 +53,22 @@ export const MVTWorkerLoader: Loader<
44
53
  tileIndex: null
45
54
  }
46
55
  }
47
- };
56
+ } as const satisfies Loader<
57
+ any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,
58
+ never,
59
+ MVTLoaderOptions
60
+ >;
48
61
 
49
62
  /**
50
63
  * Loader for the Mapbox Vector Tile format
51
64
  */
52
- export const MVTLoader: LoaderWithParser<
53
- any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,
54
- never,
55
- MVTLoaderOptions
56
- > = {
65
+ export const MVTLoader = {
57
66
  ...MVTWorkerLoader,
58
67
  parse: async (arrayBuffer, options?: MVTLoaderOptions) => parseMVT(arrayBuffer, options),
59
68
  parseSync: parseMVT,
60
69
  binary: true
61
- };
70
+ } as const satisfies LoaderWithParser<
71
+ any, // BinaryFeatureCollection | GeoJSONTable | Feature<Geometry, GeoJsonProperties>,
72
+ never,
73
+ MVTLoaderOptions
74
+ >;
@@ -21,7 +21,10 @@ export type TileJSONLoaderOptions = LoaderOptions & {
21
21
  /**
22
22
  * Loader for TileJSON metadata
23
23
  */
24
- export const TileJSONLoader: LoaderWithParser<TileJSON, never, TileJSONLoaderOptions> = {
24
+ export const TileJSONLoader = {
25
+ dataType: null as unknown as TileJSON,
26
+ batchType: null as never,
27
+
25
28
  name: 'TileJSON',
26
29
  id: 'tilejson',
27
30
  module: 'pmtiles',
@@ -46,4 +49,4 @@ export const TileJSONLoader: LoaderWithParser<TileJSON, never, TileJSONLoaderOpt
46
49
  const tilejsonOptions = {...TileJSONLoader.options.tilejson, ...options?.tilejson};
47
50
  return parseTileJSON(json, tilejsonOptions) as TileJSON;
48
51
  }
49
- };
52
+ } as const satisfies LoaderWithParser<TileJSON, never, TileJSONLoaderOptions>;
@@ -1,3 +1,7 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+
1
5
  import {MVTLoader} from '../mvt-loader';
2
6
  import {createLoaderWorker} from '@loaders.gl/loader-utils';
3
7