@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
@@ -1,358 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TEST_EXPORTS = exports.featuresToBinary = void 0;
4
- /* eslint-disable indent */
5
- const polygon_1 = require("@math.gl/polygon");
6
- /**
7
- * Convert binary features to flat binary arrays. Similar to
8
- * `geojsonToBinary` helper function, except that it expects
9
- * a binary representation of the feature data, which enables
10
- * 2X-3X speed increase in parse speed, compared to using
11
- * geoJSON. See `binary-vector-tile/VectorTileFeature` for
12
- * data format detais
13
- *
14
- * @param features
15
- * @param firstPassData
16
- * @param options
17
- * @returns filled arrays
18
- */
19
- function featuresToBinary(features, firstPassData, options) {
20
- const propArrayTypes = extractNumericPropTypes(features);
21
- const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
22
- return fillArrays(features, firstPassData, {
23
- numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
24
- propArrayTypes,
25
- PositionDataType: options ? options.PositionDataType : Float32Array
26
- });
27
- }
28
- exports.featuresToBinary = featuresToBinary;
29
- exports.TEST_EXPORTS = {
30
- fillArrays
31
- };
32
- /**
33
- * Extracts properties that are always numeric
34
- *
35
- * @param features
36
- * @returns object with numeric types
37
- */
38
- function extractNumericPropTypes(features) {
39
- const propArrayTypes = {};
40
- for (const feature of features) {
41
- if (feature.properties) {
42
- for (const key in feature.properties) {
43
- // If property has not been seen before, or if property has been numeric
44
- // in all previous features, check if numeric in this feature
45
- // If not numeric, Array is stored to prevent rechecking in the future
46
- // Additionally, detects if 64 bit precision is required
47
- const val = feature.properties[key];
48
- propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
49
- }
50
- }
51
- }
52
- return propArrayTypes;
53
- }
54
- /**
55
- * Fills coordinates into pre-allocated typed arrays
56
- *
57
- * @param features
58
- * @param firstPassData
59
- * @param options
60
- * @returns an accessor object with value and size keys
61
- */
62
- // eslint-disable-next-line complexity
63
- function fillArrays(features, firstPassData, options) {
64
- const { pointPositionsCount, pointFeaturesCount, linePositionsCount, linePathsCount, lineFeaturesCount, polygonPositionsCount, polygonObjectsCount, polygonRingsCount, polygonFeaturesCount } = firstPassData;
65
- const { numericPropKeys, propArrayTypes, PositionDataType = Float32Array } = options;
66
- const hasGlobalId = features[0] && 'id' in features[0];
67
- const coordLength = 2;
68
- const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
69
- const points = {
70
- positions: new PositionDataType(pointPositionsCount * coordLength),
71
- globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
72
- featureIds: pointFeaturesCount > 65535
73
- ? new Uint32Array(pointPositionsCount)
74
- : new Uint16Array(pointPositionsCount),
75
- numericProps: {},
76
- properties: [],
77
- fields: []
78
- };
79
- const lines = {
80
- pathIndices: linePositionsCount > 65535
81
- ? new Uint32Array(linePathsCount + 1)
82
- : new Uint16Array(linePathsCount + 1),
83
- positions: new PositionDataType(linePositionsCount * coordLength),
84
- globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
85
- featureIds: lineFeaturesCount > 65535
86
- ? new Uint32Array(linePositionsCount)
87
- : new Uint16Array(linePositionsCount),
88
- numericProps: {},
89
- properties: [],
90
- fields: []
91
- };
92
- const polygons = {
93
- polygonIndices: polygonPositionsCount > 65535
94
- ? new Uint32Array(polygonObjectsCount + 1)
95
- : new Uint16Array(polygonObjectsCount + 1),
96
- primitivePolygonIndices: polygonPositionsCount > 65535
97
- ? new Uint32Array(polygonRingsCount + 1)
98
- : new Uint16Array(polygonRingsCount + 1),
99
- positions: new PositionDataType(polygonPositionsCount * coordLength),
100
- triangles: [],
101
- globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
102
- featureIds: polygonFeaturesCount > 65535
103
- ? new Uint32Array(polygonPositionsCount)
104
- : new Uint16Array(polygonPositionsCount),
105
- numericProps: {},
106
- properties: [],
107
- fields: []
108
- };
109
- // Instantiate numeric properties arrays; one value per vertex
110
- for (const object of [points, lines, polygons]) {
111
- for (const propName of numericPropKeys) {
112
- // If property has been numeric in all previous features in which the property existed, check
113
- // if numeric in this feature
114
- const TypedArray = propArrayTypes[propName];
115
- object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
116
- }
117
- }
118
- // Set last element of path/polygon indices as positions length
119
- lines.pathIndices[linePathsCount] = linePositionsCount;
120
- polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
121
- polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
122
- const indexMap = {
123
- pointPosition: 0,
124
- pointFeature: 0,
125
- linePosition: 0,
126
- linePath: 0,
127
- lineFeature: 0,
128
- polygonPosition: 0,
129
- polygonObject: 0,
130
- polygonRing: 0,
131
- polygonFeature: 0,
132
- feature: 0
133
- };
134
- for (const feature of features) {
135
- const geometry = feature.geometry;
136
- const properties = feature.properties || {};
137
- switch (geometry.type) {
138
- case 'Point':
139
- case 'MultiPoint':
140
- handlePoint(geometry, points, indexMap, coordLength, properties);
141
- points.properties.push(keepStringProperties(properties, numericPropKeys));
142
- if (hasGlobalId) {
143
- points.fields.push({ id: feature.id });
144
- }
145
- indexMap.pointFeature++;
146
- break;
147
- case 'LineString':
148
- case 'MultiLineString':
149
- handleLineString(geometry, lines, indexMap, coordLength, properties);
150
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
151
- if (hasGlobalId) {
152
- lines.fields.push({ id: feature.id });
153
- }
154
- indexMap.lineFeature++;
155
- break;
156
- case 'Polygon':
157
- case 'MultiPolygon':
158
- handlePolygon(geometry, polygons, indexMap, coordLength, properties);
159
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
160
- if (hasGlobalId) {
161
- polygons.fields.push({ id: feature.id });
162
- }
163
- indexMap.polygonFeature++;
164
- break;
165
- default:
166
- throw new Error('Invalid geometry type');
167
- }
168
- indexMap.feature++;
169
- }
170
- // Wrap each array in an accessor object with value and size keys
171
- return makeAccessorObjects(points, lines, polygons, coordLength);
172
- }
173
- /**
174
- * Fills (Multi)Point coordinates into points object of arrays
175
- *
176
- * @param geometry
177
- * @param points
178
- * @param indexMap
179
- * @param coordLength
180
- * @param properties
181
- */
182
- function handlePoint(geometry, points, indexMap, coordLength, properties) {
183
- points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
184
- const nPositions = geometry.data.length / coordLength;
185
- fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
186
- points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
187
- points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
188
- indexMap.pointPosition += nPositions;
189
- }
190
- /**
191
- * Fills (Multi)LineString coordinates into lines object of arrays
192
- *
193
- * @param geometry
194
- * @param lines
195
- * @param indexMap
196
- * @param coordLength
197
- * @param properties
198
- */
199
- function handleLineString(geometry, lines, indexMap, coordLength, properties) {
200
- lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
201
- const nPositions = geometry.data.length / coordLength;
202
- fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
203
- lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
204
- lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
205
- for (let i = 0, il = geometry.lines.length; i < il; ++i) {
206
- // Extract range of data we are working with, defined by start
207
- // and end indices (these index into the geometry.data array)
208
- const start = geometry.lines[i];
209
- const end = i === il - 1
210
- ? geometry.data.length // last line, so read to end of data
211
- : geometry.lines[i + 1]; // start index for next line
212
- lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
213
- indexMap.linePosition += (end - start) / coordLength;
214
- }
215
- }
216
- /**
217
- * Fills (Multi)Polygon coordinates into polygons object of arrays
218
- *
219
- * @param geometry
220
- * @param polygons
221
- * @param indexMap
222
- * @param coordLength
223
- * @param properties
224
- */
225
- function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
226
- polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
227
- const nPositions = geometry.data.length / coordLength;
228
- fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
229
- polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
230
- polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
231
- // Unlike Point & LineString geometry.lines is a 2D array
232
- for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {
233
- const startPosition = indexMap.polygonPosition;
234
- polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
235
- const areas = geometry.areas[l];
236
- const lines = geometry.lines[l];
237
- const nextLines = geometry.lines[l + 1];
238
- for (let i = 0, il = lines.length; i < il; ++i) {
239
- const start = lines[i];
240
- const end = i === il - 1
241
- ? // last line, so either read to:
242
- nextLines === undefined
243
- ? geometry.data.length // end of data (no next lines)
244
- : nextLines[0] // start of first line in nextLines
245
- : lines[i + 1]; // start index for next line
246
- polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
247
- indexMap.polygonPosition += (end - start) / coordLength;
248
- }
249
- const endPosition = indexMap.polygonPosition;
250
- triangulatePolygon(polygons, areas, lines, { startPosition, endPosition, coordLength });
251
- }
252
- }
253
- /**
254
- * Triangulate polygon using earcut
255
- *
256
- * @param polygons
257
- * @param areas
258
- * @param lines
259
- * @param param3
260
- */
261
- function triangulatePolygon(polygons, areas, lines, { startPosition, endPosition, coordLength }) {
262
- const start = startPosition * coordLength;
263
- const end = endPosition * coordLength;
264
- // Extract positions and holes for just this polygon
265
- const polygonPositions = polygons.positions.subarray(start, end);
266
- // Holes are referenced relative to outer polygon
267
- const offset = lines[0];
268
- const holes = lines.slice(1).map((n) => (n - offset) / coordLength);
269
- // Compute triangulation
270
- const indices = (0, polygon_1.earcut)(polygonPositions, holes, coordLength, areas);
271
- // Indices returned by triangulation are relative to start
272
- // of polygon, so we need to offset
273
- for (let t = 0, tl = indices.length; t < tl; ++t) {
274
- polygons.triangles.push(startPosition + indices[t]);
275
- }
276
- }
277
- /**
278
- * Wrap each array in an accessor object with value and size keys
279
- *
280
- * @param points
281
- * @param lines
282
- * @param polygons
283
- * @param coordLength
284
- * @returns object
285
- */
286
- function makeAccessorObjects(points, lines, polygons, coordLength) {
287
- const returnObj = {
288
- points: {
289
- ...points,
290
- positions: { value: points.positions, size: coordLength },
291
- globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
292
- featureIds: { value: points.featureIds, size: 1 }
293
- },
294
- lines: {
295
- ...lines,
296
- pathIndices: { value: lines.pathIndices, size: 1 },
297
- positions: { value: lines.positions, size: coordLength },
298
- globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
299
- featureIds: { value: lines.featureIds, size: 1 }
300
- },
301
- polygons: {
302
- ...polygons,
303
- polygonIndices: { value: polygons.polygonIndices, size: 1 },
304
- primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
305
- positions: { value: polygons.positions, size: coordLength },
306
- triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
307
- globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
308
- featureIds: { value: polygons.featureIds, size: 1 }
309
- }
310
- };
311
- for (const geomType in returnObj) {
312
- for (const numericProp in returnObj[geomType].numericProps) {
313
- returnObj[geomType].numericProps[numericProp] = {
314
- value: returnObj[geomType].numericProps[numericProp],
315
- size: 1
316
- };
317
- }
318
- }
319
- return returnObj;
320
- }
321
- /**
322
- * Add numeric properties to object
323
- *
324
- * @param object
325
- * @param properties
326
- * @param index
327
- * @param length
328
- */
329
- function fillNumericProperties(object, properties, index, length) {
330
- for (const numericPropName in object.numericProps) {
331
- if (numericPropName in properties) {
332
- object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);
333
- }
334
- }
335
- }
336
- /**
337
- * Keep string properties in object
338
- *
339
- * @param properties
340
- * @param numericKeys
341
- * @returns object
342
- */
343
- function keepStringProperties(properties, numericKeys) {
344
- const props = {};
345
- for (const key in properties) {
346
- if (!numericKeys.includes(key)) {
347
- props[key] = properties[key];
348
- }
349
- }
350
- return props;
351
- }
352
- function deduceArrayType(x, constructor) {
353
- if (constructor === Array || !Number.isFinite(x)) {
354
- return Array;
355
- }
356
- // If this or previous value required 64bits use Float64Array
357
- return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
358
- }