@loaders.gl/mvt 3.0.12 → 3.1.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 (98) hide show
  1. package/dist/dist.min.js +2 -2
  2. package/dist/dist.min.js.map +1 -1
  3. package/dist/es5/bundle.js +2 -4
  4. package/dist/es5/bundle.js.map +1 -1
  5. package/dist/es5/helpers/binary-util-functions.js +95 -0
  6. package/dist/es5/helpers/binary-util-functions.js.map +1 -0
  7. package/dist/es5/helpers/mapbox-util-functions.js +62 -0
  8. package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
  9. package/dist/es5/lib/binary-vector-tile/features-to-binary.js +4 -7
  10. package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +1 -1
  11. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +23 -94
  12. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  13. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +15 -3
  14. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  15. package/dist/es5/lib/binary-vector-tile/vector-tile.js +8 -3
  16. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -1
  17. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +15 -55
  18. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
  19. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +15 -3
  20. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -1
  21. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +8 -3
  22. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -1
  23. package/dist/es5/lib/parse-mvt.js +56 -53
  24. package/dist/es5/lib/parse-mvt.js.map +1 -1
  25. package/dist/es5/lib/types.js +2 -0
  26. package/dist/es5/lib/types.js.map +1 -0
  27. package/dist/es5/mvt-loader.js +1 -1
  28. package/dist/es5/mvt-loader.js.map +1 -1
  29. package/dist/es5/workers/mvt-worker.js +7 -3
  30. package/dist/es5/workers/mvt-worker.js.map +1 -0
  31. package/dist/esm/bundle.js +2 -4
  32. package/dist/esm/bundle.js.map +1 -1
  33. package/dist/esm/helpers/binary-util-functions.js +81 -0
  34. package/dist/esm/helpers/binary-util-functions.js.map +1 -0
  35. package/dist/esm/helpers/mapbox-util-functions.js +49 -0
  36. package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
  37. package/dist/esm/lib/binary-vector-tile/features-to-binary.js +4 -4
  38. package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +1 -1
  39. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +27 -92
  40. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  41. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +22 -3
  42. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  43. package/dist/esm/lib/binary-vector-tile/vector-tile.js +8 -3
  44. package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -1
  45. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +20 -54
  46. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
  47. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +22 -3
  48. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -1
  49. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +8 -3
  50. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -1
  51. package/dist/esm/lib/parse-mvt.js +57 -52
  52. package/dist/esm/lib/parse-mvt.js.map +1 -1
  53. package/dist/esm/lib/types.js +2 -0
  54. package/dist/esm/lib/types.js.map +1 -0
  55. package/dist/esm/mvt-loader.js +1 -1
  56. package/dist/esm/mvt-loader.js.map +1 -1
  57. package/dist/esm/workers/mvt-worker.js +3 -3
  58. package/dist/esm/workers/mvt-worker.js.map +1 -0
  59. package/dist/mvt-worker.js +2 -2
  60. package/dist/mvt-worker.js.map +1 -1
  61. package/package.json +5 -5
  62. package/src/bundle.ts +2 -3
  63. package/src/helpers/binary-util-functions.ts +119 -0
  64. package/src/helpers/mapbox-util-functions.ts +78 -0
  65. package/src/lib/binary-vector-tile/{features-to-binary.js → features-to-binary.ts} +184 -29
  66. package/src/lib/binary-vector-tile/{vector-tile-feature.js → vector-tile-feature.ts} +41 -109
  67. package/src/lib/binary-vector-tile/vector-tile-layer.ts +109 -0
  68. package/src/lib/binary-vector-tile/vector-tile.ts +28 -0
  69. package/src/lib/mapbox-vector-tile/{vector-tile-feature.js → vector-tile-feature.ts} +31 -72
  70. package/src/lib/mapbox-vector-tile/{vector-tile-layer.js → vector-tile-layer.ts} +42 -14
  71. package/src/lib/mapbox-vector-tile/vector-tile.ts +28 -0
  72. package/src/lib/parse-mvt.ts +174 -0
  73. package/src/lib/types.ts +92 -0
  74. package/src/workers/{mvt-worker.js → mvt-worker.ts} +0 -0
  75. package/dist/dist.es5.min.js +0 -4
  76. package/dist/dist.es5.min.js.map +0 -1
  77. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.d.ts +0 -39
  78. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.d.ts +0 -25
  79. package/dist/es5/lib/binary-vector-tile/vector-tile.d.ts +0 -16
  80. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.d.ts +0 -19
  81. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.d.ts +0 -14
  82. package/dist/es5/lib/mapbox-vector-tile/vector-tile.d.ts +0 -7
  83. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.d.ts +0 -39
  84. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.d.ts +0 -25
  85. package/dist/esm/lib/binary-vector-tile/vector-tile.d.ts +0 -16
  86. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.d.ts +0 -19
  87. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.d.ts +0 -14
  88. package/dist/esm/lib/mapbox-vector-tile/vector-tile.d.ts +0 -7
  89. package/src/lib/binary-vector-tile/vector-tile-feature.d.ts +0 -39
  90. package/src/lib/binary-vector-tile/vector-tile-layer.d.ts +0 -25
  91. package/src/lib/binary-vector-tile/vector-tile-layer.js +0 -79
  92. package/src/lib/binary-vector-tile/vector-tile.d.ts +0 -16
  93. package/src/lib/binary-vector-tile/vector-tile.js +0 -18
  94. package/src/lib/mapbox-vector-tile/vector-tile-feature.d.ts +0 -19
  95. package/src/lib/mapbox-vector-tile/vector-tile-layer.d.ts +0 -14
  96. package/src/lib/mapbox-vector-tile/vector-tile.d.ts +0 -7
  97. package/src/lib/mapbox-vector-tile/vector-tile.js +0 -18
  98. package/src/lib/parse-mvt.js +0 -142
@@ -1,16 +0,0 @@
1
- import VectorTileLayer from './vector-tile-layer';
2
- import Protobuf from 'pbf';
3
-
4
- /**
5
- * Wrapper around Mapbox PBF representation of
6
- * a vector tile. It has the same semantics
7
- * as the original library (https://github.com/mapbox/vector-tile-js)
8
- * except that the features it contains expose their data
9
- * in a binary optimized format, rather than GeoJSON.
10
- *
11
- * The VectorTile class is unmodified from the original source
12
- */
13
- export default class VectorTile {
14
- constructor(pbf: Protobuf, end?);
15
- layers: VectorTileLayer[];
16
- }
@@ -1,18 +0,0 @@
1
- // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
2
-
3
- import VectorTileLayer from './vector-tile-layer';
4
-
5
- export default class VectorTile {
6
- constructor(pbf, end) {
7
- this.layers = pbf.readFields(readTile, {}, end);
8
- }
9
- }
10
-
11
- function readTile(tag, layers, pbf) {
12
- if (tag === 3) {
13
- const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
14
- if (layer.length) {
15
- layers[layer.name] = layer;
16
- }
17
- }
18
- }
@@ -1,19 +0,0 @@
1
- import Protobuf from 'pbf';
2
-
3
- export default class VectorTileFeature {
4
- static types: ['Unknown', 'Point', 'LineString', 'Polygon'];
5
-
6
- properties: object;
7
- extent: any;
8
- type: number;
9
- id?: number;
10
-
11
- constructor(pbf: Protobuf, end, extent, keys, values);
12
-
13
- loadGeometry();
14
- any;
15
- bbox(): [number, number, number, number];
16
- toGeoJSON(
17
- options: {x: number; y: number; z: number} | (([[number]], VectorTileFeature) => void)
18
- ): object;
19
- }
@@ -1,14 +0,0 @@
1
- import VectorTileFeature from './vector-tile-feature';
2
-
3
- export default class VectorTileLayer {
4
- // Public
5
- version: number;
6
- name: string;
7
- extent: number;
8
- length: number;
9
-
10
- constructor(pbf, end);
11
-
12
- /** return feature `i` from this layer as a `VectorTileFeature` */
13
- feature(i: number): VectorTileFeature;
14
- }
@@ -1,7 +0,0 @@
1
- import VectorTileLayer from './vector-tile-layer';
2
- import Protobuf from 'pbf';
3
-
4
- export default class VectorTile {
5
- constructor(pbf: Protobuf, end?);
6
- layers: VectorTileLayer[];
7
- }
@@ -1,18 +0,0 @@
1
- // This code is forked from https://github.com/mapbox/vector-tile-js under BSD 3-clause license.
2
-
3
- import VectorTileLayer from './vector-tile-layer';
4
-
5
- export default class VectorTile {
6
- constructor(pbf, end) {
7
- this.layers = pbf.readFields(readTile, {}, end);
8
- }
9
- }
10
-
11
- function readTile(tag, layers, pbf) {
12
- if (tag === 3) {
13
- const layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos);
14
- if (layer.length) {
15
- layers[layer.name] = layer;
16
- }
17
- }
18
- }
@@ -1,142 +0,0 @@
1
- // import {VectorTile} from '@mapbox/vector-tile';
2
- import VectorTile from './mapbox-vector-tile/vector-tile';
3
- import BinaryVectorTile from './binary-vector-tile/vector-tile';
4
-
5
- import {featuresToBinary} from './binary-vector-tile/features-to-binary';
6
- import Protobuf from 'pbf';
7
-
8
- /*
9
- * Parse MVT arrayBuffer and return GeoJSON.
10
- *
11
- * @param {arrayBuffer} _ A MVT arrayBuffer
12
- * @return {?Object} A GeoJSON geometry object or a binary representation
13
- */
14
- export default function parseMVT(arrayBuffer, options) {
15
- options = normalizeOptions(options);
16
-
17
- const binary = options.gis.format === 'binary';
18
- const features = [];
19
- const firstPassData = {
20
- pointPositionsCount: 0,
21
- pointFeaturesCount: 0,
22
- linePositionsCount: 0,
23
- linePathsCount: 0,
24
- lineFeaturesCount: 0,
25
- polygonPositionsCount: 0,
26
- polygonObjectsCount: 0,
27
- polygonRingsCount: 0,
28
- polygonFeaturesCount: 0
29
- };
30
-
31
- if (arrayBuffer.byteLength > 0) {
32
- const tile = binary
33
- ? new BinaryVectorTile(new Protobuf(arrayBuffer))
34
- : new VectorTile(new Protobuf(arrayBuffer));
35
- const loaderOptions = options.mvt;
36
-
37
- const selectedLayers = Array.isArray(loaderOptions.layers)
38
- ? loaderOptions.layers
39
- : Object.keys(tile.layers);
40
-
41
- selectedLayers.forEach((layerName) => {
42
- const vectorTileLayer = tile.layers[layerName];
43
- const featureOptions = {...loaderOptions, layerName};
44
-
45
- if (!vectorTileLayer) {
46
- return;
47
- }
48
-
49
- for (let i = 0; i < vectorTileLayer.length; i++) {
50
- const vectorTileFeature = vectorTileLayer.feature(i, firstPassData);
51
-
52
- const decodedFeature = binary
53
- ? getDecodedFeatureBinary(vectorTileFeature, featureOptions)
54
- : getDecodedFeature(vectorTileFeature, featureOptions);
55
- features.push(decodedFeature);
56
- }
57
- });
58
- }
59
-
60
- if (binary) {
61
- const data = featuresToBinary(features, firstPassData, options.gis);
62
- // Add the original byteLength (as a reasonable approximation of the size of the binary data)
63
- // TODO decide where to store extra fields like byteLength (header etc) and document
64
- // @ts-ignore
65
- data.byteLength = arrayBuffer.byteLength;
66
- return data;
67
- }
68
-
69
- return features;
70
- }
71
-
72
- function normalizeOptions(options) {
73
- options = {
74
- ...options,
75
- mvt: options.mvt || {},
76
- gis: options.gis || {}
77
- };
78
-
79
- // Validate
80
- const wgs84Coordinates = options.coordinates === 'wgs84';
81
- const {tileIndex} = options;
82
- const hasTileIndex =
83
- tileIndex &&
84
- Number.isFinite(tileIndex.x) &&
85
- Number.isFinite(tileIndex.y) &&
86
- Number.isFinite(tileIndex.z);
87
-
88
- if (wgs84Coordinates && !hasTileIndex) {
89
- throw new Error('MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.');
90
- }
91
-
92
- return options;
93
- }
94
-
95
- function getDecodedFeature(feature, options = {}) {
96
- const decodedFeature = feature.toGeoJSON(
97
- options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates
98
- );
99
-
100
- // Add layer name to GeoJSON properties
101
- if (options.layerProperty) {
102
- decodedFeature.properties[options.layerProperty] = options.layerName;
103
- }
104
-
105
- return decodedFeature;
106
- }
107
-
108
- function getDecodedFeatureBinary(feature, options = {}) {
109
- const decodedFeature = feature.toBinaryCoordinates(
110
- options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary
111
- );
112
-
113
- // Add layer name to GeoJSON properties
114
- if (options.layerProperty) {
115
- decodedFeature.properties[options.layerProperty] = options.layerName;
116
- }
117
-
118
- return decodedFeature;
119
- }
120
-
121
- function transformToLocalCoordinates(line, feature) {
122
- // This function transforms local coordinates in a
123
- // [0 - bufferSize, this.extent + bufferSize] range to a
124
- // [0 - (bufferSize / this.extent), 1 + (bufferSize / this.extent)] range.
125
- // The resulting extent would be 1.
126
- const {extent} = feature;
127
-
128
- for (let i = 0; i < line.length; i++) {
129
- const p = line[i];
130
- p[0] /= extent;
131
- p[1] /= extent;
132
- }
133
- }
134
-
135
- function transformToLocalCoordinatesBinary(data, feature) {
136
- // For the binary code path, the feature data is just
137
- // one big flat array, so we just divide each value
138
- const {extent} = feature;
139
- for (let i = 0, il = data.length; i < il; ++i) {
140
- data[i] /= extent;
141
- }
142
- }