@loaders.gl/gis 3.1.0 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/es5/index.js +16 -0
  2. package/dist/es5/index.js.map +1 -1
  3. package/dist/es5/lib/extract-geometry-info.js +204 -0
  4. package/dist/es5/lib/extract-geometry-info.js.map +1 -0
  5. package/dist/es5/lib/flat-geojson-to-binary-types.js +2 -0
  6. package/dist/es5/lib/flat-geojson-to-binary-types.js.map +1 -0
  7. package/dist/es5/lib/flat-geojson-to-binary.js +397 -0
  8. package/dist/es5/lib/flat-geojson-to-binary.js.map +1 -0
  9. package/dist/es5/lib/geojson-to-binary.js +15 -579
  10. package/dist/es5/lib/geojson-to-binary.js.map +1 -1
  11. package/dist/es5/lib/geojson-to-flat-geojson.js +169 -0
  12. package/dist/es5/lib/geojson-to-flat-geojson.js.map +1 -0
  13. package/dist/esm/index.js +2 -0
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/lib/extract-geometry-info.js +105 -0
  16. package/dist/esm/lib/extract-geometry-info.js.map +1 -0
  17. package/dist/esm/lib/flat-geojson-to-binary-types.js +2 -0
  18. package/dist/esm/lib/flat-geojson-to-binary-types.js.map +1 -0
  19. package/dist/esm/lib/flat-geojson-to-binary.js +339 -0
  20. package/dist/esm/lib/flat-geojson-to-binary.js.map +1 -0
  21. package/dist/esm/lib/geojson-to-binary.js +17 -410
  22. package/dist/esm/lib/geojson-to-binary.js.map +1 -1
  23. package/dist/esm/lib/geojson-to-flat-geojson.js +116 -0
  24. package/dist/esm/lib/geojson-to-flat-geojson.js.map +1 -0
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +5 -1
  28. package/dist/lib/extract-geometry-info.d.ts +8 -0
  29. package/dist/lib/extract-geometry-info.d.ts.map +1 -0
  30. package/dist/lib/extract-geometry-info.js +96 -0
  31. package/dist/lib/flat-geojson-to-binary-types.d.ts +58 -0
  32. package/dist/lib/flat-geojson-to-binary-types.d.ts.map +1 -0
  33. package/dist/lib/flat-geojson-to-binary-types.js +2 -0
  34. package/dist/lib/flat-geojson-to-binary.d.ts +37 -0
  35. package/dist/lib/flat-geojson-to-binary.d.ts.map +1 -0
  36. package/dist/lib/flat-geojson-to-binary.js +375 -0
  37. package/dist/lib/geojson-to-binary.d.ts +12 -36
  38. package/dist/lib/geojson-to-binary.d.ts.map +1 -1
  39. package/dist/lib/geojson-to-binary.js +18 -360
  40. package/dist/lib/geojson-to-flat-geojson.d.ts +17 -0
  41. package/dist/lib/geojson-to-flat-geojson.d.ts.map +1 -0
  42. package/dist/lib/geojson-to-flat-geojson.js +128 -0
  43. package/package.json +5 -4
  44. package/src/index.ts +2 -0
  45. package/src/lib/extract-geometry-info.ts +101 -0
  46. package/src/lib/flat-geojson-to-binary-types.ts +58 -0
  47. package/src/lib/flat-geojson-to-binary.ts +564 -0
  48. package/src/lib/geojson-to-binary.ts +24 -459
  49. package/src/lib/geojson-to-flat-geojson.ts +171 -0
package/dist/es5/index.js CHANGED
@@ -3,12 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "flatGeojsonToBinary", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _flatGeojsonToBinary.flatGeojsonToBinary;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "geojsonToBinary", {
7
13
  enumerable: true,
8
14
  get: function get() {
9
15
  return _geojsonToBinary.geojsonToBinary;
10
16
  }
11
17
  });
18
+ Object.defineProperty(exports, "geojsonToFlatGeojson", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _geojsonToFlatGeojson.geojsonToFlatGeojson;
22
+ }
23
+ });
12
24
  Object.defineProperty(exports, "binaryToGeojson", {
13
25
  enumerable: true,
14
26
  get: function get() {
@@ -40,8 +52,12 @@ Object.defineProperty(exports, "transformGeoJsonCoords", {
40
52
  }
41
53
  });
42
54
 
55
+ var _flatGeojsonToBinary = require("./lib/flat-geojson-to-binary");
56
+
43
57
  var _geojsonToBinary = require("./lib/geojson-to-binary");
44
58
 
59
+ var _geojsonToFlatGeojson = require("./lib/geojson-to-flat-geojson");
60
+
45
61
  var _binaryToGeojson = require("./lib/binary-to-geojson");
46
62
 
47
63
  var _transform = require("./lib/transform");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA","sourcesContent":["// Types from `@loaders.gl/schema`\n\n// Functions\nexport {geojsonToBinary} from './lib/geojson-to-binary';\nexport {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA","sourcesContent":["// Types from `@loaders.gl/schema`\n\n// Functions\nexport {flatGeojsonToBinary} from './lib/flat-geojson-to-binary';\nexport {geojsonToBinary} from './lib/geojson-to-binary';\nexport {geojsonToFlatGeojson} from './lib/geojson-to-flat-geojson';\nexport {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"file":"index.js"}
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.extractGeometryInfo = extractGeometryInfo;
9
+
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+
12
+ 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; } } }; }
13
+
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); }
15
+
16
+ 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; }
17
+
18
+ function extractGeometryInfo(features) {
19
+ var pointPositionsCount = 0;
20
+ var pointFeaturesCount = 0;
21
+ var linePositionsCount = 0;
22
+ var linePathsCount = 0;
23
+ var lineFeaturesCount = 0;
24
+ var polygonPositionsCount = 0;
25
+ var polygonObjectsCount = 0;
26
+ var polygonRingsCount = 0;
27
+ var polygonFeaturesCount = 0;
28
+ var coordLengths = new Set();
29
+
30
+ var _iterator = _createForOfIteratorHelper(features),
31
+ _step;
32
+
33
+ try {
34
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
35
+ var feature = _step.value;
36
+ var geometry = feature.geometry;
37
+
38
+ switch (geometry.type) {
39
+ case 'Point':
40
+ pointFeaturesCount++;
41
+ pointPositionsCount++;
42
+ coordLengths.add(geometry.coordinates.length);
43
+ break;
44
+
45
+ case 'MultiPoint':
46
+ pointFeaturesCount++;
47
+ pointPositionsCount += geometry.coordinates.length;
48
+
49
+ var _iterator2 = _createForOfIteratorHelper(geometry.coordinates),
50
+ _step2;
51
+
52
+ try {
53
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
54
+ var point = _step2.value;
55
+ coordLengths.add(point.length);
56
+ }
57
+ } catch (err) {
58
+ _iterator2.e(err);
59
+ } finally {
60
+ _iterator2.f();
61
+ }
62
+
63
+ break;
64
+
65
+ case 'LineString':
66
+ lineFeaturesCount++;
67
+ linePositionsCount += geometry.coordinates.length;
68
+ linePathsCount++;
69
+
70
+ var _iterator3 = _createForOfIteratorHelper(geometry.coordinates),
71
+ _step3;
72
+
73
+ try {
74
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
75
+ var coord = _step3.value;
76
+ coordLengths.add(coord.length);
77
+ }
78
+ } catch (err) {
79
+ _iterator3.e(err);
80
+ } finally {
81
+ _iterator3.f();
82
+ }
83
+
84
+ break;
85
+
86
+ case 'MultiLineString':
87
+ lineFeaturesCount++;
88
+
89
+ var _iterator4 = _createForOfIteratorHelper(geometry.coordinates),
90
+ _step4;
91
+
92
+ try {
93
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
94
+ var line = _step4.value;
95
+ linePositionsCount += line.length;
96
+ linePathsCount++;
97
+
98
+ var _iterator5 = _createForOfIteratorHelper(line),
99
+ _step5;
100
+
101
+ try {
102
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
103
+ var _coord = _step5.value;
104
+ coordLengths.add(_coord.length);
105
+ }
106
+ } catch (err) {
107
+ _iterator5.e(err);
108
+ } finally {
109
+ _iterator5.f();
110
+ }
111
+ }
112
+ } catch (err) {
113
+ _iterator4.e(err);
114
+ } finally {
115
+ _iterator4.f();
116
+ }
117
+
118
+ break;
119
+
120
+ case 'Polygon':
121
+ polygonFeaturesCount++;
122
+ polygonObjectsCount++;
123
+ polygonRingsCount += geometry.coordinates.length;
124
+ var flattened = geometry.coordinates.flat();
125
+ polygonPositionsCount += flattened.length;
126
+
127
+ var _iterator6 = _createForOfIteratorHelper(flattened),
128
+ _step6;
129
+
130
+ try {
131
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
132
+ var _coord2 = _step6.value;
133
+ coordLengths.add(_coord2.length);
134
+ }
135
+ } catch (err) {
136
+ _iterator6.e(err);
137
+ } finally {
138
+ _iterator6.f();
139
+ }
140
+
141
+ break;
142
+
143
+ case 'MultiPolygon':
144
+ polygonFeaturesCount++;
145
+
146
+ var _iterator7 = _createForOfIteratorHelper(geometry.coordinates),
147
+ _step7;
148
+
149
+ try {
150
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
151
+ var polygon = _step7.value;
152
+ polygonObjectsCount++;
153
+ polygonRingsCount += polygon.length;
154
+
155
+ var _flattened = polygon.flat();
156
+
157
+ polygonPositionsCount += _flattened.length;
158
+
159
+ var _iterator8 = _createForOfIteratorHelper(_flattened),
160
+ _step8;
161
+
162
+ try {
163
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
164
+ var _coord3 = _step8.value;
165
+ coordLengths.add(_coord3.length);
166
+ }
167
+ } catch (err) {
168
+ _iterator8.e(err);
169
+ } finally {
170
+ _iterator8.f();
171
+ }
172
+ }
173
+ } catch (err) {
174
+ _iterator7.e(err);
175
+ } finally {
176
+ _iterator7.f();
177
+ }
178
+
179
+ break;
180
+
181
+ default:
182
+ throw new Error("Unsupported geometry type: ".concat(geometry.type));
183
+ }
184
+ }
185
+ } catch (err) {
186
+ _iterator.e(err);
187
+ } finally {
188
+ _iterator.f();
189
+ }
190
+
191
+ return {
192
+ coordLength: coordLengths.size > 0 ? Math.max.apply(Math, (0, _toConsumableArray2.default)(coordLengths)) : 2,
193
+ pointPositionsCount: pointPositionsCount,
194
+ pointFeaturesCount: pointFeaturesCount,
195
+ linePositionsCount: linePositionsCount,
196
+ linePathsCount: linePathsCount,
197
+ lineFeaturesCount: lineFeaturesCount,
198
+ polygonPositionsCount: polygonPositionsCount,
199
+ polygonObjectsCount: polygonObjectsCount,
200
+ polygonRingsCount: polygonRingsCount,
201
+ polygonFeaturesCount: polygonFeaturesCount
202
+ };
203
+ }
204
+ //# sourceMappingURL=extract-geometry-info.js.map
@@ -0,0 +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;;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IAAAA,mBAAmB,EAAnBA,mBATK;AAULC,IAAAA,iBAAiB,EAAjBA,iBAVK;AAWLC,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"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=flat-geojson-to-binary-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"flat-geojson-to-binary-types.js"}
@@ -0,0 +1,397 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.flatGeojsonToBinary = flatGeojsonToBinary;
9
+ exports.TEST_EXPORTS = void 0;
10
+
11
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
+
13
+ var _polygon = require("@math.gl/polygon");
14
+
15
+ 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
+ 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
+ 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
+
25
+ function flatGeojsonToBinary(features, geometryInfo, options) {
26
+ var propArrayTypes = extractNumericPropTypes(features);
27
+ var numericPropKeys = Object.keys(propArrayTypes).filter(function (k) {
28
+ return propArrayTypes[k] !== Array;
29
+ });
30
+ return fillArrays(features, _objectSpread({
31
+ propArrayTypes: propArrayTypes
32
+ }, geometryInfo), {
33
+ numericPropKeys: options && options.numericPropKeys || numericPropKeys,
34
+ PositionDataType: options ? options.PositionDataType : Float32Array
35
+ });
36
+ }
37
+
38
+ var TEST_EXPORTS = {
39
+ extractNumericPropTypes: extractNumericPropTypes
40
+ };
41
+ exports.TEST_EXPORTS = TEST_EXPORTS;
42
+
43
+ function extractNumericPropTypes(features) {
44
+ var propArrayTypes = {};
45
+
46
+ var _iterator = _createForOfIteratorHelper(features),
47
+ _step;
48
+
49
+ try {
50
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
51
+ var feature = _step.value;
52
+
53
+ if (feature.properties) {
54
+ for (var _key in feature.properties) {
55
+ var val = feature.properties[_key];
56
+ propArrayTypes[_key] = deduceArrayType(val, propArrayTypes[_key]);
57
+ }
58
+ }
59
+ }
60
+ } catch (err) {
61
+ _iterator.e(err);
62
+ } finally {
63
+ _iterator.f();
64
+ }
65
+
66
+ return propArrayTypes;
67
+ }
68
+
69
+ function fillArrays(features, geometryInfo, options) {
70
+ 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;
81
+ 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;
85
+ var hasGlobalId = features[0] && 'id' in features[0];
86
+ var GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
87
+ var points = {
88
+ type: 'Point',
89
+ positions: new PositionDataType(pointPositionsCount * coordLength),
90
+ globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
91
+ featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
92
+ numericProps: {},
93
+ properties: [],
94
+ fields: []
95
+ };
96
+ var lines = {
97
+ type: 'LineString',
98
+ pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
99
+ positions: new PositionDataType(linePositionsCount * coordLength),
100
+ globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
101
+ featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
102
+ numericProps: {},
103
+ properties: [],
104
+ fields: []
105
+ };
106
+ var polygons = {
107
+ type: 'Polygon',
108
+ polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
109
+ primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
110
+ positions: new PositionDataType(polygonPositionsCount * coordLength),
111
+ triangles: [],
112
+ globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
113
+ featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
114
+ numericProps: {},
115
+ properties: [],
116
+ fields: []
117
+ };
118
+
119
+ for (var _i = 0, _arr = [points, lines, polygons]; _i < _arr.length; _i++) {
120
+ var object = _arr[_i];
121
+
122
+ var _iterator2 = _createForOfIteratorHelper(numericPropKeys),
123
+ _step2;
124
+
125
+ try {
126
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
127
+ var propName = _step2.value;
128
+ var T = propArrayTypes[propName];
129
+ object.numericProps[propName] = new T(object.positions.length / coordLength);
130
+ }
131
+ } catch (err) {
132
+ _iterator2.e(err);
133
+ } finally {
134
+ _iterator2.f();
135
+ }
136
+ }
137
+
138
+ lines.pathIndices[linePathsCount] = linePositionsCount;
139
+ polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
140
+ polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
141
+ var indexMap = {
142
+ pointPosition: 0,
143
+ pointFeature: 0,
144
+ linePosition: 0,
145
+ linePath: 0,
146
+ lineFeature: 0,
147
+ polygonPosition: 0,
148
+ polygonObject: 0,
149
+ polygonRing: 0,
150
+ polygonFeature: 0,
151
+ feature: 0
152
+ };
153
+
154
+ var _iterator3 = _createForOfIteratorHelper(features),
155
+ _step3;
156
+
157
+ try {
158
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
159
+ var feature = _step3.value;
160
+ var geometry = feature.geometry;
161
+ var properties = feature.properties || {};
162
+
163
+ switch (geometry.type) {
164
+ case 'Point':
165
+ handlePoint(geometry, points, indexMap, coordLength, properties);
166
+ points.properties.push(keepStringProperties(properties, numericPropKeys));
167
+
168
+ if (hasGlobalId) {
169
+ points.fields.push({
170
+ id: feature.id
171
+ });
172
+ }
173
+
174
+ indexMap.pointFeature++;
175
+ break;
176
+
177
+ case 'LineString':
178
+ handleLineString(geometry, lines, indexMap, coordLength, properties);
179
+ lines.properties.push(keepStringProperties(properties, numericPropKeys));
180
+
181
+ if (hasGlobalId) {
182
+ lines.fields.push({
183
+ id: feature.id
184
+ });
185
+ }
186
+
187
+ indexMap.lineFeature++;
188
+ break;
189
+
190
+ case 'Polygon':
191
+ handlePolygon(geometry, polygons, indexMap, coordLength, properties);
192
+ polygons.properties.push(keepStringProperties(properties, numericPropKeys));
193
+
194
+ if (hasGlobalId) {
195
+ polygons.fields.push({
196
+ id: feature.id
197
+ });
198
+ }
199
+
200
+ indexMap.polygonFeature++;
201
+ break;
202
+
203
+ default:
204
+ throw new Error('Invalid geometry type');
205
+ }
206
+
207
+ indexMap.feature++;
208
+ }
209
+ } catch (err) {
210
+ _iterator3.e(err);
211
+ } finally {
212
+ _iterator3.f();
213
+ }
214
+
215
+ return makeAccessorObjects(points, lines, polygons, coordLength);
216
+ }
217
+
218
+ function handlePoint(geometry, points, indexMap, coordLength, properties) {
219
+ points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
220
+ var nPositions = geometry.data.length / coordLength;
221
+ fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
222
+ points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
223
+ points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
224
+ indexMap.pointPosition += nPositions;
225
+ }
226
+
227
+ function handleLineString(geometry, lines, indexMap, coordLength, properties) {
228
+ lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
229
+ var nPositions = geometry.data.length / coordLength;
230
+ fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
231
+ lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
232
+ lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
233
+
234
+ for (var i = 0, il = geometry.indices.length; i < il; ++i) {
235
+ var start = geometry.indices[i];
236
+ var end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
237
+ lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
238
+ indexMap.linePosition += (end - start) / coordLength;
239
+ }
240
+ }
241
+
242
+ function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
243
+ polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
244
+ var nPositions = geometry.data.length / coordLength;
245
+ fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
246
+ polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
247
+ polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
248
+
249
+ for (var l = 0, ll = geometry.indices.length; l < ll; ++l) {
250
+ var startPosition = indexMap.polygonPosition;
251
+ polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
252
+ var areas = geometry.areas[l];
253
+ var indices = geometry.indices[l];
254
+ var nextIndices = geometry.indices[l + 1];
255
+
256
+ for (var i = 0, il = indices.length; i < il; ++i) {
257
+ var start = indices[i];
258
+ var end = i === il - 1 ? nextIndices === undefined ? geometry.data.length : nextIndices[0] : indices[i + 1];
259
+ polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
260
+ indexMap.polygonPosition += (end - start) / coordLength;
261
+ }
262
+
263
+ var endPosition = indexMap.polygonPosition;
264
+ triangulatePolygon(polygons, areas, indices, {
265
+ startPosition: startPosition,
266
+ endPosition: endPosition,
267
+ coordLength: coordLength
268
+ });
269
+ }
270
+ }
271
+
272
+ function triangulatePolygon(polygons, areas, indices, _ref) {
273
+ var startPosition = _ref.startPosition,
274
+ endPosition = _ref.endPosition,
275
+ coordLength = _ref.coordLength;
276
+ var start = startPosition * coordLength;
277
+ var end = endPosition * coordLength;
278
+ var polygonPositions = polygons.positions.subarray(start, end);
279
+ var offset = indices[0];
280
+ var holes = indices.slice(1).map(function (n) {
281
+ return (n - offset) / coordLength;
282
+ });
283
+ var triangles = (0, _polygon.earcut)(polygonPositions, holes, coordLength, areas);
284
+
285
+ for (var t = 0, tl = triangles.length; t < tl; ++t) {
286
+ polygons.triangles.push(startPosition + triangles[t]);
287
+ }
288
+ }
289
+
290
+ function wrapProps(obj, size) {
291
+ var returnObj = {};
292
+
293
+ for (var _key2 in obj) {
294
+ returnObj[_key2] = {
295
+ value: obj[_key2],
296
+ size: size
297
+ };
298
+ }
299
+
300
+ return returnObj;
301
+ }
302
+
303
+ function makeAccessorObjects(points, lines, polygons, coordLength) {
304
+ return {
305
+ points: _objectSpread(_objectSpread({}, points), {}, {
306
+ positions: {
307
+ value: points.positions,
308
+ size: coordLength
309
+ },
310
+ globalFeatureIds: {
311
+ value: points.globalFeatureIds,
312
+ size: 1
313
+ },
314
+ featureIds: {
315
+ value: points.featureIds,
316
+ size: 1
317
+ },
318
+ numericProps: wrapProps(points.numericProps, 1)
319
+ }),
320
+ lines: _objectSpread(_objectSpread({}, lines), {}, {
321
+ positions: {
322
+ value: lines.positions,
323
+ size: coordLength
324
+ },
325
+ pathIndices: {
326
+ value: lines.pathIndices,
327
+ size: 1
328
+ },
329
+ globalFeatureIds: {
330
+ value: lines.globalFeatureIds,
331
+ size: 1
332
+ },
333
+ featureIds: {
334
+ value: lines.featureIds,
335
+ size: 1
336
+ },
337
+ numericProps: wrapProps(lines.numericProps, 1)
338
+ }),
339
+ polygons: _objectSpread(_objectSpread({}, polygons), {}, {
340
+ positions: {
341
+ value: polygons.positions,
342
+ size: coordLength
343
+ },
344
+ polygonIndices: {
345
+ value: polygons.polygonIndices,
346
+ size: 1
347
+ },
348
+ primitivePolygonIndices: {
349
+ value: polygons.primitivePolygonIndices,
350
+ size: 1
351
+ },
352
+ triangles: {
353
+ value: new Uint32Array(polygons.triangles),
354
+ size: 1
355
+ },
356
+ globalFeatureIds: {
357
+ value: polygons.globalFeatureIds,
358
+ size: 1
359
+ },
360
+ featureIds: {
361
+ value: polygons.featureIds,
362
+ size: 1
363
+ },
364
+ numericProps: wrapProps(polygons.numericProps, 1)
365
+ })
366
+ };
367
+ }
368
+
369
+ function fillNumericProperties(object, properties, index, length) {
370
+ for (var numericPropName in object.numericProps) {
371
+ if (numericPropName in properties) {
372
+ var value = properties[numericPropName];
373
+ object.numericProps[numericPropName].fill(value, index, index + length);
374
+ }
375
+ }
376
+ }
377
+
378
+ function keepStringProperties(properties, numericKeys) {
379
+ var props = {};
380
+
381
+ for (var _key3 in properties) {
382
+ if (!numericKeys.includes(_key3)) {
383
+ props[_key3] = properties[_key3];
384
+ }
385
+ }
386
+
387
+ return props;
388
+ }
389
+
390
+ function deduceArrayType(x, constructor) {
391
+ if (constructor === Array || !Number.isFinite(x)) {
392
+ return Array;
393
+ }
394
+
395
+ return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
396
+ }
397
+ //# sourceMappingURL=flat-geojson-to-binary.js.map