@loaders.gl/gis 3.3.0-alpha.5 → 3.3.0-alpha.6

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 (37) hide show
  1. package/dist/es5/bundle.js +0 -1
  2. package/dist/es5/bundle.js.map +1 -1
  3. package/dist/es5/index.js +12 -17
  4. package/dist/es5/index.js.map +1 -1
  5. package/dist/es5/lib/binary-to-geojson.js +5 -62
  6. package/dist/es5/lib/binary-to-geojson.js.map +1 -1
  7. package/dist/es5/lib/extract-geometry-info.js +8 -43
  8. package/dist/es5/lib/extract-geometry-info.js.map +1 -1
  9. package/dist/es5/lib/flat-geojson-to-binary-types.js.map +1 -1
  10. package/dist/es5/lib/flat-geojson-to-binary.js +30 -59
  11. package/dist/es5/lib/flat-geojson-to-binary.js.map +1 -1
  12. package/dist/es5/lib/geojson-to-binary.js +0 -4
  13. package/dist/es5/lib/geojson-to-binary.js.map +1 -1
  14. package/dist/es5/lib/geojson-to-flat-geojson.js +4 -30
  15. package/dist/es5/lib/geojson-to-flat-geojson.js.map +1 -1
  16. package/dist/es5/lib/transform.js +1 -15
  17. package/dist/es5/lib/transform.js.map +1 -1
  18. package/dist/esm/bundle.js +1 -1
  19. package/dist/esm/bundle.js.map +1 -1
  20. package/dist/esm/index.js +2 -0
  21. package/dist/esm/index.js.map +1 -1
  22. package/dist/esm/lib/binary-to-geojson.js +17 -49
  23. package/dist/esm/lib/binary-to-geojson.js.map +1 -1
  24. package/dist/esm/lib/extract-geometry-info.js +1 -19
  25. package/dist/esm/lib/extract-geometry-info.js.map +1 -1
  26. package/dist/esm/lib/flat-geojson-to-binary-types.js.map +1 -1
  27. package/dist/esm/lib/flat-geojson-to-binary.js +21 -30
  28. package/dist/esm/lib/flat-geojson-to-binary.js.map +1 -1
  29. package/dist/esm/lib/geojson-to-binary.js +5 -3
  30. package/dist/esm/lib/geojson-to-binary.js.map +1 -1
  31. package/dist/esm/lib/geojson-to-flat-geojson.js +7 -19
  32. package/dist/esm/lib/geojson-to-flat-geojson.js.map +1 -1
  33. package/dist/esm/lib/transform.js +1 -8
  34. package/dist/esm/lib/transform.js.map +1 -1
  35. package/dist/lib/flat-geojson-to-binary.js +1 -0
  36. package/package.json +4 -4
  37. package/src/lib/flat-geojson-to-binary.ts +1 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/extract-geometry-info.ts"],"names":["extractGeometryInfo","features","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","coordLengths","Set","feature","geometry","type","add","coordinates","length","point","coord","line","flattened","flat","polygon","Error","coordLength","size","Math","max"],"mappings":";;;;;;;;;;;;;;;;;AAQO,SAASA,mBAAT,CAA6BC,QAA7B,EAAuE;AAE5E,MAAIC,mBAAmB,GAAG,CAA1B;AACA,MAAIC,kBAAkB,GAAG,CAAzB;AACA,MAAIC,kBAAkB,GAAG,CAAzB;AACA,MAAIC,cAAc,GAAG,CAArB;AACA,MAAIC,iBAAiB,GAAG,CAAxB;AACA,MAAIC,qBAAqB,GAAG,CAA5B;AACA,MAAIC,mBAAmB,GAAG,CAA1B;AACA,MAAIC,iBAAiB,GAAG,CAAxB;AACA,MAAIC,oBAAoB,GAAG,CAA3B;AACA,MAAMC,YAAY,GAAG,IAAIC,GAAJ,EAArB;;AAX4E,6CAatDX,QAbsD;AAAA;;AAAA;AAa5E,wDAAgC;AAAA,UAArBY,OAAqB;AAC9B,UAAMC,QAAQ,GAAGD,OAAO,CAACC,QAAzB;;AACA,cAAQA,QAAQ,CAACC,IAAjB;AACE,aAAK,OAAL;AACEZ,UAAAA,kBAAkB;AAClBD,UAAAA,mBAAmB;AACnBS,UAAAA,YAAY,CAACK,GAAb,CAAiBF,QAAQ,CAACG,WAAT,CAAqBC,MAAtC;AACA;;AACF,aAAK,YAAL;AACEf,UAAAA,kBAAkB;AAClBD,UAAAA,mBAAmB,IAAIY,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AWLC,IAAAA,oBAAoB,EAApBA;AAXK,GAAP;AAaD","sourcesContent":["import {Feature, GeojsonGeometryInfo} from '@loaders.gl/schema';\n\n/**\n * Initial scan over GeoJSON features\n * Counts number of coordinates of each geometry type and\n * keeps track of the max coordinate dimensions\n */\n// eslint-disable-next-line complexity, max-statements\nexport function extractGeometryInfo(features: Feature[]): GeojsonGeometryInfo {\n // Counts the number of _positions_, so [x, y, z] counts as one\n let pointPositionsCount = 0;\n let pointFeaturesCount = 0;\n let linePositionsCount = 0;\n let linePathsCount = 0;\n let lineFeaturesCount = 0;\n let polygonPositionsCount = 0;\n let polygonObjectsCount = 0;\n let polygonRingsCount = 0;\n let polygonFeaturesCount = 0;\n const coordLengths = new Set<number>();\n\n for (const feature of features) {\n const geometry = feature.geometry;\n switch (geometry.type) {\n case 'Point':\n pointFeaturesCount++;\n pointPositionsCount++;\n coordLengths.add(geometry.coordinates.length);\n break;\n case 'MultiPoint':\n pointFeaturesCount++;\n pointPositionsCount += geometry.coordinates.length;\n for (const point of geometry.coordinates) {\n coordLengths.add(point.length);\n }\n break;\n case 'LineString':\n lineFeaturesCount++;\n linePositionsCount += geometry.coordinates.length;\n linePathsCount++;\n\n for (const coord of geometry.coordinates) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiLineString':\n lineFeaturesCount++;\n for (const line of geometry.coordinates) {\n linePositionsCount += line.length;\n linePathsCount++;\n\n // eslint-disable-next-line max-depth\n for (const coord of line) {\n coordLengths.add(coord.length);\n }\n }\n break;\n case 'Polygon':\n polygonFeaturesCount++;\n polygonObjectsCount++;\n polygonRingsCount += geometry.coordinates.length;\n const flattened = geometry.coordinates.flat();\n polygonPositionsCount += flattened.length;\n\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiPolygon':\n polygonFeaturesCount++;\n for (const polygon of geometry.coordinates) {\n polygonObjectsCount++;\n polygonRingsCount += polygon.length;\n const flattened = polygon.flat();\n polygonPositionsCount += flattened.length;\n\n // eslint-disable-next-line max-depth\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n }\n break;\n default:\n throw new Error(`Unsupported geometry type: ${geometry.type}`);\n }\n }\n\n return {\n coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,\n\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n };\n}\n"],"file":"extract-geometry-info.js"}
1
+ {"version":3,"file":"extract-geometry-info.js","names":["extractGeometryInfo","features","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","coordLengths","Set","feature","geometry","type","add","coordinates","length","point","coord","line","flattened","flat","polygon","Error","coordLength","size","Math","max"],"sources":["../../../src/lib/extract-geometry-info.ts"],"sourcesContent":["import {Feature, GeojsonGeometryInfo} from '@loaders.gl/schema';\n\n/**\n * Initial scan over GeoJSON features\n * Counts number of coordinates of each geometry type and\n * keeps track of the max coordinate dimensions\n */\n// eslint-disable-next-line complexity, max-statements\nexport function extractGeometryInfo(features: Feature[]): GeojsonGeometryInfo {\n // Counts the number of _positions_, so [x, y, z] counts as one\n let pointPositionsCount = 0;\n let pointFeaturesCount = 0;\n let linePositionsCount = 0;\n let linePathsCount = 0;\n let lineFeaturesCount = 0;\n let polygonPositionsCount = 0;\n let polygonObjectsCount = 0;\n let polygonRingsCount = 0;\n let polygonFeaturesCount = 0;\n const coordLengths = new Set<number>();\n\n for (const feature of features) {\n const geometry = feature.geometry;\n switch (geometry.type) {\n case 'Point':\n pointFeaturesCount++;\n pointPositionsCount++;\n coordLengths.add(geometry.coordinates.length);\n break;\n case 'MultiPoint':\n pointFeaturesCount++;\n pointPositionsCount += geometry.coordinates.length;\n for (const point of geometry.coordinates) {\n coordLengths.add(point.length);\n }\n break;\n case 'LineString':\n lineFeaturesCount++;\n linePositionsCount += geometry.coordinates.length;\n linePathsCount++;\n\n for (const coord of geometry.coordinates) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiLineString':\n lineFeaturesCount++;\n for (const line of geometry.coordinates) {\n linePositionsCount += line.length;\n linePathsCount++;\n\n // eslint-disable-next-line max-depth\n for (const coord of line) {\n coordLengths.add(coord.length);\n }\n }\n break;\n case 'Polygon':\n polygonFeaturesCount++;\n polygonObjectsCount++;\n polygonRingsCount += geometry.coordinates.length;\n const flattened = geometry.coordinates.flat();\n polygonPositionsCount += flattened.length;\n\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiPolygon':\n polygonFeaturesCount++;\n for (const polygon of geometry.coordinates) {\n polygonObjectsCount++;\n polygonRingsCount += polygon.length;\n const flattened = polygon.flat();\n polygonPositionsCount += flattened.length;\n\n // eslint-disable-next-line max-depth\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n }\n break;\n default:\n throw new Error(`Unsupported geometry type: ${geometry.type}`);\n }\n }\n\n return {\n coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,\n\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n };\n}\n"],"mappings":";;;;;;;;;;;AAQO,SAASA,mBAAmB,CAACC,QAAmB,EAAuB;EAE5E,IAAIC,mBAAmB,GAAG,CAAC;EAC3B,IAAIC,kBAAkB,GAAG,CAAC;EAC1B,IAAIC,kBAAkB,GAAG,CAAC;EAC1B,IAAIC,cAAc,GAAG,CAAC;EACtB,IAAIC,iBAAiB,GAAG,CAAC;EACzB,IAAIC,qBAAqB,GAAG,CAAC;EAC7B,IAAIC,mBAAmB,GAAG,CAAC;EAC3B,IAAIC,iBAAiB,GAAG,CAAC;EACzB,IAAIC,oBAAoB,GAAG,CAAC;EAC5B,IAAMC,YAAY,GAAG,IAAIC,GAAG,EAAU;EA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;IACdC,iBAAiB,EAAjBA,iBAAiB;IACjBC,qBAAqB,EAArBA,qBAAqB;IACrBC,mBAAmB,EAAnBA,mBAAmB;IACnBC,iBAAiB,EAAjBA,iBAAiB;IACjBC,oBAAoB,EAApBA;EACF,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"flat-geojson-to-binary-types.js"}
1
+ {"version":3,"file":"flat-geojson-to-binary-types.js","names":[],"sources":["../../../src/lib/flat-geojson-to-binary-types.ts"],"sourcesContent":["import type {TypedArray} from '@loaders.gl/schema';\n\n/**\n * Permissable constructor for numeric props\n */\nexport type PropArrayConstructor =\n | Float32ArrayConstructor\n | Float64ArrayConstructor\n | ArrayConstructor;\n\n/**\n * Collection type for holding intermediate binary data before conversion to `BinaryPointGeometry`\n */\nexport type Points = {\n type: 'Point';\n positions: Float32Array | Float64Array;\n globalFeatureIds: Uint16Array | Uint32Array;\n featureIds: Uint16Array | Uint32Array;\n numericProps: {[key: string]: TypedArray};\n properties: {}[];\n fields: {\n id?: string | number;\n }[];\n};\n\n/**\n * Collection type for holding intermediate binary data before conversion to `BinaryLineStringGeometry`\n */\nexport type Lines = {\n type: 'LineString';\n positions: Float32Array | Float64Array;\n pathIndices: Uint16Array | Uint32Array;\n globalFeatureIds: Uint16Array | Uint32Array;\n featureIds: Uint16Array | Uint32Array;\n numericProps: {[key: string]: TypedArray};\n properties: {}[];\n fields: {\n id?: string | number;\n }[];\n};\n\n/**\n * Collection type for holding intermediate binary data before conversion to `BinaryPolygonGeometry`\n */\nexport type Polygons = {\n type: 'Polygon';\n positions: Float32Array | Float64Array;\n polygonIndices: Uint16Array | Uint32Array;\n primitivePolygonIndices: Uint16Array | Uint32Array;\n triangles: number[];\n globalFeatureIds: Uint16Array | Uint32Array;\n featureIds: Uint16Array | Uint32Array;\n numericProps: {[key: string]: TypedArray};\n properties: {}[];\n fields: {\n id?: string | number;\n }[];\n};\n"],"mappings":""}
@@ -1,27 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.flatGeojsonToBinary = flatGeojsonToBinary;
9
7
  exports.TEST_EXPORTS = void 0;
10
-
8
+ exports.flatGeojsonToBinary = flatGeojsonToBinary;
11
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
-
13
10
  var _polygon = require("@math.gl/polygon");
14
-
15
11
  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; } } }; }
16
-
17
12
  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); }
18
-
19
13
  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; }
20
-
21
- 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; }
22
-
23
- 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; }
24
-
14
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
16
  function flatGeojsonToBinary(features, geometryInfo, options) {
26
17
  var propArrayTypes = extractNumericPropTypes(features);
27
18
  var numericPropKeys = Object.keys(propArrayTypes).filter(function (k) {
@@ -38,18 +29,15 @@ function flatGeojsonToBinary(features, geometryInfo, options) {
38
29
  var TEST_EXPORTS = {
39
30
  extractNumericPropTypes: extractNumericPropTypes
40
31
  };
41
- exports.TEST_EXPORTS = TEST_EXPORTS;
42
32
 
33
+ exports.TEST_EXPORTS = TEST_EXPORTS;
43
34
  function extractNumericPropTypes(features) {
44
35
  var propArrayTypes = {};
45
-
46
36
  var _iterator = _createForOfIteratorHelper(features),
47
- _step;
48
-
37
+ _step;
49
38
  try {
50
39
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
51
40
  var feature = _step.value;
52
-
53
41
  if (feature.properties) {
54
42
  for (var _key in feature.properties) {
55
43
  var val = feature.properties[_key];
@@ -62,26 +50,25 @@ function extractNumericPropTypes(features) {
62
50
  } finally {
63
51
  _iterator.f();
64
52
  }
65
-
66
53
  return propArrayTypes;
67
54
  }
68
55
 
69
56
  function fillArrays(features, geometryInfo, options) {
70
57
  var pointPositionsCount = geometryInfo.pointPositionsCount,
71
- pointFeaturesCount = geometryInfo.pointFeaturesCount,
72
- linePositionsCount = geometryInfo.linePositionsCount,
73
- linePathsCount = geometryInfo.linePathsCount,
74
- lineFeaturesCount = geometryInfo.lineFeaturesCount,
75
- polygonPositionsCount = geometryInfo.polygonPositionsCount,
76
- polygonObjectsCount = geometryInfo.polygonObjectsCount,
77
- polygonRingsCount = geometryInfo.polygonRingsCount,
78
- polygonFeaturesCount = geometryInfo.polygonFeaturesCount,
79
- propArrayTypes = geometryInfo.propArrayTypes,
80
- coordLength = geometryInfo.coordLength;
58
+ pointFeaturesCount = geometryInfo.pointFeaturesCount,
59
+ linePositionsCount = geometryInfo.linePositionsCount,
60
+ linePathsCount = geometryInfo.linePathsCount,
61
+ lineFeaturesCount = geometryInfo.lineFeaturesCount,
62
+ polygonPositionsCount = geometryInfo.polygonPositionsCount,
63
+ polygonObjectsCount = geometryInfo.polygonObjectsCount,
64
+ polygonRingsCount = geometryInfo.polygonRingsCount,
65
+ polygonFeaturesCount = geometryInfo.polygonFeaturesCount,
66
+ propArrayTypes = geometryInfo.propArrayTypes,
67
+ coordLength = geometryInfo.coordLength;
81
68
  var _options$numericPropK = options.numericPropKeys,
82
- numericPropKeys = _options$numericPropK === void 0 ? [] : _options$numericPropK,
83
- _options$PositionData = options.PositionDataType,
84
- PositionDataType = _options$PositionData === void 0 ? Float32Array : _options$PositionData;
69
+ numericPropKeys = _options$numericPropK === void 0 ? [] : _options$numericPropK,
70
+ _options$PositionData = options.PositionDataType,
71
+ PositionDataType = _options$PositionData === void 0 ? Float32Array : _options$PositionData;
85
72
  var hasGlobalId = features[0] && 'id' in features[0];
86
73
  var GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
87
74
  var points = {
@@ -118,10 +105,8 @@ function fillArrays(features, geometryInfo, options) {
118
105
 
119
106
  for (var _i = 0, _arr = [points, lines, polygons]; _i < _arr.length; _i++) {
120
107
  var object = _arr[_i];
121
-
122
108
  var _iterator2 = _createForOfIteratorHelper(numericPropKeys),
123
- _step2;
124
-
109
+ _step2;
125
110
  try {
126
111
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
127
112
  var propName = _step2.value;
@@ -150,68 +135,55 @@ function fillArrays(features, geometryInfo, options) {
150
135
  polygonFeature: 0,
151
136
  feature: 0
152
137
  };
153
-
154
138
  var _iterator3 = _createForOfIteratorHelper(features),
155
- _step3;
156
-
139
+ _step3;
157
140
  try {
158
141
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
159
142
  var feature = _step3.value;
160
143
  var geometry = feature.geometry;
161
144
  var properties = feature.properties || {};
162
-
163
145
  switch (geometry.type) {
164
146
  case 'Point':
165
147
  handlePoint(geometry, points, indexMap, coordLength, properties);
166
148
  points.properties.push(keepStringProperties(properties, numericPropKeys));
167
-
168
149
  if (hasGlobalId) {
169
150
  points.fields.push({
170
151
  id: feature.id
171
152
  });
172
153
  }
173
-
174
154
  indexMap.pointFeature++;
175
155
  break;
176
-
177
156
  case 'LineString':
178
157
  handleLineString(geometry, lines, indexMap, coordLength, properties);
179
158
  lines.properties.push(keepStringProperties(properties, numericPropKeys));
180
-
181
159
  if (hasGlobalId) {
182
160
  lines.fields.push({
183
161
  id: feature.id
184
162
  });
185
163
  }
186
-
187
164
  indexMap.lineFeature++;
188
165
  break;
189
-
190
166
  case 'Polygon':
191
167
  handlePolygon(geometry, polygons, indexMap, coordLength, properties);
192
168
  polygons.properties.push(keepStringProperties(properties, numericPropKeys));
193
-
194
169
  if (hasGlobalId) {
195
170
  polygons.fields.push({
196
171
  id: feature.id
197
172
  });
198
173
  }
199
-
200
174
  indexMap.polygonFeature++;
201
175
  break;
202
-
203
176
  default:
204
177
  throw new Error('Invalid geometry type');
205
178
  }
206
-
207
179
  indexMap.feature++;
208
180
  }
181
+
209
182
  } catch (err) {
210
183
  _iterator3.e(err);
211
184
  } finally {
212
185
  _iterator3.f();
213
186
  }
214
-
215
187
  return makeAccessorObjects(points, lines, polygons, coordLength);
216
188
  }
217
189
 
@@ -230,10 +202,10 @@ function handleLineString(geometry, lines, indexMap, coordLength, properties) {
230
202
  fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
231
203
  lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
232
204
  lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
233
-
234
205
  for (var i = 0, il = geometry.indices.length; i < il; ++i) {
235
206
  var start = geometry.indices[i];
236
207
  var end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
208
+
237
209
  lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
238
210
  indexMap.linePosition += (end - start) / coordLength;
239
211
  }
@@ -252,14 +224,14 @@ function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
252
224
  var areas = geometry.areas[l];
253
225
  var indices = geometry.indices[l];
254
226
  var nextIndices = geometry.indices[l + 1];
255
-
256
227
  for (var i = 0, il = indices.length; i < il; ++i) {
257
228
  var start = indices[i];
258
- var end = i === il - 1 ? nextIndices === undefined ? geometry.data.length : nextIndices[0] : indices[i + 1];
229
+ var end = i === il - 1 ?
230
+ nextIndices === undefined ? geometry.data.length : nextIndices[0] : indices[i + 1];
231
+
259
232
  polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
260
233
  indexMap.polygonPosition += (end - start) / coordLength;
261
234
  }
262
-
263
235
  var endPosition = indexMap.polygonPosition;
264
236
  triangulatePolygon(polygons, areas, indices, {
265
237
  startPosition: startPosition,
@@ -271,15 +243,18 @@ function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
271
243
 
272
244
  function triangulatePolygon(polygons, areas, indices, _ref) {
273
245
  var startPosition = _ref.startPosition,
274
- endPosition = _ref.endPosition,
275
- coordLength = _ref.coordLength;
246
+ endPosition = _ref.endPosition,
247
+ coordLength = _ref.coordLength;
276
248
  var start = startPosition * coordLength;
277
249
  var end = endPosition * coordLength;
250
+
278
251
  var polygonPositions = polygons.positions.subarray(start, end);
252
+
279
253
  var offset = indices[0];
280
254
  var holes = indices.slice(1).map(function (n) {
281
255
  return (n - offset) / coordLength;
282
256
  });
257
+
283
258
  var triangles = (0, _polygon.earcut)(polygonPositions, holes, coordLength, areas);
284
259
 
285
260
  for (var t = 0, tl = triangles.length; t < tl; ++t) {
@@ -289,14 +264,12 @@ function triangulatePolygon(polygons, areas, indices, _ref) {
289
264
 
290
265
  function wrapProps(obj, size) {
291
266
  var returnObj = {};
292
-
293
267
  for (var _key2 in obj) {
294
268
  returnObj[_key2] = {
295
269
  value: obj[_key2],
296
270
  size: size
297
271
  };
298
272
  }
299
-
300
273
  return returnObj;
301
274
  }
302
275
 
@@ -377,13 +350,11 @@ function fillNumericProperties(object, properties, index, length) {
377
350
 
378
351
  function keepStringProperties(properties, numericKeys) {
379
352
  var props = {};
380
-
381
353
  for (var _key3 in properties) {
382
354
  if (!numericKeys.includes(_key3)) {
383
355
  props[_key3] = properties[_key3];
384
356
  }
385
357
  }
386
-
387
358
  return props;
388
359
  }
389
360
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/flat-geojson-to-binary.ts"],"names":["flatGeojsonToBinary","features","geometryInfo","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","coordLength","hasGlobalId","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","type","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","T","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","indices","start","end","l","ll","startPosition","areas","nextIndices","undefined","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","t","tl","wrapProps","obj","size","returnObj","value","index","numericPropName","numericKeys","props","includes","x","constructor","Number","isFinite","Float64Array","Math","fround"],"mappings":";;;;;;;;;;;;AACA;;;;;;;;;;;;AA0BO,SAASA,mBAAT,CACLC,QADK,EAELC,YAFK,EAGLC,OAHK,EAIL;AACA,MAAMC,cAAc,GAAGC,uBAAuB,CAACJ,QAAD,CAA9C;AACA,MAAMK,eAAe,GAAGC,MAAM,CAACC,IAAP,CAAYJ,cAAZ,EAA4BK,MAA5B,CAAmC,UAACC,CAAD;AAAA,WAAON,cAAc,CAACM,CAAD,CAAd,KAAsBC,KAA7B;AAAA,GAAnC,CAAxB;AACA,SAAOC,UAAU,CACfX,QADe;AAGbG,IAAAA,cAAc,EAAdA;AAHa,KAIVF,YAJU,GAMf;AACEI,IAAAA,eAAe,EAAGH,OAAO,IAAIA,OAAO,CAACG,eAApB,IAAwCA,eAD3D;AAEEO,IAAAA,gBAAgB,EAAEV,OAAO,GAAGA,OAAO,CAACU,gBAAX,GAA8BC;AAFzD,GANe,CAAjB;AAWD;;AAUM,IAAMC,YAAY,GAAG;AAC1BV,EAAAA,uBAAuB,EAAvBA;AAD0B,CAAr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oB+D,eAApB,EAAqC7B,IAArC,CAA0C2B,KAA1C,EAAiDC,KAAjD,EAAwDA,KAAK,GAAGtE,MAAhE;AACD;AACF;AACF;;AASD,SAASgC,oBAAT,CACEhD,UADF,EAEEwF,WAFF,EAGE;AACA,MAAMC,KAAK,GAAG,EAAd;;AACA,OAAK,IAAMxF,KAAX,IAAkBD,UAAlB,EAA8B;AAC5B,QAAI,CAACwF,WAAW,CAACE,QAAZ,CAAqBzF,KAArB,CAAL,EAAgC;AAC9BwF,MAAAA,KAAK,CAACxF,KAAD,CAAL,GAAaD,UAAU,CAACC,KAAD,CAAvB;AACD;AACF;;AACD,SAAOwF,KAAP;AACD;;AAUD,SAAStF,eAAT,CAAyBwF,CAAzB,EAAiCC,WAAjC,EAA0F;AACxF,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 type {\n BinaryAttribute,\n BinaryFeatures,\n FlatFeature,\n FlatPoint,\n FlatLineString,\n FlatPolygon,\n GeojsonGeometryInfo,\n TypedArray\n} from '@loaders.gl/schema';\nimport {PropArrayConstructor, Lines, Points, Polygons} from './flat-geojson-to-binary-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 geometryInfo\n * @param options\n * @returns filled arrays\n */\nexport function flatGeojsonToBinary(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo,\n options?: FlatGeojsonToBinaryOptions\n) {\n const propArrayTypes = extractNumericPropTypes(features);\n const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);\n return fillArrays(\n features,\n {\n propArrayTypes,\n ...geometryInfo\n },\n {\n numericPropKeys: (options && options.numericPropKeys) || numericPropKeys,\n PositionDataType: options ? options.PositionDataType : Float32Array\n }\n );\n}\n\n/**\n * Options for `flatGeojsonToBinary`\n */\nexport type FlatGeojsonToBinaryOptions = {\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\nexport const TEST_EXPORTS = {\n extractNumericPropTypes\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric types\n */\nfunction extractNumericPropTypes(features: FlatFeature[]): {\n [key: string]: PropArrayConstructor;\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 geometryInfo\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo & {\n propArrayTypes: {[key: string]: PropArrayConstructor};\n },\n options: FlatGeojsonToBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount,\n propArrayTypes,\n coordLength\n } = geometryInfo;\n const {numericPropKeys = [], PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: Points = {\n type: 'Point',\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: Lines = {\n type: 'LineString',\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: Polygons = {\n type: 'Polygon',\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 T = propArrayTypes[propName];\n object.numericProps[propName] = new T(object.positions.length / coordLength) as TypedArray;\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 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 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 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: FlatPoint,\n points: Points,\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: FlatLineString,\n lines: Lines,\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.indices.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.indices[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.indices[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: FlatPolygon,\n polygons: Polygons,\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.indices is a 2D array\n for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas[l];\n const indices = geometry.indices[l];\n const nextIndices = geometry.indices[l + 1];\n\n for (let i = 0, il = indices.length; i < il; ++i) {\n const start = indices[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextIndices === undefined\n ? geometry.data.length // end of data (no next indices)\n : nextIndices[0] // start of first line in nextIndices\n : indices[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, indices, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param indices\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: Polygons,\n areas: number[],\n indices: 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 = indices[0];\n const holes = indices.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const triangles = 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 = triangles.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + triangles[t]);\n }\n}\n\n/**\n * Wraps an object containing array into accessors\n *\n * @param obj\n * @param size\n */\nfunction wrapProps(\n obj: {[key: string]: TypedArray},\n size: number\n): {[key: string]: BinaryAttribute} {\n const returnObj = {};\n for (const key in obj) {\n returnObj[key] = {value: obj[key], size};\n }\n return returnObj;\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: Points,\n lines: Lines,\n polygons: Polygons,\n coordLength: number\n): BinaryFeatures {\n return {\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 numericProps: wrapProps(points.numericProps, 1)\n },\n lines: {\n ...lines,\n positions: {value: lines.positions, size: coordLength},\n pathIndices: {value: lines.pathIndices, size: 1},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1},\n numericProps: wrapProps(lines.numericProps, 1)\n },\n polygons: {\n ...polygons,\n positions: {value: polygons.positions, size: coordLength},\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1},\n numericProps: wrapProps(polygons.numericProps, 1)\n }\n };\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: Points | Lines | Polygons,\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 const value = properties[numericPropName] as number;\n object.numericProps[numericPropName].fill(value, 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\n/**\n *\n * Deduce correct array constructor to use for a given value\n *\n * @param x value to test\n * @param constructor previous constructor deduced\n * @returns PropArrayConstructor\n */\nfunction deduceArrayType(x: any, constructor: PropArrayConstructor): PropArrayConstructor {\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":"flat-geojson-to-binary.js"}
1
+ {"version":3,"file":"flat-geojson-to-binary.js","names":["flatGeojsonToBinary","features","geometryInfo","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","coordLength","hasGlobalId","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","type","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","T","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","indices","start","end","l","ll","startPosition","areas","nextIndices","undefined","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","earcut","t","tl","wrapProps","obj","size","returnObj","value","index","numericPropName","numericKeys","props","includes","x","constructor","Number","isFinite","Float64Array","Math","fround"],"sources":["../../../src/lib/flat-geojson-to-binary.ts"],"sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport type {\n BinaryAttribute,\n BinaryFeatures,\n FlatFeature,\n FlatPoint,\n FlatLineString,\n FlatPolygon,\n GeojsonGeometryInfo,\n TypedArray\n} from '@loaders.gl/schema';\nimport {PropArrayConstructor, Lines, Points, Polygons} from './flat-geojson-to-binary-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 geometryInfo\n * @param options\n * @returns filled arrays\n */\nexport function flatGeojsonToBinary(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo,\n options?: FlatGeojsonToBinaryOptions\n) {\n const propArrayTypes = extractNumericPropTypes(features);\n const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);\n return fillArrays(\n features,\n {\n propArrayTypes,\n ...geometryInfo\n },\n {\n numericPropKeys: (options && options.numericPropKeys) || numericPropKeys,\n PositionDataType: options ? options.PositionDataType : Float32Array\n }\n );\n}\n\n/**\n * Options for `flatGeojsonToBinary`\n */\nexport type FlatGeojsonToBinaryOptions = {\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\nexport const TEST_EXPORTS = {\n extractNumericPropTypes\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric types\n */\nfunction extractNumericPropTypes(features: FlatFeature[]): {\n [key: string]: PropArrayConstructor;\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 geometryInfo\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo & {\n propArrayTypes: {[key: string]: PropArrayConstructor};\n },\n options: FlatGeojsonToBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount,\n propArrayTypes,\n coordLength\n } = geometryInfo;\n const {numericPropKeys = [], PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: Points = {\n type: 'Point',\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: Lines = {\n type: 'LineString',\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: Polygons = {\n type: 'Polygon',\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 T = propArrayTypes[propName];\n object.numericProps[propName] = new T(object.positions.length / coordLength) as TypedArray;\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 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 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 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: FlatPoint,\n points: Points,\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: FlatLineString,\n lines: Lines,\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.indices.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.indices[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.indices[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: FlatPolygon,\n polygons: Polygons,\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.indices is a 2D array\n for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas[l];\n const indices = geometry.indices[l];\n const nextIndices = geometry.indices[l + 1];\n\n for (let i = 0, il = indices.length; i < il; ++i) {\n const start = indices[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextIndices === undefined\n ? geometry.data.length // end of data (no next indices)\n : nextIndices[0] // start of first line in nextIndices\n : indices[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, indices, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param indices\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: Polygons,\n areas: number[],\n indices: 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 = indices[0];\n const holes = indices.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n // @ts-expect-error TODO can earcut handle binary arrays? Add tests?\n const triangles = 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 = triangles.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + triangles[t]);\n }\n}\n\n/**\n * Wraps an object containing array into accessors\n *\n * @param obj\n * @param size\n */\nfunction wrapProps(\n obj: {[key: string]: TypedArray},\n size: number\n): {[key: string]: BinaryAttribute} {\n const returnObj = {};\n for (const key in obj) {\n returnObj[key] = {value: obj[key], size};\n }\n return returnObj;\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: Points,\n lines: Lines,\n polygons: Polygons,\n coordLength: number\n): BinaryFeatures {\n return {\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 numericProps: wrapProps(points.numericProps, 1)\n },\n lines: {\n ...lines,\n positions: {value: lines.positions, size: coordLength},\n pathIndices: {value: lines.pathIndices, size: 1},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1},\n numericProps: wrapProps(lines.numericProps, 1)\n },\n polygons: {\n ...polygons,\n positions: {value: polygons.positions, size: coordLength},\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1},\n numericProps: wrapProps(polygons.numericProps, 1)\n }\n };\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: Points | Lines | Polygons,\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 const value = properties[numericPropName] as number;\n object.numericProps[numericPropName].fill(value, 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\n/**\n *\n * Deduce correct array constructor to use for a given value\n *\n * @param x value to test\n * @param constructor previous constructor deduced\n * @returns PropArrayConstructor\n */\nfunction deduceArrayType(x: any, constructor: PropArrayConstructor): PropArrayConstructor {\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"],"mappings":";;;;;;;;;AACA;AAAwC;AAAA;AAAA;AAAA;AAAA;AA0BjC,SAASA,mBAAmB,CACjCC,QAAuB,EACvBC,YAAiC,EACjCC,OAAoC,EACpC;EACA,IAAMC,cAAc,GAAGC,uBAAuB,CAACJ,QAAQ,CAAC;EACxD,IAAMK,eAAe,GAAGC,MAAM,CAACC,IAAI,CAACJ,cAAc,CAAC,CAACK,MAAM,CAAC,UAACC,CAAC;IAAA,OAA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
-
8
7
  var _extractGeometryInfo = require("./extract-geometry-info");
9
-
10
8
  var _geojsonToFlatGeojson = require("./geojson-to-flat-geojson");
11
-
12
9
  var _flatGeojsonToBinary = require("./flat-geojson-to-binary");
13
-
14
10
  function geojsonToBinary(features) {
15
11
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
16
12
  fixRingWinding: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/geojson-to-binary.ts"],"names":["geojsonToBinary","features","options","fixRingWinding","geometryInfo","coordLength","flatFeatures","numericPropKeys","PositionDataType","Float32Array"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAkBO,SAASA,eAAT,CACLC,QADK,EAGW;AAAA,MADhBC,OACgB,uEADkB;AAACC,IAAAA,cAAc,EAAE;AAAjB,GAClB;AAChB,MAAMC,YAAY,GAAG,8CAAoBH,QAApB,CAArB;AACA,MAAMI,WAAW,GAAGD,YAAY,CAACC,WAAjC;AACA,MAAOF,cAAP,GAAyBD,OAAzB,CAAOC,cAAP;AACA,MAAMG,YAAY,GAAG,gDAAqBL,QAArB,EAA+B;AAACI,IAAAA,WAAW,EAAXA,WAAD;AAAcF,IAAAA,cAAc,EAAdA;AAAd,GAA/B,CAArB;AACA,SAAO,8CAAoBG,YAApB,EAAkCF,YAAlC,EAAgD;AACrDG,IAAAA,eAAe,EAAEL,OAAO,CAACK,eAD4B;AAErDC,IAAAA,gBAAgB,EAAEN,OAAO,CAACM,gBAAR,IAA4BC;AAFO,GAAhD,CAAP;AAID","sourcesContent":["import type {Feature} from '@loaders.gl/schema';\nimport type {BinaryFeatures} from '@loaders.gl/schema';\n\nimport {extractGeometryInfo} from './extract-geometry-info';\nimport {geojsonToFlatGeojson} from './geojson-to-flat-geojson';\nimport {flatGeojsonToBinary} from './flat-geojson-to-binary';\n\n/**\n * Options for `geojsonToBinary`\n */\nexport type GeojsonToBinaryOptions = {\n fixRingWinding: boolean;\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\n/**\n * Convert GeoJSON features to flat binary arrays\n *\n * @param features\n * @param options\n * @returns features in binary format, grouped by geometry type\n */\nexport function geojsonToBinary(\n features: Feature[],\n options: GeojsonToBinaryOptions = {fixRingWinding: true}\n): BinaryFeatures {\n const geometryInfo = extractGeometryInfo(features);\n const coordLength = geometryInfo.coordLength;\n const {fixRingWinding} = options;\n const flatFeatures = geojsonToFlatGeojson(features, {coordLength, fixRingWinding});\n return flatGeojsonToBinary(flatFeatures, geometryInfo, {\n numericPropKeys: options.numericPropKeys,\n PositionDataType: options.PositionDataType || Float32Array\n });\n}\n"],"file":"geojson-to-binary.js"}
1
+ {"version":3,"file":"geojson-to-binary.js","names":["geojsonToBinary","features","options","fixRingWinding","geometryInfo","extractGeometryInfo","coordLength","flatFeatures","geojsonToFlatGeojson","flatGeojsonToBinary","numericPropKeys","PositionDataType","Float32Array"],"sources":["../../../src/lib/geojson-to-binary.ts"],"sourcesContent":["import type {Feature} from '@loaders.gl/schema';\nimport type {BinaryFeatures} from '@loaders.gl/schema';\n\nimport {extractGeometryInfo} from './extract-geometry-info';\nimport {geojsonToFlatGeojson} from './geojson-to-flat-geojson';\nimport {flatGeojsonToBinary} from './flat-geojson-to-binary';\n\n/**\n * Options for `geojsonToBinary`\n */\nexport type GeojsonToBinaryOptions = {\n fixRingWinding: boolean;\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\n/**\n * Convert GeoJSON features to flat binary arrays\n *\n * @param features\n * @param options\n * @returns features in binary format, grouped by geometry type\n */\nexport function geojsonToBinary(\n features: Feature[],\n options: GeojsonToBinaryOptions = {fixRingWinding: true}\n): BinaryFeatures {\n const geometryInfo = extractGeometryInfo(features);\n const coordLength = geometryInfo.coordLength;\n const {fixRingWinding} = options;\n const flatFeatures = geojsonToFlatGeojson(features, {coordLength, fixRingWinding});\n return flatGeojsonToBinary(flatFeatures, geometryInfo, {\n numericPropKeys: options.numericPropKeys,\n PositionDataType: options.PositionDataType || Float32Array\n });\n}\n"],"mappings":";;;;;;AAGA;AACA;AACA;AAkBO,SAASA,eAAe,CAC7BC,QAAmB,EAEH;EAAA,IADhBC,OAA+B,uEAAG;IAACC,cAAc,EAAE;EAAI,CAAC;EAExD,IAAMC,YAAY,GAAG,IAAAC,wCAAmB,EAACJ,QAAQ,CAAC;EAClD,IAAMK,WAAW,GAAGF,YAAY,CAACE,WAAW;EAC5C,IAAOH,cAAc,GAAID,OAAO,CAAzBC,cAAc;EACrB,IAAMI,YAAY,GAAG,IAAAC,0CAAoB,EAACP,QAAQ,EAAE;IAACK,WAAW,EAAXA,WAAW;IAAEH,cAAc,EAAdA;EAAc,CAAC,CAAC;EAClF,OAAO,IAAAM,wCAAmB,EAACF,YAAY,EAAEH,YAAY,EAAE;IACrDM,eAAe,EAAER,OAAO,CAACQ,eAAe;IACxCC,gBAAgB,EAAET,OAAO,CAACS,gBAAgB,IAAIC;EAChD,CAAC,CAAC;AACJ"}
@@ -1,28 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.geojsonToFlatGeojson = geojsonToFlatGeojson;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
-
14
10
  var _polygon = require("@math.gl/polygon");
15
-
16
- 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; }
17
-
18
- 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; }
19
-
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
20
13
  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; } } }; }
21
-
22
14
  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); }
23
-
24
15
  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; }
25
-
26
16
  function geojsonToFlatGeojson(features) {
27
17
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
28
18
  coordLength: 2,
@@ -44,10 +34,8 @@ function flattenPoint(coordinates, data, indices, options) {
44
34
 
45
35
  function flattenLineString(coordinates, data, indices, options) {
46
36
  indices.push(data.length);
47
-
48
37
  var _iterator = _createForOfIteratorHelper(coordinates),
49
- _step;
50
-
38
+ _step;
51
39
  try {
52
40
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
53
41
  var c = _step.value;
@@ -68,10 +56,8 @@ function flattenPolygon(coordinates, data, indices, areas, options) {
68
56
  var count = 0;
69
57
  var ringAreas = [];
70
58
  var polygons = [];
71
-
72
59
  var _iterator2 = _createForOfIteratorHelper(coordinates),
73
- _step2;
74
-
60
+ _step2;
75
61
  try {
76
62
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
77
63
  var lineString = _step2.value;
@@ -85,7 +71,6 @@ function flattenPolygon(coordinates, data, indices, areas, options) {
85
71
  lineString.reverse();
86
72
  area = -area;
87
73
  }
88
-
89
74
  ringAreas.push(area);
90
75
  flattenLineString(lineString, data, polygons, options);
91
76
  count++;
@@ -95,7 +80,6 @@ function flattenPolygon(coordinates, data, indices, areas, options) {
95
80
  } finally {
96
81
  _iterator2.f();
97
82
  }
98
-
99
83
  if (count > 0) {
100
84
  areas.push(ringAreas);
101
85
  indices.push(polygons);
@@ -104,47 +88,39 @@ function flattenPolygon(coordinates, data, indices, areas, options) {
104
88
 
105
89
  function flattenFeature(feature, options) {
106
90
  var geometry = feature.geometry;
107
-
108
91
  if (geometry.type === 'GeometryCollection') {
109
92
  throw new Error('GeometryCollection type not supported');
110
93
  }
111
-
112
94
  var data = [];
113
95
  var indices = [];
114
96
  var areas;
115
97
  var type;
116
-
117
98
  switch (geometry.type) {
118
99
  case 'Point':
119
100
  type = 'Point';
120
101
  flattenPoint(geometry.coordinates, data, indices, options);
121
102
  break;
122
-
123
103
  case 'MultiPoint':
124
104
  type = 'Point';
125
105
  geometry.coordinates.map(function (c) {
126
106
  return flattenPoint(c, data, indices, options);
127
107
  });
128
108
  break;
129
-
130
109
  case 'LineString':
131
110
  type = 'LineString';
132
111
  flattenLineString(geometry.coordinates, data, indices, options);
133
112
  break;
134
-
135
113
  case 'MultiLineString':
136
114
  type = 'LineString';
137
115
  geometry.coordinates.map(function (c) {
138
116
  return flattenLineString(c, data, indices, options);
139
117
  });
140
118
  break;
141
-
142
119
  case 'Polygon':
143
120
  type = 'Polygon';
144
121
  areas = [];
145
122
  flattenPolygon(geometry.coordinates, data, indices, areas, options);
146
123
  break;
147
-
148
124
  case 'MultiPolygon':
149
125
  type = 'Polygon';
150
126
  areas = [];
@@ -152,11 +128,9 @@ function flattenFeature(feature, options) {
152
128
  return flattenPolygon(c, data, indices, areas, options);
153
129
  });
154
130
  break;
155
-
156
131
  default:
157
132
  throw new Error("Unknown type: ".concat(type));
158
133
  }
159
-
160
134
  return _objectSpread(_objectSpread({}, feature), {}, {
161
135
  geometry: {
162
136
  type: type,