@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,331 +0,0 @@
1
- import { earcut } from '@math.gl/polygon';
2
- export function featuresToBinary(features, firstPassData, options) {
3
- const propArrayTypes = extractNumericPropTypes(features);
4
- const numericPropKeys = Object.keys(propArrayTypes).filter(k => propArrayTypes[k] !== Array);
5
- return fillArrays(features, firstPassData, {
6
- numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
7
- propArrayTypes,
8
- PositionDataType: options ? options.PositionDataType : Float32Array
9
- });
10
- }
11
- export const TEST_EXPORTS = {
12
- fillArrays
13
- };
14
-
15
- function extractNumericPropTypes(features) {
16
- const propArrayTypes = {};
17
-
18
- for (const feature of features) {
19
- if (feature.properties) {
20
- for (const key in feature.properties) {
21
- const val = feature.properties[key];
22
- propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
23
- }
24
- }
25
- }
26
-
27
- return propArrayTypes;
28
- }
29
-
30
- function fillArrays(features, firstPassData, options) {
31
- const {
32
- pointPositionsCount,
33
- pointFeaturesCount,
34
- linePositionsCount,
35
- linePathsCount,
36
- lineFeaturesCount,
37
- polygonPositionsCount,
38
- polygonObjectsCount,
39
- polygonRingsCount,
40
- polygonFeaturesCount
41
- } = firstPassData;
42
- const {
43
- numericPropKeys,
44
- propArrayTypes,
45
- PositionDataType = Float32Array
46
- } = options;
47
- const hasGlobalId = features[0] && 'id' in features[0];
48
- const coordLength = 2;
49
- const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
50
- const points = {
51
- positions: new PositionDataType(pointPositionsCount * coordLength),
52
- globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
53
- featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
54
- numericProps: {},
55
- properties: [],
56
- fields: []
57
- };
58
- const lines = {
59
- pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
60
- positions: new PositionDataType(linePositionsCount * coordLength),
61
- globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
62
- featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
63
- numericProps: {},
64
- properties: [],
65
- fields: []
66
- };
67
- const polygons = {
68
- polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
69
- primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
70
- positions: new PositionDataType(polygonPositionsCount * coordLength),
71
- triangles: [],
72
- globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
73
- featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
74
- numericProps: {},
75
- properties: [],
76
- fields: []
77
- };
78
-
79
- for (const object of [points, lines, polygons]) {
80
- for (const propName of numericPropKeys) {
81
- const TypedArray = propArrayTypes[propName];
82
- object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
83
- }
84
- }
85
-
86
- lines.pathIndices[linePathsCount] = linePositionsCount;
87
- polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
88
- polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
89
- const indexMap = {
90
- pointPosition: 0,
91
- pointFeature: 0,
92
- linePosition: 0,
93
- linePath: 0,
94
- lineFeature: 0,
95
- polygonPosition: 0,
96
- polygonObject: 0,
97
- polygonRing: 0,
98
- polygonFeature: 0,
99
- feature: 0
100
- };
101
-
102
- for (const feature of features) {
103
- const geometry = feature.geometry;
104
- const properties = feature.properties || {};
105
-
106
- switch (geometry.type) {
107
- case 'Point':
108
- case 'MultiPoint':
109
- handlePoint(geometry, points, indexMap, coordLength, properties);
110
- points.properties.push(keepStringProperties(properties, numericPropKeys));
111
-
112
- if (hasGlobalId) {
113
- points.fields.push({
114
- id: feature.id
115
- });
116
- }
117
-
118
- indexMap.pointFeature++;
119
- break;
120
-
121
- case 'LineString':
122
- case 'MultiLineString':
123
- handleLineString(geometry, lines, indexMap, coordLength, properties);
124
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
125
-
126
- if (hasGlobalId) {
127
- lines.fields.push({
128
- id: feature.id
129
- });
130
- }
131
-
132
- indexMap.lineFeature++;
133
- break;
134
-
135
- case 'Polygon':
136
- case 'MultiPolygon':
137
- handlePolygon(geometry, polygons, indexMap, coordLength, properties);
138
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
139
-
140
- if (hasGlobalId) {
141
- polygons.fields.push({
142
- id: feature.id
143
- });
144
- }
145
-
146
- indexMap.polygonFeature++;
147
- break;
148
-
149
- default:
150
- throw new Error('Invalid geometry type');
151
- }
152
-
153
- indexMap.feature++;
154
- }
155
-
156
- return makeAccessorObjects(points, lines, polygons, coordLength);
157
- }
158
-
159
- function handlePoint(geometry, points, indexMap, coordLength, properties) {
160
- points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
161
- const nPositions = geometry.data.length / coordLength;
162
- fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
163
- points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
164
- points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
165
- indexMap.pointPosition += nPositions;
166
- }
167
-
168
- function handleLineString(geometry, lines, indexMap, coordLength, properties) {
169
- lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
170
- const nPositions = geometry.data.length / coordLength;
171
- fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
172
- lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
173
- lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
174
-
175
- for (let i = 0, il = geometry.lines.length; i < il; ++i) {
176
- const start = geometry.lines[i];
177
- const end = i === il - 1 ? geometry.data.length : geometry.lines[i + 1];
178
- lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
179
- indexMap.linePosition += (end - start) / coordLength;
180
- }
181
- }
182
-
183
- function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
184
- polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
185
- const nPositions = geometry.data.length / coordLength;
186
- fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
187
- polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
188
- polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
189
-
190
- for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {
191
- const startPosition = indexMap.polygonPosition;
192
- polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
193
- const areas = geometry.areas[l];
194
- const lines = geometry.lines[l];
195
- const nextLines = geometry.lines[l + 1];
196
-
197
- for (let i = 0, il = lines.length; i < il; ++i) {
198
- const start = lines[i];
199
- const end = i === il - 1 ? nextLines === undefined ? geometry.data.length : nextLines[0] : lines[i + 1];
200
- polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
201
- indexMap.polygonPosition += (end - start) / coordLength;
202
- }
203
-
204
- const endPosition = indexMap.polygonPosition;
205
- triangulatePolygon(polygons, areas, lines, {
206
- startPosition,
207
- endPosition,
208
- coordLength
209
- });
210
- }
211
- }
212
-
213
- function triangulatePolygon(polygons, areas, lines, {
214
- startPosition,
215
- endPosition,
216
- coordLength
217
- }) {
218
- const start = startPosition * coordLength;
219
- const end = endPosition * coordLength;
220
- const polygonPositions = polygons.positions.subarray(start, end);
221
- const offset = lines[0];
222
- const holes = lines.slice(1).map(n => (n - offset) / coordLength);
223
- const indices = earcut(polygonPositions, holes, coordLength, areas);
224
-
225
- for (let t = 0, tl = indices.length; t < tl; ++t) {
226
- polygons.triangles.push(startPosition + indices[t]);
227
- }
228
- }
229
-
230
- function makeAccessorObjects(points, lines, polygons, coordLength) {
231
- const returnObj = {
232
- points: { ...points,
233
- positions: {
234
- value: points.positions,
235
- size: coordLength
236
- },
237
- globalFeatureIds: {
238
- value: points.globalFeatureIds,
239
- size: 1
240
- },
241
- featureIds: {
242
- value: points.featureIds,
243
- size: 1
244
- }
245
- },
246
- lines: { ...lines,
247
- pathIndices: {
248
- value: lines.pathIndices,
249
- size: 1
250
- },
251
- positions: {
252
- value: lines.positions,
253
- size: coordLength
254
- },
255
- globalFeatureIds: {
256
- value: lines.globalFeatureIds,
257
- size: 1
258
- },
259
- featureIds: {
260
- value: lines.featureIds,
261
- size: 1
262
- }
263
- },
264
- polygons: { ...polygons,
265
- polygonIndices: {
266
- value: polygons.polygonIndices,
267
- size: 1
268
- },
269
- primitivePolygonIndices: {
270
- value: polygons.primitivePolygonIndices,
271
- size: 1
272
- },
273
- positions: {
274
- value: polygons.positions,
275
- size: coordLength
276
- },
277
- triangles: {
278
- value: new Uint32Array(polygons.triangles),
279
- size: 1
280
- },
281
- globalFeatureIds: {
282
- value: polygons.globalFeatureIds,
283
- size: 1
284
- },
285
- featureIds: {
286
- value: polygons.featureIds,
287
- size: 1
288
- }
289
- }
290
- };
291
-
292
- for (const geomType in returnObj) {
293
- for (const numericProp in returnObj[geomType].numericProps) {
294
- returnObj[geomType].numericProps[numericProp] = {
295
- value: returnObj[geomType].numericProps[numericProp],
296
- size: 1
297
- };
298
- }
299
- }
300
-
301
- return returnObj;
302
- }
303
-
304
- function fillNumericProperties(object, properties, index, length) {
305
- for (const numericPropName in object.numericProps) {
306
- if (numericPropName in properties) {
307
- object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);
308
- }
309
- }
310
- }
311
-
312
- function keepStringProperties(properties, numericKeys) {
313
- const props = {};
314
-
315
- for (const key in properties) {
316
- if (!numericKeys.includes(key)) {
317
- props[key] = properties[key];
318
- }
319
- }
320
-
321
- return props;
322
- }
323
-
324
- function deduceArrayType(x, constructor) {
325
- if (constructor === Array || !Number.isFinite(x)) {
326
- return Array;
327
- }
328
-
329
- return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
330
- }
331
- //# sourceMappingURL=features-to-binary.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":["earcut","featuresToBinary","features","firstPassData","options","propArrayTypes","extractNumericPropTypes","numericPropKeys","Object","keys","filter","k","Array","fillArrays","PositionDataType","Float32Array","TEST_EXPORTS","feature","properties","key","val","deduceArrayType","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","hasGlobalId","coordLength","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","TypedArray","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","type","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","start","end","l","ll","startPosition","areas","nextLines","undefined","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","indices","t","tl","returnObj","value","size","geomType","numericProp","index","numericPropName","numericKeys","props","includes","x","constructor","Number","isFinite","Float64Array","Math","fround"],"mappings":"AACA,SAAQA,MAAR,QAAqB,kBAArB;AAyBA,OAAO,SAASC,gBAAT,CACLC,QADK,EAELC,aAFK,EAGLC,OAHK,EAIL;AACA,QAAMC,cAAc,GAAGC,uBAAuB,CAACJ,QAAD,CAA9C;AACA,QAAMK,eAAe,GAAGC,MAAM,CAACC,IAAP,CAAYJ,cAAZ,EAA4BK,MAA5B,CAAoCC,CAAD,IAAON,cAAc,CAACM,CAAD,CAAd,KAAsBC,KAAhE,CAAxB;AACA,SAAOC,UAAU,CAACX,QAAD,EAAWC,aAAX,EAA0B;AACzCI,IAAAA,eAAe,EAAEH,OAAO,GAAGA,OAAO,CAACG,eAAX,GAA6BA,eADZ;AAEzCF,IAAAA,cAFyC;AAGzCS,IAAAA,gBAAgB,EAAEV,OAAO,GAAGA,OAAO,CAACU,gBAAX,GAA8BC;AAHd,GAA1B,CAAjB;AAKD;AAED,OAAO,MAAMC,YAAY,GAAG;AAC1BH,EAAAA;AAD0B,CAArB;;AAUP,SAASP,uBAAT,CAAiCJ,QAAjC,EAEE;AACA,QAAMG,cAAc,GAAG,EAAvB;;AACA,OAAK,MAAMY,OAAX,IAAsBf,QAAtB,EAAgC;AAC9B,QAAIe,OAAO,CAACC,UAAZ,EAAwB;AACtB,WAAK,MAAMC,GAAX,IAAkBF,OAAO,CAACC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/B,UAFF,EAGEsF,KAHF,EAIEtE,MAJF,EAKQ;AACN,OAAK,MAAMuE,eAAX,IAA8BxD,MAAM,CAACR,YAArC,EAAmD;AACjD,QAAIgE,eAAe,IAAIvF,UAAvB,EAAmC;AACjC+B,MAAAA,MAAM,CAACR,YAAP,CAAoBgE,eAApB,EAAqC7B,IAArC,CAA0C1D,UAAU,CAACuF,eAAD,CAApD,EAAuED,KAAvE,EAA8EA,KAAK,GAAGtE,MAAtF;AACD;AACF;AACF;;AASD,SAASgC,oBAAT,CACEhD,UADF,EAEEwF,WAFF,EAGE;AACA,QAAMC,KAAK,GAAG,EAAd;;AACA,OAAK,MAAMxF,GAAX,IAAkBD,UAAlB,EAA8B;AAC5B,QAAI,CAACwF,WAAW,CAACE,QAAZ,CAAqBzF,GAArB,CAAL,EAAgC;AAC9BwF,MAAAA,KAAK,CAACxF,GAAD,CAAL,GAAaD,UAAU,CAACC,GAAD,CAAvB;AACD;AACF;;AACD,SAAOwF,KAAP;AACD;;AAED,SAAStF,eAAT,CAAyBwF,CAAzB,EAAiCC,WAAjC,EAAgG;AAC9F,MAAIA,WAAW,KAAKlG,KAAhB,IAAyB,CAACmG,MAAM,CAACC,QAAP,CAAgBH,CAAhB,CAA9B,EAAkD;AAChD,WAAOjG,KAAP;AACD;;AAGD,SAAOkG,WAAW,KAAKG,YAAhB,IAAgCC,IAAI,CAACC,MAAL,CAAYN,CAAZ,MAAmBA,CAAnD,GAAuDI,YAAvD,GAAsElG,YAA7E;AACD","sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport {\n MvtBinaryCoordinates,\n MvtBinaryGeometry,\n MvtBinaryOptions,\n MvtPropArrayConstructor,\n MvtFirstPassedData,\n MvtLines,\n MvtPoints,\n MvtPolygons\n} from '../types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns filled arrays\n */\nexport function featuresToBinary(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options?: MvtBinaryOptions\n) {\n const propArrayTypes = extractNumericPropTypes(features);\n const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);\n return fillArrays(features, firstPassData, {\n numericPropKeys: options ? options.numericPropKeys : numericPropKeys,\n propArrayTypes,\n PositionDataType: options ? options.PositionDataType : Float32Array\n });\n}\n\nexport const TEST_EXPORTS = {\n fillArrays\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric types\n */\nfunction extractNumericPropTypes(features: MvtBinaryCoordinates[]): {\n [key: string]: MvtPropArrayConstructor;\n} {\n const propArrayTypes = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, Array is stored to prevent rechecking in the future\n // Additionally, detects if 64 bit precision is required\n const val = feature.properties[key];\n propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);\n }\n }\n }\n\n return propArrayTypes;\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options: MvtBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n } = firstPassData;\n const {numericPropKeys, propArrayTypes, PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const coordLength = 2;\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: MvtPoints = {\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const lines: MvtLines = {\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: MvtPolygons = {\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n const TypedArray = propArrayTypes[propName];\n object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n case 'MultiPoint':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n case 'MultiLineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n case 'MultiPolygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: MvtBinaryGeometry,\n points: MvtPoints,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: MvtBinaryGeometry,\n lines: MvtLines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.lines.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.lines[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.lines[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: MvtBinaryGeometry,\n polygons: MvtPolygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.lines is a 2D array\n for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas![l];\n const lines = geometry.lines[l];\n const nextLines = geometry.lines[l + 1];\n\n for (let i = 0, il = lines.length; i < il; ++i) {\n const start = lines[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextLines === undefined\n ? geometry.data.length // end of data (no next lines)\n : nextLines[0] // start of first line in nextLines\n : lines[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, lines, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param lines\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: MvtPolygons,\n areas: number,\n lines: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = lines[0];\n const holes = lines.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const indices = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = indices.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + indices[t]);\n }\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: MvtPoints,\n lines: MvtLines,\n polygons: MvtPolygons,\n coordLength: number\n) {\n const returnObj = {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1}\n },\n lines: {\n ...lines,\n pathIndices: {value: lines.pathIndices, size: 1},\n positions: {value: lines.positions, size: coordLength},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1}\n },\n polygons: {\n ...polygons,\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n positions: {value: polygons.positions, size: coordLength},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1}\n }\n };\n\n for (const geomType in returnObj) {\n for (const numericProp in returnObj[geomType].numericProps) {\n returnObj[geomType].numericProps[numericProp] = {\n value: returnObj[geomType].numericProps[numericProp],\n size: 1\n };\n }\n }\n return returnObj;\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: MvtPoints,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\nfunction deduceArrayType(x: any, constructor: MvtPropArrayConstructor): MvtPropArrayConstructor {\n if (constructor === Array || !Number.isFinite(x)) {\n return Array;\n }\n\n // If this or previous value required 64bits use Float64Array\n return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;\n}\n"],"file":"features-to-binary.js"}
@@ -1,177 +0,0 @@
1
- import { MvtBinaryCoordinates, MvtBinaryOptions, MvtFirstPassedData } from '../types';
2
- /**
3
- * Convert binary features to flat binary arrays. Similar to
4
- * `geojsonToBinary` helper function, except that it expects
5
- * a binary representation of the feature data, which enables
6
- * 2X-3X speed increase in parse speed, compared to using
7
- * geoJSON. See `binary-vector-tile/VectorTileFeature` for
8
- * data format detais
9
- *
10
- * @param features
11
- * @param firstPassData
12
- * @param options
13
- * @returns filled arrays
14
- */
15
- export declare function featuresToBinary(features: MvtBinaryCoordinates[], firstPassData: MvtFirstPassedData, options?: MvtBinaryOptions): {
16
- points: {
17
- positions: {
18
- value: Float32Array;
19
- size: number;
20
- };
21
- globalFeatureIds: {
22
- value: Uint16Array | Uint32Array;
23
- size: number;
24
- };
25
- featureIds: {
26
- value: Uint16Array | Uint32Array;
27
- size: number;
28
- };
29
- numericProps: object;
30
- properties: {}[];
31
- fields: {
32
- id?: number | undefined;
33
- }[];
34
- };
35
- lines: {
36
- pathIndices: {
37
- value: Uint16Array | Uint32Array;
38
- size: number;
39
- };
40
- positions: {
41
- value: Float32Array;
42
- size: number;
43
- };
44
- globalFeatureIds: {
45
- value: Uint16Array | Uint32Array;
46
- size: number;
47
- };
48
- featureIds: {
49
- value: Uint16Array | Uint32Array;
50
- size: number;
51
- };
52
- numericProps: object;
53
- properties: {}[];
54
- fields: {
55
- id?: number | undefined;
56
- }[];
57
- };
58
- polygons: {
59
- polygonIndices: {
60
- value: Uint16Array | Uint32Array;
61
- size: number;
62
- };
63
- primitivePolygonIndices: {
64
- value: Uint16Array | Uint32Array;
65
- size: number;
66
- };
67
- positions: {
68
- value: Float32Array;
69
- size: number;
70
- };
71
- triangles: {
72
- value: Uint32Array;
73
- size: number;
74
- };
75
- globalFeatureIds: {
76
- value: Uint16Array | Uint32Array;
77
- size: number;
78
- };
79
- featureIds: {
80
- value: Uint16Array | Uint32Array;
81
- size: number;
82
- };
83
- numericProps: object;
84
- properties: {}[];
85
- fields: {
86
- id?: number | undefined;
87
- }[];
88
- };
89
- };
90
- export declare const TEST_EXPORTS: {
91
- fillArrays: typeof fillArrays;
92
- };
93
- /**
94
- * Fills coordinates into pre-allocated typed arrays
95
- *
96
- * @param features
97
- * @param firstPassData
98
- * @param options
99
- * @returns an accessor object with value and size keys
100
- */
101
- declare function fillArrays(features: MvtBinaryCoordinates[], firstPassData: MvtFirstPassedData, options: MvtBinaryOptions): {
102
- points: {
103
- positions: {
104
- value: Float32Array;
105
- size: number;
106
- };
107
- globalFeatureIds: {
108
- value: Uint16Array | Uint32Array;
109
- size: number;
110
- };
111
- featureIds: {
112
- value: Uint16Array | Uint32Array;
113
- size: number;
114
- };
115
- numericProps: object;
116
- properties: {}[];
117
- fields: {
118
- id?: number | undefined;
119
- }[];
120
- };
121
- lines: {
122
- pathIndices: {
123
- value: Uint16Array | Uint32Array;
124
- size: number;
125
- };
126
- positions: {
127
- value: Float32Array;
128
- size: number;
129
- };
130
- globalFeatureIds: {
131
- value: Uint16Array | Uint32Array;
132
- size: number;
133
- };
134
- featureIds: {
135
- value: Uint16Array | Uint32Array;
136
- size: number;
137
- };
138
- numericProps: object;
139
- properties: {}[];
140
- fields: {
141
- id?: number | undefined;
142
- }[];
143
- };
144
- polygons: {
145
- polygonIndices: {
146
- value: Uint16Array | Uint32Array;
147
- size: number;
148
- };
149
- primitivePolygonIndices: {
150
- value: Uint16Array | Uint32Array;
151
- size: number;
152
- };
153
- positions: {
154
- value: Float32Array;
155
- size: number;
156
- };
157
- triangles: {
158
- value: Uint32Array;
159
- size: number;
160
- };
161
- globalFeatureIds: {
162
- value: Uint16Array | Uint32Array;
163
- size: number;
164
- };
165
- featureIds: {
166
- value: Uint16Array | Uint32Array;
167
- size: number;
168
- };
169
- numericProps: object;
170
- properties: {}[];
171
- fields: {
172
- id?: number | undefined;
173
- }[];
174
- };
175
- };
176
- export {};
177
- //# sourceMappingURL=features-to-binary.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"features-to-binary.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EAEpB,gBAAgB,EAEhB,kBAAkB,EAInB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,CAAC,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAS3B;AAED,eAAO,MAAM,YAAY;;CAExB,CAAC;AA4BF;;;;;;;GAOG;AAEH,iBAAS,UAAU,CACjB,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqI1B"}