@loaders.gl/gis 3.1.0-beta.3 → 3.1.0

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.
@@ -1,13 +1,30 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports.geojsonToBinary = geojsonToBinary;
7
9
  exports.TEST_EXPORTS = void 0;
8
10
 
9
- function geojsonToBinary(features, options = {}) {
10
- const firstPassData = firstPass(features);
11
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
+
13
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
14
+
15
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
16
+
17
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
18
+
19
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
20
+
21
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
22
+
23
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
24
+
25
+ function geojsonToBinary(features) {
26
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
27
+ var firstPassData = firstPass(features);
11
28
  return secondPass(features, firstPassData, {
12
29
  coordLength: options.coordLength || firstPassData.coordLength,
13
30
  numericPropKeys: options.numericPropKeys || firstPassData.numericPropKeys,
@@ -15,143 +32,224 @@ function geojsonToBinary(features, options = {}) {
15
32
  });
16
33
  }
17
34
 
18
- const TEST_EXPORTS = {
19
- firstPass,
20
- secondPass
35
+ var TEST_EXPORTS = {
36
+ firstPass: firstPass,
37
+ secondPass: secondPass
21
38
  };
22
39
  exports.TEST_EXPORTS = TEST_EXPORTS;
23
40
 
24
41
  function firstPass(features) {
25
- let pointPositionsCount = 0;
26
- let pointFeaturesCount = 0;
27
- let linePositionsCount = 0;
28
- let linePathsCount = 0;
29
- let lineFeaturesCount = 0;
30
- let polygonPositionsCount = 0;
31
- let polygonObjectsCount = 0;
32
- let polygonRingsCount = 0;
33
- let polygonFeaturesCount = 0;
34
- const coordLengths = new Set();
35
- const numericPropKeys = {};
36
-
37
- for (const feature of features) {
38
- const geometry = feature.geometry;
39
-
40
- switch (geometry.type) {
41
- case 'Point':
42
- pointFeaturesCount++;
43
- pointPositionsCount++;
44
- coordLengths.add(geometry.coordinates.length);
45
- break;
46
-
47
- case 'MultiPoint':
48
- pointFeaturesCount++;
49
- pointPositionsCount += geometry.coordinates.length;
50
-
51
- for (const point of geometry.coordinates) {
52
- coordLengths.add(point.length);
53
- }
54
-
55
- break;
56
-
57
- case 'LineString':
58
- lineFeaturesCount++;
59
- linePositionsCount += geometry.coordinates.length;
60
- linePathsCount++;
61
-
62
- for (const coord of geometry.coordinates) {
63
- coordLengths.add(coord.length);
64
- }
65
-
66
- break;
42
+ var pointPositionsCount = 0;
43
+ var pointFeaturesCount = 0;
44
+ var linePositionsCount = 0;
45
+ var linePathsCount = 0;
46
+ var lineFeaturesCount = 0;
47
+ var polygonPositionsCount = 0;
48
+ var polygonObjectsCount = 0;
49
+ var polygonRingsCount = 0;
50
+ var polygonFeaturesCount = 0;
51
+ var coordLengths = new Set();
52
+ var propArrayTypes = {};
53
+
54
+ var _iterator = _createForOfIteratorHelper(features),
55
+ _step;
56
+
57
+ try {
58
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
59
+ var feature = _step.value;
60
+ var geometry = feature.geometry;
61
+
62
+ switch (geometry.type) {
63
+ case 'Point':
64
+ pointFeaturesCount++;
65
+ pointPositionsCount++;
66
+ coordLengths.add(geometry.coordinates.length);
67
+ break;
68
+
69
+ case 'MultiPoint':
70
+ pointFeaturesCount++;
71
+ pointPositionsCount += geometry.coordinates.length;
72
+
73
+ var _iterator2 = _createForOfIteratorHelper(geometry.coordinates),
74
+ _step2;
75
+
76
+ try {
77
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
78
+ var point = _step2.value;
79
+ coordLengths.add(point.length);
80
+ }
81
+ } catch (err) {
82
+ _iterator2.e(err);
83
+ } finally {
84
+ _iterator2.f();
85
+ }
67
86
 
68
- case 'MultiLineString':
69
- lineFeaturesCount++;
87
+ break;
70
88
 
71
- for (const line of geometry.coordinates) {
72
- linePositionsCount += line.length;
89
+ case 'LineString':
90
+ lineFeaturesCount++;
91
+ linePositionsCount += geometry.coordinates.length;
73
92
  linePathsCount++;
74
93
 
75
- for (const coord of line) {
76
- coordLengths.add(coord.length);
94
+ var _iterator3 = _createForOfIteratorHelper(geometry.coordinates),
95
+ _step3;
96
+
97
+ try {
98
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
99
+ var coord = _step3.value;
100
+ coordLengths.add(coord.length);
101
+ }
102
+ } catch (err) {
103
+ _iterator3.e(err);
104
+ } finally {
105
+ _iterator3.f();
77
106
  }
78
- }
79
-
80
- break;
81
-
82
- case 'Polygon':
83
- polygonFeaturesCount++;
84
- polygonObjectsCount++;
85
- polygonRingsCount += geometry.coordinates.length;
86
- polygonPositionsCount += flatten(geometry.coordinates).length;
87
107
 
88
- for (const coord of flatten(geometry.coordinates)) {
89
- coordLengths.add(coord.length);
90
- }
91
-
92
- break;
108
+ break;
109
+
110
+ case 'MultiLineString':
111
+ lineFeaturesCount++;
112
+
113
+ var _iterator4 = _createForOfIteratorHelper(geometry.coordinates),
114
+ _step4;
115
+
116
+ try {
117
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
118
+ var line = _step4.value;
119
+ linePositionsCount += line.length;
120
+ linePathsCount++;
121
+
122
+ var _iterator5 = _createForOfIteratorHelper(line),
123
+ _step5;
124
+
125
+ try {
126
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
127
+ var _coord = _step5.value;
128
+ coordLengths.add(_coord.length);
129
+ }
130
+ } catch (err) {
131
+ _iterator5.e(err);
132
+ } finally {
133
+ _iterator5.f();
134
+ }
135
+ }
136
+ } catch (err) {
137
+ _iterator4.e(err);
138
+ } finally {
139
+ _iterator4.f();
140
+ }
93
141
 
94
- case 'MultiPolygon':
95
- polygonFeaturesCount++;
142
+ break;
96
143
 
97
- for (const polygon of geometry.coordinates) {
144
+ case 'Polygon':
145
+ polygonFeaturesCount++;
98
146
  polygonObjectsCount++;
99
- polygonRingsCount += polygon.length;
100
- polygonPositionsCount += flatten(polygon).length;
147
+ polygonRingsCount += geometry.coordinates.length;
148
+ polygonPositionsCount += flatten(geometry.coordinates).length;
149
+
150
+ var _iterator6 = _createForOfIteratorHelper(flatten(geometry.coordinates)),
151
+ _step6;
152
+
153
+ try {
154
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
155
+ var _coord2 = _step6.value;
156
+ coordLengths.add(_coord2.length);
157
+ }
158
+ } catch (err) {
159
+ _iterator6.e(err);
160
+ } finally {
161
+ _iterator6.f();
162
+ }
101
163
 
102
- for (const coord of flatten(polygon)) {
103
- coordLengths.add(coord.length);
164
+ break;
165
+
166
+ case 'MultiPolygon':
167
+ polygonFeaturesCount++;
168
+
169
+ var _iterator7 = _createForOfIteratorHelper(geometry.coordinates),
170
+ _step7;
171
+
172
+ try {
173
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
174
+ var polygon = _step7.value;
175
+ polygonObjectsCount++;
176
+ polygonRingsCount += polygon.length;
177
+ polygonPositionsCount += flatten(polygon).length;
178
+
179
+ var _iterator8 = _createForOfIteratorHelper(flatten(polygon)),
180
+ _step8;
181
+
182
+ try {
183
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
184
+ var _coord3 = _step8.value;
185
+ coordLengths.add(_coord3.length);
186
+ }
187
+ } catch (err) {
188
+ _iterator8.e(err);
189
+ } finally {
190
+ _iterator8.f();
191
+ }
192
+ }
193
+ } catch (err) {
194
+ _iterator7.e(err);
195
+ } finally {
196
+ _iterator7.f();
104
197
  }
105
- }
106
198
 
107
- break;
199
+ break;
108
200
 
109
- default:
110
- throw new Error("Unsupported geometry type: ".concat(geometry.type));
111
- }
201
+ default:
202
+ throw new Error("Unsupported geometry type: ".concat(geometry.type));
203
+ }
112
204
 
113
- if (feature.properties) {
114
- for (const key in feature.properties) {
115
- const val = feature.properties[key];
116
- numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === undefined ? isNumeric(val) : numericPropKeys[key];
205
+ if (feature.properties) {
206
+ for (var _key in feature.properties) {
207
+ var val = feature.properties[_key];
208
+ propArrayTypes[_key] = deduceArrayType(val, propArrayTypes[_key]);
209
+ }
117
210
  }
118
211
  }
212
+ } catch (err) {
213
+ _iterator.e(err);
214
+ } finally {
215
+ _iterator.f();
119
216
  }
120
217
 
121
218
  return {
122
- coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
123
- pointPositionsCount,
124
- pointFeaturesCount,
125
- linePositionsCount,
126
- linePathsCount,
127
- lineFeaturesCount,
128
- polygonPositionsCount,
129
- polygonObjectsCount,
130
- polygonRingsCount,
131
- polygonFeaturesCount,
132
- numericPropKeys: Object.keys(numericPropKeys).filter(k => numericPropKeys[k])
219
+ coordLength: coordLengths.size > 0 ? Math.max.apply(Math, (0, _toConsumableArray2.default)(coordLengths)) : 2,
220
+ pointPositionsCount: pointPositionsCount,
221
+ pointFeaturesCount: pointFeaturesCount,
222
+ linePositionsCount: linePositionsCount,
223
+ linePathsCount: linePathsCount,
224
+ lineFeaturesCount: lineFeaturesCount,
225
+ polygonPositionsCount: polygonPositionsCount,
226
+ polygonObjectsCount: polygonObjectsCount,
227
+ polygonRingsCount: polygonRingsCount,
228
+ polygonFeaturesCount: polygonFeaturesCount,
229
+ numericPropKeys: Object.keys(propArrayTypes).filter(function (k) {
230
+ return propArrayTypes[k] !== Array;
231
+ }),
232
+ propArrayTypes: propArrayTypes
133
233
  };
134
234
  }
135
235
 
136
236
  function secondPass(features, firstPassData, options) {
137
- const {
138
- pointPositionsCount,
139
- pointFeaturesCount,
140
- linePositionsCount,
141
- linePathsCount,
142
- lineFeaturesCount,
143
- polygonPositionsCount,
144
- polygonObjectsCount,
145
- polygonRingsCount,
146
- polygonFeaturesCount
147
- } = firstPassData;
148
- const {
149
- coordLength,
150
- numericPropKeys,
151
- PositionDataType = Float32Array
152
- } = options;
153
- const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
154
- const points = {
237
+ var pointPositionsCount = firstPassData.pointPositionsCount,
238
+ pointFeaturesCount = firstPassData.pointFeaturesCount,
239
+ linePositionsCount = firstPassData.linePositionsCount,
240
+ linePathsCount = firstPassData.linePathsCount,
241
+ lineFeaturesCount = firstPassData.lineFeaturesCount,
242
+ polygonPositionsCount = firstPassData.polygonPositionsCount,
243
+ polygonObjectsCount = firstPassData.polygonObjectsCount,
244
+ polygonRingsCount = firstPassData.polygonRingsCount,
245
+ propArrayTypes = firstPassData.propArrayTypes,
246
+ polygonFeaturesCount = firstPassData.polygonFeaturesCount;
247
+ var coordLength = options.coordLength,
248
+ numericPropKeys = options.numericPropKeys,
249
+ _options$PositionData = options.PositionDataType,
250
+ PositionDataType = _options$PositionData === void 0 ? Float32Array : _options$PositionData;
251
+ var GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
252
+ var points = {
155
253
  positions: new PositionDataType(pointPositionsCount * coordLength),
156
254
  globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
157
255
  featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
@@ -159,7 +257,7 @@ function secondPass(features, firstPassData, options) {
159
257
  properties: Array(),
160
258
  fields: Array()
161
259
  };
162
- const lines = {
260
+ var lines = {
163
261
  positions: new PositionDataType(linePositionsCount * coordLength),
164
262
  pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
165
263
  globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
@@ -168,7 +266,7 @@ function secondPass(features, firstPassData, options) {
168
266
  properties: Array(),
169
267
  fields: Array()
170
268
  };
171
- const polygons = {
269
+ var polygons = {
172
270
  positions: new PositionDataType(polygonPositionsCount * coordLength),
173
271
  polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
174
272
  primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
@@ -179,16 +277,29 @@ function secondPass(features, firstPassData, options) {
179
277
  fields: Array()
180
278
  };
181
279
 
182
- for (const object of [points, lines, polygons]) {
183
- for (const propName of numericPropKeys || []) {
184
- object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
280
+ for (var _i = 0, _arr = [points, lines, polygons]; _i < _arr.length; _i++) {
281
+ var object = _arr[_i];
282
+
283
+ var _iterator9 = _createForOfIteratorHelper(numericPropKeys || []),
284
+ _step9;
285
+
286
+ try {
287
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
288
+ var propName = _step9.value;
289
+ var TypedArray = propArrayTypes[propName];
290
+ object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
291
+ }
292
+ } catch (err) {
293
+ _iterator9.e(err);
294
+ } finally {
295
+ _iterator9.f();
185
296
  }
186
297
  }
187
298
 
188
299
  lines.pathIndices[linePathsCount] = linePositionsCount;
189
300
  polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
190
301
  polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
191
- const indexMap = {
302
+ var indexMap = {
192
303
  pointPosition: 0,
193
304
  pointFeature: 0,
194
305
  linePosition: 0,
@@ -201,52 +312,62 @@ function secondPass(features, firstPassData, options) {
201
312
  feature: 0
202
313
  };
203
314
 
204
- for (const feature of features) {
205
- const geometry = feature.geometry;
206
- const properties = feature.properties || {};
207
-
208
- switch (geometry.type) {
209
- case 'Point':
210
- handlePoint(geometry.coordinates, points, indexMap, coordLength, properties);
211
- points.properties.push(keepStringProperties(properties, numericPropKeys));
212
- indexMap.pointFeature++;
213
- break;
214
-
215
- case 'MultiPoint':
216
- handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);
217
- points.properties.push(keepStringProperties(properties, numericPropKeys));
218
- indexMap.pointFeature++;
219
- break;
220
-
221
- case 'LineString':
222
- handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
223
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
224
- indexMap.lineFeature++;
225
- break;
226
-
227
- case 'MultiLineString':
228
- handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
229
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
230
- indexMap.lineFeature++;
231
- break;
232
-
233
- case 'Polygon':
234
- handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
235
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
236
- indexMap.polygonFeature++;
237
- break;
238
-
239
- case 'MultiPolygon':
240
- handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
241
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
242
- indexMap.polygonFeature++;
243
- break;
244
-
245
- default:
246
- throw new Error('Invalid geometry type');
247
- }
315
+ var _iterator10 = _createForOfIteratorHelper(features),
316
+ _step10;
317
+
318
+ try {
319
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
320
+ var feature = _step10.value;
321
+ var geometry = feature.geometry;
322
+ var properties = feature.properties || {};
323
+
324
+ switch (geometry.type) {
325
+ case 'Point':
326
+ handlePoint(geometry.coordinates, points, indexMap, coordLength, properties);
327
+ points.properties.push(keepStringProperties(properties, numericPropKeys));
328
+ indexMap.pointFeature++;
329
+ break;
330
+
331
+ case 'MultiPoint':
332
+ handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);
333
+ points.properties.push(keepStringProperties(properties, numericPropKeys));
334
+ indexMap.pointFeature++;
335
+ break;
336
+
337
+ case 'LineString':
338
+ handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
339
+ lines.properties.push(keepStringProperties(properties, numericPropKeys));
340
+ indexMap.lineFeature++;
341
+ break;
342
+
343
+ case 'MultiLineString':
344
+ handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
345
+ lines.properties.push(keepStringProperties(properties, numericPropKeys));
346
+ indexMap.lineFeature++;
347
+ break;
348
+
349
+ case 'Polygon':
350
+ handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
351
+ polygons.properties.push(keepStringProperties(properties, numericPropKeys));
352
+ indexMap.polygonFeature++;
353
+ break;
354
+
355
+ case 'MultiPolygon':
356
+ handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
357
+ polygons.properties.push(keepStringProperties(properties, numericPropKeys));
358
+ indexMap.polygonFeature++;
359
+ break;
360
+
361
+ default:
362
+ throw new Error('Invalid geometry type');
363
+ }
248
364
 
249
- indexMap.feature++;
365
+ indexMap.feature++;
366
+ }
367
+ } catch (err) {
368
+ _iterator10.e(err);
369
+ } finally {
370
+ _iterator10.f();
250
371
  }
251
372
 
252
373
  return makeAccessorObjects(points, lines, polygons, coordLength);
@@ -261,8 +382,18 @@ function handlePoint(coords, points, indexMap, coordLength, properties) {
261
382
  }
262
383
 
263
384
  function handleMultiPoint(coords, points, indexMap, coordLength, properties) {
264
- for (const point of coords) {
265
- handlePoint(point, points, indexMap, coordLength, properties);
385
+ var _iterator11 = _createForOfIteratorHelper(coords),
386
+ _step11;
387
+
388
+ try {
389
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
390
+ var point = _step11.value;
391
+ handlePoint(point, points, indexMap, coordLength, properties);
392
+ }
393
+ } catch (err) {
394
+ _iterator11.e(err);
395
+ } finally {
396
+ _iterator11.f();
266
397
  }
267
398
  }
268
399
 
@@ -270,7 +401,7 @@ function handleLineString(coords, lines, indexMap, coordLength, properties) {
270
401
  lines.pathIndices[indexMap.linePath] = indexMap.linePosition;
271
402
  indexMap.linePath++;
272
403
  fillCoords(lines.positions, coords, indexMap.linePosition, coordLength);
273
- const nPositions = coords.length;
404
+ var nPositions = coords.length;
274
405
  fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
275
406
  lines.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.linePosition);
276
407
  lines.featureIds.set(new Uint32Array(nPositions).fill(indexMap.lineFeature), indexMap.linePosition);
@@ -278,8 +409,18 @@ function handleLineString(coords, lines, indexMap, coordLength, properties) {
278
409
  }
279
410
 
280
411
  function handleMultiLineString(coords, lines, indexMap, coordLength, properties) {
281
- for (const line of coords) {
282
- handleLineString(line, lines, indexMap, coordLength, properties);
412
+ var _iterator12 = _createForOfIteratorHelper(coords),
413
+ _step12;
414
+
415
+ try {
416
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
417
+ var line = _step12.value;
418
+ handleLineString(line, lines, indexMap, coordLength, properties);
419
+ }
420
+ } catch (err) {
421
+ _iterator12.e(err);
422
+ } finally {
423
+ _iterator12.f();
283
424
  }
284
425
  }
285
426
 
@@ -287,27 +428,47 @@ function handlePolygon(coords, polygons, indexMap, coordLength, properties) {
287
428
  polygons.polygonIndices[indexMap.polygonObject] = indexMap.polygonPosition;
288
429
  indexMap.polygonObject++;
289
430
 
290
- for (const ring of coords) {
291
- polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition;
292
- indexMap.polygonRing++;
293
- fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength);
294
- const nPositions = ring.length;
295
- fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
296
- polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition);
297
- polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition);
298
- indexMap.polygonPosition += nPositions;
431
+ var _iterator13 = _createForOfIteratorHelper(coords),
432
+ _step13;
433
+
434
+ try {
435
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
436
+ var ring = _step13.value;
437
+ polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition;
438
+ indexMap.polygonRing++;
439
+ fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength);
440
+ var nPositions = ring.length;
441
+ fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
442
+ polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition);
443
+ polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition);
444
+ indexMap.polygonPosition += nPositions;
445
+ }
446
+ } catch (err) {
447
+ _iterator13.e(err);
448
+ } finally {
449
+ _iterator13.f();
299
450
  }
300
451
  }
301
452
 
302
453
  function handleMultiPolygon(coords, polygons, indexMap, coordLength, properties) {
303
- for (const polygon of coords) {
304
- handlePolygon(polygon, polygons, indexMap, coordLength, properties);
454
+ var _iterator14 = _createForOfIteratorHelper(coords),
455
+ _step14;
456
+
457
+ try {
458
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
459
+ var polygon = _step14.value;
460
+ handlePolygon(polygon, polygons, indexMap, coordLength, properties);
461
+ }
462
+ } catch (err) {
463
+ _iterator14.e(err);
464
+ } finally {
465
+ _iterator14.f();
305
466
  }
306
467
  }
307
468
 
308
469
  function makeAccessorObjects(points, lines, polygons, coordLength) {
309
- const returnObj = {
310
- points: { ...points,
470
+ var returnObj = {
471
+ points: _objectSpread(_objectSpread({}, points), {}, {
311
472
  positions: {
312
473
  value: points.positions,
313
474
  size: coordLength
@@ -321,8 +482,8 @@ function makeAccessorObjects(points, lines, polygons, coordLength) {
321
482
  size: 1
322
483
  },
323
484
  type: 'Point'
324
- },
325
- lines: { ...lines,
485
+ }),
486
+ lines: _objectSpread(_objectSpread({}, lines), {}, {
326
487
  pathIndices: {
327
488
  value: lines.pathIndices,
328
489
  size: 1
@@ -340,8 +501,8 @@ function makeAccessorObjects(points, lines, polygons, coordLength) {
340
501
  size: 1
341
502
  },
342
503
  type: 'LineString'
343
- },
344
- polygons: { ...polygons,
504
+ }),
505
+ polygons: _objectSpread(_objectSpread({}, polygons), {}, {
345
506
  polygonIndices: {
346
507
  value: polygons.polygonIndices,
347
508
  size: 1
@@ -363,11 +524,11 @@ function makeAccessorObjects(points, lines, polygons, coordLength) {
363
524
  size: 1
364
525
  },
365
526
  type: 'Polygon'
366
- }
527
+ })
367
528
  };
368
529
 
369
- for (const geomType in returnObj) {
370
- for (const numericProp in returnObj[geomType].numericProps) {
530
+ for (var geomType in returnObj) {
531
+ for (var numericProp in returnObj[geomType].numericProps) {
371
532
  returnObj[geomType].numericProps[numericProp] = {
372
533
  value: returnObj[geomType].numericProps[numericProp],
373
534
  size: 1
@@ -379,7 +540,7 @@ function makeAccessorObjects(points, lines, polygons, coordLength) {
379
540
  }
380
541
 
381
542
  function fillNumericProperties(object, properties, index, length) {
382
- for (const numericPropName in object.numericProps) {
543
+ for (var numericPropName in object.numericProps) {
383
544
  if (numericPropName in properties) {
384
545
  object.numericProps[numericPropName].set(new Array(length).fill(properties[numericPropName]), index);
385
546
  }
@@ -387,11 +548,11 @@ function fillNumericProperties(object, properties, index, length) {
387
548
  }
388
549
 
389
550
  function keepStringProperties(properties, numericKeys) {
390
- const props = {};
551
+ var props = {};
391
552
 
392
- for (const key in properties) {
393
- if (!numericKeys.includes(key)) {
394
- props[key] = properties[key];
553
+ for (var _key2 in properties) {
554
+ if (!numericKeys.includes(_key2)) {
555
+ props[_key2] = properties[_key2];
395
556
  }
396
557
  }
397
558
 
@@ -399,19 +560,35 @@ function keepStringProperties(properties, numericKeys) {
399
560
  }
400
561
 
401
562
  function fillCoords(array, coords, startVertex, coordLength) {
402
- let index = startVertex * coordLength;
563
+ var index = startVertex * coordLength;
403
564
 
404
- for (const coord of coords) {
405
- array.set(coord, index);
406
- index += coordLength;
565
+ var _iterator15 = _createForOfIteratorHelper(coords),
566
+ _step15;
567
+
568
+ try {
569
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
570
+ var coord = _step15.value;
571
+ array.set(coord, index);
572
+ index += coordLength;
573
+ }
574
+ } catch (err) {
575
+ _iterator15.e(err);
576
+ } finally {
577
+ _iterator15.f();
407
578
  }
408
579
  }
409
580
 
410
581
  function flatten(arrays) {
411
- return [].concat(...arrays);
582
+ var _ref;
583
+
584
+ return (_ref = []).concat.apply(_ref, (0, _toConsumableArray2.default)(arrays));
412
585
  }
413
586
 
414
- function isNumeric(x) {
415
- return Number.isFinite(x);
587
+ function deduceArrayType(x, constructor) {
588
+ if (constructor === Array || !Number.isFinite(x)) {
589
+ return Array;
590
+ }
591
+
592
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
416
593
  }
417
594
  //# sourceMappingURL=geojson-to-binary.js.map