@loaders.gl/shapefile 3.1.0-alpha.4 → 3.1.0-beta.3

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 (110) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +7554 -0
  4. package/dist/dbf-loader.d.ts +8 -0
  5. package/dist/dbf-loader.d.ts.map +1 -0
  6. package/dist/dbf-loader.js +32 -0
  7. package/dist/dbf-worker.js +912 -2
  8. package/dist/es5/bundle.js +1 -1
  9. package/dist/es5/bundle.js.map +1 -1
  10. package/dist/es5/dbf-loader.js +5 -40
  11. package/dist/es5/dbf-loader.js.map +1 -1
  12. package/dist/es5/index.js +5 -5
  13. package/dist/es5/lib/parsers/parse-dbf.js +86 -232
  14. package/dist/es5/lib/parsers/parse-dbf.js.map +1 -1
  15. package/dist/es5/lib/parsers/parse-shapefile.js +151 -404
  16. package/dist/es5/lib/parsers/parse-shapefile.js.map +1 -1
  17. package/dist/es5/lib/parsers/parse-shp-geometry.js +49 -96
  18. package/dist/es5/lib/parsers/parse-shp-geometry.js.map +1 -1
  19. package/dist/es5/lib/parsers/parse-shp-header.js +4 -4
  20. package/dist/es5/lib/parsers/parse-shp-header.js.map +1 -1
  21. package/dist/es5/lib/parsers/parse-shp.js +47 -165
  22. package/dist/es5/lib/parsers/parse-shp.js.map +1 -1
  23. package/dist/es5/lib/parsers/parse-shx.js +11 -11
  24. package/dist/es5/lib/parsers/parse-shx.js.map +1 -1
  25. package/dist/es5/lib/streaming/binary-chunk-reader.js +99 -172
  26. package/dist/es5/lib/streaming/binary-chunk-reader.js.map +1 -1
  27. package/dist/es5/lib/streaming/binary-reader.js +24 -35
  28. package/dist/es5/lib/streaming/binary-reader.js.map +1 -1
  29. package/dist/es5/lib/streaming/zip-batch-iterators.js +37 -96
  30. package/dist/es5/lib/streaming/zip-batch-iterators.js.map +1 -1
  31. package/dist/es5/shapefile-loader.js +3 -3
  32. package/dist/es5/shapefile-loader.js.map +1 -1
  33. package/dist/es5/shp-loader.js +6 -41
  34. package/dist/es5/shp-loader.js.map +1 -1
  35. package/dist/es5/workers/dbf-worker.js +7 -3
  36. package/dist/es5/workers/dbf-worker.js.map +1 -0
  37. package/dist/es5/workers/shp-worker.js +7 -3
  38. package/dist/es5/workers/shp-worker.js.map +1 -0
  39. package/dist/esm/dbf-loader.js +1 -1
  40. package/dist/esm/dbf-loader.js.map +1 -1
  41. package/dist/esm/lib/parsers/parse-dbf.js +4 -6
  42. package/dist/esm/lib/parsers/parse-dbf.js.map +1 -1
  43. package/dist/esm/lib/parsers/parse-shapefile.js +1 -1
  44. package/dist/esm/lib/parsers/parse-shapefile.js.map +1 -1
  45. package/dist/esm/lib/parsers/parse-shp-geometry.js +1 -1
  46. package/dist/esm/lib/parsers/parse-shp-geometry.js.map +1 -1
  47. package/dist/esm/lib/parsers/parse-shp-header.js +2 -2
  48. package/dist/esm/lib/parsers/parse-shp-header.js.map +1 -1
  49. package/dist/esm/lib/parsers/parse-shp.js +2 -2
  50. package/dist/esm/lib/parsers/parse-shp.js.map +1 -1
  51. package/dist/esm/shapefile-loader.js +1 -1
  52. package/dist/esm/shapefile-loader.js.map +1 -1
  53. package/dist/esm/shp-loader.js +1 -1
  54. package/dist/esm/shp-loader.js.map +1 -1
  55. package/dist/esm/workers/dbf-worker.js +3 -3
  56. package/dist/esm/workers/dbf-worker.js.map +1 -0
  57. package/dist/esm/workers/shp-worker.js +3 -3
  58. package/dist/esm/workers/shp-worker.js.map +1 -0
  59. package/dist/index.d.ts +4 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +11 -0
  62. package/dist/lib/parsers/parse-dbf.d.ts +28 -0
  63. package/dist/lib/parsers/parse-dbf.d.ts.map +1 -0
  64. package/dist/lib/parsers/parse-dbf.js +335 -0
  65. package/dist/lib/parsers/parse-shapefile.d.ts +54 -0
  66. package/dist/lib/parsers/parse-shapefile.d.ts.map +1 -0
  67. package/dist/lib/parsers/parse-shapefile.js +245 -0
  68. package/dist/lib/parsers/parse-shp-geometry.d.ts +11 -0
  69. package/dist/lib/parsers/parse-shp-geometry.d.ts.map +1 -0
  70. package/dist/lib/parsers/parse-shp-geometry.js +287 -0
  71. package/dist/lib/parsers/parse-shp-header.d.ts +26 -0
  72. package/dist/lib/parsers/parse-shp-header.d.ts.map +1 -0
  73. package/dist/lib/parsers/parse-shp-header.js +43 -0
  74. package/dist/lib/parsers/parse-shp.d.ts +9 -0
  75. package/dist/lib/parsers/parse-shp.d.ts.map +1 -0
  76. package/dist/lib/parsers/parse-shp.js +170 -0
  77. package/dist/lib/parsers/parse-shx.d.ts +10 -0
  78. package/dist/lib/parsers/parse-shx.d.ts.map +1 -0
  79. package/dist/lib/parsers/parse-shx.js +28 -0
  80. package/dist/lib/streaming/binary-chunk-reader.d.ts +59 -0
  81. package/dist/lib/streaming/binary-chunk-reader.d.ts.map +1 -0
  82. package/dist/lib/streaming/binary-chunk-reader.js +161 -0
  83. package/dist/lib/streaming/binary-reader.d.ts +32 -0
  84. package/dist/lib/streaming/binary-reader.d.ts.map +1 -0
  85. package/dist/lib/streaming/binary-reader.js +52 -0
  86. package/dist/lib/streaming/zip-batch-iterators.d.ts +8 -0
  87. package/dist/lib/streaming/zip-batch-iterators.d.ts.map +1 -0
  88. package/dist/lib/streaming/zip-batch-iterators.js +61 -0
  89. package/dist/shapefile-loader.d.ts +26 -0
  90. package/dist/shapefile-loader.d.ts.map +1 -0
  91. package/dist/shapefile-loader.js +31 -0
  92. package/dist/shp-loader.d.ts +9 -0
  93. package/dist/shp-loader.d.ts.map +1 -0
  94. package/dist/shp-loader.js +35 -0
  95. package/dist/shp-worker.js +606 -2
  96. package/dist/workers/dbf-worker.d.ts +2 -0
  97. package/dist/workers/dbf-worker.d.ts.map +1 -0
  98. package/dist/workers/dbf-worker.js +5 -0
  99. package/dist/workers/shp-worker.d.ts +2 -0
  100. package/dist/workers/shp-worker.d.ts.map +1 -0
  101. package/dist/workers/shp-worker.js +5 -0
  102. package/package.json +10 -10
  103. package/src/lib/parsers/parse-dbf.ts +5 -3
  104. package/src/lib/parsers/parse-shp-geometry.ts +1 -1
  105. package/src/workers/{dbf-worker.js → dbf-worker.ts} +0 -0
  106. package/src/workers/{shp-worker.js → shp-worker.ts} +0 -0
  107. package/dist/dbf-worker.js.map +0 -1
  108. package/dist/dist.min.js +0 -2
  109. package/dist/dist.min.js.map +0 -1
  110. package/dist/shp-worker.js.map +0 -1
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -10,347 +8,150 @@ exports.parseShapefile = parseShapefile;
10
8
  exports.loadShapefileSidecarFiles = loadShapefileSidecarFiles;
11
9
  exports.replaceExtension = replaceExtension;
12
10
 
13
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+ var _gis = require("@loaders.gl/gis");
14
12
 
15
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+ var _proj = require("@math.gl/proj4");
16
14
 
17
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
+ var _parseShx = require("./parse-shx");
18
16
 
19
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
+ var _zipBatchIterators = require("../streaming/zip-batch-iterators");
20
18
 
21
- var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/awaitAsyncGenerator"));
19
+ var _shpLoader = require("../../shp-loader");
22
20
 
23
- var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
21
+ var _dbfLoader = require("../../dbf-loader");
24
22
 
25
- var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncIterator"));
23
+ async function* parseShapefileInBatches(asyncIterator, options, context) {
24
+ const {
25
+ reproject = false,
26
+ _targetCrs = 'WGS84'
27
+ } = (options === null || options === void 0 ? void 0 : options.gis) || {};
28
+ const {
29
+ shx,
30
+ cpg,
31
+ prj
32
+ } = await loadShapefileSidecarFiles(options, context);
33
+ const shapeIterable = await context.parseInBatches(asyncIterator, _shpLoader.SHPLoader, options);
34
+ let propertyIterable;
35
+ const dbfResponse = await context.fetch(replaceExtension((context === null || context === void 0 ? void 0 : context.url) || '', 'dbf'));
36
+
37
+ if (dbfResponse.ok) {
38
+ propertyIterable = await context.parseInBatches(dbfResponse, _dbfLoader.DBFLoader, { ...options,
39
+ dbf: {
40
+ encoding: cpg || 'latin1'
41
+ }
42
+ });
43
+ }
26
44
 
27
- var _gis = require("@loaders.gl/gis");
45
+ let shapeHeader = (await shapeIterable.next()).value;
28
46
 
29
- var _proj = require("@math.gl/proj4");
47
+ if (shapeHeader && shapeHeader.batchType === 'metadata') {
48
+ shapeHeader = (await shapeIterable.next()).value;
49
+ }
30
50
 
31
- var _parseShx = require("./parse-shx");
51
+ let dbfHeader = {};
32
52
 
33
- var _zipBatchIterators = require("../streaming/zip-batch-iterators");
53
+ if (propertyIterable) {
54
+ dbfHeader = (await propertyIterable.next()).value;
34
55
 
35
- var _shpLoader = require("../../shp-loader");
56
+ if (dbfHeader && dbfHeader.batchType === 'metadata') {
57
+ dbfHeader = (await propertyIterable.next()).value;
58
+ }
59
+ }
36
60
 
37
- var _dbfLoader = require("../../dbf-loader");
61
+ let iterator;
38
62
 
39
- 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; } } }; }
63
+ if (propertyIterable) {
64
+ iterator = (0, _zipBatchIterators.zipBatchIterators)(shapeIterable, propertyIterable);
65
+ } else {
66
+ iterator = shapeIterable;
67
+ }
40
68
 
41
- 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); }
69
+ for await (const item of iterator) {
70
+ let geometries;
71
+ let properties;
42
72
 
43
- 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; }
73
+ if (!propertyIterable) {
74
+ geometries = item;
75
+ } else {
76
+ [geometries, properties] = item;
77
+ }
44
78
 
45
- 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; }
79
+ const geojsonGeometries = parseGeometries(geometries);
80
+ let features = joinProperties(geojsonGeometries, properties);
46
81
 
47
- 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; }
82
+ if (reproject) {
83
+ features = reprojectFeatures(features, prj, _targetCrs);
84
+ }
48
85
 
49
- function parseShapefileInBatches(_x, _x2, _x3) {
50
- return _parseShapefileInBatches.apply(this, arguments);
86
+ yield {
87
+ encoding: cpg,
88
+ prj,
89
+ shx,
90
+ header: shapeHeader,
91
+ data: features
92
+ };
93
+ }
51
94
  }
52
95
 
53
- function _parseShapefileInBatches() {
54
- _parseShapefileInBatches = (0, _wrapAsyncGenerator2.default)(_regenerator.default.mark(function _callee(asyncIterator, options, context) {
55
- var _ref, _ref$reproject, reproject, _ref$_targetCrs, _targetCrs, _yield$_awaitAsyncGen, shx, cpg, prj, shapeIterable, propertyIterable, dbfResponse, shapeHeader, dbfHeader, iterator, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, item, geometries, properties, _item, geojsonGeometries, features;
56
-
57
- return _regenerator.default.wrap(function _callee$(_context) {
58
- while (1) {
59
- switch (_context.prev = _context.next) {
60
- case 0:
61
- _ref = (options === null || options === void 0 ? void 0 : options.gis) || {}, _ref$reproject = _ref.reproject, reproject = _ref$reproject === void 0 ? false : _ref$reproject, _ref$_targetCrs = _ref._targetCrs, _targetCrs = _ref$_targetCrs === void 0 ? 'WGS84' : _ref$_targetCrs;
62
- _context.next = 3;
63
- return (0, _awaitAsyncGenerator2.default)(loadShapefileSidecarFiles(options, context));
64
-
65
- case 3:
66
- _yield$_awaitAsyncGen = _context.sent;
67
- shx = _yield$_awaitAsyncGen.shx;
68
- cpg = _yield$_awaitAsyncGen.cpg;
69
- prj = _yield$_awaitAsyncGen.prj;
70
- _context.next = 9;
71
- return (0, _awaitAsyncGenerator2.default)(context.parseInBatches(asyncIterator, _shpLoader.SHPLoader, options));
72
-
73
- case 9:
74
- shapeIterable = _context.sent;
75
- _context.next = 12;
76
- return (0, _awaitAsyncGenerator2.default)(context.fetch(replaceExtension((context === null || context === void 0 ? void 0 : context.url) || '', 'dbf')));
77
-
78
- case 12:
79
- dbfResponse = _context.sent;
80
-
81
- if (!dbfResponse.ok) {
82
- _context.next = 17;
83
- break;
84
- }
85
-
86
- _context.next = 16;
87
- return (0, _awaitAsyncGenerator2.default)(context.parseInBatches(dbfResponse, _dbfLoader.DBFLoader, _objectSpread(_objectSpread({}, options), {}, {
88
- dbf: {
89
- encoding: cpg || 'latin1'
90
- }
91
- })));
92
-
93
- case 16:
94
- propertyIterable = _context.sent;
95
-
96
- case 17:
97
- _context.next = 19;
98
- return (0, _awaitAsyncGenerator2.default)(shapeIterable.next());
99
-
100
- case 19:
101
- shapeHeader = _context.sent.value;
102
-
103
- if (!(shapeHeader && shapeHeader.batchType === 'metadata')) {
104
- _context.next = 24;
105
- break;
106
- }
107
-
108
- _context.next = 23;
109
- return (0, _awaitAsyncGenerator2.default)(shapeIterable.next());
110
-
111
- case 23:
112
- shapeHeader = _context.sent.value;
113
-
114
- case 24:
115
- dbfHeader = {};
116
-
117
- if (!propertyIterable) {
118
- _context.next = 33;
119
- break;
120
- }
121
-
122
- _context.next = 28;
123
- return (0, _awaitAsyncGenerator2.default)(propertyIterable.next());
124
-
125
- case 28:
126
- dbfHeader = _context.sent.value;
127
-
128
- if (!(dbfHeader && dbfHeader.batchType === 'metadata')) {
129
- _context.next = 33;
130
- break;
131
- }
132
-
133
- _context.next = 32;
134
- return (0, _awaitAsyncGenerator2.default)(propertyIterable.next());
135
-
136
- case 32:
137
- dbfHeader = _context.sent.value;
138
-
139
- case 33:
140
- if (propertyIterable) {
141
- iterator = (0, _zipBatchIterators.zipBatchIterators)(shapeIterable, propertyIterable);
142
- } else {
143
- iterator = shapeIterable;
144
- }
145
-
146
- _iteratorNormalCompletion = true;
147
- _didIteratorError = false;
148
- _context.prev = 36;
149
- _iterator = (0, _asyncIterator2.default)(iterator);
150
-
151
- case 38:
152
- _context.next = 40;
153
- return (0, _awaitAsyncGenerator2.default)(_iterator.next());
154
-
155
- case 40:
156
- _step = _context.sent;
157
- _iteratorNormalCompletion = _step.done;
158
- _context.next = 44;
159
- return (0, _awaitAsyncGenerator2.default)(_step.value);
160
-
161
- case 44:
162
- _value = _context.sent;
163
-
164
- if (_iteratorNormalCompletion) {
165
- _context.next = 58;
166
- break;
167
- }
168
-
169
- item = _value;
170
- geometries = void 0;
171
- properties = void 0;
172
-
173
- if (!propertyIterable) {
174
- geometries = item;
175
- } else {
176
- _item = (0, _slicedToArray2.default)(item, 2);
177
- geometries = _item[0];
178
- properties = _item[1];
179
- }
180
-
181
- geojsonGeometries = parseGeometries(geometries);
182
- features = joinProperties(geojsonGeometries, properties);
183
-
184
- if (reproject) {
185
- features = reprojectFeatures(features, prj, _targetCrs);
186
- }
187
-
188
- _context.next = 55;
189
- return {
190
- encoding: cpg,
191
- prj: prj,
192
- shx: shx,
193
- header: shapeHeader,
194
- data: features
195
- };
196
-
197
- case 55:
198
- _iteratorNormalCompletion = true;
199
- _context.next = 38;
200
- break;
201
-
202
- case 58:
203
- _context.next = 64;
204
- break;
205
-
206
- case 60:
207
- _context.prev = 60;
208
- _context.t0 = _context["catch"](36);
209
- _didIteratorError = true;
210
- _iteratorError = _context.t0;
211
-
212
- case 64:
213
- _context.prev = 64;
214
- _context.prev = 65;
215
-
216
- if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
217
- _context.next = 69;
218
- break;
219
- }
220
-
221
- _context.next = 69;
222
- return (0, _awaitAsyncGenerator2.default)(_iterator.return());
223
-
224
- case 69:
225
- _context.prev = 69;
226
-
227
- if (!_didIteratorError) {
228
- _context.next = 72;
229
- break;
230
- }
231
-
232
- throw _iteratorError;
233
-
234
- case 72:
235
- return _context.finish(69);
236
-
237
- case 73:
238
- return _context.finish(64);
239
-
240
- case 74:
241
- case "end":
242
- return _context.stop();
243
- }
96
+ async function parseShapefile(arrayBuffer, options, context) {
97
+ const {
98
+ reproject = false,
99
+ _targetCrs = 'WGS84'
100
+ } = (options === null || options === void 0 ? void 0 : options.gis) || {};
101
+ const {
102
+ shx,
103
+ cpg,
104
+ prj
105
+ } = await loadShapefileSidecarFiles(options, context);
106
+ const {
107
+ header,
108
+ geometries
109
+ } = await context.parse(arrayBuffer, _shpLoader.SHPLoader, options);
110
+ const geojsonGeometries = parseGeometries(geometries);
111
+ let properties = [];
112
+ const dbfResponse = await context.fetch(replaceExtension(context.url, 'dbf'));
113
+
114
+ if (dbfResponse.ok) {
115
+ properties = await context.parse(dbfResponse, _dbfLoader.DBFLoader, {
116
+ dbf: {
117
+ encoding: cpg || 'latin1'
244
118
  }
245
- }, _callee, null, [[36, 60, 64, 74], [65,, 69, 73]]);
246
- }));
247
- return _parseShapefileInBatches.apply(this, arguments);
248
- }
119
+ });
120
+ }
249
121
 
250
- function parseShapefile(_x4, _x5, _x6) {
251
- return _parseShapefile.apply(this, arguments);
252
- }
122
+ let features = joinProperties(geojsonGeometries, properties);
253
123
 
254
- function _parseShapefile() {
255
- _parseShapefile = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(arrayBuffer, options, context) {
256
- var _ref2, _ref2$reproject, reproject, _ref2$_targetCrs, _targetCrs, _yield$loadShapefileS, shx, cpg, prj, _yield$context$parse, header, geometries, geojsonGeometries, properties, dbfResponse, features;
257
-
258
- return _regenerator.default.wrap(function _callee2$(_context2) {
259
- while (1) {
260
- switch (_context2.prev = _context2.next) {
261
- case 0:
262
- _ref2 = (options === null || options === void 0 ? void 0 : options.gis) || {}, _ref2$reproject = _ref2.reproject, reproject = _ref2$reproject === void 0 ? false : _ref2$reproject, _ref2$_targetCrs = _ref2._targetCrs, _targetCrs = _ref2$_targetCrs === void 0 ? 'WGS84' : _ref2$_targetCrs;
263
- _context2.next = 3;
264
- return loadShapefileSidecarFiles(options, context);
265
-
266
- case 3:
267
- _yield$loadShapefileS = _context2.sent;
268
- shx = _yield$loadShapefileS.shx;
269
- cpg = _yield$loadShapefileS.cpg;
270
- prj = _yield$loadShapefileS.prj;
271
- _context2.next = 9;
272
- return context.parse(arrayBuffer, _shpLoader.SHPLoader, options);
273
-
274
- case 9:
275
- _yield$context$parse = _context2.sent;
276
- header = _yield$context$parse.header;
277
- geometries = _yield$context$parse.geometries;
278
- geojsonGeometries = parseGeometries(geometries);
279
- properties = [];
280
- _context2.next = 16;
281
- return context.fetch(replaceExtension(context.url, 'dbf'));
282
-
283
- case 16:
284
- dbfResponse = _context2.sent;
285
-
286
- if (!dbfResponse.ok) {
287
- _context2.next = 21;
288
- break;
289
- }
290
-
291
- _context2.next = 20;
292
- return context.parse(dbfResponse, _dbfLoader.DBFLoader, {
293
- dbf: {
294
- encoding: cpg || 'latin1'
295
- }
296
- });
297
-
298
- case 20:
299
- properties = _context2.sent;
300
-
301
- case 21:
302
- features = joinProperties(geojsonGeometries, properties);
303
-
304
- if (reproject) {
305
- features = reprojectFeatures(features, prj, _targetCrs);
306
- }
307
-
308
- return _context2.abrupt("return", {
309
- encoding: cpg,
310
- prj: prj,
311
- shx: shx,
312
- header: header,
313
- data: features
314
- });
315
-
316
- case 24:
317
- case "end":
318
- return _context2.stop();
319
- }
320
- }
321
- }, _callee2);
322
- }));
323
- return _parseShapefile.apply(this, arguments);
124
+ if (reproject) {
125
+ features = reprojectFeatures(features, prj, _targetCrs);
126
+ }
127
+
128
+ return {
129
+ encoding: cpg,
130
+ prj,
131
+ shx,
132
+ header,
133
+ data: features
134
+ };
324
135
  }
325
136
 
326
137
  function parseGeometries(geometries) {
327
- var geojsonGeometries = [];
138
+ const geojsonGeometries = [];
328
139
 
329
- var _iterator2 = _createForOfIteratorHelper(geometries),
330
- _step2;
331
-
332
- try {
333
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
334
- var geom = _step2.value;
335
- geojsonGeometries.push((0, _gis.binaryToGeometry)(geom));
336
- }
337
- } catch (err) {
338
- _iterator2.e(err);
339
- } finally {
340
- _iterator2.f();
140
+ for (const geom of geometries) {
141
+ geojsonGeometries.push((0, _gis.binaryToGeometry)(geom));
341
142
  }
342
143
 
343
144
  return geojsonGeometries;
344
145
  }
345
146
 
346
147
  function joinProperties(geometries, properties) {
347
- var features = [];
148
+ const features = [];
348
149
 
349
- for (var i = 0; i < geometries.length; i++) {
350
- var geometry = geometries[i];
351
- var feature = {
150
+ for (let i = 0; i < geometries.length; i++) {
151
+ const geometry = geometries[i];
152
+ const feature = {
352
153
  type: 'Feature',
353
- geometry: geometry,
154
+ geometry,
354
155
  properties: properties && properties[i] || {}
355
156
  };
356
157
  features.push(feature);
@@ -360,109 +161,55 @@ function joinProperties(geometries, properties) {
360
161
  }
361
162
 
362
163
  function reprojectFeatures(features, sourceCrs, targetCrs) {
363
- var projection = new _proj.Proj4Projection({
164
+ const projection = new _proj.Proj4Projection({
364
165
  from: sourceCrs || 'WGS84',
365
166
  to: targetCrs || 'WGS84'
366
167
  });
367
- return (0, _gis.transformGeoJsonCoords)(features, function (coord) {
368
- return projection.project(coord);
369
- });
168
+ return (0, _gis.transformGeoJsonCoords)(features, coord => projection.project(coord));
370
169
  }
371
170
 
372
- function loadShapefileSidecarFiles(_x7, _x8) {
373
- return _loadShapefileSidecarFiles.apply(this, arguments);
374
- }
171
+ async function loadShapefileSidecarFiles(options, context) {
172
+ const {
173
+ url,
174
+ fetch
175
+ } = context;
176
+ const shxPromise = fetch(replaceExtension(url, 'shx'));
177
+ const cpgPromise = fetch(replaceExtension(url, 'cpg'));
178
+ const prjPromise = fetch(replaceExtension(url, 'prj'));
179
+ await Promise.all([shxPromise, cpgPromise, prjPromise]);
180
+ let shx;
181
+ let cpg;
182
+ let prj;
183
+ const shxResponse = await shxPromise;
184
+
185
+ if (shxResponse.ok) {
186
+ const arrayBuffer = await shxResponse.arrayBuffer();
187
+ shx = (0, _parseShx.parseShx)(arrayBuffer);
188
+ }
375
189
 
376
- function _loadShapefileSidecarFiles() {
377
- _loadShapefileSidecarFiles = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(options, context) {
378
- var url, fetch, shxPromise, cpgPromise, prjPromise, shx, cpg, prj, shxResponse, arrayBuffer, cpgResponse, prjResponse;
379
- return _regenerator.default.wrap(function _callee3$(_context3) {
380
- while (1) {
381
- switch (_context3.prev = _context3.next) {
382
- case 0:
383
- url = context.url, fetch = context.fetch;
384
- shxPromise = fetch(replaceExtension(url, 'shx'));
385
- cpgPromise = fetch(replaceExtension(url, 'cpg'));
386
- prjPromise = fetch(replaceExtension(url, 'prj'));
387
- _context3.next = 6;
388
- return Promise.all([shxPromise, cpgPromise, prjPromise]);
389
-
390
- case 6:
391
- _context3.next = 8;
392
- return shxPromise;
393
-
394
- case 8:
395
- shxResponse = _context3.sent;
396
-
397
- if (!shxResponse.ok) {
398
- _context3.next = 14;
399
- break;
400
- }
401
-
402
- _context3.next = 12;
403
- return shxResponse.arrayBuffer();
404
-
405
- case 12:
406
- arrayBuffer = _context3.sent;
407
- shx = (0, _parseShx.parseShx)(arrayBuffer);
408
-
409
- case 14:
410
- _context3.next = 16;
411
- return cpgPromise;
412
-
413
- case 16:
414
- cpgResponse = _context3.sent;
415
-
416
- if (!cpgResponse.ok) {
417
- _context3.next = 21;
418
- break;
419
- }
420
-
421
- _context3.next = 20;
422
- return cpgResponse.text();
423
-
424
- case 20:
425
- cpg = _context3.sent;
426
-
427
- case 21:
428
- _context3.next = 23;
429
- return prjPromise;
430
-
431
- case 23:
432
- prjResponse = _context3.sent;
433
-
434
- if (!prjResponse.ok) {
435
- _context3.next = 28;
436
- break;
437
- }
438
-
439
- _context3.next = 27;
440
- return prjResponse.text();
441
-
442
- case 27:
443
- prj = _context3.sent;
444
-
445
- case 28:
446
- return _context3.abrupt("return", {
447
- shx: shx,
448
- cpg: cpg,
449
- prj: prj
450
- });
451
-
452
- case 29:
453
- case "end":
454
- return _context3.stop();
455
- }
456
- }
457
- }, _callee3);
458
- }));
459
- return _loadShapefileSidecarFiles.apply(this, arguments);
190
+ const cpgResponse = await cpgPromise;
191
+
192
+ if (cpgResponse.ok) {
193
+ cpg = await cpgResponse.text();
194
+ }
195
+
196
+ const prjResponse = await prjPromise;
197
+
198
+ if (prjResponse.ok) {
199
+ prj = await prjResponse.text();
200
+ }
201
+
202
+ return {
203
+ shx,
204
+ cpg,
205
+ prj
206
+ };
460
207
  }
461
208
 
462
209
  function replaceExtension(url, newExtension) {
463
- var baseName = basename(url);
464
- var extension = extname(url);
465
- var isUpperCase = extension === extension.toUpperCase();
210
+ const baseName = basename(url);
211
+ const extension = extname(url);
212
+ const isUpperCase = extension === extension.toUpperCase();
466
213
 
467
214
  if (isUpperCase) {
468
215
  newExtension = newExtension.toUpperCase();
@@ -472,7 +219,7 @@ function replaceExtension(url, newExtension) {
472
219
  }
473
220
 
474
221
  function basename(url) {
475
- var extIndex = url && url.lastIndexOf('.');
222
+ const extIndex = url && url.lastIndexOf('.');
476
223
 
477
224
  if (typeof extIndex === 'number') {
478
225
  return extIndex >= 0 ? url.substr(0, extIndex) : '';
@@ -482,7 +229,7 @@ function basename(url) {
482
229
  }
483
230
 
484
231
  function extname(url) {
485
- var extIndex = url && url.lastIndexOf('.');
232
+ const extIndex = url && url.lastIndexOf('.');
486
233
 
487
234
  if (typeof extIndex === 'number') {
488
235
  return extIndex >= 0 ? url.substr(extIndex + 1) : '';