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