@loaders.gl/mvt 3.1.0 → 3.1.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 (49) hide show
  1. package/dist/bundle.js +5 -2281
  2. package/dist/dist.min.js +2289 -0
  3. package/dist/es5/helpers/binary-util-functions.js +8 -5
  4. package/dist/es5/helpers/binary-util-functions.js.map +1 -1
  5. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +33 -31
  6. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  7. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +2 -2
  8. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  9. package/dist/es5/lib/parse-mvt.js +6 -5
  10. package/dist/es5/lib/parse-mvt.js.map +1 -1
  11. package/dist/es5/mvt-loader.js +1 -1
  12. package/dist/esm/helpers/binary-util-functions.js +8 -5
  13. package/dist/esm/helpers/binary-util-functions.js.map +1 -1
  14. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +31 -30
  15. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  16. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +2 -2
  17. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  18. package/dist/esm/lib/parse-mvt.js +6 -5
  19. package/dist/esm/lib/parse-mvt.js.map +1 -1
  20. package/dist/esm/mvt-loader.js +1 -1
  21. package/dist/helpers/binary-util-functions.d.ts +2 -6
  22. package/dist/helpers/binary-util-functions.d.ts.map +1 -1
  23. package/dist/helpers/binary-util-functions.js +7 -5
  24. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +12 -7
  25. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
  26. package/dist/lib/binary-vector-tile/vector-tile-feature.js +32 -39
  27. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +3 -3
  28. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
  29. package/dist/lib/binary-vector-tile/vector-tile-layer.js +3 -3
  30. package/dist/lib/parse-mvt.d.ts +8 -76
  31. package/dist/lib/parse-mvt.d.ts.map +1 -1
  32. package/dist/lib/parse-mvt.js +6 -5
  33. package/dist/lib/types.d.ts +0 -68
  34. package/dist/lib/types.d.ts.map +1 -1
  35. package/dist/mvt-worker.js +90 -89
  36. package/package.json +7 -6
  37. package/src/helpers/binary-util-functions.ts +9 -7
  38. package/src/lib/binary-vector-tile/vector-tile-feature.ts +36 -44
  39. package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
  40. package/src/lib/parse-mvt.ts +10 -8
  41. package/src/lib/types.ts +0 -75
  42. package/dist/es5/lib/binary-vector-tile/features-to-binary.js +0 -389
  43. package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  44. package/dist/esm/lib/binary-vector-tile/features-to-binary.js +0 -331
  45. package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  46. package/dist/lib/binary-vector-tile/features-to-binary.d.ts +0 -177
  47. package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +0 -1
  48. package/dist/lib/binary-vector-tile/features-to-binary.js +0 -358
  49. package/src/lib/binary-vector-tile/features-to-binary.ts +0 -527
@@ -25,16 +25,16 @@ class VectorTileLayer {
25
25
  * return feature `i` from this layer as a `VectorTileFeature`
26
26
  *
27
27
  * @param index
28
- * @param firstPassData
28
+ * @param geometryInfo
29
29
  * @returns {VectorTileFeature}
30
30
  */
31
- feature(i, firstPassData) {
31
+ feature(i, geometryInfo) {
32
32
  if (i < 0 || i >= this._features.length) {
33
33
  throw new Error('feature index out of bounds');
34
34
  }
35
35
  this._pbf.pos = this._features[i];
36
36
  const end = this._pbf.readVarint() + this._pbf.pos;
37
- return new vector_tile_feature_1.default(this._pbf, end, this.extent, this._keys, this._values, firstPassData);
37
+ return new vector_tile_feature_1.default(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
38
38
  }
39
39
  }
40
40
  exports.default = VectorTileLayer;
@@ -1,4 +1,4 @@
1
- import { MvtBinaryCoordinates, MvtMapboxCoordinates } from '../lib/types';
1
+ import type { MvtMapboxCoordinates } from '../lib/types';
2
2
  import { LoaderOptions } from '@loaders.gl/loader-utils';
3
3
  /**
4
4
  * Parse MVT arrayBuffer and return GeoJSON.
@@ -7,79 +7,11 @@ import { LoaderOptions } from '@loaders.gl/loader-utils';
7
7
  * @param options
8
8
  * @returns A GeoJSON geometry object or a binary representation
9
9
  */
10
- export default function parseMVT(arrayBuffer: ArrayBuffer, options?: LoaderOptions): {
11
- points: {
12
- positions: {
13
- value: Float32Array;
14
- size: number;
15
- };
16
- globalFeatureIds: {
17
- value: Uint16Array | Uint32Array;
18
- size: number;
19
- };
20
- featureIds: {
21
- value: Uint16Array | Uint32Array;
22
- size: number;
23
- };
24
- numericProps: object;
25
- properties: {}[];
26
- fields: {
27
- id?: number | undefined;
28
- }[];
29
- };
30
- lines: {
31
- pathIndices: {
32
- value: Uint16Array | Uint32Array;
33
- size: number;
34
- };
35
- positions: {
36
- value: Float32Array;
37
- size: number;
38
- };
39
- globalFeatureIds: {
40
- value: Uint16Array | Uint32Array;
41
- size: number;
42
- };
43
- featureIds: {
44
- value: Uint16Array | Uint32Array;
45
- size: number;
46
- };
47
- numericProps: object;
48
- properties: {}[];
49
- fields: {
50
- id?: number | undefined;
51
- }[];
52
- };
53
- polygons: {
54
- polygonIndices: {
55
- value: Uint16Array | Uint32Array;
56
- size: number;
57
- };
58
- primitivePolygonIndices: {
59
- value: Uint16Array | Uint32Array;
60
- size: number;
61
- };
62
- positions: {
63
- value: Float32Array;
64
- size: number;
65
- };
66
- triangles: {
67
- value: Uint32Array;
68
- size: number;
69
- };
70
- globalFeatureIds: {
71
- value: Uint16Array | Uint32Array;
72
- size: number;
73
- };
74
- featureIds: {
75
- value: Uint16Array | Uint32Array;
76
- size: number;
77
- };
78
- numericProps: object;
79
- properties: {}[];
80
- fields: {
81
- id?: number | undefined;
82
- }[];
83
- };
84
- } | (MvtBinaryCoordinates | MvtMapboxCoordinates)[];
10
+ export default function parseMVT(arrayBuffer: ArrayBuffer, options?: LoaderOptions): (MvtMapboxCoordinates | {
11
+ type: "Feature";
12
+ geometry: import("@loaders.gl/schema").FlatGeometry;
13
+ id?: string | number | undefined;
14
+ properties: import("geojson").GeoJsonProperties;
15
+ bbox?: import("geojson").BBox | undefined;
16
+ })[] | import("@loaders.gl/schema").BinaryFeatures;
85
17
  //# sourceMappingURL=parse-mvt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,oBAAoB,EAAE,oBAAoB,EAAa,MAAM,cAAc,CAAC;AAGpF,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oDAyDjF"}
1
+ {"version":3,"file":"parse-mvt.d.ts","sourceRoot":"","sources":["../../src/lib/parse-mvt.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,oBAAoB,EAAa,MAAM,cAAc,CAAC;AAGnE,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,aAAa;;;;;;mDA0DjF"}
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  // import {VectorTile} from '@mapbox/vector-tile';
7
7
  const vector_tile_1 = __importDefault(require("./mapbox-vector-tile/vector-tile"));
8
8
  const vector_tile_2 = __importDefault(require("./binary-vector-tile/vector-tile"));
9
- const features_to_binary_1 = require("./binary-vector-tile/features-to-binary");
9
+ const gis_1 = require("@loaders.gl/gis");
10
10
  const pbf_1 = __importDefault(require("pbf"));
11
11
  /**
12
12
  * Parse MVT arrayBuffer and return GeoJSON.
@@ -20,7 +20,8 @@ function parseMVT(arrayBuffer, options) {
20
20
  const features = [];
21
21
  if (options) {
22
22
  const binary = options.gis.format === 'binary';
23
- const firstPassData = {
23
+ const geometryInfo = {
24
+ coordLength: 2,
24
25
  pointPositionsCount: 0,
25
26
  pointFeaturesCount: 0,
26
27
  linePositionsCount: 0,
@@ -46,7 +47,7 @@ function parseMVT(arrayBuffer, options) {
46
47
  return;
47
48
  }
48
49
  for (let i = 0; i < vectorTileLayer.length; i++) {
49
- const vectorTileFeature = vectorTileLayer.feature(i, firstPassData);
50
+ const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);
50
51
  const decodedFeature = binary
51
52
  ? getDecodedFeatureBinary(vectorTileFeature, featureOptions)
52
53
  : getDecodedFeature(vectorTileFeature, featureOptions);
@@ -55,7 +56,7 @@ function parseMVT(arrayBuffer, options) {
55
56
  });
56
57
  }
57
58
  if (binary) {
58
- const data = (0, features_to_binary_1.featuresToBinary)(features, firstPassData);
59
+ const data = (0, gis_1.flatGeojsonToBinary)(features, geometryInfo);
59
60
  // Add the original byteLength (as a reasonable approximation of the size of the binary data)
60
61
  // TODO decide where to store extra fields like byteLength (header etc) and document
61
62
  // @ts-ignore
@@ -111,7 +112,7 @@ function getDecodedFeature(feature, options) {
111
112
  function getDecodedFeatureBinary(feature, options) {
112
113
  const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
113
114
  // Add layer name to GeoJSON properties
114
- if (options.layerProperty) {
115
+ if (options.layerProperty && decodedFeature.properties) {
115
116
  decodedFeature.properties[options.layerProperty] = options.layerName;
116
117
  }
117
118
  return decodedFeature;
@@ -8,27 +8,12 @@ export declare type MvtOptions = {
8
8
  layerProperty: string | number;
9
9
  layerName: string;
10
10
  };
11
- export declare type MvtBinaryGeometry = {
12
- data: number[];
13
- lines: any[];
14
- areas?: number[];
15
- type?: string;
16
- id?: number;
17
- };
18
11
  export declare type MvtMapboxGeometry = {
19
12
  type?: string;
20
13
  id?: number;
21
14
  length: number;
22
15
  coordinates?: any[];
23
16
  };
24
- export declare type MvtBinaryCoordinates = {
25
- type: string;
26
- geometry: MvtBinaryGeometry;
27
- properties: {
28
- [x: string]: string | number | boolean | null;
29
- };
30
- id?: number;
31
- };
32
17
  export declare type MvtMapboxCoordinates = {
33
18
  type: string;
34
19
  geometry: {
@@ -40,57 +25,4 @@ export declare type MvtMapboxCoordinates = {
40
25
  };
41
26
  id?: number;
42
27
  };
43
- export declare type MvtPropArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor | ArrayConstructor;
44
- export declare type MvtBinaryOptions = {
45
- numericPropKeys: string[];
46
- propArrayTypes: {
47
- [key: string]: MvtPropArrayConstructor;
48
- };
49
- PositionDataType: Float32ArrayConstructor;
50
- };
51
- export declare type MvtFirstPassedData = {
52
- pointPositionsCount: number;
53
- pointFeaturesCount: number;
54
- linePositionsCount: number;
55
- linePathsCount: number;
56
- lineFeaturesCount: number;
57
- polygonPositionsCount: number;
58
- polygonObjectsCount: number;
59
- polygonRingsCount: number;
60
- polygonFeaturesCount: number;
61
- };
62
- export declare type MvtPoints = {
63
- positions: Float32Array;
64
- globalFeatureIds: Uint16Array | Uint32Array;
65
- featureIds: Uint16Array | Uint32Array;
66
- numericProps: object;
67
- properties: {}[];
68
- fields: {
69
- id?: number;
70
- }[];
71
- };
72
- export declare type MvtLines = {
73
- pathIndices: Uint16Array | Uint32Array;
74
- positions: Float32Array;
75
- globalFeatureIds: Uint16Array | Uint32Array;
76
- featureIds: Uint16Array | Uint32Array;
77
- numericProps: object;
78
- properties: {}[];
79
- fields: {
80
- id?: number;
81
- }[];
82
- };
83
- export declare type MvtPolygons = {
84
- polygonIndices: Uint16Array | Uint32Array;
85
- primitivePolygonIndices: Uint16Array | Uint32Array;
86
- positions: Float32Array;
87
- triangles: number[];
88
- globalFeatureIds: Uint16Array | Uint32Array;
89
- featureIds: Uint16Array | Uint32Array;
90
- numericProps: object;
91
- properties: {}[];
92
- fields: {
93
- id?: number;
94
- }[];
95
- };
96
28
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU,GAAG;IACvB,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC/B,SAAS,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;IAC7C,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oBAAY,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,GAAG,EAAE,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,oBAAY,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;CACrB,CAAC;AAEF,oBAAY,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,EAAE,CA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