@deck.gl-community/geo-layers 9.2.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +5 -0
- package/dist/global-grid-layer/global-grid-cluster-layer.d.ts +36 -0
- package/dist/global-grid-layer/global-grid-cluster-layer.d.ts.map +1 -0
- package/dist/global-grid-layer/global-grid-cluster-layer.js +55 -0
- package/dist/global-grid-layer/global-grid-cluster-layer.js.map +1 -0
- package/dist/global-grid-layer/global-grid-layer.d.ts +21 -0
- package/dist/global-grid-layer/global-grid-layer.d.ts.map +1 -0
- package/dist/global-grid-layer/global-grid-layer.js +33 -0
- package/dist/global-grid-layer/global-grid-layer.js.map +1 -0
- package/dist/global-grid-systems/grids/a5-grid.d.ts +18 -0
- package/dist/global-grid-systems/grids/a5-grid.d.ts.map +1 -0
- package/dist/global-grid-systems/grids/a5-grid.js +23 -0
- package/dist/global-grid-systems/grids/a5-grid.js.map +1 -0
- package/dist/global-grid-systems/grids/geohash-grid.d.ts +15 -0
- package/dist/global-grid-systems/grids/geohash-grid.d.ts.map +1 -0
- package/dist/global-grid-systems/grids/geohash-grid.js +92 -0
- package/dist/global-grid-systems/grids/geohash-grid.js.map +1 -0
- package/dist/global-grid-systems/grids/global-grid.d.ts +31 -0
- package/dist/global-grid-systems/grids/global-grid.d.ts.map +1 -0
- package/dist/global-grid-systems/grids/global-grid.js +5 -0
- package/dist/global-grid-systems/grids/global-grid.js.map +1 -0
- package/dist/global-grid-systems/grids/h3-grid.d.ts +16 -0
- package/dist/global-grid-systems/grids/h3-grid.d.ts.map +1 -0
- package/dist/global-grid-systems/grids/h3-grid.js +29 -0
- package/dist/global-grid-systems/grids/h3-grid.js.map +1 -0
- package/dist/global-grid-systems/grids/quadkey-grid.d.ts +41 -0
- package/dist/global-grid-systems/grids/quadkey-grid.d.ts.map +1 -0
- package/dist/global-grid-systems/grids/quadkey-grid.js +166 -0
- package/dist/global-grid-systems/grids/quadkey-grid.js.map +1 -0
- package/dist/global-grid-systems/grids/s2-grid.d.ts +16 -0
- package/dist/global-grid-systems/grids/s2-grid.d.ts.map +1 -0
- package/dist/global-grid-systems/grids/s2-grid.js +74 -0
- package/dist/global-grid-systems/grids/s2-grid.js.map +1 -0
- package/dist/global-grid-systems/h3-js-bigint/h3-js-bigint.d.ts +9 -0
- package/dist/global-grid-systems/h3-js-bigint/h3-js-bigint.d.ts.map +1 -0
- package/dist/global-grid-systems/h3-js-bigint/h3-js-bigint.js +62 -0
- package/dist/global-grid-systems/h3-js-bigint/h3-js-bigint.js.map +1 -0
- package/dist/global-grid-systems/s2-geometry/s2-geometry.d.ts +13 -0
- package/dist/global-grid-systems/s2-geometry/s2-geometry.d.ts.map +1 -0
- package/dist/global-grid-systems/s2-geometry/s2-geometry.js +139 -0
- package/dist/global-grid-systems/s2-geometry/s2-geometry.js.map +1 -0
- package/dist/global-grid-systems/s2-geometry/s2-to-boundary.d.ts +14 -0
- package/dist/global-grid-systems/s2-geometry/s2-to-boundary.d.ts.map +1 -0
- package/dist/global-grid-systems/s2-geometry/s2-to-boundary.js +60 -0
- package/dist/global-grid-systems/s2-geometry/s2-to-boundary.js.map +1 -0
- package/dist/global-grid-systems/s2-geometry/s2-token.d.ts +13 -0
- package/dist/global-grid-systems/s2-geometry/s2-token.d.ts.map +1 -0
- package/dist/global-grid-systems/s2-geometry/s2-token.js +61 -0
- package/dist/global-grid-systems/s2-geometry/s2-token.js.map +1 -0
- package/dist/global-grid-systems/utils/geometry-utils.d.ts +4 -0
- package/dist/global-grid-systems/utils/geometry-utils.d.ts.map +1 -0
- package/dist/global-grid-systems/utils/geometry-utils.js +26 -0
- package/dist/global-grid-systems/utils/geometry-utils.js.map +1 -0
- package/dist/global-grid-systems/utils/h3-utils.d.ts +5 -0
- package/dist/global-grid-systems/utils/h3-utils.d.ts.map +1 -0
- package/dist/global-grid-systems/utils/h3-utils.js +41 -0
- package/dist/global-grid-systems/utils/h3-utils.js.map +1 -0
- package/dist/global-grid-systems/utils/hex-utils.d.ts +8 -0
- package/dist/global-grid-systems/utils/hex-utils.d.ts.map +1 -0
- package/dist/global-grid-systems/utils/hex-utils.js +34 -0
- package/dist/global-grid-systems/utils/hex-utils.js.map +1 -0
- package/dist/index.cjs +640 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/tile-source-layer/tile-source-layer.d.ts +45 -0
- package/dist/tile-source-layer/tile-source-layer.d.ts.map +1 -0
- package/dist/tile-source-layer/tile-source-layer.js +110 -0
- package/dist/tile-source-layer/tile-source-layer.js.map +1 -0
- package/package.json +53 -0
- package/src/global-grid-layer/global-grid-cluster-layer.ts +93 -0
- package/src/global-grid-layer/global-grid-layer.ts +54 -0
- package/src/global-grid-systems/grids/a5-grid.ts +38 -0
- package/src/global-grid-systems/grids/geohash-grid.ts +105 -0
- package/src/global-grid-systems/grids/global-grid.ts +40 -0
- package/src/global-grid-systems/grids/h3-grid.ts +45 -0
- package/src/global-grid-systems/grids/quadkey-grid.ts +190 -0
- package/src/global-grid-systems/grids/s2-grid.ts +86 -0
- package/src/global-grid-systems/h3-js-bigint/h3-js-bigint.ts +85 -0
- package/src/global-grid-systems/s2-geometry/s2-geometry.ts +180 -0
- package/src/global-grid-systems/s2-geometry/s2-to-boundary.ts +76 -0
- package/src/global-grid-systems/s2-geometry/s2-token.ts +70 -0
- package/src/global-grid-systems/utils/geometry-utils.ts +28 -0
- package/src/global-grid-systems/utils/h3-utils.ts +52 -0
- package/src/global-grid-systems/utils/hex-utils.ts +37 -0
- package/src/index.ts +15 -0
- package/src/tile-source-layer/tile-source-layer.ts +156 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
const TILE_SIZE = 512;
|
|
5
|
+
/** Decoder for the quadkey DGGS */
|
|
6
|
+
export const QuadkeyGrid = {
|
|
7
|
+
name: 'quadkey',
|
|
8
|
+
hasNumericRepresentation: true,
|
|
9
|
+
// cellToToken: (cell: bigint): string => quadkeyCellToToken(cell),
|
|
10
|
+
// tokenToCell: (cell: string): bigint => quadKeyToBigint(cell),
|
|
11
|
+
cellToLngLat: (cell) => quadkeyCellToLngLat(getString(cell)),
|
|
12
|
+
cellToBoundary: (cell) => quadkeyCellToBoundary(getString(cell))
|
|
13
|
+
// cellToBoundaryPolygonFlat: (cell: string | bigint): number[] => getQuadkeyBoundaryFlat(cell),
|
|
14
|
+
// cellToBounds: (cell: string | bigint): Bounds2D => getQuadkeyBounds(cell)
|
|
15
|
+
};
|
|
16
|
+
/** Quadkey only supports strings */
|
|
17
|
+
const getString = (cell) => {
|
|
18
|
+
if (typeof cell !== 'string') {
|
|
19
|
+
throw new Error('geohash must be a string');
|
|
20
|
+
}
|
|
21
|
+
return cell;
|
|
22
|
+
};
|
|
23
|
+
function quadkeyCellToLngLat(quadkey) {
|
|
24
|
+
const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
|
|
25
|
+
const [w, n] = worldToLngLat(topLeft);
|
|
26
|
+
const [e, s] = worldToLngLat(bottomRight);
|
|
27
|
+
return [(e + w) / 2, (s + n) / 2];
|
|
28
|
+
}
|
|
29
|
+
function quadkeyCellToBoundary(quadkey) {
|
|
30
|
+
const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
|
|
31
|
+
const [w, n] = worldToLngLat(topLeft);
|
|
32
|
+
const [e, s] = worldToLngLat(bottomRight);
|
|
33
|
+
return [
|
|
34
|
+
[e, n],
|
|
35
|
+
[e, s],
|
|
36
|
+
[w, s],
|
|
37
|
+
[w, n],
|
|
38
|
+
[e, n]
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
export function quadkeyCellToBoundaryFlat(quadkey) {
|
|
42
|
+
const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
|
|
43
|
+
const [w, n] = worldToLngLat(topLeft);
|
|
44
|
+
const [e, s] = worldToLngLat(bottomRight);
|
|
45
|
+
return [e, n, e, s, w, s, w, n, e, n];
|
|
46
|
+
}
|
|
47
|
+
export function quadkeyCellToBounds(quadkey) {
|
|
48
|
+
const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
|
|
49
|
+
const [w, n] = worldToLngLat(topLeft);
|
|
50
|
+
const [e, s] = worldToLngLat(bottomRight);
|
|
51
|
+
return [
|
|
52
|
+
[w, s],
|
|
53
|
+
[e, n]
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
export function quadkeyToWorldBounds(quadkey) {
|
|
57
|
+
let x = 0;
|
|
58
|
+
let y = 0;
|
|
59
|
+
let mask = 1 << quadkey.length;
|
|
60
|
+
const scale = mask / TILE_SIZE;
|
|
61
|
+
for (let i = 0; i < quadkey.length; i++) {
|
|
62
|
+
mask >>= 1;
|
|
63
|
+
const q = parseInt(quadkey[i], 10);
|
|
64
|
+
if (q % 2)
|
|
65
|
+
x |= mask;
|
|
66
|
+
if (q > 1)
|
|
67
|
+
y |= mask;
|
|
68
|
+
}
|
|
69
|
+
return [
|
|
70
|
+
[x / scale, TILE_SIZE - y / scale],
|
|
71
|
+
[(x + 0.99) / scale, TILE_SIZE - (y + 0.99) / scale]
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
// CONSTANTS
|
|
75
|
+
const PI = Math.PI;
|
|
76
|
+
const PI_4 = PI / 4;
|
|
77
|
+
const RADIANS_TO_DEGREES = 180 / PI;
|
|
78
|
+
/**
|
|
79
|
+
* Unproject world point [x,y] on map onto {lat, lon} on sphere
|
|
80
|
+
*
|
|
81
|
+
* @param xy - array with [x,y] members
|
|
82
|
+
* representing point on projected map plane
|
|
83
|
+
* @return - array with [x,y] of point on sphere.
|
|
84
|
+
* Has toArray method if you need a GeoJSON Array.
|
|
85
|
+
* Per cartographic tradition, lat and lon are specified as degrees.
|
|
86
|
+
*/
|
|
87
|
+
function worldToLngLat(xy) {
|
|
88
|
+
const [x, y] = xy;
|
|
89
|
+
const lambda2 = (x / TILE_SIZE) * (2 * PI) - PI;
|
|
90
|
+
const phi2 = 2 * (Math.atan(Math.exp((y / TILE_SIZE) * (2 * PI) - PI)) - PI_4);
|
|
91
|
+
return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];
|
|
92
|
+
}
|
|
93
|
+
// EXPERIMENTAL BIGINT ENCODING FOR QUADKEYS
|
|
94
|
+
/**
|
|
95
|
+
* Encodes a QuadKey string into a bigint.
|
|
96
|
+
* @param quadkey - The QuadKey string.
|
|
97
|
+
* @returns The bigint representation of the QuadKey.
|
|
98
|
+
*/
|
|
99
|
+
export function quadKeyToBigint(quadkey) {
|
|
100
|
+
let result = 0n;
|
|
101
|
+
for (const digit of quadkey) {
|
|
102
|
+
const value = BigInt(parseInt(digit, 4));
|
|
103
|
+
result = (result << 2n) | value;
|
|
104
|
+
}
|
|
105
|
+
const zoom = quadkey.length;
|
|
106
|
+
// Shift the result to align with the most significant bits
|
|
107
|
+
const shift = 64 - 5 - zoom * 2; // Reserve 5 bits for zoom level
|
|
108
|
+
result = result << BigInt(shift);
|
|
109
|
+
// Append the zoom level in the least significant 5 bits
|
|
110
|
+
return result | BigInt(zoom);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Decodes a bigint-encoded QuadKey back into its string representation.
|
|
114
|
+
* @param encoded - The bigint representation of the QuadKey with embedded zoom level.
|
|
115
|
+
* @returns The decoded QuadKey string.
|
|
116
|
+
*/
|
|
117
|
+
export function bigintToQuadKey(encoded) {
|
|
118
|
+
const zoom = Number(encoded & 31n); // Extract the last 5 bits for zoom level
|
|
119
|
+
const shift = BigInt(64 - 5 - zoom * 2); // Calculate the shift to align the QuadKey bits
|
|
120
|
+
const quadkeyBits = (encoded >> shift) & ((1n << BigInt(zoom * 2)) - 1n); // Extract QuadKey bits
|
|
121
|
+
let quadkey = '';
|
|
122
|
+
for (let i = zoom - 1; i >= 0; i--) {
|
|
123
|
+
const digit = Number((quadkeyBits >> BigInt(i * 2)) & 3n);
|
|
124
|
+
quadkey += digit.toString();
|
|
125
|
+
}
|
|
126
|
+
return quadkey;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Checks if the child QuadKey is contained within the parent QuadKey.
|
|
130
|
+
* @param parent - The bigint representation of the parent QuadKey.
|
|
131
|
+
* @param child - The bigint representation of the child QuadKey.
|
|
132
|
+
* @returns True if the child is contained within the parent; otherwise, false.
|
|
133
|
+
*/
|
|
134
|
+
export function isContained(parent, child) {
|
|
135
|
+
const parentZoom = Number(parent & 31n); // Extract zoom level from parent
|
|
136
|
+
const childZoom = Number(child & 31n); // Extract zoom level from child
|
|
137
|
+
if (parentZoom >= childZoom)
|
|
138
|
+
return false;
|
|
139
|
+
const parentShift = BigInt(64 - 5 - parentZoom * 2);
|
|
140
|
+
const childShift = BigInt(64 - 5 - childZoom * 2);
|
|
141
|
+
const parentPrefix = (parent >> parentShift) & ((1n << BigInt(parentZoom * 2)) - 1n);
|
|
142
|
+
const childPrefix = (child >> childShift) & ((1n << BigInt(parentZoom * 2)) - 1n);
|
|
143
|
+
return parentPrefix === childPrefix;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Decodes a bigint-encoded QuadKey into tile X, tile Y, and zoom level.
|
|
147
|
+
* @param encoded - The bigint representation of the QuadKey with embedded zoom level.
|
|
148
|
+
* @returns An object containing tileX, tileY, and zoom.
|
|
149
|
+
*/
|
|
150
|
+
export function decodeBigintQuadKey(encoded) {
|
|
151
|
+
const zoom = Number(encoded & 31n); // Extract the last 5 bits for zoom level
|
|
152
|
+
const quadKeyBits = encoded >> 5n; // Remove the zoom level bits
|
|
153
|
+
let tileX = 0;
|
|
154
|
+
let tileY = 0;
|
|
155
|
+
for (let i = 0; i < zoom; i++) {
|
|
156
|
+
const shift = BigInt((zoom - i - 1) * 2);
|
|
157
|
+
const digit = Number((quadKeyBits >> shift) & 3n);
|
|
158
|
+
const mask = 1 << (zoom - i - 1);
|
|
159
|
+
if (digit & 1)
|
|
160
|
+
tileX |= mask;
|
|
161
|
+
if (digit & 2)
|
|
162
|
+
tileY |= mask;
|
|
163
|
+
}
|
|
164
|
+
return { tileX, tileY, zoom };
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=quadkey-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quadkey-grid.js","sourceRoot":"","sources":["../../../src/global-grid-systems/grids/quadkey-grid.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAKpC,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,mCAAmC;AACnC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,SAAS;IACf,wBAAwB,EAAE,IAAI;IAE9B,mEAAmE;IACnE,gEAAgE;IAEhE,YAAY,EAAE,CAAC,IAAqB,EAAoB,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/F,cAAc,EAAE,CAAC,IAAqB,EAAsB,EAAE,CAC5D,qBAAqB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAExC,gGAAgG;IAChG,4EAA4E;CAC/C,CAAC;AAEhC,oCAAoC;AACpC,MAAM,SAAS,GAAG,CAAC,IAAqB,EAAU,EAAE;IAClD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,SAAS,mBAAmB,CAAC,OAAe;IAC1C,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC7D,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CA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readonly hasNumericRepresentation: true;
|
|
6
|
+
readonly tokenToCell: (cell: string) => bigint;
|
|
7
|
+
readonly cellToToken: (cell: string | bigint) => string;
|
|
8
|
+
readonly cellToLngLat: (cell: string | bigint) => [number, number];
|
|
9
|
+
readonly cellToBoundary: (cell: string | bigint) => [number, number][];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve S2 geometry center
|
|
13
|
+
*/
|
|
14
|
+
export declare function getS2LngLat(cell: bigint): [number, number];
|
|
15
|
+
export declare function getS2Bounds(cell: bigint): Bounds2D;
|
|
16
|
+
//# sourceMappingURL=s2-grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-grid.d.ts","sourceRoot":"","sources":["../../../src/global-grid-systems/grids/s2-grid.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,KAAK,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAO7C,8BAA8B;AAC9B,eAAO,MAAM,MAAM;;;iCAIG,MAAM,KAAG,MAAM;iCACf,MAAM,GAAG,MAAM,KAAG,MAAM;kCACvB,MAAM,GAAG,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC;oCAChC,MAAM,GAAG,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;CAI9B,CAAC;AAOhC;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAS1D;AAuBD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAoBlD"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { getS2IndexFromToken, getS2TokenFromIndex } from "../s2-geometry/s2-token.js";
|
|
5
|
+
import { getS2GeoBounds } from "../s2-geometry/s2-to-boundary.js";
|
|
6
|
+
import { getS2Cell, IJToST, STToUV, FaceUVToXYZ, XYZToLngLat } from "../s2-geometry/s2-geometry.js";
|
|
7
|
+
/** Decoder for the S2 DGGS */
|
|
8
|
+
export const S2Grid = {
|
|
9
|
+
name: 'S2',
|
|
10
|
+
hasNumericRepresentation: true,
|
|
11
|
+
tokenToCell: (cell) => getS2IndexFromToken(cell),
|
|
12
|
+
cellToToken: (cell) => getS2TokenFromIndex(getBigInt(cell)),
|
|
13
|
+
cellToLngLat: (cell) => getS2LngLat(getBigInt(cell)),
|
|
14
|
+
cellToBoundary: (cell) => getS2Boundary(getBigInt(cell))
|
|
15
|
+
// cellToBoundaryPolygonFlat: (cell: bigint): number[] => getS2BoundaryFlat(cell),
|
|
16
|
+
// cellToBounds: (cell: bigint): Bounds2D => getS2Bounds(cell)
|
|
17
|
+
};
|
|
18
|
+
/** S2 functions operate on bigints */
|
|
19
|
+
const getBigInt = (value) => {
|
|
20
|
+
return typeof value === 'string' ? getS2IndexFromToken(value) : value;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Retrieve S2 geometry center
|
|
24
|
+
*/
|
|
25
|
+
export function getS2LngLat(cell) {
|
|
26
|
+
const s2Cell = getS2Cell(cell);
|
|
27
|
+
const st = IJToST(s2Cell.ij, s2Cell.level, [0.5, 0.5]);
|
|
28
|
+
const uv = STToUV(st);
|
|
29
|
+
const xyz = FaceUVToXYZ(s2Cell.face, uv);
|
|
30
|
+
const lngLat = XYZToLngLat(xyz);
|
|
31
|
+
return lngLat;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get a polygon with corner coordinates for an s2 cell
|
|
35
|
+
* @param - This can be an S2 key or token
|
|
36
|
+
* @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
|
|
37
|
+
* - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
|
|
38
|
+
*/
|
|
39
|
+
function getS2BoundaryFlat(cell) {
|
|
40
|
+
const float64Array = getS2GeoBounds(cell);
|
|
41
|
+
// TODO - inefficient
|
|
42
|
+
return Array.from(float64Array);
|
|
43
|
+
}
|
|
44
|
+
function getS2Boundary(cell) {
|
|
45
|
+
const flatBoundary = getS2BoundaryFlat(cell);
|
|
46
|
+
const boundary = [];
|
|
47
|
+
for (let i = 0; i < flatBoundary.length; i += 2) {
|
|
48
|
+
boundary.push([flatBoundary[i], flatBoundary[i + 1]]);
|
|
49
|
+
}
|
|
50
|
+
return boundary;
|
|
51
|
+
}
|
|
52
|
+
export function getS2Bounds(cell) {
|
|
53
|
+
const flatBoundary = getS2Boundary(cell);
|
|
54
|
+
// We know that we have at least one point, no Infinity will be returned.
|
|
55
|
+
let xmin = Infinity;
|
|
56
|
+
let ymin = Infinity;
|
|
57
|
+
let xmax = -Infinity;
|
|
58
|
+
let ymax = -Infinity;
|
|
59
|
+
for (const [x, y] of flatBoundary) {
|
|
60
|
+
if (x < xmin)
|
|
61
|
+
xmin = x;
|
|
62
|
+
if (x > xmax)
|
|
63
|
+
xmax = x;
|
|
64
|
+
if (y < ymin)
|
|
65
|
+
ymin = y;
|
|
66
|
+
if (y > ymax)
|
|
67
|
+
ymax = y;
|
|
68
|
+
}
|
|
69
|
+
return [
|
|
70
|
+
[xmin, ymin],
|
|
71
|
+
[xmax, ymax]
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=s2-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-grid.js","sourceRoot":"","sources":["../../../src/global-grid-systems/grids/s2-grid.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAKpC,OAAO,EAAC,mBAAmB,EAAE,mBAAmB,EAAC,mCAAgC;AACjF,OAAO,EAAC,cAAc,EAAC,yCAAsC;AAC7D,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAC,sCAAmC;AAE/F,8BAA8B;AAC9B,MAAM,CAA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} from 'h3-js';
|
|
2
|
+
export { type CoordPair, type SplitLong, latLngToCell };
|
|
3
|
+
export type H3IndexInput = bigint | string | SplitLong;
|
|
4
|
+
export declare function h3IndexToSplitLong(h3Index: H3IndexInput, target?: SplitLong): SplitLong;
|
|
5
|
+
export declare function h3IndexToBigInt(h3Index: H3IndexInput): bigint;
|
|
6
|
+
export declare function cellToLatLng(h3Index: H3IndexInput): [number, number];
|
|
7
|
+
export declare function cellToBoundary(h3Index: H3IndexInput, formatAsGeoJson?: boolean): CoordPair[];
|
|
8
|
+
export declare function cellsToMultiPolygon(h3Indexes: H3IndexInput[], formatAsGeoJson?: boolean): CoordPair[][][];
|
|
9
|
+
//# sourceMappingURL=h3-js-bigint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"h3-js-bigint.d.ts","sourceRoot":"","sources":["../../../src/global-grid-systems/h3-js-bigint/h3-js-bigint.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,YAAY,EAMb,MAAM,OAAO,CAAC;AAEf,OAAO,EAAC,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,YAAY,EAAC,CAAC;AAEtD,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAIvD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,SAAS,CAKvF;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAM7D;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAIpE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,EAAE,CAI5F;AAED,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,YAAY,EAAE,EACzB,eAAe,CAAC,EAAE,OAAO,GACxB,SAAS,EAAE,EAAE,EAAE,CAIjB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// deck.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// A thin wrapper around h3-js that support BigInts
|
|
5
|
+
// Note: incurs some overhead as we need to convert between BigInt and SplitLong
|
|
6
|
+
import { latLngToCell, cellToBoundary as _cellToBoundary, cellToLatLng as _cellToLatLng, cellsToMultiPolygon as _cellsToMultiPolygon, h3IndexToSplitLong as _h3IndexToSplitLong
|
|
7
|
+
// splitLongToH3Index as _splitLongToH3Index
|
|
8
|
+
} from 'h3-js';
|
|
9
|
+
export { latLngToCell };
|
|
10
|
+
const scratchSplitLong = [0, 0];
|
|
11
|
+
export function h3IndexToSplitLong(h3Index, target) {
|
|
12
|
+
if (typeof h3Index === 'bigint') {
|
|
13
|
+
return bigIntToSplitLong(h3Index, target ?? [0, 0]);
|
|
14
|
+
}
|
|
15
|
+
return _h3IndexToSplitLong(h3Index);
|
|
16
|
+
}
|
|
17
|
+
export function h3IndexToBigInt(h3Index) {
|
|
18
|
+
if (typeof h3Index === 'bigint') {
|
|
19
|
+
return h3Index;
|
|
20
|
+
}
|
|
21
|
+
const splitLong = h3IndexToSplitLong(h3Index, scratchSplitLong);
|
|
22
|
+
return splitLongToBigInt(splitLong);
|
|
23
|
+
}
|
|
24
|
+
export function cellToLatLng(h3Index) {
|
|
25
|
+
const splitLong = h3IndexToSplitLong(h3Index, scratchSplitLong);
|
|
26
|
+
const latLng = _cellToLatLng(splitLong);
|
|
27
|
+
return latLng;
|
|
28
|
+
}
|
|
29
|
+
export function cellToBoundary(h3Index, formatAsGeoJson) {
|
|
30
|
+
const splitLong = h3IndexToSplitLong(h3Index, scratchSplitLong);
|
|
31
|
+
const vertices = _cellToBoundary(splitLong, formatAsGeoJson);
|
|
32
|
+
return vertices;
|
|
33
|
+
}
|
|
34
|
+
export function cellsToMultiPolygon(h3Indexes, formatAsGeoJson) {
|
|
35
|
+
const splitLongs = h3Indexes.map((h3Index) => h3IndexToSplitLong(h3Index));
|
|
36
|
+
const polygons = _cellsToMultiPolygon(splitLongs, formatAsGeoJson);
|
|
37
|
+
return polygons;
|
|
38
|
+
}
|
|
39
|
+
// HELPERS
|
|
40
|
+
/**
|
|
41
|
+
* Splits a bigint into a 2-element array of 32-bit numbers.
|
|
42
|
+
* @param value - The bigint to split.
|
|
43
|
+
* @returns A 2-element array containing the high and low 32-bit numbers.
|
|
44
|
+
*/
|
|
45
|
+
function bigIntToSplitLong(value, target = [0, 0]) {
|
|
46
|
+
// Mask lower 32 bits
|
|
47
|
+
target[0] = Number(value & 0xffffffffn); // BigInt & BigInt ⇒ BigInt :contentReference[oaicite:2]{index=2}
|
|
48
|
+
// Shift right to get upper 32 bits
|
|
49
|
+
target[1] = Number((value >> 32n) & 0xffffffffn); // BigInt >> BigInt ⇒ BigInt :contentReference[oaicite:3]{index=3}
|
|
50
|
+
return target;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Joins two 32-bit numbers into a bigint.
|
|
54
|
+
* @param high - The high 32-bit number.
|
|
55
|
+
* @param low - The low 32-bit number.
|
|
56
|
+
* @returns The combined bigint.
|
|
57
|
+
*/
|
|
58
|
+
function splitLongToBigInt([low, high]) {
|
|
59
|
+
// Shift high half back and OR with low half
|
|
60
|
+
return (BigInt(high) << 32n) | BigInt(low); // BigInt << BigInt ⇒ BigInt; BigInt | BigInt ⇒ BigInt :contentReference[oaicite:4]{index=4}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=h3-js-bigint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"h3-js-bigint.js","sourceRoot":"","sources":["../../../src/global-grid-systems/h3-js-bigint/h3-js-bigint.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,mDAAmD;AACnD,gFAAgF;AAEhF,OAAO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AyB,EACzB,eAAyB;IAEzB,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3E,MAAM,QAAQ,GAAG,oBAAoB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;IACnE,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,UAAU;AAEV;;;;GAIG;AACH,SAAS,iBAAiB,CAAC,KAAa,EAAE,SAAoB,CAAC,CAAC,EAAE,CAAC,CAAC;IAClE,qBAAqB;IACrB,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,iEAAiE;IAC1G,mCAAmC;IACnC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK,IAAI,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,kEAAkE;IACpH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,CAAC,GAAG,EAAE,IAAI,CAAY;IAC/C,4CAA4C;IAC5C,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,4FAA4F;AAC1I,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type S2Cell = {
|
|
2
|
+
face: number;
|
|
3
|
+
ij: [number, number];
|
|
4
|
+
level: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function getS2Cell(s2Index: bigint): S2Cell;
|
|
7
|
+
export declare function fromHilbertQuadKey(hilbertQuadkey: string): S2Cell;
|
|
8
|
+
export declare function toHilbertQuadkey(id: bigint): string;
|
|
9
|
+
export declare function IJToST(ij: [number, number], order: number, offsets: [number, number]): [number, number];
|
|
10
|
+
export declare function STToUV(st: [number, number]): [number, number];
|
|
11
|
+
export declare function FaceUVToXYZ(face: number, [u, v]: [number, number]): [number, number, number];
|
|
12
|
+
export declare function XYZToLngLat([x, y, z]: [number, number, number]): [number, number];
|
|
13
|
+
//# sourceMappingURL=s2-geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-geometry.d.ts","sourceRoot":"","sources":["../../../src/global-grid-systems/s2-geometry/s2-geometry.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIjD;AAcD,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CA0CjE;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAsCnD;AAED,wBAAgB,MAAM,CACpB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACpB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GACxB,CAAC,MAAM,EAAE,MAAM,CAAC,CAIlB;AASD,wBAAgB,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAE7D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAiB5F;AAED,wBAAgB,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAKjF"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT and ISC
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
export function getS2Cell(s2Index) {
|
|
5
|
+
const key = toHilbertQuadkey(s2Index);
|
|
6
|
+
const s2cell = fromHilbertQuadKey(key);
|
|
7
|
+
return s2cell;
|
|
8
|
+
}
|
|
9
|
+
//
|
|
10
|
+
// Functional Style
|
|
11
|
+
//
|
|
12
|
+
const FACE_BITS = 3;
|
|
13
|
+
const MAX_LEVEL = 30;
|
|
14
|
+
const POS_BITS = 2 * MAX_LEVEL + 1; // 61 (60 bits of data, 1 bit lsb marker)
|
|
15
|
+
const RADIAN_TO_DEGREE = 180 / Math.PI;
|
|
16
|
+
/*
|
|
17
|
+
Original function taken from deck.gl doesn't support the case of (face <= 5)
|
|
18
|
+
It's fixed here.
|
|
19
|
+
*/
|
|
20
|
+
export function fromHilbertQuadKey(hilbertQuadkey) {
|
|
21
|
+
const parts = hilbertQuadkey.split('/');
|
|
22
|
+
const face = parseInt(parts[0], 10);
|
|
23
|
+
const position = parts[1];
|
|
24
|
+
/*
|
|
25
|
+
Fix for the case of level==0 that corresponds to (face <= 5)
|
|
26
|
+
const maxLevel = position.length;
|
|
27
|
+
let level;
|
|
28
|
+
*/
|
|
29
|
+
const maxLevel = face > 5 ? position.length : 0;
|
|
30
|
+
let level = 0;
|
|
31
|
+
const point = [0, 0];
|
|
32
|
+
for (let i = maxLevel - 1; i >= 0; i--) {
|
|
33
|
+
level = maxLevel - i;
|
|
34
|
+
const bit = position[i];
|
|
35
|
+
let rx = 0;
|
|
36
|
+
let ry = 0;
|
|
37
|
+
if (bit === '1') {
|
|
38
|
+
ry = 1;
|
|
39
|
+
}
|
|
40
|
+
else if (bit === '2') {
|
|
41
|
+
rx = 1;
|
|
42
|
+
ry = 1;
|
|
43
|
+
}
|
|
44
|
+
else if (bit === '3') {
|
|
45
|
+
rx = 1;
|
|
46
|
+
}
|
|
47
|
+
const val = Math.pow(2, level - 1);
|
|
48
|
+
rotateAndFlipQuadrant(val, point, rx, ry);
|
|
49
|
+
point[0] += val * rx;
|
|
50
|
+
point[1] += val * ry;
|
|
51
|
+
}
|
|
52
|
+
if (face % 2 === 1) {
|
|
53
|
+
const t = point[0];
|
|
54
|
+
point[0] = point[1];
|
|
55
|
+
point[1] = t;
|
|
56
|
+
}
|
|
57
|
+
return { face, ij: point, level };
|
|
58
|
+
}
|
|
59
|
+
export function toHilbertQuadkey(id) {
|
|
60
|
+
let bin = id.toString(2);
|
|
61
|
+
while (bin.length < FACE_BITS + POS_BITS) {
|
|
62
|
+
// eslint-disable-next-line prefer-template
|
|
63
|
+
bin = '0' + bin;
|
|
64
|
+
}
|
|
65
|
+
// MUST come AFTER binstr has been left-padded with '0's
|
|
66
|
+
const lsbIndex = bin.lastIndexOf('1');
|
|
67
|
+
// substr(start, len)
|
|
68
|
+
// substring(start, end) // includes start, does not include end
|
|
69
|
+
const faceB = bin.substring(0, 3);
|
|
70
|
+
// posB will always be a multiple of 2 (or it's invalid)
|
|
71
|
+
const posB = bin.substring(3, lsbIndex);
|
|
72
|
+
const levelN = posB.length / 2;
|
|
73
|
+
const faceS = BigInt(`0b${faceB}`).toString(10);
|
|
74
|
+
/*
|
|
75
|
+
Here is a fix for the case when posB is an empty string that causes an exception in Long.fromString
|
|
76
|
+
|
|
77
|
+
let posS = Long.fromString(posB, true, 2).toString(4);
|
|
78
|
+
*/
|
|
79
|
+
let posS = '0';
|
|
80
|
+
if (levelN !== 0) {
|
|
81
|
+
// posB is not an empty string< because levelN!==0
|
|
82
|
+
posS = BigInt(`0b${posB}`).toString(4);
|
|
83
|
+
while (posS.length < levelN) {
|
|
84
|
+
// eslint-disable-next-line prefer-template
|
|
85
|
+
posS = '0' + posS;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Note, posS will be "0" for the level==0
|
|
89
|
+
// TODO: Is it ok?
|
|
90
|
+
return `${faceS}/${posS}`;
|
|
91
|
+
}
|
|
92
|
+
export function IJToST(ij, order, offsets) {
|
|
93
|
+
const maxSize = 1 << order;
|
|
94
|
+
return [(ij[0] + offsets[0]) / maxSize, (ij[1] + offsets[1]) / maxSize];
|
|
95
|
+
}
|
|
96
|
+
function singleSTtoUV(st) {
|
|
97
|
+
if (st >= 0.5) {
|
|
98
|
+
return (1 / 3.0) * (4 * st * st - 1);
|
|
99
|
+
}
|
|
100
|
+
return (1 / 3.0) * (1 - 4 * (1 - st) * (1 - st));
|
|
101
|
+
}
|
|
102
|
+
export function STToUV(st) {
|
|
103
|
+
return [singleSTtoUV(st[0]), singleSTtoUV(st[1])];
|
|
104
|
+
}
|
|
105
|
+
export function FaceUVToXYZ(face, [u, v]) {
|
|
106
|
+
switch (face) {
|
|
107
|
+
case 0:
|
|
108
|
+
return [1, u, v];
|
|
109
|
+
case 1:
|
|
110
|
+
return [-u, 1, v];
|
|
111
|
+
case 2:
|
|
112
|
+
return [-u, -v, 1];
|
|
113
|
+
case 3:
|
|
114
|
+
return [-1, -v, -u];
|
|
115
|
+
case 4:
|
|
116
|
+
return [v, -1, -u];
|
|
117
|
+
case 5:
|
|
118
|
+
return [v, u, -1];
|
|
119
|
+
default:
|
|
120
|
+
throw new Error('Invalid face');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export function XYZToLngLat([x, y, z]) {
|
|
124
|
+
const lat = Math.atan2(z, Math.sqrt(x * x + y * y));
|
|
125
|
+
const lng = Math.atan2(y, x);
|
|
126
|
+
return [lng * RADIAN_TO_DEGREE, lat * RADIAN_TO_DEGREE];
|
|
127
|
+
}
|
|
128
|
+
function rotateAndFlipQuadrant(n, point, rx, ry) {
|
|
129
|
+
if (ry === 0) {
|
|
130
|
+
if (rx === 1) {
|
|
131
|
+
point[0] = n - 1 - point[0];
|
|
132
|
+
point[1] = n - 1 - point[1];
|
|
133
|
+
}
|
|
134
|
+
const x = point[0];
|
|
135
|
+
point[0] = point[1];
|
|
136
|
+
point[1] = x;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=s2-geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-geometry.js","sourceRoot":"","sources":["../../../src/global-grid-systems/s2-geometry/s2-geometry.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,uCAAuC;AACvC,oCAAoC;AAiBpC,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,MAAM,GAAG,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACvC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,EAAE;AACF,mBAAmB;AACnB,EAAE;AACF,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,QAAQ,GAAG,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,yCAAyC;AAC7E,MAAM,gBAAgB,GAAG,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC;AAEvC;;;EAGE;AACF,MAAM,UAAU,kBAAkB,CAAC,cAAsB;IACvD,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAC1B;;;;MAIE;IACF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,MAAM,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,CAAqB,CAAC;IAEzC,KAAK,IAAI,CAAC,GAAG,QAAQ,GAAG,CAAC,EAAE,CAAC,IAAI,CAA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K,CAAC,cAAc,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAA2B;IAC7D,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAE7B,OAAO,CAAC,GAAG,GAAG,gBAAgB,EAAE,GAAG,GAAG,gBAAgB,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,qBAAqB,CAAC,CAAS,EAAE,KAAuB,EAAE,EAAU,EAAE,EAAU;IACvF,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;QACb,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;YACb,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAC5B,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAC9B,CAAC;QAED,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACpB,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function getS2GeoBounds(s2Index: bigint): Float64Array;
|
|
2
|
+
/**
|
|
3
|
+
* The S2 cell edge is curved: http://s2geometry.io/
|
|
4
|
+
* This is more prominent at lower levels
|
|
5
|
+
* resolution is the number of segments to generate per edge.
|
|
6
|
+
* We exponentially reduce resolution as level increases so it doesn't affect perf
|
|
7
|
+
* when there are a large number of cells
|
|
8
|
+
*/
|
|
9
|
+
export declare function getS2GeoBoundsFromCell({ face, ij, level }: {
|
|
10
|
+
face: number;
|
|
11
|
+
ij: [number, number];
|
|
12
|
+
level: number;
|
|
13
|
+
}): Float64Array;
|
|
14
|
+
//# sourceMappingURL=s2-to-boundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-to-boundary.d.ts","sourceRoot":"","sources":["../../../src/global-grid-systems/s2-geometry/s2-to-boundary.ts"],"names":[],"mappings":"AAQA,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAG5D;AAED;;;;;;GAMG;AAEH,wBAAgB,sBAAsB,CAAC,EACrC,IAAI,EACJ,EAAE,EACF,KAAK,EACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,YAAY,CA8Cf"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { IJToST, STToUV, FaceUVToXYZ, XYZToLngLat, getS2Cell } from "./s2-geometry.js";
|
|
5
|
+
const MAX_RESOLUTION = 100;
|
|
6
|
+
export function getS2GeoBounds(s2Index) {
|
|
7
|
+
const s2Cell = getS2Cell(s2Index);
|
|
8
|
+
return getS2GeoBoundsFromCell(s2Cell);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The S2 cell edge is curved: http://s2geometry.io/
|
|
12
|
+
* This is more prominent at lower levels
|
|
13
|
+
* resolution is the number of segments to generate per edge.
|
|
14
|
+
* We exponentially reduce resolution as level increases so it doesn't affect perf
|
|
15
|
+
* when there are a large number of cells
|
|
16
|
+
*/
|
|
17
|
+
// eslint-disable-next-line max-statements
|
|
18
|
+
export function getS2GeoBoundsFromCell({ face, ij, level }) {
|
|
19
|
+
const offsets = [
|
|
20
|
+
[0, 0],
|
|
21
|
+
[0, 1],
|
|
22
|
+
[1, 1],
|
|
23
|
+
[1, 0],
|
|
24
|
+
[0, 0]
|
|
25
|
+
];
|
|
26
|
+
const resolution = Math.max(1, Math.ceil(MAX_RESOLUTION * Math.pow(2, -level)));
|
|
27
|
+
const result = new Float64Array(4 * resolution * 2 + 2);
|
|
28
|
+
let ptIndex = 0;
|
|
29
|
+
let prevLng = 0;
|
|
30
|
+
for (let i = 0; i < 4; i++) {
|
|
31
|
+
const offset = offsets[i].slice(0);
|
|
32
|
+
const nextOffset = offsets[i + 1];
|
|
33
|
+
const stepI = (nextOffset[0] - offset[0]) / resolution;
|
|
34
|
+
const stepJ = (nextOffset[1] - offset[1]) / resolution;
|
|
35
|
+
for (let j = 0; j < resolution; j++) {
|
|
36
|
+
offset[0] += stepI;
|
|
37
|
+
offset[1] += stepJ;
|
|
38
|
+
// Cell can be represented by coordinates IJ, ST, UV, XYZ
|
|
39
|
+
// http://s2geometry.io/devguide/s2cell_hierarchy#coordinate-systems
|
|
40
|
+
const st = IJToST(ij, level, offset);
|
|
41
|
+
const uv = STToUV(st);
|
|
42
|
+
const xyz = FaceUVToXYZ(face, uv);
|
|
43
|
+
const lngLat = XYZToLngLat(xyz);
|
|
44
|
+
// Adjust longitude for Web Mercator projection
|
|
45
|
+
if (Math.abs(lngLat[1]) > 89.999) {
|
|
46
|
+
lngLat[0] = prevLng;
|
|
47
|
+
}
|
|
48
|
+
const deltaLng = lngLat[0] - prevLng;
|
|
49
|
+
lngLat[0] += deltaLng > 180 ? -360 : deltaLng < -180 ? 360 : 0;
|
|
50
|
+
result[ptIndex++] = lngLat[0];
|
|
51
|
+
result[ptIndex++] = lngLat[1];
|
|
52
|
+
prevLng = lngLat[0];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// close the loop
|
|
56
|
+
result[ptIndex++] = result[0];
|
|
57
|
+
result[ptIndex++] = result[1];
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=s2-to-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-to-boundary.js","sourceRoot":"","sources":["../../../src/global-grid-systems/s2-geometry/s2-to-boundary.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAC,yBAAsB;AAElF,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;GAMG;AACH,0CAA0C;AAC1C,MAAM,UAAU,sBAAsB,CAAC,EACrC,IAAI,EACJ,EAAE,EACF,KAAK,EAKN;IACC,MAAM,OAAO,GAAG;QACd,CAAC,CAAC,EAAE,CAAC,CAAC;QACN,CAAC,CAAC,EAAE,CAAC,CAAC;QACN,CAAC,CAAC,EAAE,CAAC,CAAC;QACN,CAAC,CAAC,EAAE,CAAC,CAAC;QACN,CAAC,CAAC,EAAE,CAAC,CAAC;KACP,CAAC;IAEF,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,CAAC,GAAG,UAAU,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACxD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EA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AC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAE/D,MAAM,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC9B,MAAM,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC9B,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IACD,iBAAiB;IACjB,MAAM,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given an S2 token (String) this function convert the token to 64 bit id (Index)
|
|
3
|
+
* 'X' is the empty cell
|
|
4
|
+
* https://github.com/google/s2-geometry-library-java/blob/c04b68bf3197a9c34082327eeb3aec7ab7c85da1/src/com/google/common/geometry/S2CellId.java#L439
|
|
5
|
+
*/
|
|
6
|
+
export declare function getS2IndexFromToken(token: string): bigint;
|
|
7
|
+
/**
|
|
8
|
+
* Convert a 64 bit number to a string token
|
|
9
|
+
* 'X' is the empty cell
|
|
10
|
+
*/
|
|
11
|
+
export declare function getS2TokenFromIndex(cellId: bigint): string;
|
|
12
|
+
export declare function getS2ChildIndex(s2Index: bigint, index: number): bigint;
|
|
13
|
+
//# sourceMappingURL=s2-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s2-token.d.ts","sourceRoot":"","sources":["../../../src/global-grid-systems/s2-geometry/s2-token.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOzD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAe1D;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAMtE"}
|