@map-colonies/mc-utils 3.1.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +67 -67
  2. package/dist/arrays/index.d.ts +1 -1
  3. package/dist/arrays/index.js +17 -17
  4. package/dist/arrays/subGroups.d.ts +8 -8
  5. package/dist/arrays/subGroups.js +33 -33
  6. package/dist/communication/http/httpClient.d.ts +29 -29
  7. package/dist/communication/http/httpClient.d.ts.map +1 -1
  8. package/dist/communication/http/httpClient.js +353 -317
  9. package/dist/communication/http/httpClient.js.map +1 -1
  10. package/dist/communication/http/index.d.ts +1 -1
  11. package/dist/communication/http/index.js +17 -17
  12. package/dist/communication/index.d.ts +1 -1
  13. package/dist/communication/index.js +17 -17
  14. package/dist/dateTime/getUTCDate.d.ts +1 -1
  15. package/dist/dateTime/getUTCDate.js +10 -10
  16. package/dist/dateTime/index.d.ts +1 -1
  17. package/dist/dateTime/index.js +17 -17
  18. package/dist/geo/bboxUtils.d.ts +23 -23
  19. package/dist/geo/bboxUtils.js +89 -89
  20. package/dist/geo/geoConvertor.d.ts +18 -18
  21. package/dist/geo/geoConvertor.js +49 -49
  22. package/dist/geo/geoHash.d.ts +24 -24
  23. package/dist/geo/geoHash.js +134 -134
  24. package/dist/geo/geoIntersection.d.ts +19 -19
  25. package/dist/geo/geoIntersection.js +70 -70
  26. package/dist/geo/index.d.ts +8 -8
  27. package/dist/geo/index.js +24 -24
  28. package/dist/geo/tileBatcher.d.ts +8 -8
  29. package/dist/geo/tileBatcher.js +97 -97
  30. package/dist/geo/tileRanger.d.ts +46 -46
  31. package/dist/geo/tileRanger.js +232 -232
  32. package/dist/geo/tiles.d.ts +82 -82
  33. package/dist/geo/tiles.js +219 -219
  34. package/dist/geo/tilesGenerator.d.ts +2 -2
  35. package/dist/geo/tilesGenerator.js +17 -17
  36. package/dist/index.d.ts +6 -6
  37. package/dist/index.js +22 -22
  38. package/dist/models/enums/gdal/dataType.d.ts +16 -16
  39. package/dist/models/enums/gdal/dataType.js +20 -20
  40. package/dist/models/enums/gdal/index.d.ts +2 -2
  41. package/dist/models/enums/gdal/index.js +18 -18
  42. package/dist/models/enums/gdal/resamplingMethod.d.ts +16 -16
  43. package/dist/models/enums/gdal/resamplingMethod.js +20 -20
  44. package/dist/models/enums/geo/index.d.ts +1 -1
  45. package/dist/models/enums/geo/index.js +17 -17
  46. package/dist/models/enums/geo/tileOrigin.d.ts +7 -7
  47. package/dist/models/enums/geo/tileOrigin.js +11 -11
  48. package/dist/models/enums/index.d.ts +2 -2
  49. package/dist/models/enums/index.js +18 -18
  50. package/dist/models/index.d.ts +2 -2
  51. package/dist/models/index.js +18 -18
  52. package/dist/models/interfaces/geo/iPoint.d.ts +7 -7
  53. package/dist/models/interfaces/geo/iPoint.js +2 -2
  54. package/dist/models/interfaces/geo/iTile.d.ts +15 -15
  55. package/dist/models/interfaces/geo/iTile.js +2 -2
  56. package/dist/models/interfaces/geo/index.d.ts +2 -2
  57. package/dist/models/interfaces/geo/index.js +18 -18
  58. package/dist/models/interfaces/index.d.ts +1 -1
  59. package/dist/models/interfaces/index.js +17 -17
  60. package/dist/utils/index.d.ts +1 -1
  61. package/dist/utils/index.js +17 -17
  62. package/dist/utils/timeout.d.ts +4 -4
  63. package/dist/utils/timeout.js +22 -22
  64. package/package.json +79 -79
@@ -1,233 +1,233 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TileRanger = void 0;
4
- const turf_1 = require("@turf/turf");
5
- const bboxUtils_1 = require("./bboxUtils");
6
- const tiles_1 = require("./tiles");
7
- const tilesGenerator_1 = require("./tilesGenerator");
8
- var TileIntersectionState;
9
- (function (TileIntersectionState) {
10
- TileIntersectionState["FULL"] = "full";
11
- TileIntersectionState["PARTIAL"] = "partial";
12
- TileIntersectionState["NONE"] = "none";
13
- })(TileIntersectionState || (TileIntersectionState = {}));
14
- /**
15
- * class for generating and decoding tile hashes
16
- */
17
- class TileRanger {
18
- /**
19
- * converts tile to tile range of specified zoom level
20
- * @param tile
21
- * @param zoom target tile range zoom
22
- * @returns
23
- */
24
- tileToRange(tile, zoom) {
25
- let minX, minY, maxX, maxY;
26
- minX = tile.x;
27
- maxX = tile.x + 1;
28
- minY = tile.y;
29
- maxY = tile.y + 1;
30
- if (tile.zoom < zoom) {
31
- const dz = zoom - tile.zoom;
32
- minX = minX << dz;
33
- maxX = maxX << dz;
34
- minY = minY << dz;
35
- maxY = maxY << dz;
36
- }
37
- else if (tile.zoom > zoom) {
38
- const dz = tile.zoom - zoom;
39
- minX = minX >> dz;
40
- minY = minY >> dz;
41
- maxX = minX + 1;
42
- maxY = minY + 1;
43
- }
44
- return {
45
- minX,
46
- minY,
47
- maxX,
48
- maxY,
49
- zoom,
50
- };
51
- }
52
- /**
53
- * generate tile hashes
54
- * @param footprint footprint to cover with generated tile hashes
55
- * @param zoom max hash zoom
56
- * @returns
57
- */
58
- async *encodeFootprint(footprint, zoom, verbose = false) {
59
- ////////////////////////////////
60
- /// Step 1: check if the footprint is identical to its bbox
61
- ////////////////////////////////
62
- if (verbose) {
63
- console.log('encode footprint');
64
- }
65
- ////////////////////////////////
66
- /// Step 2: convert footprint to BBOX
67
- ////////////////////////////////
68
- const bbox = (0, turf_1.bbox)(footprint);
69
- if (this.isBbox(footprint)) {
70
- // if it is convert its bbox directly to tile range and return it (bbox to tiles conversion is fast and direct mathematical conversion)
71
- const tileRange = (0, bboxUtils_1.bboxToTileRange)(bbox, zoom);
72
- if (verbose) {
73
- console.log(`footprint is identical to its bbox - return BBOX tile range zoom: ${tileRange.zoom} : X ${tileRange.minX} - ${tileRange.maxX} : Y ${tileRange.minY} - ${tileRange.maxY}`);
74
- }
75
- yield await Promise.resolve(tileRange);
76
- }
77
- else {
78
- const intersectionParams = {
79
- footprint,
80
- maxZoom: zoom,
81
- };
82
- if (verbose) {
83
- console.log('footprint is different from its bbox - generateRanges');
84
- }
85
- yield* await Promise.resolve(this.generateRanges(bbox, zoom, intersectionParams, this.tileFootprintIntersection, verbose));
86
- }
87
- }
88
- generateTiles(area, zoom) {
89
- let gen;
90
- if (Array.isArray(area)) {
91
- const tileRangeGen = async function* tileRangeGenerator() {
92
- yield await Promise.resolve((0, bboxUtils_1.bboxToTileRange)(area, zoom));
93
- };
94
- gen = tileRangeGen();
95
- }
96
- else {
97
- gen = this.encodeFootprint(area, zoom);
98
- }
99
- return (0, tilesGenerator_1.tilesGenerator)(gen);
100
- }
101
- async *generateRanges(bbox, zoom, intersectionTarget, intersectionFunction, verbose = false) {
102
- /////////////////////////////////////////////////////////////////////////////////////////////////
103
- /// Step 3: Convert the bbox to tile range of the requested zoom
104
- /////////////////////////////////////////////////////////////////////////////////////////////////
105
- if (verbose) {
106
- console.log('Convert the bbox to tile range of the requested zoom');
107
- }
108
- const boundingRange = (0, bboxUtils_1.bboxToTileRange)(bbox, zoom);
109
- if (verbose) {
110
- const bboxString = `BBOX[0]: ${bbox[0]}, BBOX[1]: ${bbox[1]}, BBOX[2]: ${bbox[2]}, BBOX[3]: ${bbox[3]}`;
111
- console.log(`${bboxString}, Zoom: ${zoom}, bounding range: minX: ${boundingRange.minX}, maxX: ${boundingRange.maxX}, minY: ${boundingRange.minY}, maxY: ${boundingRange.maxY}`);
112
- }
113
- /////////////////////////////////////////////////////////////////////////////////////////////////
114
- /// Step 4: Use range size to calculate zoom level where the target area is smaller then 1 tile
115
- /// (use zoom zero in-case there is no such zoom, for example in global bbox).
116
- /////////////////////////////////////////////////////////////////////////////////////////////////
117
- // find minimal zoom where the the area can be converted by area the size of single tile to skip levels that can't have full hashes
118
- if (verbose) {
119
- console.log("find minimal zoom where the the area can be converted by area the size of single tile to skip levels that can't have full hashes");
120
- }
121
- const dx = boundingRange.maxX - boundingRange.minX;
122
- const dy = boundingRange.maxY - boundingRange.minY;
123
- const minXZoom = Math.max(Math.floor(Math.log2(1 << (zoom + 1)) / dx) - 1, 0);
124
- const minYZoom = Math.max(Math.floor(Math.log2(1 << zoom) / dy), 0);
125
- const minZoom = Math.min(minXZoom, minYZoom);
126
- if (verbose) {
127
- console.log(`MinZoom: ${minZoom}`);
128
- }
129
- /////////////////////////////////////////////////////////////////////////////////////////////////
130
- /// Step 5: convert the requested bbox to to tile range of the zoom level calculated in step 3 (this reduce the iteration required for the calculation)
131
- /////////////////////////////////////////////////////////////////////////////////////////////////
132
- //find base hashes
133
- const minimalRange = (0, bboxUtils_1.bboxToTileRange)(bbox, minZoom);
134
- for (let x = minimalRange.minX; x < minimalRange.maxX; x++) {
135
- for (let y = minimalRange.minY; y < minimalRange.maxY; y++) {
136
- /////////////////////////////////////////////////////////////////////////////////////////////////
137
- /// Step 6: for every tile in the current range:
138
- /// Step 7: check the tile intersection with the footprint
139
- /////////////////////////////////////////////////////////////////////////////////////////////////
140
- const tile = { x, y, zoom: minimalRange.zoom };
141
- const intersection = intersectionFunction(tile, intersectionTarget);
142
- if (verbose) {
143
- console.log(`Tile X: ${tile.x}, Y: ${tile.y} zoom ${tile.zoom}, intersection: ${intersection}`);
144
- }
145
- /// if it is completely covered or the tile is in the requested zoom:
146
- if (intersection === TileIntersectionState.FULL) {
147
- /// convert it to tile range of the requested resolution
148
- /// add the range to the result set (yield is used for lazy calculation to improve memory usage)
149
- const tileRange = this.tileToRange(tile, zoom);
150
- if (verbose) {
151
- console.log(`return BBOX tile range zoom: ${tileRange.zoom} : X ${tileRange.minX} - ${tileRange.maxX} : Y ${tileRange.minY} - ${tileRange.maxY}`);
152
- }
153
- yield await Promise.resolve(tileRange);
154
- }
155
- else if (intersection === TileIntersectionState.PARTIAL) {
156
- /// if it partly covered:
157
- // calculate the sub tiles contained in the current tile (in the next zoom level)
158
- // for every sub tile recursively run step 6
159
- //optimize partial base hashes
160
- yield* await Promise.resolve(this.optimizeHash(tile, zoom, intersectionTarget, intersectionFunction, verbose));
161
- }
162
- /// else do nothing as this tiles aren't intersected with the original footprint
163
- }
164
- }
165
- }
166
- /**
167
- * generate tile
168
- * @param tile tile to get all intersecting tiles from
169
- * @param targetZoom target tiles zoom level
170
- * @param intersectionTarget original zoom level and footprint to intersect
171
- * @param intersectionFunction the intersection function to be called
172
- */
173
- *optimizeHash(tile, targetZoom, intersectionTarget, intersectionFunction, verbose = false) {
174
- /// generate from a tile the next zoom level tiles that compose the tile
175
- if (verbose) {
176
- console.log(`optimizeHash: Tile X: ${tile.x}, Y: ${tile.y} zoom ${tile.zoom}, intersectionTarget ${intersectionTarget.maxZoom}, - generate from a tile the next zoom level tiles that compose the tile`);
177
- }
178
- const tiles = this.generateSubTiles(tile);
179
- for (const subTile of tiles) {
180
- const intersection = intersectionFunction(subTile, intersectionTarget);
181
- if (verbose) {
182
- console.log(`Tile X: ${subTile.x}, Y: ${subTile.y} zoom ${subTile.zoom}, intersection: ${intersection}`);
183
- }
184
- if (intersection === TileIntersectionState.FULL) {
185
- /// convert it to tile range of the requested resolution
186
- /// add the range to the result set (yield is used for lazy calculation to improve memory usage)
187
- const tileRange = this.tileToRange(subTile, targetZoom);
188
- if (verbose) {
189
- console.log(`return BBOX tile range zoom: ${tileRange.zoom} : X ${tileRange.minX} - ${tileRange.maxX} : Y ${tileRange.minY} - ${tileRange.maxY}`);
190
- }
191
- yield tileRange;
192
- }
193
- else if (intersection === TileIntersectionState.PARTIAL) {
194
- /// if it partly covered:
195
- // calculate the sub tiles contained in the current tile (in the next zoom level) - recursive
196
- yield* this.optimizeHash(subTile, targetZoom, intersectionTarget, intersectionFunction, verbose);
197
- }
198
- }
199
- }
200
- generateSubTiles(tile) {
201
- const tile0 = { x: tile.x << 1, y: tile.y << 1, zoom: tile.zoom + 1 };
202
- const tile1 = { x: tile0.x + 1, y: tile0.y, zoom: tile0.zoom };
203
- const tile2 = { x: tile0.x, y: tile0.y + 1, zoom: tile0.zoom };
204
- const tile3 = { x: tile0.x + 1, y: tile0.y + 1, zoom: tile0.zoom };
205
- const tiles = [tile0, tile1, tile2, tile3];
206
- return tiles;
207
- }
208
- tileFootprintIntersection = (tile, intersectionParams) => {
209
- const tileBbox = (0, tiles_1.tileToBbox)(tile);
210
- const tilePoly = (0, turf_1.bboxPolygon)(tileBbox);
211
- const intersection = (0, turf_1.intersect)(intersectionParams.footprint, tilePoly);
212
- if (intersection === null) {
213
- return TileIntersectionState.NONE;
214
- }
215
- // stop condition
216
- if (tile.zoom === intersectionParams.maxZoom) {
217
- return TileIntersectionState.FULL;
218
- }
219
- const intArea = (0, turf_1.area)(intersection);
220
- const hashArea = (0, turf_1.area)(tilePoly);
221
- if (intArea == hashArea) {
222
- return TileIntersectionState.FULL;
223
- }
224
- return TileIntersectionState.PARTIAL;
225
- };
226
- isBbox(footprint) {
227
- const bbox = (0, turf_1.bbox)(footprint);
228
- const bboxPoly = (0, turf_1.bboxPolygon)(bbox);
229
- return (0, turf_1.booleanEqual)(footprint, bboxPoly);
230
- }
231
- }
232
- exports.TileRanger = TileRanger;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TileRanger = void 0;
4
+ const turf_1 = require("@turf/turf");
5
+ const bboxUtils_1 = require("./bboxUtils");
6
+ const tiles_1 = require("./tiles");
7
+ const tilesGenerator_1 = require("./tilesGenerator");
8
+ var TileIntersectionState;
9
+ (function (TileIntersectionState) {
10
+ TileIntersectionState["FULL"] = "full";
11
+ TileIntersectionState["PARTIAL"] = "partial";
12
+ TileIntersectionState["NONE"] = "none";
13
+ })(TileIntersectionState || (TileIntersectionState = {}));
14
+ /**
15
+ * class for generating and decoding tile hashes
16
+ */
17
+ class TileRanger {
18
+ /**
19
+ * converts tile to tile range of specified zoom level
20
+ * @param tile
21
+ * @param zoom target tile range zoom
22
+ * @returns
23
+ */
24
+ tileToRange(tile, zoom) {
25
+ let minX, minY, maxX, maxY;
26
+ minX = tile.x;
27
+ maxX = tile.x + 1;
28
+ minY = tile.y;
29
+ maxY = tile.y + 1;
30
+ if (tile.zoom < zoom) {
31
+ const dz = zoom - tile.zoom;
32
+ minX = minX << dz;
33
+ maxX = maxX << dz;
34
+ minY = minY << dz;
35
+ maxY = maxY << dz;
36
+ }
37
+ else if (tile.zoom > zoom) {
38
+ const dz = tile.zoom - zoom;
39
+ minX = minX >> dz;
40
+ minY = minY >> dz;
41
+ maxX = minX + 1;
42
+ maxY = minY + 1;
43
+ }
44
+ return {
45
+ minX,
46
+ minY,
47
+ maxX,
48
+ maxY,
49
+ zoom,
50
+ };
51
+ }
52
+ /**
53
+ * generate tile hashes
54
+ * @param footprint footprint to cover with generated tile hashes
55
+ * @param zoom max hash zoom
56
+ * @returns
57
+ */
58
+ async *encodeFootprint(footprint, zoom, verbose = false) {
59
+ ////////////////////////////////
60
+ /// Step 1: check if the footprint is identical to its bbox
61
+ ////////////////////////////////
62
+ if (verbose) {
63
+ console.log('encode footprint');
64
+ }
65
+ ////////////////////////////////
66
+ /// Step 2: convert footprint to BBOX
67
+ ////////////////////////////////
68
+ const bbox = (0, turf_1.bbox)(footprint);
69
+ if (this.isBbox(footprint)) {
70
+ // if it is convert its bbox directly to tile range and return it (bbox to tiles conversion is fast and direct mathematical conversion)
71
+ const tileRange = (0, bboxUtils_1.bboxToTileRange)(bbox, zoom);
72
+ if (verbose) {
73
+ console.log(`footprint is identical to its bbox - return BBOX tile range zoom: ${tileRange.zoom} : X ${tileRange.minX} - ${tileRange.maxX} : Y ${tileRange.minY} - ${tileRange.maxY}`);
74
+ }
75
+ yield await Promise.resolve(tileRange);
76
+ }
77
+ else {
78
+ const intersectionParams = {
79
+ footprint,
80
+ maxZoom: zoom,
81
+ };
82
+ if (verbose) {
83
+ console.log('footprint is different from its bbox - generateRanges');
84
+ }
85
+ yield* await Promise.resolve(this.generateRanges(bbox, zoom, intersectionParams, this.tileFootprintIntersection, verbose));
86
+ }
87
+ }
88
+ generateTiles(area, zoom) {
89
+ let gen;
90
+ if (Array.isArray(area)) {
91
+ const tileRangeGen = async function* tileRangeGenerator() {
92
+ yield await Promise.resolve((0, bboxUtils_1.bboxToTileRange)(area, zoom));
93
+ };
94
+ gen = tileRangeGen();
95
+ }
96
+ else {
97
+ gen = this.encodeFootprint(area, zoom);
98
+ }
99
+ return (0, tilesGenerator_1.tilesGenerator)(gen);
100
+ }
101
+ async *generateRanges(bbox, zoom, intersectionTarget, intersectionFunction, verbose = false) {
102
+ /////////////////////////////////////////////////////////////////////////////////////////////////
103
+ /// Step 3: Convert the bbox to tile range of the requested zoom
104
+ /////////////////////////////////////////////////////////////////////////////////////////////////
105
+ if (verbose) {
106
+ console.log('Convert the bbox to tile range of the requested zoom');
107
+ }
108
+ const boundingRange = (0, bboxUtils_1.bboxToTileRange)(bbox, zoom);
109
+ if (verbose) {
110
+ const bboxString = `BBOX[0]: ${bbox[0]}, BBOX[1]: ${bbox[1]}, BBOX[2]: ${bbox[2]}, BBOX[3]: ${bbox[3]}`;
111
+ console.log(`${bboxString}, Zoom: ${zoom}, bounding range: minX: ${boundingRange.minX}, maxX: ${boundingRange.maxX}, minY: ${boundingRange.minY}, maxY: ${boundingRange.maxY}`);
112
+ }
113
+ /////////////////////////////////////////////////////////////////////////////////////////////////
114
+ /// Step 4: Use range size to calculate zoom level where the target area is smaller then 1 tile
115
+ /// (use zoom zero in-case there is no such zoom, for example in global bbox).
116
+ /////////////////////////////////////////////////////////////////////////////////////////////////
117
+ // find minimal zoom where the the area can be converted by area the size of single tile to skip levels that can't have full hashes
118
+ if (verbose) {
119
+ console.log("find minimal zoom where the the area can be converted by area the size of single tile to skip levels that can't have full hashes");
120
+ }
121
+ const dx = boundingRange.maxX - boundingRange.minX;
122
+ const dy = boundingRange.maxY - boundingRange.minY;
123
+ const minXZoom = Math.max(Math.floor(Math.log2(1 << (zoom + 1)) / dx) - 1, 0);
124
+ const minYZoom = Math.max(Math.floor(Math.log2(1 << zoom) / dy), 0);
125
+ const minZoom = Math.min(minXZoom, minYZoom);
126
+ if (verbose) {
127
+ console.log(`MinZoom: ${minZoom}`);
128
+ }
129
+ /////////////////////////////////////////////////////////////////////////////////////////////////
130
+ /// Step 5: convert the requested bbox to to tile range of the zoom level calculated in step 3 (this reduce the iteration required for the calculation)
131
+ /////////////////////////////////////////////////////////////////////////////////////////////////
132
+ //find base hashes
133
+ const minimalRange = (0, bboxUtils_1.bboxToTileRange)(bbox, minZoom);
134
+ for (let x = minimalRange.minX; x < minimalRange.maxX; x++) {
135
+ for (let y = minimalRange.minY; y < minimalRange.maxY; y++) {
136
+ /////////////////////////////////////////////////////////////////////////////////////////////////
137
+ /// Step 6: for every tile in the current range:
138
+ /// Step 7: check the tile intersection with the footprint
139
+ /////////////////////////////////////////////////////////////////////////////////////////////////
140
+ const tile = { x, y, zoom: minimalRange.zoom };
141
+ const intersection = intersectionFunction(tile, intersectionTarget);
142
+ if (verbose) {
143
+ console.log(`Tile X: ${tile.x}, Y: ${tile.y} zoom ${tile.zoom}, intersection: ${intersection}`);
144
+ }
145
+ /// if it is completely covered or the tile is in the requested zoom:
146
+ if (intersection === TileIntersectionState.FULL) {
147
+ /// convert it to tile range of the requested resolution
148
+ /// add the range to the result set (yield is used for lazy calculation to improve memory usage)
149
+ const tileRange = this.tileToRange(tile, zoom);
150
+ if (verbose) {
151
+ console.log(`return BBOX tile range zoom: ${tileRange.zoom} : X ${tileRange.minX} - ${tileRange.maxX} : Y ${tileRange.minY} - ${tileRange.maxY}`);
152
+ }
153
+ yield await Promise.resolve(tileRange);
154
+ }
155
+ else if (intersection === TileIntersectionState.PARTIAL) {
156
+ /// if it partly covered:
157
+ // calculate the sub tiles contained in the current tile (in the next zoom level)
158
+ // for every sub tile recursively run step 6
159
+ //optimize partial base hashes
160
+ yield* await Promise.resolve(this.optimizeHash(tile, zoom, intersectionTarget, intersectionFunction, verbose));
161
+ }
162
+ /// else do nothing as this tiles aren't intersected with the original footprint
163
+ }
164
+ }
165
+ }
166
+ /**
167
+ * generate tile
168
+ * @param tile tile to get all intersecting tiles from
169
+ * @param targetZoom target tiles zoom level
170
+ * @param intersectionTarget original zoom level and footprint to intersect
171
+ * @param intersectionFunction the intersection function to be called
172
+ */
173
+ *optimizeHash(tile, targetZoom, intersectionTarget, intersectionFunction, verbose = false) {
174
+ /// generate from a tile the next zoom level tiles that compose the tile
175
+ if (verbose) {
176
+ console.log(`optimizeHash: Tile X: ${tile.x}, Y: ${tile.y} zoom ${tile.zoom}, intersectionTarget ${intersectionTarget.maxZoom}, - generate from a tile the next zoom level tiles that compose the tile`);
177
+ }
178
+ const tiles = this.generateSubTiles(tile);
179
+ for (const subTile of tiles) {
180
+ const intersection = intersectionFunction(subTile, intersectionTarget);
181
+ if (verbose) {
182
+ console.log(`Tile X: ${subTile.x}, Y: ${subTile.y} zoom ${subTile.zoom}, intersection: ${intersection}`);
183
+ }
184
+ if (intersection === TileIntersectionState.FULL) {
185
+ /// convert it to tile range of the requested resolution
186
+ /// add the range to the result set (yield is used for lazy calculation to improve memory usage)
187
+ const tileRange = this.tileToRange(subTile, targetZoom);
188
+ if (verbose) {
189
+ console.log(`return BBOX tile range zoom: ${tileRange.zoom} : X ${tileRange.minX} - ${tileRange.maxX} : Y ${tileRange.minY} - ${tileRange.maxY}`);
190
+ }
191
+ yield tileRange;
192
+ }
193
+ else if (intersection === TileIntersectionState.PARTIAL) {
194
+ /// if it partly covered:
195
+ // calculate the sub tiles contained in the current tile (in the next zoom level) - recursive
196
+ yield* this.optimizeHash(subTile, targetZoom, intersectionTarget, intersectionFunction, verbose);
197
+ }
198
+ }
199
+ }
200
+ generateSubTiles(tile) {
201
+ const tile0 = { x: tile.x << 1, y: tile.y << 1, zoom: tile.zoom + 1 };
202
+ const tile1 = { x: tile0.x + 1, y: tile0.y, zoom: tile0.zoom };
203
+ const tile2 = { x: tile0.x, y: tile0.y + 1, zoom: tile0.zoom };
204
+ const tile3 = { x: tile0.x + 1, y: tile0.y + 1, zoom: tile0.zoom };
205
+ const tiles = [tile0, tile1, tile2, tile3];
206
+ return tiles;
207
+ }
208
+ tileFootprintIntersection = (tile, intersectionParams) => {
209
+ const tileBbox = (0, tiles_1.tileToBbox)(tile);
210
+ const tilePoly = (0, turf_1.bboxPolygon)(tileBbox);
211
+ const intersection = (0, turf_1.intersect)(intersectionParams.footprint, tilePoly);
212
+ if (intersection === null) {
213
+ return TileIntersectionState.NONE;
214
+ }
215
+ // stop condition
216
+ if (tile.zoom === intersectionParams.maxZoom) {
217
+ return TileIntersectionState.FULL;
218
+ }
219
+ const intArea = (0, turf_1.area)(intersection);
220
+ const hashArea = (0, turf_1.area)(tilePoly);
221
+ if (intArea == hashArea) {
222
+ return TileIntersectionState.FULL;
223
+ }
224
+ return TileIntersectionState.PARTIAL;
225
+ };
226
+ isBbox(footprint) {
227
+ const bbox = (0, turf_1.bbox)(footprint);
228
+ const bboxPoly = (0, turf_1.bboxPolygon)(bbox);
229
+ return (0, turf_1.booleanEqual)(footprint, bboxPoly);
230
+ }
231
+ }
232
+ exports.TileRanger = TileRanger;
233
233
  //# sourceMappingURL=tileRanger.js.map