@loaders.gl/mvt 4.0.0-alpha.1 → 4.0.0-alpha.11

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 (198) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/dist.min.js +3124 -0
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/helpers/binary-util-functions.js +82 -0
  8. package/dist/es5/helpers/binary-util-functions.js.map +1 -0
  9. package/dist/es5/helpers/mapbox-util-functions.js +50 -0
  10. package/dist/es5/helpers/mapbox-util-functions.js.map +1 -0
  11. package/dist/es5/index.js +26 -0
  12. package/dist/es5/index.js.map +1 -0
  13. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +168 -0
  14. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  15. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +62 -0
  16. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  17. package/dist/es5/lib/binary-vector-tile/vector-tile.js +28 -0
  18. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -0
  19. package/dist/es5/lib/geojson-tiler/LICENSE +19 -0
  20. package/dist/es5/lib/geojson-tiler/clip.js +237 -0
  21. package/dist/es5/lib/geojson-tiler/clip.js.map +1 -0
  22. package/dist/es5/lib/geojson-tiler/convert.js +161 -0
  23. package/dist/es5/lib/geojson-tiler/convert.js.map +1 -0
  24. package/dist/es5/lib/geojson-tiler/feature.js +62 -0
  25. package/dist/es5/lib/geojson-tiler/feature.js.map +1 -0
  26. package/dist/es5/lib/geojson-tiler/geojson-tiler.js +186 -0
  27. package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  28. package/dist/es5/lib/geojson-tiler/simplify.js +52 -0
  29. package/dist/es5/lib/geojson-tiler/simplify.js.map +1 -0
  30. package/dist/es5/lib/geojson-tiler/tile.js +121 -0
  31. package/dist/es5/lib/geojson-tiler/tile.js.map +1 -0
  32. package/dist/es5/lib/geojson-tiler/transform.js +50 -0
  33. package/dist/es5/lib/geojson-tiler/transform.js.map +1 -0
  34. package/dist/es5/lib/geojson-tiler/wrap.js +122 -0
  35. package/dist/es5/lib/geojson-tiler/wrap.js.map +1 -0
  36. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +184 -0
  37. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  38. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +62 -0
  39. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  40. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +28 -0
  41. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  42. package/dist/es5/lib/parse-mvt.js +143 -0
  43. package/dist/es5/lib/parse-mvt.js.map +1 -0
  44. package/dist/es5/lib/types.js +2 -0
  45. package/dist/es5/lib/types.js.map +1 -0
  46. package/dist/es5/mvt-loader.js +58 -0
  47. package/dist/es5/mvt-loader.js.map +1 -0
  48. package/dist/es5/workers/mvt-worker.js +6 -0
  49. package/dist/es5/workers/mvt-worker.js.map +1 -0
  50. package/dist/esm/bundle.js +4 -0
  51. package/dist/esm/bundle.js.map +1 -0
  52. package/dist/esm/helpers/binary-util-functions.js +73 -0
  53. package/dist/esm/helpers/binary-util-functions.js.map +1 -0
  54. package/dist/esm/helpers/mapbox-util-functions.js +41 -0
  55. package/dist/esm/helpers/mapbox-util-functions.js.map +1 -0
  56. package/dist/esm/index.js +3 -0
  57. package/dist/esm/index.js.map +1 -0
  58. package/dist/esm/lib/binary-vector-tile/LICENSE.txt +31 -0
  59. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +136 -0
  60. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
  61. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +47 -0
  62. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
  63. package/dist/esm/lib/binary-vector-tile/vector-tile.js +19 -0
  64. package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +1 -0
  65. package/dist/esm/lib/geojson-tiler/LICENSE +19 -0
  66. package/dist/esm/lib/geojson-tiler/clip.js +173 -0
  67. package/dist/esm/lib/geojson-tiler/clip.js.map +1 -0
  68. package/dist/esm/lib/geojson-tiler/convert.js +116 -0
  69. package/dist/esm/lib/geojson-tiler/convert.js.map +1 -0
  70. package/dist/esm/lib/geojson-tiler/feature.js +35 -0
  71. package/dist/esm/lib/geojson-tiler/feature.js.map +1 -0
  72. package/dist/esm/lib/geojson-tiler/geojson-tiler.js +171 -0
  73. package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +1 -0
  74. package/dist/esm/lib/geojson-tiler/simplify.js +46 -0
  75. package/dist/esm/lib/geojson-tiler/simplify.js.map +1 -0
  76. package/dist/esm/lib/geojson-tiler/tile.js +103 -0
  77. package/dist/esm/lib/geojson-tiler/tile.js.map +1 -0
  78. package/dist/esm/lib/geojson-tiler/transform.js +32 -0
  79. package/dist/esm/lib/geojson-tiler/transform.js.map +1 -0
  80. package/dist/esm/lib/geojson-tiler/wrap.js +67 -0
  81. package/dist/esm/lib/geojson-tiler/wrap.js.map +1 -0
  82. package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +31 -0
  83. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js +163 -0
  84. package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
  85. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js +47 -0
  86. package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
  87. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js +19 -0
  88. package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
  89. package/dist/esm/lib/parse-mvt.js +138 -0
  90. package/dist/esm/lib/parse-mvt.js.map +1 -0
  91. package/dist/esm/lib/types.js +2 -0
  92. package/dist/esm/lib/types.js.map +1 -0
  93. package/dist/esm/mvt-loader.js +29 -0
  94. package/dist/esm/mvt-loader.js.map +1 -0
  95. package/dist/esm/workers/mvt-worker.js +4 -0
  96. package/dist/esm/workers/mvt-worker.js.map +1 -0
  97. package/dist/helpers/binary-util-functions.d.ts +35 -0
  98. package/dist/helpers/binary-util-functions.d.ts.map +1 -0
  99. package/dist/helpers/binary-util-functions.js +111 -74
  100. package/dist/helpers/mapbox-util-functions.d.ts +29 -0
  101. package/dist/helpers/mapbox-util-functions.d.ts.map +1 -0
  102. package/dist/helpers/mapbox-util-functions.js +78 -45
  103. package/dist/index.d.ts +4 -0
  104. package/dist/index.d.ts.map +1 -0
  105. package/dist/index.js +9 -2
  106. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +41 -0
  107. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -0
  108. package/dist/lib/binary-vector-tile/vector-tile-feature.js +142 -142
  109. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +23 -0
  110. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -0
  111. package/dist/lib/binary-vector-tile/vector-tile-layer.js +85 -58
  112. package/dist/lib/binary-vector-tile/vector-tile.d.ts +9 -0
  113. package/dist/lib/binary-vector-tile/vector-tile.d.ts.map +1 -0
  114. package/dist/lib/binary-vector-tile/vector-tile.js +25 -19
  115. package/dist/lib/geojson-tiler/clip.d.ts +16 -0
  116. package/dist/lib/geojson-tiler/clip.d.ts.map +1 -0
  117. package/dist/lib/geojson-tiler/clip.js +209 -0
  118. package/dist/lib/geojson-tiler/convert.d.ts +10 -0
  119. package/dist/lib/geojson-tiler/convert.d.ts.map +1 -0
  120. package/dist/lib/geojson-tiler/convert.js +134 -0
  121. package/dist/lib/geojson-tiler/feature.d.ts +3 -0
  122. package/dist/lib/geojson-tiler/feature.d.ts.map +1 -0
  123. package/dist/lib/geojson-tiler/feature.js +46 -0
  124. package/dist/lib/geojson-tiler/geojson-tiler.d.ts +44 -0
  125. package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -0
  126. package/dist/lib/geojson-tiler/geojson-tiler.js +210 -0
  127. package/dist/lib/geojson-tiler/simplify.d.ts +10 -0
  128. package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -0
  129. package/dist/lib/geojson-tiler/simplify.js +68 -0
  130. package/dist/lib/geojson-tiler/tile.d.ts +38 -0
  131. package/dist/lib/geojson-tiler/tile.d.ts.map +1 -0
  132. package/dist/lib/geojson-tiler/tile.js +125 -0
  133. package/dist/lib/geojson-tiler/transform.d.ts +7 -0
  134. package/dist/lib/geojson-tiler/transform.d.ts.map +1 -0
  135. package/dist/lib/geojson-tiler/transform.js +43 -0
  136. package/dist/lib/geojson-tiler/wrap.d.ts +17 -0
  137. package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -0
  138. package/dist/lib/geojson-tiler/wrap.js +86 -0
  139. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts +27 -0
  140. package/dist/lib/mapbox-vector-tile/vector-tile-feature.d.ts.map +1 -0
  141. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js +161 -193
  142. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts +20 -0
  143. package/dist/lib/mapbox-vector-tile/vector-tile-layer.d.ts.map +1 -0
  144. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js +83 -58
  145. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts +9 -0
  146. package/dist/lib/mapbox-vector-tile/vector-tile.d.ts.map +1 -0
  147. package/dist/lib/mapbox-vector-tile/vector-tile.js +25 -19
  148. package/dist/lib/parse-mvt.d.ts +14 -0
  149. package/dist/lib/parse-mvt.d.ts.map +1 -0
  150. package/dist/lib/parse-mvt.js +149 -98
  151. package/dist/lib/types.d.ts +69 -0
  152. package/dist/lib/types.d.ts.map +1 -0
  153. package/dist/lib/types.js +2 -2
  154. package/dist/mvt-loader.d.ts +10 -0
  155. package/dist/mvt-loader.d.ts.map +1 -0
  156. package/dist/mvt-loader.js +43 -22
  157. package/dist/mvt-worker.js +845 -766
  158. package/dist/workers/mvt-worker.d.ts +2 -0
  159. package/dist/workers/mvt-worker.d.ts.map +1 -0
  160. package/dist/workers/mvt-worker.js +5 -4
  161. package/package.json +10 -9
  162. package/src/helpers/binary-util-functions.ts +9 -7
  163. package/src/helpers/mapbox-util-functions.ts +2 -2
  164. package/src/index.ts +7 -0
  165. package/src/lib/binary-vector-tile/vector-tile-feature.ts +42 -45
  166. package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
  167. package/src/lib/geojson-tiler/LICENSE +19 -0
  168. package/src/lib/geojson-tiler/clip.ts +248 -0
  169. package/src/lib/geojson-tiler/convert.ts +158 -0
  170. package/src/lib/geojson-tiler/feature.ts +45 -0
  171. package/src/lib/geojson-tiler/geojson-tiler.ts +281 -0
  172. package/src/lib/geojson-tiler/simplify.ts +77 -0
  173. package/src/lib/geojson-tiler/tile.ts +185 -0
  174. package/src/lib/geojson-tiler/transform.ts +55 -0
  175. package/src/lib/geojson-tiler/wrap.ts +108 -0
  176. package/src/lib/mapbox-vector-tile/vector-tile-feature.ts +4 -4
  177. package/src/lib/parse-mvt.ts +138 -93
  178. package/src/lib/types.ts +49 -72
  179. package/src/mvt-loader.ts +13 -9
  180. package/dist/bundle.js.map +0 -1
  181. package/dist/helpers/binary-util-functions.js.map +0 -1
  182. package/dist/helpers/mapbox-util-functions.js.map +0 -1
  183. package/dist/index.js.map +0 -1
  184. package/dist/lib/binary-vector-tile/features-to-binary.js +0 -327
  185. package/dist/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  186. package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
  187. package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
  188. package/dist/lib/binary-vector-tile/vector-tile.js.map +0 -1
  189. package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
  190. package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
  191. package/dist/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
  192. package/dist/lib/parse-mvt.js.map +0 -1
  193. package/dist/lib/types.js.map +0 -1
  194. package/dist/mvt-loader.js.map +0 -1
  195. package/dist/workers/mvt-worker.js.map +0 -1
  196. package/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
  197. /package/dist/{lib → es5/lib}/binary-vector-tile/LICENSE.txt +0 -0
  198. /package/dist/{lib → es5/lib}/mapbox-vector-tile/LICENSE.txt +0 -0
@@ -1,116 +1,167 @@
1
- import VectorTile from './mapbox-vector-tile/vector-tile';
2
- import BinaryVectorTile from './binary-vector-tile/vector-tile';
3
- import { featuresToBinary } from './binary-vector-tile/features-to-binary';
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';
11
- const firstPassData = {
12
- pointPositionsCount: 0,
13
- pointFeaturesCount: 0,
14
- linePositionsCount: 0,
15
- linePathsCount: 0,
16
- lineFeaturesCount: 0,
17
- polygonPositionsCount: 0,
18
- polygonObjectsCount: 0,
19
- polygonRingsCount: 0,
20
- polygonFeaturesCount: 0
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 = [];
52
+ const geometryInfo = {
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
21
63
  };
22
-
23
- if (arrayBuffer.byteLength > 0) {
24
- const tile = binary ? new BinaryVectorTile(new Protobuf(arrayBuffer)) : new VectorTile(new Protobuf(arrayBuffer));
25
- const loaderOptions = options.mvt;
26
- const selectedLayers = Array.isArray(loaderOptions.layers) ? loaderOptions.layers : Object.keys(tile.layers);
27
- 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) => {
28
70
  const vectorTileLayer = tile.layers[layerName];
29
- const featureOptions = { ...loaderOptions,
30
- layerName
31
- };
32
-
33
71
  if (!vectorTileLayer) {
34
- return;
72
+ return;
35
73
  }
36
-
37
74
  for (let i = 0; i < vectorTileLayer.length; i++) {
38
- const vectorTileFeature = vectorTileLayer.feature(i, firstPassData);
39
- const decodedFeature = binary ? getDecodedFeatureBinary(vectorTileFeature, featureOptions) : getDecodedFeature(vectorTileFeature, featureOptions);
40
- features.push(decodedFeature);
75
+ const vectorTileFeature = vectorTileLayer.feature(i, geometryInfo);
76
+ const decodedFeature = getDecodedFeatureBinary(vectorTileFeature, options, layerName);
77
+ features.push(decodedFeature);
41
78
  }
42
- });
43
- }
44
-
45
- if (binary) {
46
- const data = featuresToBinary(features, firstPassData);
47
- data.byteLength = arrayBuffer.byteLength;
48
- return data;
79
+ });
80
+ return [features, geometryInfo];
81
+ }
82
+ function parseToGeojson(arrayBuffer, options) {
83
+ if (arrayBuffer.byteLength <= 0) {
84
+ return [];
49
85
  }
50
- }
51
-
52
- 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;
53
101
  }
54
-
55
102
  function normalizeOptions(options) {
56
- if (options) {
57
- options = { ...options,
58
- mvt: options.mvt || {},
59
- gis: options.gis || {}
60
- };
61
- const wgs84Coordinates = options.coordinates === 'wgs84';
62
- const {
63
- tileIndex
64
- } = options;
65
- const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
66
-
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);
67
113
  if (wgs84Coordinates && !hasTileIndex) {
68
- throw new Error('MVT Loader: WGS84 coordinates need tileIndex property. Check documentation.');
114
+ throw new Error('MVT Loader: WGS84 coordinates need tileIndex property');
69
115
  }
70
- }
71
-
72
- return options;
116
+ return options.mvt;
73
117
  }
74
-
75
- function getDecodedFeature(feature, options) {
76
- const decodedFeature = feature.toGeoJSON(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinates);
77
-
78
- if (options.layerProperty) {
79
- decodedFeature.properties[options.layerProperty] = options.layerName;
80
- }
81
-
82
- 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;
83
130
  }
84
-
85
- function getDecodedFeatureBinary(feature, options) {
86
- const decodedFeature = feature.toBinaryCoordinates(options.coordinates === 'wgs84' ? options.tileIndex : transformToLocalCoordinatesBinary);
87
-
88
- if (options.layerProperty) {
89
- decodedFeature.properties[options.layerProperty] = options.layerName;
90
- }
91
-
92
- 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;
93
143
  }
94
-
144
+ /**
145
+ * @param line
146
+ * @param feature
147
+ */
95
148
  function transformToLocalCoordinates(line, feature) {
96
- const {
97
- extent
98
- } = feature;
99
-
100
- for (let i = 0; i < line.length; i++) {
101
- const p = line[i];
102
- p[0] /= extent;
103
- p[1] /= extent;
104
- }
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
+ }
105
159
  }
106
-
107
160
  function transformToLocalCoordinatesBinary(data, feature) {
108
- const {
109
- extent
110
- } = feature;
111
-
112
- for (let i = 0, il = data.length; i < il; ++i) {
113
- data[i] /= extent;
114
- }
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
+ }
115
167
  }
116
- //# sourceMappingURL=parse-mvt.js.map
@@ -0,0 +1,69 @@
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
+ */
20
+ tileIndex: {
21
+ x: number;
22
+ y: number;
23
+ z: number;
24
+ };
25
+ };
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 = {
41
+ type?: string;
42
+ id?: number;
43
+ length: number;
44
+ coordinates?: any[];
45
+ };
46
+ export type MVTMapboxCoordinates = {
47
+ type: string;
48
+ geometry: {
49
+ type: string;
50
+ coordinates: MVTMapboxGeometry;
51
+ };
52
+ properties: {
53
+ [x: string]: string | number | boolean | null;
54
+ };
55
+ id?: number;
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 {};
69
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
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 });
@@ -0,0 +1,10 @@
1
+ import type { Loader, LoaderWithParser } from '@loaders.gl/loader-utils';
2
+ /**
3
+ * Worker loader for the Mapbox Vector Tile format
4
+ */
5
+ export declare const MVTWorkerLoader: Loader;
6
+ /**
7
+ * Loader for the Mapbox Vector Tile format
8
+ */
9
+ export declare const MVTLoader: LoaderWithParser;
10
+ //# sourceMappingURL=mvt-loader.d.ts.map
@@ -0,0 +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;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.1" !== 'undefined' ? "4.0.0-alpha.1" : '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