@loaders.gl/mvt 4.0.0-alpha.5 → 4.0.0-alpha.7

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 (175) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +1748 -913
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/helpers/binary-util-functions.js +82 -0
  6. package/dist/es5/helpers/binary-util-functions.js.map +1 -0
  7. package/dist/es5/helpers/mapbox-util-functions.js +50 -0
  8. package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
  9. package/dist/es5/index.js +26 -0
  10. package/dist/es5/index.js.map +1 -0
  11. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +168 -0
  12. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  13. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +62 -0
  14. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  15. package/dist/es5/lib/binary-vector-tile/vector-tile.js +28 -0
  16. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
  17. package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
  18. package/dist/es5/lib/geojson-tiler/clip.js +237 -0
  19. package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
  20. package/dist/es5/lib/geojson-tiler/convert.js +161 -0
  21. package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
  22. package/dist/es5/lib/geojson-tiler/feature.js +62 -0
  23. package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
  24. package/dist/es5/lib/geojson-tiler/geojson-tiler.js +186 -0
  25. package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  26. package/dist/es5/lib/geojson-tiler/simplify.js +52 -0
  27. package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
  28. package/dist/es5/lib/geojson-tiler/tile.js +121 -0
  29. package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
  30. package/dist/es5/lib/geojson-tiler/transform.js +50 -0
  31. package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
  32. package/dist/es5/lib/geojson-tiler/wrap.js +122 -0
  33. package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
  34. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +184 -0
  35. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  36. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +62 -0
  37. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  38. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +28 -0
  39. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  40. package/dist/es5/lib/parse-mvt.js +143 -0
  41. package/dist/es5/lib/parse-mvt.js.map +1 -0
  42. package/dist/es5/lib/types.js +2 -0
  43. package/dist/es5/lib/types.js.map +1 -0
  44. package/dist/es5/mvt-loader.js +58 -0
  45. package/dist/es5/mvt-loader.js.map +1 -0
  46. package/dist/es5/workers/mvt-worker.js +6 -0
  47. package/dist/es5/workers/mvt-worker.js.map +1 -0
  48. package/dist/esm/bundle.js +4 -0
  49. package/dist/esm/bundle.js.map +1 -0
  50. package/dist/esm/helpers/binary-util-functions.js +73 -0
  51. package/dist/esm/helpers/binary-util-functions.js.map +1 -0
  52. package/dist/esm/helpers/mapbox-util-functions.js +41 -0
  53. package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
  54. package/dist/esm/index.js +3 -0
  55. package/dist/esm/index.js.map +1 -0
  56. package/dist/esm/lib/binary-vector-tile/LICENSE.txt +31 -0
  57. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +136 -0
  58. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  59. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +47 -0
  60. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  61. package/dist/esm/lib/binary-vector-tile/vector-tile.js +19 -0
  62. package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
  63. package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
  64. package/dist/esm/lib/geojson-tiler/clip.js +173 -0
  65. package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
  66. package/dist/esm/lib/geojson-tiler/convert.js +116 -0
  67. package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
  68. package/dist/esm/lib/geojson-tiler/feature.js +35 -0
  69. package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
  70. package/dist/esm/lib/geojson-tiler/geojson-tiler.js +171 -0
  71. package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  72. package/dist/esm/lib/geojson-tiler/simplify.js +46 -0
  73. package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
  74. package/dist/esm/lib/geojson-tiler/tile.js +103 -0
  75. package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
  76. package/dist/esm/lib/geojson-tiler/transform.js +32 -0
  77. package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
  78. package/dist/esm/lib/geojson-tiler/wrap.js +67 -0
  79. package/dist/esm/lib/geojson-tiler/wrap.js.map +1 -0
  80. package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +31 -0
  81. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +163 -0
  82. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  83. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +47 -0
  84. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  85. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +19 -0
  86. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  87. package/dist/esm/lib/parse-mvt.js +138 -0
  88. package/dist/esm/lib/parse-mvt.js.map +1 -0
  89. package/dist/esm/lib/types.js +2 -0
  90. package/dist/esm/lib/types.js.map +1 -0
  91. package/dist/esm/mvt-loader.js +29 -0
  92. package/dist/esm/mvt-loader.js.map +1 -0
  93. package/dist/esm/workers/mvt-worker.js +4 -0
  94. package/dist/esm/workers/mvt-worker.js.map +1 -0
  95. package/dist/helpers/binary-util-functions.js +111 -77
  96. package/dist/helpers/mapbox-util-functions.d.ts +2 -2
  97. package/dist/helpers/mapbox-util-functions.js +78 -45
  98. package/dist/index.d.ts +2 -0
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +9 -2
  101. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
  102. package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -143
  103. package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
  104. package/dist/lib/binary-vector-tile/vector-tile.js +25 -19
  105. package/dist/lib/geojson-tiler/clip.d.ts +16 -0
  106. package/dist/lib/geojson-tiler/clip.d.ts.map +1 -0
  107. package/dist/lib/geojson-tiler/clip.js +209 -0
  108. package/dist/lib/geojson-tiler/convert.d.ts +10 -0
  109. package/dist/lib/geojson-tiler/convert.d.ts.map +1 -0
  110. package/dist/lib/geojson-tiler/convert.js +134 -0
  111. package/dist/lib/geojson-tiler/feature.d.ts +3 -0
  112. package/dist/lib/geojson-tiler/feature.d.ts.map +1 -0
  113. package/dist/lib/geojson-tiler/feature.js +46 -0
  114. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +44 -0
  115. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -0
  116. package/dist/lib/geojson-tiler/geojson-tiler.js +210 -0
  117. package/dist/lib/geojson-tiler/simplify.d.ts +10 -0
  118. package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -0
  119. package/dist/lib/geojson-tiler/simplify.js +68 -0
  120. package/dist/lib/geojson-tiler/tile.d.ts +38 -0
  121. package/dist/lib/geojson-tiler/tile.d.ts.map +1 -0
  122. package/dist/lib/geojson-tiler/tile.js +125 -0
  123. package/dist/lib/geojson-tiler/transform.d.ts +7 -0
  124. package/dist/lib/geojson-tiler/transform.d.ts.map +1 -0
  125. package/dist/lib/geojson-tiler/transform.js +43 -0
  126. package/dist/lib/geojson-tiler/wrap.d.ts +17 -0
  127. package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -0
  128. package/dist/lib/geojson-tiler/wrap.js +86 -0
  129. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +4 -4
  130. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
  131. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
  132. package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
  133. package/dist/lib/parse-mvt.d.ts +6 -9
  134. package/dist/lib/parse-mvt.d.ts.map +1 -1
  135. package/dist/lib/parse-mvt.js +148 -98
  136. package/dist/lib/types.d.ts +48 -7
  137. package/dist/lib/types.d.ts.map +1 -1
  138. package/dist/lib/types.js +2 -2
  139. package/dist/mvt-loader.d.ts.map +1 -1
  140. package/dist/mvt-loader.js +43 -22
  141. package/dist/mvt-worker.js +903 -829
  142. package/dist/workers/mvt-worker.js +5 -4
  143. package/package.json +7 -7
  144. package/src/helpers/mapbox-util-functions.ts +2 -2
  145. package/src/index.ts +7 -0
  146. package/src/lib/binary-vector-tile/vector-tile-feature.ts +6 -1
  147. package/src/lib/geojson-tiler/LICENSE +19 -0
  148. package/src/lib/geojson-tiler/clip.ts +248 -0
  149. package/src/lib/geojson-tiler/convert.ts +158 -0
  150. package/src/lib/geojson-tiler/feature.ts +45 -0
  151. package/src/lib/geojson-tiler/geojson-tiler.ts +281 -0
  152. package/src/lib/geojson-tiler/simplify.ts +77 -0
  153. package/src/lib/geojson-tiler/tile.ts +185 -0
  154. package/src/lib/geojson-tiler/transform.ts +55 -0
  155. package/src/lib/geojson-tiler/wrap.ts +108 -0
  156. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +4 -4
  157. package/src/lib/parse-mvt.ts +136 -93
  158. package/src/lib/types.ts +53 -7
  159. package/src/mvt-loader.ts +13 -9
  160. package/dist/bundle.js.map +0 -1
  161. package/dist/helpers/binary-util-functions.js.map +0 -1
  162. package/dist/helpers/mapbox-util-functions.js.map +0 -1
  163. package/dist/index.js.map +0 -1
  164. package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
  165. package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
  166. package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
  167. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
  168. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
  169. package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
  170. package/dist/lib/parse-mvt.js.map +0 -1
  171. package/dist/lib/types.js.map +0 -1
  172. package/dist/mvt-loader.js.map +0 -1
  173. package/dist/workers/mvt-worker.js.map +0 -1
  174. /package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
  175. /package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
@@ -1,117 +1,167 @@
1
- import VectorTile from './mapbox-vector-tile/vector-tile';
2
- import BinaryVectorTile from './binary-vector-tile/vector-tile';
3
- import { flatGeojsonToBinary } from '@loaders.gl/gis';
4
- import Protobuf from 'pbf';
5
- export default function parseMVT(arrayBuffer, options) {
6
- options = normalizeOptions(options);
7
- const features = [];
8
-
9
- if (options) {
10
- const binary = options.gis.format === 'binary';
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const gis_1 = require("@loaders.gl/gis");
7
+ const pbf_1 = __importDefault(require("pbf"));
8
+ const vector_tile_1 = __importDefault(require("./mapbox-vector-tile/vector-tile"));
9
+ const vector_tile_2 = __importDefault(require("./binary-vector-tile/vector-tile"));
10
+ /**
11
+ * Parse MVT arrayBuffer and return GeoJSON.
12
+ *
13
+ * @param arrayBuffer A MVT arrayBuffer
14
+ * @param options
15
+ * @returns A GeoJSON geometry object or a binary representation
16
+ */
17
+ function parseMVT(arrayBuffer, options) {
18
+ const mvtOptions = normalizeOptions(options);
19
+ const shape = options?.gis?.format || options?.mvt?.shape;
20
+ switch (shape) {
21
+ case 'columnar-table': // binary + some JS arrays
22
+ return { shape: 'columnar-table', data: parseToBinary(arrayBuffer, mvtOptions) };
23
+ case 'geojson-row-table': {
24
+ const table = {
25
+ shape: 'geojson-row-table',
26
+ data: parseToGeojson(arrayBuffer, mvtOptions)
27
+ };
28
+ return table;
29
+ }
30
+ case 'geojson':
31
+ return parseToGeojson(arrayBuffer, mvtOptions);
32
+ case 'binary-geometry':
33
+ return parseToBinary(arrayBuffer, mvtOptions);
34
+ case 'binary':
35
+ return parseToBinary(arrayBuffer, mvtOptions);
36
+ default:
37
+ throw new Error(shape);
38
+ }
39
+ }
40
+ exports.default = parseMVT;
41
+ function parseToBinary(arrayBuffer, options) {
42
+ const [flatGeoJsonFeatures, geometryInfo] = parseToFlatGeoJson(arrayBuffer, options);
43
+ const binaryData = (0, gis_1.flatGeojsonToBinary)(flatGeoJsonFeatures, geometryInfo);
44
+ // Add the original byteLength (as a reasonable approximation of the size of the binary data)
45
+ // TODO decide where to store extra fields like byteLength (header etc) and document
46
+ // @ts-ignore
47
+ binaryData.byteLength = arrayBuffer.byteLength;
48
+ return binaryData;
49
+ }
50
+ function parseToFlatGeoJson(arrayBuffer, options) {
51
+ const features = [];
11
52
  const geometryInfo = {
12
- coordLength: 2,
13
- pointPositionsCount: 0,
14
- pointFeaturesCount: 0,
15
- linePositionsCount: 0,
16
- linePathsCount: 0,
17
- lineFeaturesCount: 0,
18
- polygonPositionsCount: 0,
19
- polygonObjectsCount: 0,
20
- polygonRingsCount: 0,
21
- polygonFeaturesCount: 0
53
+ coordLength: 2,
54
+ pointPositionsCount: 0,
55
+ pointFeaturesCount: 0,
56
+ linePositionsCount: 0,
57
+ linePathsCount: 0,
58
+ lineFeaturesCount: 0,
59
+ polygonPositionsCount: 0,
60
+ polygonObjectsCount: 0,
61
+ polygonRingsCount: 0,
62
+ polygonFeaturesCount: 0
22
63
  };
23
-
24
- if (arrayBuffer.byteLength > 0) {
25
- const tile = binary ? new BinaryVectorTile(new Protobuf(arrayBuffer)) : new VectorTile(new Protobuf(arrayBuffer));
26
- const loaderOptions = options.mvt;
27
- const selectedLayers = Array.isArray(loaderOptions.layers) ? loaderOptions.layers : Object.keys(tile.layers);
28
- selectedLayers.forEach(layerName => {
64
+ if (arrayBuffer.byteLength <= 0) {
65
+ return [features, geometryInfo];
66
+ }
67
+ const tile = new vector_tile_2.default(new pbf_1.default(arrayBuffer));
68
+ const selectedLayers = options && Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
69
+ selectedLayers.forEach((layerName) => {
29
70
  const vectorTileLayer = tile.layers[layerName];
30
- const featureOptions = { ...loaderOptions,
31
- layerName
32
- };
33
-
34
71
  if (!vectorTileLayer) {
35
- return;
72
+ return;
36
73
  }
37
-
38
74
  for (let i = 0; i < vectorTileLayer.length; i++) {
39
- const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);
40
- const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
41
- features.push(decodedFeature);
75
+ const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);
76
+ const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
77
+ features.push(decodedFeature);
42
78
  }
43
- });
44
- }
45
-
46
- if (binary) {
47
- const data = flatGeojsonToBinary(features, geometryInfo);
48
- data.byteLength = arrayBuffer.byteLength;
49
- return data;
79
+ });
80
+ return [features, geometryInfo];
81
+ }
82
+ function parseToGeojson(arrayBuffer, options) {
83
+ if (arrayBuffer.byteLength <= 0) {
84
+ return [];
50
85
  }
51
- }
52
-
53
- return features;
86
+ const features = [];
87
+ const tile = new vector_tile_1.default(new pbf_1.default(arrayBuffer));
88
+ const selectedLayers = Array.isArray(options.layers) ? options.layers : Object.keys(tile.layers);
89
+ selectedLayers.forEach((layerName) => {
90
+ const vectorTileLayer = tile.layers[layerName];
91
+ if (!vectorTileLayer) {
92
+ return;
93
+ }
94
+ for (let i = 0; i < vectorTileLayer.length; i++) {
95
+ const vectorTileFeature = vectorTileLayer.feature(i);
96
+ const decodedFeature = getDecodedFeature(vectorTileFeature, options, layerName);
97
+ features.push(decodedFeature);
98
+ }
99
+ });
100
+ return features;
54
101
  }
55
-
56
102
  function normalizeOptions(options) {
57
- if (options) {
58
- options = { ...options,
59
- mvt: options.mvt || {},
60
- gis: options.gis || {}
61
- };
62
- const wgs84Coordinates = options.coordinates === 'wgs84';
63
- const {
64
- tileIndex
65
- } = options;
66
- const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
67
-
103
+ if (!options?.mvt) {
104
+ throw new Error('mvt options required');
105
+ }
106
+ // Validate
107
+ const wgs84Coordinates = options.mvt?.coordinates === 'wgs84';
108
+ const { tileIndex } = options.mvt;
109
+ const hasTileIndex = tileIndex &&
110
+ Number.isFinite(tileIndex.x) &&
111
+ Number.isFinite(tileIndex.y) &&
112
+ Number.isFinite(tileIndex.z);
68
113
  if (wgs84Coordinates && !hasTileIndex) {
69
- throw new Error('MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.');
114
+ throw new Error('MVT Loader: WGS84 coordinates need tileIndex property');
70
115
  }
71
- }
72
-
73
- return options;
116
+ return options.mvt;
74
117
  }
75
-
76
- function getDecodedFeature(feature, options) {
77
- const decodedFeature = feature.toGeoJSON(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates);
78
-
79
- if (options.layerProperty) {
80
- decodedFeature.properties[options.layerProperty] = options.layerName;
81
- }
82
-
83
- return decodedFeature;
118
+ /**
119
+ * @param feature
120
+ * @param options
121
+ * @returns decoded feature
122
+ */
123
+ function getDecodedFeature(feature, options, layerName) {
124
+ const decodedFeature = feature.toGeoJSON(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates);
125
+ // Add layer name to GeoJSON properties
126
+ if (options.layerProperty) {
127
+ decodedFeature.properties[options.layerProperty] = layerName;
128
+ }
129
+ return decodedFeature;
84
130
  }
85
-
86
- function getDecodedFeatureBinary(feature, options) {
87
- const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
88
-
89
- if (options.layerProperty && decodedFeature.properties) {
90
- decodedFeature.properties[options.layerProperty] = options.layerName;
91
- }
92
-
93
- return decodedFeature;
131
+ /**
132
+ * @param feature
133
+ * @param options
134
+ * @returns decoded binary feature
135
+ */
136
+ function getDecodedFeatureBinary(feature, options, layerName) {
137
+ const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
138
+ // Add layer name to GeoJSON properties
139
+ if (options.layerProperty && decodedFeature.properties) {
140
+ decodedFeature.properties[options.layerProperty] = layerName;
141
+ }
142
+ return decodedFeature;
94
143
  }
95
-
144
+ /**
145
+ * @param line
146
+ * @param feature
147
+ */
96
148
  function transformToLocalCoordinates(line, feature) {
97
- const {
98
- extent
99
- } = feature;
100
-
101
- for (let i = 0; i < line.length; i++) {
102
- const p = line[i];
103
- p[0] /= extent;
104
- p[1] /= extent;
105
- }
149
+ // This function transforms local coordinates in a
150
+ // [0 - bufferSize, this.extent + bufferSize] range to a
151
+ // [0 - (bufferSize / this.extent), 1 + (bufferSize / this.extent)] range.
152
+ // The resulting extent would be 1.
153
+ const { extent } = feature;
154
+ for (let i = 0; i < line.length; i++) {
155
+ const p = line[i];
156
+ p[0] /= extent;
157
+ p[1] /= extent;
158
+ }
106
159
  }
107
-
108
160
  function transformToLocalCoordinatesBinary(data, feature) {
109
- const {
110
- extent
111
- } = feature;
112
-
113
- for (let i = 0, il = data.length; i < il; ++i) {
114
- data[i] /= extent;
115
- }
161
+ // For the binary code path, the feature data is just
162
+ // one big flat array, so we just divide each value
163
+ const { extent } = feature;
164
+ for (let i = 0, il = data.length; i < il; ++i) {
165
+ data[i] /= extent;
166
+ }
116
167
  }
117
- //# sourceMappingURL=parse-mvt.js.map
@@ -1,28 +1,69 @@
1
- export declare type MvtOptions = {
2
- coordinates: string | number[];
1
+ import type { LoaderOptions } from '@loaders.gl/loader-utils';
2
+ /** For local coordinates, the tileIndex is not required */
3
+ type MVTLocalCoordinatesOptions = {
4
+ /**
5
+ * When set to `local`, the parser will return a flat array of GeoJSON objects with local coordinates decoded from tile origin.
6
+ */
7
+ coordinates: 'local';
8
+ tileIndex: null;
9
+ };
10
+ /** In WGS84 coordinates, the tileIndex is required */
11
+ type MVTWgs84CoordinatesOptions = {
12
+ /**
13
+ * When set to `wgs84`, the parser will return a flat array of GeoJSON objects with coordinates in longitude, latitude decoded from the provided tile index.
14
+ */
15
+ coordinates: 'wgs84';
16
+ /**
17
+ * Mandatory with `wgs84` coordinates option. An object containing tile index values (`x`, `y`,
18
+ * `z`) to reproject features' coordinates into WGS84.
19
+ */
3
20
  tileIndex: {
4
21
  x: number;
5
22
  y: number;
6
23
  z: number;
7
24
  };
8
- layerProperty: string | number;
9
- layerName: string;
10
25
  };
11
- export declare type MvtMapboxGeometry = {
26
+ export type MVTOptions = (MVTLocalCoordinatesOptions | MVTWgs84CoordinatesOptions) & {
27
+ /**
28
+ * When non-`null`, the layer name of each feature is added to
29
+ * `feature.properties[layerProperty]`. (A `feature.properties` object is created if the feature
30
+ * has no existing properties). If set to `null`, a layer name property will not be added.
31
+ */
32
+ layerProperty?: string | number;
33
+ /**
34
+ * Optional list of layer names. If not `null`, only features belonging to the named layers will
35
+ * be included in the output. If `null`, features from all layers are returned.
36
+ */
37
+ layers?: string[];
38
+ shape?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
39
+ };
40
+ export type MVTMapboxGeometry = {
12
41
  type?: string;
13
42
  id?: number;
14
43
  length: number;
15
44
  coordinates?: any[];
16
45
  };
17
- export declare type MvtMapboxCoordinates = {
46
+ export type MVTMapboxCoordinates = {
18
47
  type: string;
19
48
  geometry: {
20
49
  type: string;
21
- coordinates: MvtMapboxGeometry;
50
+ coordinates: MVTMapboxGeometry;
22
51
  };
23
52
  properties: {
24
53
  [x: string]: string | number | boolean | null;
25
54
  };
26
55
  id?: number;
27
56
  };
57
+ export type MVTLoaderOptions = LoaderOptions & {
58
+ mvt?: MVTOptions;
59
+ gis?: {
60
+ /**
61
+ * When set to `true`, the parser will output the data in binary format. This is equivalent to loading the data as GeoJSON and then applying [geojsonToBinary](https://loaders.gl/modules/gis/docs/api-reference/geojson-to-binary).
62
+ */
63
+ binary?: boolean;
64
+ /** @deprecated. Use options.mvt.shape */
65
+ format?: 'geojson-row-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
66
+ };
67
+ };
68
+ export {};
28
69
  //# 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,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;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,iBAAiB,CAAC;KAChC,CAAC;IACF,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAE5D,2DAA2D;AAC3D,KAAK,0BAA0B,GAAG;IAChC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC;AAEF,sDAAsD;AACtD,KAAK,0BAA0B,GAAG;IAChC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,SAAS,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,0BAA0B,GAAG,0BAA0B,CAAC,GAAG;IACnF;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEhC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;CAC3F,CAAC;AAEF,MAAM,MAAM,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,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,iBAAiB,CAAC;KAChC,CAAC;IACF,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,GAAG,CAAC,EAAE;QACJ;;WAEG;QACH,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,yCAAyC;QACzC,MAAM,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;KAC5F,CAAC;CACH,CAAC"}
package/dist/lib/types.js CHANGED
@@ -1,2 +1,2 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- {"version":3,"file":"mvt-loader.d.ts","sourceRoot":"","sources":["../src/mvt-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAOvE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAsB7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAKvB,CAAC"}
1
+ {"version":3,"file":"mvt-loader.d.ts","sourceRoot":"","sources":["../src/mvt-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAkBvE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAe7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAKvB,CAAC"}
@@ -1,26 +1,47 @@
1
- import parseMVT from './lib/parse-mvt';
2
- const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
3
- export const MVTWorkerLoader = {
4
- name: 'Mapbox Vector Tile',
5
- id: 'mvt',
6
- module: 'mvt',
7
- version: VERSION,
8
- extensions: ['mvt', 'pbf'],
9
- mimeTypes: ['application/vnd.mapbox-vector-tile', 'application/x-protobuf'],
10
- worker: true,
11
- category: 'geometry',
12
- options: {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MVTLoader = exports.MVTWorkerLoader = void 0;
7
+ const parse_mvt_1 = __importDefault(require("./lib/parse-mvt"));
8
+ // __VERSION__ is injected by babel-plugin-version-inline
9
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
10
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
11
+ const DEFAULT_MVT_LOADER_OPTIONS = {
13
12
  mvt: {
14
- coordinates: 'local',
15
- layerProperty: 'layerName',
16
- layers: null,
17
- tileIndex: null
13
+ shape: 'geojson',
14
+ coordinates: 'local',
15
+ layerProperty: 'layerName',
16
+ layers: undefined,
17
+ tileIndex: null
18
18
  }
19
- }
20
19
  };
21
- export const MVTLoader = { ...MVTWorkerLoader,
22
- parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),
23
- parseSync: parseMVT,
24
- binary: true
20
+ /**
21
+ * Worker loader for the Mapbox Vector Tile format
22
+ */
23
+ exports.MVTWorkerLoader = {
24
+ name: 'Mapbox Vector Tile',
25
+ id: 'mvt',
26
+ module: 'mvt',
27
+ version: VERSION,
28
+ // Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
29
+ extensions: ['mvt', 'pbf'],
30
+ mimeTypes: [
31
+ 'application/vnd.mapbox-vector-tile',
32
+ 'application/x-protobuf'
33
+ // 'application/octet-stream'
34
+ ],
35
+ worker: true,
36
+ category: 'geometry',
37
+ options: DEFAULT_MVT_LOADER_OPTIONS
38
+ };
39
+ /**
40
+ * Loader for the Mapbox Vector Tile format
41
+ */
42
+ exports.MVTLoader = {
43
+ ...exports.MVTWorkerLoader,
44
+ parse: async (arrayBuffer, options) => (0, parse_mvt_1.default)(arrayBuffer, options),
45
+ parseSync: parse_mvt_1.default,
46
+ binary: true
25
47
  };
26
- //# sourceMappingURL=mvt-loader.js.map