@map-colonies/mc-utils 1.6.1 → 1.7.1

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 (58) hide show
  1. package/README.md +67 -67
  2. package/dist/arrays/index.d.ts +1 -1
  3. package/dist/arrays/index.js +13 -13
  4. package/dist/arrays/subGroups.d.ts +8 -8
  5. package/dist/arrays/subGroups.js +138 -138
  6. package/dist/communication/http/httpClient.d.ts +26 -26
  7. package/dist/communication/http/httpClient.js +333 -333
  8. package/dist/communication/http/index.d.ts +1 -1
  9. package/dist/communication/http/index.js +13 -13
  10. package/dist/communication/index.d.ts +1 -1
  11. package/dist/communication/index.js +13 -13
  12. package/dist/dateTime/getUTCDate.d.ts +1 -1
  13. package/dist/dateTime/getUTCDate.js +10 -10
  14. package/dist/dateTime/index.d.ts +1 -1
  15. package/dist/dateTime/index.js +13 -13
  16. package/dist/geo/bboxUtils.d.ts +23 -23
  17. package/dist/geo/bboxUtils.js +89 -89
  18. package/dist/geo/geoConvertor.d.ts +18 -18
  19. package/dist/geo/geoConvertor.js +51 -51
  20. package/dist/geo/geoHash.d.ts +24 -24
  21. package/dist/geo/geoHash.js +242 -242
  22. package/dist/geo/geoIntersection.d.ts +19 -12
  23. package/dist/geo/geoIntersection.d.ts.map +1 -1
  24. package/dist/geo/geoIntersection.js +70 -27
  25. package/dist/geo/geoIntersection.js.map +1 -1
  26. package/dist/geo/index.d.ts +8 -8
  27. package/dist/geo/index.js +20 -20
  28. package/dist/geo/tileBatcher.d.ts +8 -8
  29. package/dist/geo/tileBatcher.js +167 -167
  30. package/dist/geo/tileRanger.d.ts +46 -39
  31. package/dist/geo/tileRanger.d.ts.map +1 -1
  32. package/dist/geo/tileRanger.js +327 -254
  33. package/dist/geo/tileRanger.js.map +1 -1
  34. package/dist/geo/tiles.d.ts +44 -32
  35. package/dist/geo/tiles.d.ts.map +1 -1
  36. package/dist/geo/tiles.js +133 -65
  37. package/dist/geo/tiles.js.map +1 -1
  38. package/dist/geo/tilesGenerator.d.ts +2 -2
  39. package/dist/geo/tilesGenerator.js +94 -94
  40. package/dist/index.d.ts +5 -5
  41. package/dist/index.js +17 -17
  42. package/dist/models/enums/geo/index.d.ts +1 -1
  43. package/dist/models/enums/geo/index.js +13 -13
  44. package/dist/models/enums/geo/tileOrigin.d.ts +7 -7
  45. package/dist/models/enums/geo/tileOrigin.js +11 -11
  46. package/dist/models/enums/index.d.ts +1 -1
  47. package/dist/models/enums/index.js +13 -13
  48. package/dist/models/index.d.ts +2 -2
  49. package/dist/models/index.js +14 -14
  50. package/dist/models/interfaces/geo/iPoint.d.ts +7 -7
  51. package/dist/models/interfaces/geo/iPoint.js +2 -2
  52. package/dist/models/interfaces/geo/iTile.d.ts +15 -15
  53. package/dist/models/interfaces/geo/iTile.js +2 -2
  54. package/dist/models/interfaces/geo/index.d.ts +2 -2
  55. package/dist/models/interfaces/geo/index.js +14 -14
  56. package/dist/models/interfaces/index.d.ts +1 -1
  57. package/dist/models/interfaces/index.js +13 -13
  58. package/package.json +77 -77
@@ -1,243 +1,243 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- var __values = (this && this.__values) || function(o) {
49
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
50
- if (m) return m.call(o);
51
- if (o && typeof o.length === "number") return {
52
- next: function () {
53
- if (o && i >= o.length) o = void 0;
54
- return { value: o && o[i++], done: !o };
55
- }
56
- };
57
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
58
- };
59
- Object.defineProperty(exports, "__esModule", { value: true });
60
- exports.tileGenerator = exports.createGeoHashGenerator = exports.decodeGeoHash = void 0;
61
- var turf_1 = require("@turf/turf");
62
- var ngeohash = __importStar(require("ngeohash"));
63
- var tileOrigin_1 = require("../models/enums/geo/tileOrigin");
64
- var geoConvertor_1 = require("./geoConvertor");
65
- var bboxUtils_1 = require("./bboxUtils");
66
- var MAX_STANDARD_ZOOM = 21;
67
- var bboxIntersection = function (bbox1, bbox2) {
68
- var minLon = Math.max(bbox1[0], bbox2[0]);
69
- var minLat = Math.max(bbox1[1], bbox2[1]);
70
- var maxLon = Math.min(bbox1[2], bbox2[2]);
71
- var maxLat = Math.min(bbox1[3], bbox2[3]);
72
- return [minLon, minLat, maxLon, maxLat];
73
- };
74
- var isSubHash = function (hash, parent) {
75
- return hash.startsWith(parent);
76
- };
77
- function geoHash(precision, maxPrecision, polygon, bbox, parentHash) {
78
- var hashes, hashes_1, hashes_1_1, hash, hashBbox, hashPoly, intersection, intArea, hashArea, subBbox, e_1_1;
79
- var e_1, _a;
80
- if (parentHash === void 0) { parentHash = ''; }
81
- return __generator(this, function (_b) {
82
- switch (_b.label) {
83
- case 0:
84
- hashes = ngeohash.bboxes(bbox[1], bbox[0], bbox[3], bbox[2], precision);
85
- if (!(hashes.length > 0)) return [3 /*break*/, 10];
86
- _b.label = 1;
87
- case 1:
88
- _b.trys.push([1, 8, 9, 10]);
89
- hashes_1 = __values(hashes), hashes_1_1 = hashes_1.next();
90
- _b.label = 2;
91
- case 2:
92
- if (!!hashes_1_1.done) return [3 /*break*/, 7];
93
- hash = hashes_1_1.value;
94
- hashBbox = (0, exports.decodeGeoHash)(hash);
95
- hashPoly = (0, turf_1.bboxPolygon)(hashBbox);
96
- intersection = (0, turf_1.intersect)(polygon, hashPoly);
97
- if (intersection === null || !isSubHash(hash, parentHash)) {
98
- return [3 /*break*/, 6];
99
- }
100
- intArea = (0, turf_1.area)(intersection);
101
- hashArea = (0, turf_1.area)(hashPoly);
102
- if (!(intArea == hashArea || precision == maxPrecision)) return [3 /*break*/, 4];
103
- return [4 /*yield*/, hash];
104
- case 3:
105
- _b.sent();
106
- return [3 /*break*/, 6];
107
- case 4:
108
- subBbox = bboxIntersection(hashBbox, bbox);
109
- return [5 /*yield**/, __values(geoHash(precision + 1, maxPrecision, polygon, subBbox, hash))];
110
- case 5:
111
- _b.sent();
112
- _b.label = 6;
113
- case 6:
114
- hashes_1_1 = hashes_1.next();
115
- return [3 /*break*/, 2];
116
- case 7: return [3 /*break*/, 10];
117
- case 8:
118
- e_1_1 = _b.sent();
119
- e_1 = { error: e_1_1 };
120
- return [3 /*break*/, 10];
121
- case 9:
122
- try {
123
- if (hashes_1_1 && !hashes_1_1.done && (_a = hashes_1.return)) _a.call(hashes_1);
124
- }
125
- finally { if (e_1) throw e_1.error; }
126
- return [7 /*endfinally*/];
127
- case 10: return [2 /*return*/];
128
- }
129
- });
130
- }
131
- /**
132
- * converts geohash string to its bbox in wgs84 degrees
133
- * @param geohash geohash string
134
- * @returns bbox of the supplied geohash
135
- */
136
- var decodeGeoHash = function (geohash) {
137
- var bboxFromGeohash = ngeohash.decode_bbox(geohash);
138
- // ngeohash.decode_bbox gives a lat-lon array. we change it to lon-lat so @turf can use it.
139
- var lonLatBbox = [bboxFromGeohash[1], bboxFromGeohash[0], bboxFromGeohash[3], bboxFromGeohash[2]];
140
- return lonLatBbox;
141
- };
142
- exports.decodeGeoHash = decodeGeoHash;
143
- /**
144
- * generates optimized geohash iterator for given polygon and target zoom level
145
- * @param polygon polygon to cover with geohashes
146
- * @param maxTileZoom target zoom level
147
- * @returns generator that yields the matching geohashes
148
- */
149
- var createGeoHashGenerator = function (polygon, maxTileZoom) {
150
- if (maxTileZoom === void 0) { maxTileZoom = MAX_STANDARD_ZOOM; }
151
- var bbox = (0, turf_1.bbox)(polygon);
152
- bbox = (0, bboxUtils_1.snapBBoxToTileGrid)(bbox, maxTileZoom);
153
- //at this precision ea geo hash is a tile or smaller
154
- /* eslint-disable @typescript-eslint/no-magic-numbers */
155
- var zoomPrecision = Math.floor((2 / 5) * (maxTileZoom + 1));
156
- var precisionMod = maxTileZoom % 5;
157
- if (precisionMod > 0 && precisionMod <= 3) {
158
- zoomPrecision++;
159
- }
160
- else if (precisionMod > 3) {
161
- zoomPrecision += 2;
162
- }
163
- /* eslint-enable @typescript-eslint/no-magic-numbers */
164
- return geoHash(1, zoomPrecision, polygon, bbox);
165
- };
166
- exports.createGeoHashGenerator = createGeoHashGenerator;
167
- /**
168
- * generate all tiles in supplied polygon
169
- * @param polygon polygon to cover with tiles
170
- * @param tileZoom target tiles zoom level
171
- * @param origin target tiles grid origin location (default ll)
172
- */
173
- function tileGenerator(polygon, tileZoom, origin) {
174
- var hashGen, hashGen_1, hashGen_1_1, hash, bbox, minTile, maxTile, minX, maxX, minY, maxY, x, y, e_2_1;
175
- var e_2, _a;
176
- if (origin === void 0) { origin = tileOrigin_1.TileOrigin.LOWER_LEFT; }
177
- return __generator(this, function (_b) {
178
- switch (_b.label) {
179
- case 0:
180
- hashGen = (0, exports.createGeoHashGenerator)(polygon, tileZoom);
181
- _b.label = 1;
182
- case 1:
183
- _b.trys.push([1, 10, 11, 12]);
184
- hashGen_1 = __values(hashGen), hashGen_1_1 = hashGen_1.next();
185
- _b.label = 2;
186
- case 2:
187
- if (!!hashGen_1_1.done) return [3 /*break*/, 9];
188
- hash = hashGen_1_1.value;
189
- bbox = (0, exports.decodeGeoHash)(hash);
190
- minTile = (0, geoConvertor_1.degreesToTile)({
191
- longitude: bbox[0],
192
- latitude: bbox[1],
193
- }, tileZoom, origin);
194
- maxTile = (0, geoConvertor_1.degreesToTile)({
195
- longitude: bbox[2],
196
- latitude: bbox[3],
197
- }, tileZoom, origin);
198
- minX = Math.min(minTile.x, maxTile.x);
199
- maxX = minTile.x + maxTile.x - minX;
200
- minY = Math.min(minTile.y, maxTile.y);
201
- maxY = minTile.y + maxTile.y - minY;
202
- x = minX;
203
- _b.label = 3;
204
- case 3:
205
- if (!(x < maxX)) return [3 /*break*/, 8];
206
- y = minY;
207
- _b.label = 4;
208
- case 4:
209
- if (!(y < maxY)) return [3 /*break*/, 7];
210
- return [4 /*yield*/, {
211
- x: x,
212
- y: y,
213
- zoom: tileZoom,
214
- }];
215
- case 5:
216
- _b.sent();
217
- _b.label = 6;
218
- case 6:
219
- y++;
220
- return [3 /*break*/, 4];
221
- case 7:
222
- x++;
223
- return [3 /*break*/, 3];
224
- case 8:
225
- hashGen_1_1 = hashGen_1.next();
226
- return [3 /*break*/, 2];
227
- case 9: return [3 /*break*/, 12];
228
- case 10:
229
- e_2_1 = _b.sent();
230
- e_2 = { error: e_2_1 };
231
- return [3 /*break*/, 12];
232
- case 11:
233
- try {
234
- if (hashGen_1_1 && !hashGen_1_1.done && (_a = hashGen_1.return)) _a.call(hashGen_1);
235
- }
236
- finally { if (e_2) throw e_2.error; }
237
- return [7 /*endfinally*/];
238
- case 12: return [2 /*return*/];
239
- }
240
- });
241
- }
242
- exports.tileGenerator = tileGenerator;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __values = (this && this.__values) || function(o) {
49
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
50
+ if (m) return m.call(o);
51
+ if (o && typeof o.length === "number") return {
52
+ next: function () {
53
+ if (o && i >= o.length) o = void 0;
54
+ return { value: o && o[i++], done: !o };
55
+ }
56
+ };
57
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
58
+ };
59
+ Object.defineProperty(exports, "__esModule", { value: true });
60
+ exports.tileGenerator = exports.createGeoHashGenerator = exports.decodeGeoHash = void 0;
61
+ var turf_1 = require("@turf/turf");
62
+ var ngeohash = __importStar(require("ngeohash"));
63
+ var tileOrigin_1 = require("../models/enums/geo/tileOrigin");
64
+ var geoConvertor_1 = require("./geoConvertor");
65
+ var bboxUtils_1 = require("./bboxUtils");
66
+ var MAX_STANDARD_ZOOM = 21;
67
+ var bboxIntersection = function (bbox1, bbox2) {
68
+ var minLon = Math.max(bbox1[0], bbox2[0]);
69
+ var minLat = Math.max(bbox1[1], bbox2[1]);
70
+ var maxLon = Math.min(bbox1[2], bbox2[2]);
71
+ var maxLat = Math.min(bbox1[3], bbox2[3]);
72
+ return [minLon, minLat, maxLon, maxLat];
73
+ };
74
+ var isSubHash = function (hash, parent) {
75
+ return hash.startsWith(parent);
76
+ };
77
+ function geoHash(precision, maxPrecision, polygon, bbox, parentHash) {
78
+ var hashes, hashes_1, hashes_1_1, hash, hashBbox, hashPoly, intersection, intArea, hashArea, subBbox, e_1_1;
79
+ var e_1, _a;
80
+ if (parentHash === void 0) { parentHash = ''; }
81
+ return __generator(this, function (_b) {
82
+ switch (_b.label) {
83
+ case 0:
84
+ hashes = ngeohash.bboxes(bbox[1], bbox[0], bbox[3], bbox[2], precision);
85
+ if (!(hashes.length > 0)) return [3 /*break*/, 10];
86
+ _b.label = 1;
87
+ case 1:
88
+ _b.trys.push([1, 8, 9, 10]);
89
+ hashes_1 = __values(hashes), hashes_1_1 = hashes_1.next();
90
+ _b.label = 2;
91
+ case 2:
92
+ if (!!hashes_1_1.done) return [3 /*break*/, 7];
93
+ hash = hashes_1_1.value;
94
+ hashBbox = (0, exports.decodeGeoHash)(hash);
95
+ hashPoly = (0, turf_1.bboxPolygon)(hashBbox);
96
+ intersection = (0, turf_1.intersect)(polygon, hashPoly);
97
+ if (intersection === null || !isSubHash(hash, parentHash)) {
98
+ return [3 /*break*/, 6];
99
+ }
100
+ intArea = (0, turf_1.area)(intersection);
101
+ hashArea = (0, turf_1.area)(hashPoly);
102
+ if (!(intArea == hashArea || precision == maxPrecision)) return [3 /*break*/, 4];
103
+ return [4 /*yield*/, hash];
104
+ case 3:
105
+ _b.sent();
106
+ return [3 /*break*/, 6];
107
+ case 4:
108
+ subBbox = bboxIntersection(hashBbox, bbox);
109
+ return [5 /*yield**/, __values(geoHash(precision + 1, maxPrecision, polygon, subBbox, hash))];
110
+ case 5:
111
+ _b.sent();
112
+ _b.label = 6;
113
+ case 6:
114
+ hashes_1_1 = hashes_1.next();
115
+ return [3 /*break*/, 2];
116
+ case 7: return [3 /*break*/, 10];
117
+ case 8:
118
+ e_1_1 = _b.sent();
119
+ e_1 = { error: e_1_1 };
120
+ return [3 /*break*/, 10];
121
+ case 9:
122
+ try {
123
+ if (hashes_1_1 && !hashes_1_1.done && (_a = hashes_1.return)) _a.call(hashes_1);
124
+ }
125
+ finally { if (e_1) throw e_1.error; }
126
+ return [7 /*endfinally*/];
127
+ case 10: return [2 /*return*/];
128
+ }
129
+ });
130
+ }
131
+ /**
132
+ * converts geohash string to its bbox in wgs84 degrees
133
+ * @param geohash geohash string
134
+ * @returns bbox of the supplied geohash
135
+ */
136
+ var decodeGeoHash = function (geohash) {
137
+ var bboxFromGeohash = ngeohash.decode_bbox(geohash);
138
+ // ngeohash.decode_bbox gives a lat-lon array. we change it to lon-lat so @turf can use it.
139
+ var lonLatBbox = [bboxFromGeohash[1], bboxFromGeohash[0], bboxFromGeohash[3], bboxFromGeohash[2]];
140
+ return lonLatBbox;
141
+ };
142
+ exports.decodeGeoHash = decodeGeoHash;
143
+ /**
144
+ * generates optimized geohash iterator for given polygon and target zoom level
145
+ * @param polygon polygon to cover with geohashes
146
+ * @param maxTileZoom target zoom level
147
+ * @returns generator that yields the matching geohashes
148
+ */
149
+ var createGeoHashGenerator = function (polygon, maxTileZoom) {
150
+ if (maxTileZoom === void 0) { maxTileZoom = MAX_STANDARD_ZOOM; }
151
+ var bbox = (0, turf_1.bbox)(polygon);
152
+ bbox = (0, bboxUtils_1.snapBBoxToTileGrid)(bbox, maxTileZoom);
153
+ //at this precision ea geo hash is a tile or smaller
154
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
155
+ var zoomPrecision = Math.floor((2 / 5) * (maxTileZoom + 1));
156
+ var precisionMod = maxTileZoom % 5;
157
+ if (precisionMod > 0 && precisionMod <= 3) {
158
+ zoomPrecision++;
159
+ }
160
+ else if (precisionMod > 3) {
161
+ zoomPrecision += 2;
162
+ }
163
+ /* eslint-enable @typescript-eslint/no-magic-numbers */
164
+ return geoHash(1, zoomPrecision, polygon, bbox);
165
+ };
166
+ exports.createGeoHashGenerator = createGeoHashGenerator;
167
+ /**
168
+ * generate all tiles in supplied polygon
169
+ * @param polygon polygon to cover with tiles
170
+ * @param tileZoom target tiles zoom level
171
+ * @param origin target tiles grid origin location (default ll)
172
+ */
173
+ function tileGenerator(polygon, tileZoom, origin) {
174
+ var hashGen, hashGen_1, hashGen_1_1, hash, bbox, minTile, maxTile, minX, maxX, minY, maxY, x, y, e_2_1;
175
+ var e_2, _a;
176
+ if (origin === void 0) { origin = tileOrigin_1.TileOrigin.LOWER_LEFT; }
177
+ return __generator(this, function (_b) {
178
+ switch (_b.label) {
179
+ case 0:
180
+ hashGen = (0, exports.createGeoHashGenerator)(polygon, tileZoom);
181
+ _b.label = 1;
182
+ case 1:
183
+ _b.trys.push([1, 10, 11, 12]);
184
+ hashGen_1 = __values(hashGen), hashGen_1_1 = hashGen_1.next();
185
+ _b.label = 2;
186
+ case 2:
187
+ if (!!hashGen_1_1.done) return [3 /*break*/, 9];
188
+ hash = hashGen_1_1.value;
189
+ bbox = (0, exports.decodeGeoHash)(hash);
190
+ minTile = (0, geoConvertor_1.degreesToTile)({
191
+ longitude: bbox[0],
192
+ latitude: bbox[1],
193
+ }, tileZoom, origin);
194
+ maxTile = (0, geoConvertor_1.degreesToTile)({
195
+ longitude: bbox[2],
196
+ latitude: bbox[3],
197
+ }, tileZoom, origin);
198
+ minX = Math.min(minTile.x, maxTile.x);
199
+ maxX = minTile.x + maxTile.x - minX;
200
+ minY = Math.min(minTile.y, maxTile.y);
201
+ maxY = minTile.y + maxTile.y - minY;
202
+ x = minX;
203
+ _b.label = 3;
204
+ case 3:
205
+ if (!(x < maxX)) return [3 /*break*/, 8];
206
+ y = minY;
207
+ _b.label = 4;
208
+ case 4:
209
+ if (!(y < maxY)) return [3 /*break*/, 7];
210
+ return [4 /*yield*/, {
211
+ x: x,
212
+ y: y,
213
+ zoom: tileZoom,
214
+ }];
215
+ case 5:
216
+ _b.sent();
217
+ _b.label = 6;
218
+ case 6:
219
+ y++;
220
+ return [3 /*break*/, 4];
221
+ case 7:
222
+ x++;
223
+ return [3 /*break*/, 3];
224
+ case 8:
225
+ hashGen_1_1 = hashGen_1.next();
226
+ return [3 /*break*/, 2];
227
+ case 9: return [3 /*break*/, 12];
228
+ case 10:
229
+ e_2_1 = _b.sent();
230
+ e_2 = { error: e_2_1 };
231
+ return [3 /*break*/, 12];
232
+ case 11:
233
+ try {
234
+ if (hashGen_1_1 && !hashGen_1_1.done && (_a = hashGen_1.return)) _a.call(hashGen_1);
235
+ }
236
+ finally { if (e_2) throw e_2.error; }
237
+ return [7 /*endfinally*/];
238
+ case 12: return [2 /*return*/];
239
+ }
240
+ });
241
+ }
242
+ exports.tileGenerator = tileGenerator;
243
243
  //# sourceMappingURL=geoHash.js.map
@@ -1,13 +1,20 @@
1
- import { Feature, MultiPolygon, Polygon } from '@turf/turf';
2
- /**
3
- * tuft intersect supported footprint types
4
- */
5
- declare type Footprint = Polygon | MultiPolygon | Feature<Polygon | MultiPolygon>;
6
- /**
7
- * return the intersection footprint of all specified footprints or null when there is no intersection
8
- * @param footprints footprint list to intersect
9
- * @returns intersection footprint or null
10
- */
11
- declare const multiIntersect: (footprints: Footprint[]) => Footprint | null;
12
- export { multiIntersect, Footprint };
1
+ import { Feature, FeatureCollection, MultiPolygon, Polygon } from '@turf/turf';
2
+ /**
3
+ * tuft intersect supported footprint types
4
+ */
5
+ declare type Footprint = Polygon | MultiPolygon | Feature<Polygon | MultiPolygon>;
6
+ /**
7
+ * return the intersection footprint of all specified footprints or null when there is no intersection
8
+ * @param footprints footprint list to intersect
9
+ * @returns intersection footprint or null
10
+ */
11
+ declare const multiIntersect: (footprints: Footprint[]) => Footprint | null;
12
+ /**
13
+ * indicates if 2 object of type FeatureCollection are equal by validating properties and features array (order not important)
14
+ * @param fc1 first featureCollection to compare equal
15
+ * @param fc2 second featureCollection to compare equal
16
+ * @returns true if same featureCollection, false if not
17
+ */
18
+ declare const featureCollectionBooleanEqual: (fc1: FeatureCollection, fc2: FeatureCollection) => boolean;
19
+ export { multiIntersect, featureCollectionBooleanEqual, Footprint };
13
20
  //# sourceMappingURL=geoIntersection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"geoIntersection.d.ts","sourceRoot":"","sources":["../../src/geo/geoIntersection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAa,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEvE;;GAEG;AACH,OAAO,MAAM,SAAS,GAAG,OAAO,GAAG,YAAY,GAAG,OAAO,CAAC,OAAO,GAAG,YAAY,CAAC,CAAC;AAElF;;;;GAIG;AACH,QAAA,MAAM,cAAc,eAAgB,SAAS,EAAE,KAAG,SAAS,GAAG,IAe7D,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"geoIntersection.d.ts","sourceRoot":"","sources":["../../src/geo/geoIntersection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAa,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1F;;GAEG;AACH,OAAO,MAAM,SAAS,GAAG,OAAO,GAAG,YAAY,GAAG,OAAO,CAAC,OAAO,GAAG,YAAY,CAAC,CAAC;AAkClF;;;;GAIG;AACH,QAAA,MAAM,cAAc,eAAgB,SAAS,EAAE,KAAG,SAAS,GAAG,IAe7D,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,6BAA6B,QAAS,iBAAiB,OAAO,iBAAiB,KAAG,OAEvF,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,6BAA6B,EAAE,SAAS,EAAE,CAAC"}
@@ -1,28 +1,71 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.multiIntersect = void 0;
4
- var turf_1 = require("@turf/turf");
5
- /**
6
- * return the intersection footprint of all specified footprints or null when there is no intersection
7
- * @param footprints footprint list to intersect
8
- * @returns intersection footprint or null
9
- */
10
- var multiIntersect = function (footprints) {
11
- if (footprints.length === 0) {
12
- return null;
13
- }
14
- else if (footprints.length === 1) {
15
- return footprints[0];
16
- }
17
- var intersection = footprints[0];
18
- for (var i = 1; i < footprints.length; i++) {
19
- var curIntersection = (0, turf_1.intersect)(intersection, footprints[i]);
20
- if (curIntersection === null) {
21
- return null;
22
- }
23
- intersection = curIntersection;
24
- }
25
- return intersection;
26
- };
27
- exports.multiIntersect = multiIntersect;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.featureCollectionBooleanEqual = exports.multiIntersect = void 0;
7
+ var turf_1 = require("@turf/turf");
8
+ var lodash_1 = __importDefault(require("lodash"));
9
+ var featuresCustomizer = function (objectValue, otherValue) {
10
+ // compare features
11
+ // https://lodash.com/docs/4.17.15#find
12
+ if (!lodash_1.default.isEqual(objectValue.length, otherValue.length)) {
13
+ return false;
14
+ }
15
+ for (var i = 0; i < objectValue.length; i++) {
16
+ var isFeatureContained = lodash_1.default.find(otherValue, objectValue[i]);
17
+ if (isFeatureContained === undefined) {
18
+ return false;
19
+ }
20
+ }
21
+ for (var i = 0; i < otherValue.length; i++) {
22
+ var isFeatureContained = lodash_1.default.find(objectValue, otherValue[i]);
23
+ if (isFeatureContained === undefined) {
24
+ return false;
25
+ }
26
+ }
27
+ return true;
28
+ };
29
+ var featureCollectionCustomized = function (objectValue, otherValue) {
30
+ // compare type
31
+ if (!lodash_1.default.isEqual(objectValue.type, otherValue.type)) {
32
+ return false;
33
+ }
34
+ // compare features
35
+ var isFeaturesEqual = lodash_1.default.isEqualWith(objectValue.features, otherValue.features, featuresCustomizer);
36
+ return isFeaturesEqual;
37
+ };
38
+ /**
39
+ * return the intersection footprint of all specified footprints or null when there is no intersection
40
+ * @param footprints footprint list to intersect
41
+ * @returns intersection footprint or null
42
+ */
43
+ var multiIntersect = function (footprints) {
44
+ if (footprints.length === 0) {
45
+ return null;
46
+ }
47
+ else if (footprints.length === 1) {
48
+ return footprints[0];
49
+ }
50
+ var intersection = footprints[0];
51
+ for (var i = 1; i < footprints.length; i++) {
52
+ var curIntersection = (0, turf_1.intersect)(intersection, footprints[i]);
53
+ if (curIntersection === null) {
54
+ return null;
55
+ }
56
+ intersection = curIntersection;
57
+ }
58
+ return intersection;
59
+ };
60
+ exports.multiIntersect = multiIntersect;
61
+ /**
62
+ * indicates if 2 object of type FeatureCollection are equal by validating properties and features array (order not important)
63
+ * @param fc1 first featureCollection to compare equal
64
+ * @param fc2 second featureCollection to compare equal
65
+ * @returns true if same featureCollection, false if not
66
+ */
67
+ var featureCollectionBooleanEqual = function (fc1, fc2) {
68
+ return lodash_1.default.isEqualWith(fc1, fc2, featureCollectionCustomized);
69
+ };
70
+ exports.featureCollectionBooleanEqual = featureCollectionBooleanEqual;
28
71
  //# sourceMappingURL=geoIntersection.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"geoIntersection.js","sourceRoot":"","sources":["../../src/geo/geoIntersection.ts"],"names":[],"mappings":";;;AAAA,mCAAuE;AAOvE;;;;GAIG;AACH,IAAM,cAAc,GAAG,UAAC,UAAuB;IAC7C,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,OAAO,IAAI,CAAC;KACb;SAAM,IAAI,UAAU,CAAC,MAAM,K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