@map-colonies/mc-utils 2.0.0 → 2.0.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 (114) hide show
  1. package/README.md +67 -67
  2. package/dist/arrays/index.d.ts +1 -1
  3. package/dist/arrays/index.d.ts.map +0 -0
  4. package/dist/arrays/index.js +17 -17
  5. package/dist/arrays/index.js.map +0 -0
  6. package/dist/arrays/subGroups.d.ts +8 -8
  7. package/dist/arrays/subGroups.d.ts.map +0 -0
  8. package/dist/arrays/subGroups.js +138 -138
  9. package/dist/arrays/subGroups.js.map +0 -0
  10. package/dist/communication/http/httpClient.d.ts +29 -29
  11. package/dist/communication/http/httpClient.d.ts.map +0 -0
  12. package/dist/communication/http/httpClient.js +434 -434
  13. package/dist/communication/http/httpClient.js.map +0 -0
  14. package/dist/communication/http/index.d.ts +1 -1
  15. package/dist/communication/http/index.d.ts.map +0 -0
  16. package/dist/communication/http/index.js +17 -17
  17. package/dist/communication/http/index.js.map +0 -0
  18. package/dist/communication/index.d.ts +1 -1
  19. package/dist/communication/index.d.ts.map +0 -0
  20. package/dist/communication/index.js +17 -17
  21. package/dist/communication/index.js.map +0 -0
  22. package/dist/dateTime/getUTCDate.d.ts +1 -1
  23. package/dist/dateTime/getUTCDate.d.ts.map +0 -0
  24. package/dist/dateTime/getUTCDate.js +10 -10
  25. package/dist/dateTime/getUTCDate.js.map +0 -0
  26. package/dist/dateTime/index.d.ts +1 -1
  27. package/dist/dateTime/index.d.ts.map +0 -0
  28. package/dist/dateTime/index.js +17 -17
  29. package/dist/dateTime/index.js.map +0 -0
  30. package/dist/geo/bboxUtils.d.ts +23 -23
  31. package/dist/geo/bboxUtils.d.ts.map +0 -0
  32. package/dist/geo/bboxUtils.js +89 -89
  33. package/dist/geo/bboxUtils.js.map +0 -0
  34. package/dist/geo/geoConvertor.d.ts +18 -18
  35. package/dist/geo/geoConvertor.d.ts.map +0 -0
  36. package/dist/geo/geoConvertor.js +51 -51
  37. package/dist/geo/geoConvertor.js.map +0 -0
  38. package/dist/geo/geoHash.d.ts +24 -24
  39. package/dist/geo/geoHash.d.ts.map +1 -1
  40. package/dist/geo/geoHash.js +274 -246
  41. package/dist/geo/geoHash.js.map +1 -1
  42. package/dist/geo/geoIntersection.d.ts +19 -19
  43. package/dist/geo/geoIntersection.d.ts.map +0 -0
  44. package/dist/geo/geoIntersection.js +70 -70
  45. package/dist/geo/geoIntersection.js.map +0 -0
  46. package/dist/geo/index.d.ts +8 -8
  47. package/dist/geo/index.d.ts.map +0 -0
  48. package/dist/geo/index.js +24 -24
  49. package/dist/geo/index.js.map +0 -0
  50. package/dist/geo/tileBatcher.d.ts +8 -8
  51. package/dist/geo/tileBatcher.d.ts.map +1 -1
  52. package/dist/geo/tileBatcher.js +188 -167
  53. package/dist/geo/tileBatcher.js.map +1 -1
  54. package/dist/geo/tileRanger.d.ts +46 -46
  55. package/dist/geo/tileRanger.d.ts.map +0 -0
  56. package/dist/geo/tileRanger.js +327 -327
  57. package/dist/geo/tileRanger.js.map +0 -0
  58. package/dist/geo/tiles.d.ts +82 -82
  59. package/dist/geo/tiles.d.ts.map +0 -0
  60. package/dist/geo/tiles.js +246 -246
  61. package/dist/geo/tiles.js.map +0 -0
  62. package/dist/geo/tilesGenerator.d.ts +2 -2
  63. package/dist/geo/tilesGenerator.d.ts.map +0 -0
  64. package/dist/geo/tilesGenerator.js +94 -94
  65. package/dist/geo/tilesGenerator.js.map +0 -0
  66. package/dist/index.d.ts +5 -5
  67. package/dist/index.d.ts.map +0 -0
  68. package/dist/index.js +21 -21
  69. package/dist/index.js.map +0 -0
  70. package/dist/models/enums/gdal/dataType.d.ts +16 -16
  71. package/dist/models/enums/gdal/dataType.d.ts.map +0 -0
  72. package/dist/models/enums/gdal/dataType.js +20 -20
  73. package/dist/models/enums/gdal/dataType.js.map +0 -0
  74. package/dist/models/enums/gdal/index.d.ts +2 -2
  75. package/dist/models/enums/gdal/index.d.ts.map +0 -0
  76. package/dist/models/enums/gdal/index.js +18 -18
  77. package/dist/models/enums/gdal/index.js.map +0 -0
  78. package/dist/models/enums/gdal/resamplingMethod.d.ts +16 -16
  79. package/dist/models/enums/gdal/resamplingMethod.d.ts.map +0 -0
  80. package/dist/models/enums/gdal/resamplingMethod.js +20 -20
  81. package/dist/models/enums/gdal/resamplingMethod.js.map +0 -0
  82. package/dist/models/enums/geo/index.d.ts +1 -1
  83. package/dist/models/enums/geo/index.d.ts.map +0 -0
  84. package/dist/models/enums/geo/index.js +17 -17
  85. package/dist/models/enums/geo/index.js.map +0 -0
  86. package/dist/models/enums/geo/tileOrigin.d.ts +7 -7
  87. package/dist/models/enums/geo/tileOrigin.d.ts.map +0 -0
  88. package/dist/models/enums/geo/tileOrigin.js +11 -11
  89. package/dist/models/enums/geo/tileOrigin.js.map +0 -0
  90. package/dist/models/enums/index.d.ts +2 -2
  91. package/dist/models/enums/index.d.ts.map +0 -0
  92. package/dist/models/enums/index.js +18 -18
  93. package/dist/models/enums/index.js.map +0 -0
  94. package/dist/models/index.d.ts +2 -2
  95. package/dist/models/index.d.ts.map +0 -0
  96. package/dist/models/index.js +18 -18
  97. package/dist/models/index.js.map +0 -0
  98. package/dist/models/interfaces/geo/iPoint.d.ts +7 -7
  99. package/dist/models/interfaces/geo/iPoint.d.ts.map +0 -0
  100. package/dist/models/interfaces/geo/iPoint.js +2 -2
  101. package/dist/models/interfaces/geo/iPoint.js.map +0 -0
  102. package/dist/models/interfaces/geo/iTile.d.ts +15 -15
  103. package/dist/models/interfaces/geo/iTile.d.ts.map +0 -0
  104. package/dist/models/interfaces/geo/iTile.js +2 -2
  105. package/dist/models/interfaces/geo/iTile.js.map +0 -0
  106. package/dist/models/interfaces/geo/index.d.ts +2 -2
  107. package/dist/models/interfaces/geo/index.d.ts.map +0 -0
  108. package/dist/models/interfaces/geo/index.js +18 -18
  109. package/dist/models/interfaces/geo/index.js.map +0 -0
  110. package/dist/models/interfaces/index.d.ts +1 -1
  111. package/dist/models/interfaces/index.d.ts.map +0 -0
  112. package/dist/models/interfaces/index.js +17 -17
  113. package/dist/models/interfaces/index.js.map +0 -0
  114. package/package.json +79 -79
package/dist/geo/tiles.js CHANGED
@@ -1,247 +1,247 @@
1
- "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.featureCollectionToTilesCount = exports.featureToTilesCount = exports.tileRangeToTilesCount = exports.tileToBbox = exports.degreesPerPixelToZoomLevel = exports.zoomLevelToResolutionMeter = exports.zoomLevelToResolutionDeg = exports.flipYAxis = exports.degreesPerPixel = exports.degreesPerTile = void 0;
15
- var turf_1 = require("@turf/turf");
16
- var bboxUtils_1 = require("./bboxUtils");
17
- var geoConvertor_1 = require("./geoConvertor");
18
- var zoomToResolutionDegMapper = {
19
- /* eslint-disable @typescript-eslint/naming-convention */
20
- 0: 0.703125,
21
- 1: 0.3515625,
22
- 2: 0.17578125,
23
- 3: 0.087890625,
24
- 4: 0.0439453125,
25
- 5: 0.02197265625,
26
- 6: 0.010986328125,
27
- 7: 0.0054931640625,
28
- 8: 0.00274658203125,
29
- 9: 0.001373291015625,
30
- 10: 0.0006866455078125,
31
- 11: 0.00034332275390625,
32
- 12: 0.000171661376953125,
33
- 13: 0.0000858306884765625,
34
- 14: 0.0000429153442382812,
35
- 15: 0.0000214576721191406,
36
- 16: 0.0000107288360595703,
37
- 17: 0.00000536441802978516,
38
- 18: 0.00000268220901489258,
39
- 19: 0.00000134110450744629,
40
- 20: 0.000000670552253723145,
41
- 21: 0.000000335276126861572,
42
- 22: 0.000000167638063430786,
43
- /* eslint-enable @typescript-eslint/naming-convention */
44
- };
45
- var zoomToResolutionMeterMapper = {
46
- /* eslint-disable @typescript-eslint/naming-convention */
47
- 0: 78271.52,
48
- 1: 39135.76,
49
- 2: 19567.88,
50
- 3: 9783.94,
51
- 4: 4891.97,
52
- 5: 2445.98,
53
- 6: 1222.99,
54
- 7: 611.5,
55
- 8: 305.75,
56
- 9: 152.87,
57
- 10: 76.44,
58
- 11: 38.22,
59
- 12: 19.11,
60
- 13: 9.55,
61
- 14: 4.78,
62
- 15: 2.39,
63
- 16: 1.19,
64
- 17: 0.6,
65
- 18: 0.3,
66
- 19: 0.15,
67
- 20: 0.075,
68
- 21: 0.037,
69
- 22: 0.0185,
70
- /* eslint-enable @typescript-eslint/naming-convention */
71
- };
72
- /**
73
- * calculates tile size (resolution) in degrees
74
- * @param zoomLevel zoom level of returned tile size
75
- * @returns tile size (resolution) in degrees
76
- */
77
- function degreesPerTile(zoomLevel) {
78
- var latRange = 180;
79
- return latRange / (1 << zoomLevel);
80
- }
81
- exports.degreesPerTile = degreesPerTile;
82
- /**
83
- * returns pixel size (resolution) in degrees
84
- * @param zoomLevel tile zoom level of returned tile pixel size
85
- * @returns pixel size (resolution) in degrees
86
- */
87
- function degreesPerPixel(zoomLevel) {
88
- var tileSize = 256;
89
- var tileRes = degreesPerTile(zoomLevel);
90
- return tileRes / tileSize;
91
- }
92
- exports.degreesPerPixel = degreesPerPixel;
93
- /**
94
- * coverts tile coordinates between ll and ul
95
- * @param tile source tile
96
- * @returns converted tile
97
- */
98
- function flipYAxis(tile) {
99
- var yTiles = 1 << tile.zoom;
100
- return {
101
- x: tile.x,
102
- y: yTiles - tile.y - 1,
103
- zoom: tile.zoom,
104
- };
105
- }
106
- exports.flipYAxis = flipYAxis;
107
- /**
108
- * converts zoom level (integer) to matching resolution degree value
109
- * @param zoom zoom level in range of 0-22
110
- * @returns resolution represented in degrees, or undefined if zoom level is out of range
111
- */
112
- function zoomLevelToResolutionDeg(zoom) {
113
- return zoomToResolutionDegMapper[zoom];
114
- }
115
- exports.zoomLevelToResolutionDeg = zoomLevelToResolutionDeg;
116
- /**
117
- * converts zoom level (integer) to matching resolution meter value
118
- * @param zoom zoom level in range of 0-22
119
- * @returns resolution represented in Meters, or undefined if zoom level is out of range
120
- */
121
- function zoomLevelToResolutionMeter(zoom) {
122
- return zoomToResolutionMeterMapper[zoom];
123
- }
124
- exports.zoomLevelToResolutionMeter = zoomLevelToResolutionMeter;
125
- /**
126
- * converts pixel size (resolution) in degrees to matching zoom level (rounded down)
127
- * @param resolution pixel size (resolution) in degrees
128
- * @returns zoom level for given pixel size
129
- */
130
- function degreesPerPixelToZoomLevel(resolution) {
131
- var MIN_ZOOM_LEVEL = 0;
132
- // eslint-disable-next-line @typescript-eslint/no-magic-numbers
133
- var zoomLevel = Math.floor(Math.log2(180 / (resolution * 256)));
134
- if (zoomLevel < MIN_ZOOM_LEVEL) {
135
- throw new Error("Invalid zoom level ".concat(zoomLevel, " for resolution ").concat(resolution));
136
- }
137
- return zoomLevel;
138
- }
139
- exports.degreesPerPixelToZoomLevel = degreesPerPixelToZoomLevel;
140
- /**
141
- * returns bbox of given tile
142
- * @param tile
143
- * @returns
144
- */
145
- function tileToBbox(tile) {
146
- var minPoint = (0, geoConvertor_1.tileToDegrees)(tile);
147
- var tileSize = degreesPerTile(tile.zoom);
148
- return [minPoint.longitude, minPoint.latitude, minPoint.longitude + tileSize, minPoint.latitude + tileSize];
149
- }
150
- exports.tileToBbox = tileToBbox;
151
- /**
152
- * returns the batch area
153
- * @param ITileRange
154
- * @returns
155
- */
156
- function tileRangeToTilesCount(batch) {
157
- return (batch.maxX - batch.minX) * (batch.maxY - batch.minY);
158
- }
159
- exports.tileRangeToTilesCount = tileRangeToTilesCount;
160
- /**
161
- * returns tiles amount of given feature and zoom ranges - based on 2:1 tile scheme
162
- * use the bboxToTileRange method and provide sanitized bbox coverage of tiles
163
- * @param feature
164
- * If feature's properties include attributes of "maxResolutionDeg" and "minResolutionDeg" or just one of them -
165
- * It will be converted to maxZoom and minZoom instead of default params to calculate
166
- * minResolutionDeg >= 0.703125
167
- * maxResolutionDeg <= 0.000000167638063430786
168
- * @param layerFootprint - referenced layer geometry to snap on the bbox
169
- * @param defaultMaxZoom optional - default is 22 - if maxResolutionDeg property was provided, the param will be ignored
170
- * @param defaultMinZoom optional - default is 0 - if minResolutionDeg property was provided, the param will be ignored
171
- * @returns tile count included on provided feature and zooms ranges
172
- */
173
- function featureToTilesCount(feature, defaultMaxZoom, defaultMinZoom) {
174
- var _a, _b;
175
- if (defaultMaxZoom === void 0) { defaultMaxZoom = 22; }
176
- if (defaultMinZoom === void 0) { defaultMinZoom = 0; }
177
- var tilesTotalAmount = 0;
178
- if (defaultMaxZoom > 22 || defaultMinZoom < 0) {
179
- throw new RangeError("Un supported zoom levels values, min-max zoom should be [0-22] but actual [".concat(defaultMinZoom, ":").concat(defaultMaxZoom, "]"));
180
- }
181
- if (defaultMinZoom > defaultMaxZoom) {
182
- throw new RangeError("Illegal - defaultMinZoom[".concat(defaultMinZoom, "] is larger than defaultMaxZoom[").concat(defaultMaxZoom, "]"));
183
- }
184
- try {
185
- var targetMaxZoom = ((_a = feature.properties) === null || _a === void 0 ? void 0 : _a.maxResolutionDeg) !== undefined && typeof feature.properties.maxResolutionDeg === 'number'
186
- ? degreesPerPixelToZoomLevel(feature.properties.maxResolutionDeg)
187
- : defaultMaxZoom;
188
- var targetMinZoom = ((_b = feature.properties) === null || _b === void 0 ? void 0 : _b.minResolutionDeg) !== undefined && typeof feature.properties.minResolutionDeg === 'number'
189
- ? degreesPerPixelToZoomLevel(feature.properties.minResolutionDeg)
190
- : defaultMinZoom;
191
- var sanitized = (0, bboxUtils_1.snapBBoxToTileGrid)((0, turf_1.bbox)(feature.geometry), targetMaxZoom);
192
- for (var i = targetMinZoom; i <= targetMaxZoom; i++) {
193
- var zoomTilesBatch = (0, bboxUtils_1.bboxToTileRange)(sanitized, i);
194
- tilesTotalAmount += tileRangeToTilesCount(zoomTilesBatch);
195
- }
196
- return tilesTotalAmount;
197
- }
198
- catch (error) {
199
- var message = "Error occurred while trying to calculate tiles amount - encodeFootprint error: ".concat(JSON.stringify(error));
200
- throw new Error(message);
201
- }
202
- }
203
- exports.featureToTilesCount = featureToTilesCount;
204
- /**
205
- * returns tiles amount of given featureCollection [each feature may include maxResolutionDeg and minResolutionDeg
206
- * if no resolutions in property will calculate all features with optional argument]
207
- * based on 2:1 tile scheme
208
- * use the bboxToTileRange method and provide sanitized bbox coverage of tiles
209
- * @param fc - FeatureCollection
210
- * foreach feature in featuresCollection features array:
211
- * If feature's properties include attributes of "maxResolutionDeg" and "minResolutionDeg" or just one of them -
212
- * It will be converted to maxZoom and minZoom instead of default params to calculate
213
- * minResolutionDeg >= 0.703125
214
- * maxResolutionDeg <= 0.000000167638063430786
215
- * for current feature in the array
216
- * @param defaultMaxZoom optional - default is 22 - if maxResolutionDeg property was provided, the param will be ignored
217
- * @param defaultMinZoom optional - default is 0 - if minResolutionDeg property was provided, the param will be ignored
218
- * @returns tile count included on provided feature and zooms ranges
219
- */
220
- function featureCollectionToTilesCount(fc, defaultMaxZoom, defaultMinZoom) {
221
- var e_1, _a;
222
- if (defaultMaxZoom === void 0) { defaultMaxZoom = 22; }
223
- if (defaultMinZoom === void 0) { defaultMinZoom = 0; }
224
- var tilesTotalAmount = 0;
225
- try {
226
- try {
227
- for (var _b = __values(fc.features), _c = _b.next(); !_c.done; _c = _b.next()) {
228
- var feature = _c.value;
229
- tilesTotalAmount += featureToTilesCount(feature, defaultMaxZoom, defaultMinZoom);
230
- }
231
- }
232
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
233
- finally {
234
- try {
235
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
236
- }
237
- finally { if (e_1) throw e_1.error; }
238
- }
239
- return tilesTotalAmount;
240
- }
241
- catch (error) {
242
- var message = "Error occurred while trying to calculate tiles amount - encodeFootprint error: ".concat(JSON.stringify(error));
243
- throw new Error(message);
244
- }
245
- }
246
- exports.featureCollectionToTilesCount = featureCollectionToTilesCount;
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.featureCollectionToTilesCount = exports.featureToTilesCount = exports.tileRangeToTilesCount = exports.tileToBbox = exports.degreesPerPixelToZoomLevel = exports.zoomLevelToResolutionMeter = exports.zoomLevelToResolutionDeg = exports.flipYAxis = exports.degreesPerPixel = exports.degreesPerTile = void 0;
15
+ var turf_1 = require("@turf/turf");
16
+ var bboxUtils_1 = require("./bboxUtils");
17
+ var geoConvertor_1 = require("./geoConvertor");
18
+ var zoomToResolutionDegMapper = {
19
+ /* eslint-disable @typescript-eslint/naming-convention */
20
+ 0: 0.703125,
21
+ 1: 0.3515625,
22
+ 2: 0.17578125,
23
+ 3: 0.087890625,
24
+ 4: 0.0439453125,
25
+ 5: 0.02197265625,
26
+ 6: 0.010986328125,
27
+ 7: 0.0054931640625,
28
+ 8: 0.00274658203125,
29
+ 9: 0.001373291015625,
30
+ 10: 0.0006866455078125,
31
+ 11: 0.00034332275390625,
32
+ 12: 0.000171661376953125,
33
+ 13: 0.0000858306884765625,
34
+ 14: 0.0000429153442382812,
35
+ 15: 0.0000214576721191406,
36
+ 16: 0.0000107288360595703,
37
+ 17: 0.00000536441802978516,
38
+ 18: 0.00000268220901489258,
39
+ 19: 0.00000134110450744629,
40
+ 20: 0.000000670552253723145,
41
+ 21: 0.000000335276126861572,
42
+ 22: 0.000000167638063430786,
43
+ /* eslint-enable @typescript-eslint/naming-convention */
44
+ };
45
+ var zoomToResolutionMeterMapper = {
46
+ /* eslint-disable @typescript-eslint/naming-convention */
47
+ 0: 78271.52,
48
+ 1: 39135.76,
49
+ 2: 19567.88,
50
+ 3: 9783.94,
51
+ 4: 4891.97,
52
+ 5: 2445.98,
53
+ 6: 1222.99,
54
+ 7: 611.5,
55
+ 8: 305.75,
56
+ 9: 152.87,
57
+ 10: 76.44,
58
+ 11: 38.22,
59
+ 12: 19.11,
60
+ 13: 9.55,
61
+ 14: 4.78,
62
+ 15: 2.39,
63
+ 16: 1.19,
64
+ 17: 0.6,
65
+ 18: 0.3,
66
+ 19: 0.15,
67
+ 20: 0.075,
68
+ 21: 0.037,
69
+ 22: 0.0185,
70
+ /* eslint-enable @typescript-eslint/naming-convention */
71
+ };
72
+ /**
73
+ * calculates tile size (resolution) in degrees
74
+ * @param zoomLevel zoom level of returned tile size
75
+ * @returns tile size (resolution) in degrees
76
+ */
77
+ function degreesPerTile(zoomLevel) {
78
+ var latRange = 180;
79
+ return latRange / (1 << zoomLevel);
80
+ }
81
+ exports.degreesPerTile = degreesPerTile;
82
+ /**
83
+ * returns pixel size (resolution) in degrees
84
+ * @param zoomLevel tile zoom level of returned tile pixel size
85
+ * @returns pixel size (resolution) in degrees
86
+ */
87
+ function degreesPerPixel(zoomLevel) {
88
+ var tileSize = 256;
89
+ var tileRes = degreesPerTile(zoomLevel);
90
+ return tileRes / tileSize;
91
+ }
92
+ exports.degreesPerPixel = degreesPerPixel;
93
+ /**
94
+ * coverts tile coordinates between ll and ul
95
+ * @param tile source tile
96
+ * @returns converted tile
97
+ */
98
+ function flipYAxis(tile) {
99
+ var yTiles = 1 << tile.zoom;
100
+ return {
101
+ x: tile.x,
102
+ y: yTiles - tile.y - 1,
103
+ zoom: tile.zoom,
104
+ };
105
+ }
106
+ exports.flipYAxis = flipYAxis;
107
+ /**
108
+ * converts zoom level (integer) to matching resolution degree value
109
+ * @param zoom zoom level in range of 0-22
110
+ * @returns resolution represented in degrees, or undefined if zoom level is out of range
111
+ */
112
+ function zoomLevelToResolutionDeg(zoom) {
113
+ return zoomToResolutionDegMapper[zoom];
114
+ }
115
+ exports.zoomLevelToResolutionDeg = zoomLevelToResolutionDeg;
116
+ /**
117
+ * converts zoom level (integer) to matching resolution meter value
118
+ * @param zoom zoom level in range of 0-22
119
+ * @returns resolution represented in Meters, or undefined if zoom level is out of range
120
+ */
121
+ function zoomLevelToResolutionMeter(zoom) {
122
+ return zoomToResolutionMeterMapper[zoom];
123
+ }
124
+ exports.zoomLevelToResolutionMeter = zoomLevelToResolutionMeter;
125
+ /**
126
+ * converts pixel size (resolution) in degrees to matching zoom level (rounded down)
127
+ * @param resolution pixel size (resolution) in degrees
128
+ * @returns zoom level for given pixel size
129
+ */
130
+ function degreesPerPixelToZoomLevel(resolution) {
131
+ var MIN_ZOOM_LEVEL = 0;
132
+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
133
+ var zoomLevel = Math.floor(Math.log2(180 / (resolution * 256)));
134
+ if (zoomLevel < MIN_ZOOM_LEVEL) {
135
+ throw new Error("Invalid zoom level ".concat(zoomLevel, " for resolution ").concat(resolution));
136
+ }
137
+ return zoomLevel;
138
+ }
139
+ exports.degreesPerPixelToZoomLevel = degreesPerPixelToZoomLevel;
140
+ /**
141
+ * returns bbox of given tile
142
+ * @param tile
143
+ * @returns
144
+ */
145
+ function tileToBbox(tile) {
146
+ var minPoint = (0, geoConvertor_1.tileToDegrees)(tile);
147
+ var tileSize = degreesPerTile(tile.zoom);
148
+ return [minPoint.longitude, minPoint.latitude, minPoint.longitude + tileSize, minPoint.latitude + tileSize];
149
+ }
150
+ exports.tileToBbox = tileToBbox;
151
+ /**
152
+ * returns the batch area
153
+ * @param ITileRange
154
+ * @returns
155
+ */
156
+ function tileRangeToTilesCount(batch) {
157
+ return (batch.maxX - batch.minX) * (batch.maxY - batch.minY);
158
+ }
159
+ exports.tileRangeToTilesCount = tileRangeToTilesCount;
160
+ /**
161
+ * returns tiles amount of given feature and zoom ranges - based on 2:1 tile scheme
162
+ * use the bboxToTileRange method and provide sanitized bbox coverage of tiles
163
+ * @param feature
164
+ * If feature's properties include attributes of "maxResolutionDeg" and "minResolutionDeg" or just one of them -
165
+ * It will be converted to maxZoom and minZoom instead of default params to calculate
166
+ * minResolutionDeg >= 0.703125
167
+ * maxResolutionDeg <= 0.000000167638063430786
168
+ * @param layerFootprint - referenced layer geometry to snap on the bbox
169
+ * @param defaultMaxZoom optional - default is 22 - if maxResolutionDeg property was provided, the param will be ignored
170
+ * @param defaultMinZoom optional - default is 0 - if minResolutionDeg property was provided, the param will be ignored
171
+ * @returns tile count included on provided feature and zooms ranges
172
+ */
173
+ function featureToTilesCount(feature, defaultMaxZoom, defaultMinZoom) {
174
+ var _a, _b;
175
+ if (defaultMaxZoom === void 0) { defaultMaxZoom = 22; }
176
+ if (defaultMinZoom === void 0) { defaultMinZoom = 0; }
177
+ var tilesTotalAmount = 0;
178
+ if (defaultMaxZoom > 22 || defaultMinZoom < 0) {
179
+ throw new RangeError("Un supported zoom levels values, min-max zoom should be [0-22] but actual [".concat(defaultMinZoom, ":").concat(defaultMaxZoom, "]"));
180
+ }
181
+ if (defaultMinZoom > defaultMaxZoom) {
182
+ throw new RangeError("Illegal - defaultMinZoom[".concat(defaultMinZoom, "] is larger than defaultMaxZoom[").concat(defaultMaxZoom, "]"));
183
+ }
184
+ try {
185
+ var targetMaxZoom = ((_a = feature.properties) === null || _a === void 0 ? void 0 : _a.maxResolutionDeg) !== undefined && typeof feature.properties.maxResolutionDeg === 'number'
186
+ ? degreesPerPixelToZoomLevel(feature.properties.maxResolutionDeg)
187
+ : defaultMaxZoom;
188
+ var targetMinZoom = ((_b = feature.properties) === null || _b === void 0 ? void 0 : _b.minResolutionDeg) !== undefined && typeof feature.properties.minResolutionDeg === 'number'
189
+ ? degreesPerPixelToZoomLevel(feature.properties.minResolutionDeg)
190
+ : defaultMinZoom;
191
+ var sanitized = (0, bboxUtils_1.snapBBoxToTileGrid)((0, turf_1.bbox)(feature.geometry), targetMaxZoom);
192
+ for (var i = targetMinZoom; i <= targetMaxZoom; i++) {
193
+ var zoomTilesBatch = (0, bboxUtils_1.bboxToTileRange)(sanitized, i);
194
+ tilesTotalAmount += tileRangeToTilesCount(zoomTilesBatch);
195
+ }
196
+ return tilesTotalAmount;
197
+ }
198
+ catch (error) {
199
+ var message = "Error occurred while trying to calculate tiles amount - encodeFootprint error: ".concat(JSON.stringify(error));
200
+ throw new Error(message);
201
+ }
202
+ }
203
+ exports.featureToTilesCount = featureToTilesCount;
204
+ /**
205
+ * returns tiles amount of given featureCollection [each feature may include maxResolutionDeg and minResolutionDeg
206
+ * if no resolutions in property will calculate all features with optional argument]
207
+ * based on 2:1 tile scheme
208
+ * use the bboxToTileRange method and provide sanitized bbox coverage of tiles
209
+ * @param fc - FeatureCollection
210
+ * foreach feature in featuresCollection features array:
211
+ * If feature's properties include attributes of "maxResolutionDeg" and "minResolutionDeg" or just one of them -
212
+ * It will be converted to maxZoom and minZoom instead of default params to calculate
213
+ * minResolutionDeg >= 0.703125
214
+ * maxResolutionDeg <= 0.000000167638063430786
215
+ * for current feature in the array
216
+ * @param defaultMaxZoom optional - default is 22 - if maxResolutionDeg property was provided, the param will be ignored
217
+ * @param defaultMinZoom optional - default is 0 - if minResolutionDeg property was provided, the param will be ignored
218
+ * @returns tile count included on provided feature and zooms ranges
219
+ */
220
+ function featureCollectionToTilesCount(fc, defaultMaxZoom, defaultMinZoom) {
221
+ var e_1, _a;
222
+ if (defaultMaxZoom === void 0) { defaultMaxZoom = 22; }
223
+ if (defaultMinZoom === void 0) { defaultMinZoom = 0; }
224
+ var tilesTotalAmount = 0;
225
+ try {
226
+ try {
227
+ for (var _b = __values(fc.features), _c = _b.next(); !_c.done; _c = _b.next()) {
228
+ var feature = _c.value;
229
+ tilesTotalAmount += featureToTilesCount(feature, defaultMaxZoom, defaultMinZoom);
230
+ }
231
+ }
232
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
233
+ finally {
234
+ try {
235
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
236
+ }
237
+ finally { if (e_1) throw e_1.error; }
238
+ }
239
+ return tilesTotalAmount;
240
+ }
241
+ catch (error) {
242
+ var message = "Error occurred while trying to calculate tiles amount - encodeFootprint error: ".concat(JSON.stringify(error));
243
+ throw new Error(message);
244
+ }
245
+ }
246
+ exports.featureCollectionToTilesCount = featureCollectionToTilesCount;
247
247
  //# sourceMappingURL=tiles.js.map
File without changes
@@ -1,3 +1,3 @@
1
- import { ITile, ITileRange } from '../models/interfaces/geo/iTile';
2
- export declare function tilesGenerator(rangeGen: Iterable<ITileRange>): Generator<ITile>;
1
+ import { ITile, ITileRange } from '../models/interfaces/geo/iTile';
2
+ export declare function tilesGenerator(rangeGen: Iterable<ITileRange>): Generator<ITile>;
3
3
  //# sourceMappingURL=tilesGenerator.d.ts.map
File without changes