@math.gl/dggs 5.0.0-alpha.10

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 (118) hide show
  1. package/LICENSE +140 -0
  2. package/README.md +7 -0
  3. package/dist/a5-decoder.d.ts +15 -0
  4. package/dist/a5-decoder.d.ts.map +1 -0
  5. package/dist/a5-decoder.js +36 -0
  6. package/dist/a5-decoder.js.map +1 -0
  7. package/dist/a5.cjs +134 -0
  8. package/dist/a5.cjs.map +6 -0
  9. package/dist/a5.d.ts +2 -0
  10. package/dist/a5.d.ts.map +1 -0
  11. package/dist/a5.js +5 -0
  12. package/dist/a5.js.map +1 -0
  13. package/dist/converters/s2-to-obb-points.d.ts +15 -0
  14. package/dist/converters/s2-to-obb-points.d.ts.map +1 -0
  15. package/dist/converters/s2-to-obb-points.js +60 -0
  16. package/dist/converters/s2-to-obb-points.js.map +1 -0
  17. package/dist/converters/s2-to-region.d.ts +6 -0
  18. package/dist/converters/s2-to-region.d.ts.map +1 -0
  19. package/dist/converters/s2-to-region.js +27 -0
  20. package/dist/converters/s2-to-region.js.map +1 -0
  21. package/dist/dggs-decoder.d.ts +46 -0
  22. package/dist/dggs-decoder.d.ts.map +1 -0
  23. package/dist/dggs-decoder.js +52 -0
  24. package/dist/dggs-decoder.js.map +1 -0
  25. package/dist/geohash-decoder.d.ts +17 -0
  26. package/dist/geohash-decoder.d.ts.map +1 -0
  27. package/dist/geohash-decoder.js +88 -0
  28. package/dist/geohash-decoder.js.map +1 -0
  29. package/dist/geohash.cjs +181 -0
  30. package/dist/geohash.cjs.map +6 -0
  31. package/dist/geohash.d.ts +2 -0
  32. package/dist/geohash.d.ts.map +1 -0
  33. package/dist/geohash.js +5 -0
  34. package/dist/geohash.js.map +1 -0
  35. package/dist/h3-decoder.d.ts +15 -0
  36. package/dist/h3-decoder.d.ts.map +1 -0
  37. package/dist/h3-decoder.js +46 -0
  38. package/dist/h3-decoder.js.map +1 -0
  39. package/dist/h3.cjs +144 -0
  40. package/dist/h3.cjs.map +6 -0
  41. package/dist/h3.d.ts +2 -0
  42. package/dist/h3.d.ts.map +1 -0
  43. package/dist/h3.js +5 -0
  44. package/dist/h3.js.map +1 -0
  45. package/dist/index.cjs +863 -0
  46. package/dist/index.cjs.map +6 -0
  47. package/dist/index.d.ts +27 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +54 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/plus-code-decoder.d.ts +16 -0
  52. package/dist/plus-code-decoder.d.ts.map +1 -0
  53. package/dist/plus-code-decoder.js +50 -0
  54. package/dist/plus-code-decoder.js.map +1 -0
  55. package/dist/plus-code.cjs +161 -0
  56. package/dist/plus-code.cjs.map +6 -0
  57. package/dist/plus-code.d.ts +2 -0
  58. package/dist/plus-code.d.ts.map +1 -0
  59. package/dist/plus-code.js +5 -0
  60. package/dist/plus-code.js.map +1 -0
  61. package/dist/quadkey-decoder.d.ts +14 -0
  62. package/dist/quadkey-decoder.d.ts.map +1 -0
  63. package/dist/quadkey-decoder.js +86 -0
  64. package/dist/quadkey-decoder.js.map +1 -0
  65. package/dist/quadkey.cjs +179 -0
  66. package/dist/quadkey.cjs.map +6 -0
  67. package/dist/quadkey.d.ts +2 -0
  68. package/dist/quadkey.d.ts.map +1 -0
  69. package/dist/quadkey.js +5 -0
  70. package/dist/quadkey.js.map +1 -0
  71. package/dist/s2-decoder.d.ts +36 -0
  72. package/dist/s2-decoder.d.ts.map +1 -0
  73. package/dist/s2-decoder.js +144 -0
  74. package/dist/s2-decoder.js.map +1 -0
  75. package/dist/s2-geometry/s2-geometry.d.ts +33 -0
  76. package/dist/s2-geometry/s2-geometry.d.ts.map +1 -0
  77. package/dist/s2-geometry/s2-geometry.js +249 -0
  78. package/dist/s2-geometry/s2-geometry.js.map +1 -0
  79. package/dist/s2-geometry/s2-to-boundary.d.ts +14 -0
  80. package/dist/s2-geometry/s2-to-boundary.d.ts.map +1 -0
  81. package/dist/s2-geometry/s2-to-boundary.js +60 -0
  82. package/dist/s2-geometry/s2-to-boundary.js.map +1 -0
  83. package/dist/s2-geometry/s2-token.d.ts +43 -0
  84. package/dist/s2-geometry/s2-token.d.ts.map +1 -0
  85. package/dist/s2-geometry/s2-token.js +127 -0
  86. package/dist/s2-geometry/s2-token.js.map +1 -0
  87. package/dist/s2.cjs +543 -0
  88. package/dist/s2.cjs.map +6 -0
  89. package/dist/s2.d.ts +5 -0
  90. package/dist/s2.d.ts.map +1 -0
  91. package/dist/s2.js +7 -0
  92. package/dist/s2.js.map +1 -0
  93. package/dist/unwrap-dggs-boundary.d.ts +12 -0
  94. package/dist/unwrap-dggs-boundary.d.ts.map +1 -0
  95. package/dist/unwrap-dggs-boundary.js +49 -0
  96. package/dist/unwrap-dggs-boundary.js.map +1 -0
  97. package/package.json +80 -0
  98. package/src/a5-decoder.ts +47 -0
  99. package/src/a5.ts +5 -0
  100. package/src/converters/s2-to-obb-points.ts +78 -0
  101. package/src/converters/s2-to-region.ts +30 -0
  102. package/src/dggs-decoder.ts +108 -0
  103. package/src/geohash-decoder.ts +104 -0
  104. package/src/geohash.ts +5 -0
  105. package/src/h3-decoder.ts +58 -0
  106. package/src/h3.ts +5 -0
  107. package/src/index.ts +72 -0
  108. package/src/open-location-code.d.ts +19 -0
  109. package/src/plus-code-decoder.ts +61 -0
  110. package/src/plus-code.ts +5 -0
  111. package/src/quadkey-decoder.ts +103 -0
  112. package/src/quadkey.ts +5 -0
  113. package/src/s2-decoder.ts +157 -0
  114. package/src/s2-geometry/s2-geometry.ts +303 -0
  115. package/src/s2-geometry/s2-to-boundary.ts +76 -0
  116. package/src/s2-geometry/s2-token.ts +139 -0
  117. package/src/s2.ts +15 -0
  118. package/src/unwrap-dggs-boundary.ts +54 -0
@@ -0,0 +1,88 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { withDGGSBoundaryOptions, getDGGSCellToken } from "./dggs-decoder.js";
5
+ /** Decoder for the geohash dggs */
6
+ export const GeohashDecoder = withDGGSBoundaryOptions({
7
+ name: 'geohash',
8
+ hasNumericRepresentation: false,
9
+ cellColumnNames: ['geohash', 'geohashId', 'geohash_id'],
10
+ cellToLngLat: (cell) => getGeohashLngLat(getDGGSCellToken(cell, 'GeoHash')),
11
+ cellToBoundary: (cell) => getGeohashBoundary(getDGGSCellToken(cell, 'GeoHash')),
12
+ cellToBoundaryFlat: (cell) => getGeohashBoundaryFlat(getDGGSCellToken(cell, 'GeoHash')),
13
+ cellToBounds: (cell) => getGeohashBounds(getDGGSCellToken(cell, 'GeoHash'))
14
+ });
15
+ const BASE32_CODES = '0123456789bcdefghjkmnpqrstuvwxyz';
16
+ const BASE32_CODES_DICT = {};
17
+ for (let i = 0; i < BASE32_CODES.length; i++) {
18
+ BASE32_CODES_DICT[BASE32_CODES.charAt(i)] = i;
19
+ }
20
+ const MIN_LAT = -90;
21
+ const MAX_LAT = 90;
22
+ const MIN_LON = -180;
23
+ const MAX_LON = 180;
24
+ /** Return center lng,lat of geohash cell */
25
+ function getGeohashLngLat(geohash) {
26
+ const [[w, s], [e, n]] = getGeohashBounds(geohash);
27
+ return [(e + w) / 2, (n + s) / 2];
28
+ }
29
+ /** Return boundary polygon of geohash cell as lng,lat array */
30
+ function getGeohashBoundary(geohash) {
31
+ const [[w, s], [e, n]] = getGeohashBounds(geohash);
32
+ return [
33
+ [e, n],
34
+ [e, s],
35
+ [w, s],
36
+ [w, n],
37
+ [e, n]
38
+ ];
39
+ }
40
+ /** Return boundary polygon of geohash cell as flat array */
41
+ function getGeohashBoundaryFlat(geohash) {
42
+ const [[w, s], [e, n]] = getGeohashBounds(geohash);
43
+ return [e, n, e, s, w, s, w, n, e, n];
44
+ }
45
+ /**
46
+ * @note Adapted from ngeohash decode_bbox
47
+ */
48
+ /* eslint-disable max-depth */
49
+ export function getGeohashBounds(geohash) {
50
+ let isLon = true;
51
+ let maxLat = MAX_LAT;
52
+ let minLat = MIN_LAT;
53
+ let maxLon = MAX_LON;
54
+ let minLon = MIN_LON;
55
+ let mid;
56
+ let hashValue = 0;
57
+ for (let i = 0, l = geohash.length; i < l; i++) {
58
+ const code = geohash[i].toLowerCase();
59
+ hashValue = BASE32_CODES_DICT[code];
60
+ for (let bits = 4; bits >= 0; bits--) {
61
+ const bit = (hashValue >> bits) & 1;
62
+ if (isLon) {
63
+ mid = (maxLon + minLon) / 2;
64
+ if (bit === 1) {
65
+ minLon = mid;
66
+ }
67
+ else {
68
+ maxLon = mid;
69
+ }
70
+ }
71
+ else {
72
+ mid = (maxLat + minLat) / 2;
73
+ if (bit === 1) {
74
+ minLat = mid;
75
+ }
76
+ else {
77
+ maxLat = mid;
78
+ }
79
+ }
80
+ isLon = !isLon;
81
+ }
82
+ }
83
+ return [
84
+ [minLon, minLat],
85
+ [maxLon, maxLat]
86
+ ];
87
+ }
88
+ //# sourceMappingURL=geohash-decoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geohash-decoder.js","sourceRoot":"","sources":["../src/geohash-decoder.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EACL,uBAAuB,EAGvB,gBAAgB,EACjB,0BAAuB;AAExB,mCAAmC;AACnC,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAuB,CAAC;IACpD,IAAI,EAAE,SAAS;IACf,wBAAwB,EAAE,KAAK;IAC/B,eAAe,EAAE,CAAC,SAAS,EAAE,WAAW,EAAE,YAAY,CAAC;IACvD,YAAY,EAAE,CAAC,IAAc,EAAoB,EAAE,CACjD,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACrD,cAAc,EAAE,CAAC,IAAc,EAAsB,EAAE,CACrD,kBAAkB,CAAC,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACvD,kBAAkB,EAAE,CAAC,IAAc,EAAY,EAAE,CAC/C,sBAAsB,CAAC,gBAAg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AK,CAAC,EAAE,CAAC;oBACd,MAAM,GAAG,GAAG,CAAC;gBACf,CAAC;qBAAM,CAAC;oBACN,MAAM,GAAG,GAAG,CAAC;gBACf,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,GAAG,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC5B,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;oBACd,MAAM,GAAG,GAAG,CAAC;gBACf,CAAC;qBAAM,CAAC;oBACN,MAAM,GAAG,GAAG,CAAC;gBACf,CAAC;YACH,CAAC;YACD,KAAK,GAAG,CAAC,KAAK,CAAC;QACjB,CAAC;IACH,CAAC;IAED,OAAO;QACL,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;KACjB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,181 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // dist/geohash.js
20
+ var geohash_exports = {};
21
+ __export(geohash_exports, {
22
+ GeohashDecoder: () => GeohashDecoder,
23
+ getGeohashBounds: () => getGeohashBounds
24
+ });
25
+ module.exports = __toCommonJS(geohash_exports);
26
+
27
+ // dist/unwrap-dggs-boundary.js
28
+ function unwrapDGGSBoundary(boundary, referenceLongitude) {
29
+ const result = boundary.map(([longitude, latitude]) => [longitude, latitude]);
30
+ if (result.length === 0) {
31
+ return result;
32
+ }
33
+ let west = Infinity;
34
+ let east = -Infinity;
35
+ for (const [longitude] of boundary) {
36
+ west = Math.min(west, longitude);
37
+ east = Math.max(east, longitude);
38
+ }
39
+ if (east - west >= 360) {
40
+ return result;
41
+ }
42
+ let previous = referenceLongitude ?? result[0][0];
43
+ for (const point of result) {
44
+ const delta = point[0] - previous;
45
+ if (delta > 180) {
46
+ point[0] -= 360 * Math.ceil((delta - 180) / 360);
47
+ } else if (delta < -180) {
48
+ point[0] += 360 * Math.ceil((-delta - 180) / 360);
49
+ }
50
+ previous = point[0];
51
+ }
52
+ const first = boundary[0];
53
+ const last = boundary[boundary.length - 1];
54
+ if (first[0] === last[0] && first[1] === last[1]) {
55
+ if (Math.abs(result[result.length - 1][0] - result[0][0]) > 180) {
56
+ return boundary.map(([longitude, latitude]) => [longitude, latitude]);
57
+ }
58
+ result[result.length - 1] = [...result[0]];
59
+ }
60
+ return result;
61
+ }
62
+
63
+ // dist/dggs-decoder.js
64
+ function getDGGSCellToken(cell, gridName) {
65
+ if (typeof cell !== "string") {
66
+ throw new Error(`${gridName} cell identifiers must be strings`);
67
+ }
68
+ return cell;
69
+ }
70
+ function getDGGSCellBounds(boundary) {
71
+ let west = Infinity;
72
+ let south = Infinity;
73
+ let east = -Infinity;
74
+ let north = -Infinity;
75
+ for (const [longitude, latitude] of boundary) {
76
+ west = Math.min(west, longitude);
77
+ south = Math.min(south, latitude);
78
+ east = Math.max(east, longitude);
79
+ north = Math.max(north, latitude);
80
+ }
81
+ return [
82
+ [west, south],
83
+ [east, north]
84
+ ];
85
+ }
86
+ function withDGGSBoundaryOptions(decoder) {
87
+ const cellToBoundary = (cell, options) => {
88
+ const boundary = decoder.cellToBoundary(cell);
89
+ return (options == null ? void 0 : options.unwrap) ? unwrapDGGSBoundary(boundary, options.referenceLongitude) : boundary;
90
+ };
91
+ return {
92
+ ...decoder,
93
+ cellToBoundary,
94
+ cellToBoundaryFlat: (cell, options) => (options == null ? void 0 : options.unwrap) ? cellToBoundary(cell, options).flat() : decoder.cellToBoundaryFlat(cell),
95
+ cellToBounds: (cell, options) => {
96
+ const bounds = decoder.cellToBounds(cell);
97
+ if (!(options == null ? void 0 : options.unwrap) || bounds[1][0] - bounds[0][0] >= 360) {
98
+ return bounds;
99
+ }
100
+ const unwrapped = getDGGSCellBounds(cellToBoundary(cell, options));
101
+ unwrapped[0][1] = bounds[0][1];
102
+ unwrapped[1][1] = bounds[1][1];
103
+ return unwrapped;
104
+ }
105
+ };
106
+ }
107
+
108
+ // dist/geohash-decoder.js
109
+ var GeohashDecoder = withDGGSBoundaryOptions({
110
+ name: "geohash",
111
+ hasNumericRepresentation: false,
112
+ cellColumnNames: ["geohash", "geohashId", "geohash_id"],
113
+ cellToLngLat: (cell) => getGeohashLngLat(getDGGSCellToken(cell, "GeoHash")),
114
+ cellToBoundary: (cell) => getGeohashBoundary(getDGGSCellToken(cell, "GeoHash")),
115
+ cellToBoundaryFlat: (cell) => getGeohashBoundaryFlat(getDGGSCellToken(cell, "GeoHash")),
116
+ cellToBounds: (cell) => getGeohashBounds(getDGGSCellToken(cell, "GeoHash"))
117
+ });
118
+ var BASE32_CODES = "0123456789bcdefghjkmnpqrstuvwxyz";
119
+ var BASE32_CODES_DICT = {};
120
+ for (let i = 0; i < BASE32_CODES.length; i++) {
121
+ BASE32_CODES_DICT[BASE32_CODES.charAt(i)] = i;
122
+ }
123
+ var MIN_LAT = -90;
124
+ var MAX_LAT = 90;
125
+ var MIN_LON = -180;
126
+ var MAX_LON = 180;
127
+ function getGeohashLngLat(geohash) {
128
+ const [[w, s], [e, n]] = getGeohashBounds(geohash);
129
+ return [(e + w) / 2, (n + s) / 2];
130
+ }
131
+ function getGeohashBoundary(geohash) {
132
+ const [[w, s], [e, n]] = getGeohashBounds(geohash);
133
+ return [
134
+ [e, n],
135
+ [e, s],
136
+ [w, s],
137
+ [w, n],
138
+ [e, n]
139
+ ];
140
+ }
141
+ function getGeohashBoundaryFlat(geohash) {
142
+ const [[w, s], [e, n]] = getGeohashBounds(geohash);
143
+ return [e, n, e, s, w, s, w, n, e, n];
144
+ }
145
+ function getGeohashBounds(geohash) {
146
+ let isLon = true;
147
+ let maxLat = MAX_LAT;
148
+ let minLat = MIN_LAT;
149
+ let maxLon = MAX_LON;
150
+ let minLon = MIN_LON;
151
+ let mid;
152
+ let hashValue = 0;
153
+ for (let i = 0, l = geohash.length; i < l; i++) {
154
+ const code = geohash[i].toLowerCase();
155
+ hashValue = BASE32_CODES_DICT[code];
156
+ for (let bits = 4; bits >= 0; bits--) {
157
+ const bit = hashValue >> bits & 1;
158
+ if (isLon) {
159
+ mid = (maxLon + minLon) / 2;
160
+ if (bit === 1) {
161
+ minLon = mid;
162
+ } else {
163
+ maxLon = mid;
164
+ }
165
+ } else {
166
+ mid = (maxLat + minLat) / 2;
167
+ if (bit === 1) {
168
+ minLat = mid;
169
+ } else {
170
+ maxLat = mid;
171
+ }
172
+ }
173
+ isLon = !isLon;
174
+ }
175
+ }
176
+ return [
177
+ [minLon, minLat],
178
+ [maxLon, maxLat]
179
+ ];
180
+ }
181
+ //# sourceMappingURL=geohash.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/geohash.ts", "../src/unwrap-dggs-boundary.ts", "../src/dggs-decoder.ts", "../src/geohash-decoder.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACcM,SAAU,mBACd,UACA,oBAA2B;AAE3B,QAAM,SAA6B,SAAS,IAAI,CAAC,CAAC,WAAW,QAAQ,MAAM,CAAC,WAAW,QAAQ,CAAC;AAChG,MAAI,OAAO,WAAW,GAAG;AACvB,WAAO;EACT;AAEA,MAAI,OAAO;AACX,MAAI,OAAO;AACX,aAAW,CAAC,SAAS,KAAK,UAAU;AAClC,WAAO,KAAK,IAAI,MAA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,mBAAS;QACX;MACF,OAAO;AACL,eAAO,SAAS,UAAU;AAC1B,YAAI,QAAQ,GAAG;AACb,mBAAS;QACX,OAAO;AACL,mBAAS;QACX;MACF;AACA,cAAQ,CAAC;IACX;EACF;AAEA,SAAO;IACL,CAAC,QAAQ,MAAM;IACf,CAAC,QAAQ,MAAM;;AAEnB;",
5
+ "names": []
6
+ }
@@ -0,0 +1,2 @@
1
+ export { GeohashDecoder, getGeohashBounds } from "./geohash-decoder.js";
2
+ //# sourceMappingURL=geohash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geohash.d.ts","sourceRoot":"","sources":["../src/geohash.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,cAAc,EAAE,gBAAgB,EAAC,6BAA0B"}
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export { GeohashDecoder, getGeohashBounds } from "./geohash-decoder.js";
5
+ //# sourceMappingURL=geohash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geohash.js","sourceRoot":"","sources":["../src/geohash.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,cAAc,EAAE,gBAAgB,EAAC,6BAA0B"}
@@ -0,0 +1,15 @@
1
+ import { type Bounds2D } from '@math.gl/types';
2
+ import { type DGGSCell, type DGGSDecoder } from "./dggs-decoder.js";
3
+ /** Lightweight cell geometry decoder for the H3 hexagonal DGGS. */
4
+ export declare const H3Decoder: Omit<{
5
+ readonly name: "h3";
6
+ readonly hasNumericRepresentation: true;
7
+ readonly cellColumnNames: readonly ["h3", "h3Index", "h3_index", "h3Cell", "h3_cell", "h3CellId", "h3_cell_id", "hexagon"];
8
+ readonly tokenToCell: (token: string) => bigint;
9
+ readonly cellToToken: (cell: DGGSCell) => string;
10
+ readonly cellToLngLat: (cell: DGGSCell) => [number, number];
11
+ readonly cellToBoundary: (cell: DGGSCell) => [number, number][];
12
+ readonly cellToBoundaryFlat: (cell: DGGSCell) => number[];
13
+ readonly cellToBounds: (cell: DGGSCell) => Bounds2D;
14
+ }, "cellToBoundary" | "cellToBoundaryFlat" | "cellToBounds"> & Pick<DGGSDecoder, "cellToBoundary" | "cellToBoundaryFlat" | "cellToBounds">;
15
+ //# sourceMappingURL=h3-decoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"h3-decoder.d.ts","sourceRoot":"","sources":["../src/h3-decoder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,KAAK,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,WAAW,EAEjB,0BAAuB;AAExB,mEAAmE;AACnE,eAAO,MAAM,SAAS;;;;kCAaC,MAAM,KAAG,MAAM;iCAChB,QAAQ,KAAG,MAAM;kCAChB,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC;oCACzB,QAAQ,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;wCACzB,QAAQ,KAAG,MAAM,EAAE;kCACzB,QAAQ,KAAG,QAAQ;0IACT,CAAC"}
@@ -0,0 +1,46 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { cellToBoundary, cellToLatLng } from 'h3-js';
5
+ import { withDGGSBoundaryOptions, getDGGSCellBounds } from "./dggs-decoder.js";
6
+ /** Lightweight cell geometry decoder for the H3 hexagonal DGGS. */
7
+ export const H3Decoder = withDGGSBoundaryOptions({
8
+ name: 'h3',
9
+ hasNumericRepresentation: true,
10
+ cellColumnNames: [
11
+ 'h3',
12
+ 'h3Index',
13
+ 'h3_index',
14
+ 'h3Cell',
15
+ 'h3_cell',
16
+ 'h3CellId',
17
+ 'h3_cell_id',
18
+ 'hexagon'
19
+ ],
20
+ tokenToCell: (token) => getBigIntFromHexToken(token),
21
+ cellToToken: (cell) => getH3Token(cell),
22
+ cellToLngLat: (cell) => getH3LngLat(cell),
23
+ cellToBoundary: (cell) => getH3Boundary(cell),
24
+ cellToBoundaryFlat: (cell) => getH3Boundary(cell).flat(),
25
+ cellToBounds: (cell) => getDGGSCellBounds(getH3Boundary(cell))
26
+ });
27
+ function getH3Token(cell) {
28
+ return typeof cell === 'bigint' ? cell.toString(16) : removeHexPrefix(cell);
29
+ }
30
+ function getH3LngLat(cell) {
31
+ const [latitude, longitude] = cellToLatLng(getH3Token(cell));
32
+ return [longitude, latitude];
33
+ }
34
+ function getH3Boundary(cell) {
35
+ return cellToBoundary(getH3Token(cell), true).map(([longitude, latitude]) => [
36
+ longitude,
37
+ latitude
38
+ ]);
39
+ }
40
+ function getBigIntFromHexToken(token) {
41
+ return BigInt(`0x${removeHexPrefix(token)}`);
42
+ }
43
+ function removeHexPrefix(token) {
44
+ return token.startsWith('0x') || token.startsWith('0X') ? token.slice(2) : token;
45
+ }
46
+ //# sourceMappingURL=h3-decoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"h3-decoder.js","sourceRoot":"","sources":["../src/h3-decoder.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,cAAc,EAAE,YAAY,EAAC,MAAM,OAAO,CAAC;AAEnD,OAAO,EACL,uBAAuB,EAGvB,iBAAiB,EAClB,0BAAuB;AAExB,mEAAmE;AACnE,MAAM,CAAC,MAAM,SAAS,GAAG,uBAAuB,CAAC;IAC/C,IAAI,EAAE,IAAI;IACV,wBAAwB,EAAE,IAAI;IAC9B,eAAe,EAAE;QACf,IAAI;QACJ,SAAS;QACT,UAAU;QACV,QAAQ;QACR,SAAS;QACT,UAAU;QACV,YAAY;QACZ,SAAS;KACV;IACD,WAAW,EAAE,CAAC,KAAa,EAAU,EAAE,CAAC,qBAAqB,CAAC,KAAK,CAAC;IACpE,WAAW,EAAE,CAAC,IAAc,EAAU,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;I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CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACnF,CAAC"}
package/dist/h3.cjs ADDED
@@ -0,0 +1,144 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // dist/h3.js
20
+ var h3_exports = {};
21
+ __export(h3_exports, {
22
+ H3Decoder: () => H3Decoder
23
+ });
24
+ module.exports = __toCommonJS(h3_exports);
25
+
26
+ // dist/h3-decoder.js
27
+ var import_h3_js = require("h3-js");
28
+
29
+ // dist/unwrap-dggs-boundary.js
30
+ function unwrapDGGSBoundary(boundary, referenceLongitude) {
31
+ const result = boundary.map(([longitude, latitude]) => [longitude, latitude]);
32
+ if (result.length === 0) {
33
+ return result;
34
+ }
35
+ let west = Infinity;
36
+ let east = -Infinity;
37
+ for (const [longitude] of boundary) {
38
+ west = Math.min(west, longitude);
39
+ east = Math.max(east, longitude);
40
+ }
41
+ if (east - west >= 360) {
42
+ return result;
43
+ }
44
+ let previous = referenceLongitude ?? result[0][0];
45
+ for (const point of result) {
46
+ const delta = point[0] - previous;
47
+ if (delta > 180) {
48
+ point[0] -= 360 * Math.ceil((delta - 180) / 360);
49
+ } else if (delta < -180) {
50
+ point[0] += 360 * Math.ceil((-delta - 180) / 360);
51
+ }
52
+ previous = point[0];
53
+ }
54
+ const first = boundary[0];
55
+ const last = boundary[boundary.length - 1];
56
+ if (first[0] === last[0] && first[1] === last[1]) {
57
+ if (Math.abs(result[result.length - 1][0] - result[0][0]) > 180) {
58
+ return boundary.map(([longitude, latitude]) => [longitude, latitude]);
59
+ }
60
+ result[result.length - 1] = [...result[0]];
61
+ }
62
+ return result;
63
+ }
64
+
65
+ // dist/dggs-decoder.js
66
+ function getDGGSCellBounds(boundary) {
67
+ let west = Infinity;
68
+ let south = Infinity;
69
+ let east = -Infinity;
70
+ let north = -Infinity;
71
+ for (const [longitude, latitude] of boundary) {
72
+ west = Math.min(west, longitude);
73
+ south = Math.min(south, latitude);
74
+ east = Math.max(east, longitude);
75
+ north = Math.max(north, latitude);
76
+ }
77
+ return [
78
+ [west, south],
79
+ [east, north]
80
+ ];
81
+ }
82
+ function withDGGSBoundaryOptions(decoder) {
83
+ const cellToBoundary2 = (cell, options) => {
84
+ const boundary = decoder.cellToBoundary(cell);
85
+ return (options == null ? void 0 : options.unwrap) ? unwrapDGGSBoundary(boundary, options.referenceLongitude) : boundary;
86
+ };
87
+ return {
88
+ ...decoder,
89
+ cellToBoundary: cellToBoundary2,
90
+ cellToBoundaryFlat: (cell, options) => (options == null ? void 0 : options.unwrap) ? cellToBoundary2(cell, options).flat() : decoder.cellToBoundaryFlat(cell),
91
+ cellToBounds: (cell, options) => {
92
+ const bounds = decoder.cellToBounds(cell);
93
+ if (!(options == null ? void 0 : options.unwrap) || bounds[1][0] - bounds[0][0] >= 360) {
94
+ return bounds;
95
+ }
96
+ const unwrapped = getDGGSCellBounds(cellToBoundary2(cell, options));
97
+ unwrapped[0][1] = bounds[0][1];
98
+ unwrapped[1][1] = bounds[1][1];
99
+ return unwrapped;
100
+ }
101
+ };
102
+ }
103
+
104
+ // dist/h3-decoder.js
105
+ var H3Decoder = withDGGSBoundaryOptions({
106
+ name: "h3",
107
+ hasNumericRepresentation: true,
108
+ cellColumnNames: [
109
+ "h3",
110
+ "h3Index",
111
+ "h3_index",
112
+ "h3Cell",
113
+ "h3_cell",
114
+ "h3CellId",
115
+ "h3_cell_id",
116
+ "hexagon"
117
+ ],
118
+ tokenToCell: (token) => getBigIntFromHexToken(token),
119
+ cellToToken: (cell) => getH3Token(cell),
120
+ cellToLngLat: (cell) => getH3LngLat(cell),
121
+ cellToBoundary: (cell) => getH3Boundary(cell),
122
+ cellToBoundaryFlat: (cell) => getH3Boundary(cell).flat(),
123
+ cellToBounds: (cell) => getDGGSCellBounds(getH3Boundary(cell))
124
+ });
125
+ function getH3Token(cell) {
126
+ return typeof cell === "bigint" ? cell.toString(16) : removeHexPrefix(cell);
127
+ }
128
+ function getH3LngLat(cell) {
129
+ const [latitude, longitude] = (0, import_h3_js.cellToLatLng)(getH3Token(cell));
130
+ return [longitude, latitude];
131
+ }
132
+ function getH3Boundary(cell) {
133
+ return (0, import_h3_js.cellToBoundary)(getH3Token(cell), true).map(([longitude, latitude]) => [
134
+ longitude,
135
+ latitude
136
+ ]);
137
+ }
138
+ function getBigIntFromHexToken(token) {
139
+ return BigInt(`0x${removeHexPrefix(token)}`);
140
+ }
141
+ function removeHexPrefix(token) {
142
+ return token.startsWith("0x") || token.startsWith("0X") ? token.slice(2) : token;
143
+ }
144
+ //# sourceMappingURL=h3.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/h3.ts", "../src/h3-decoder.ts", "../src/unwrap-dggs-boundary.ts", "../src/dggs-decoder.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACIA,mBAA2C;;;ACUrC,SAAU,mBACd,UACA,oBAA2B;AAE3B,QAAM,SAA6B,SAAS,IAAI,CAAC,CAAC,WAAW,QAAQ,MAAM,CAAC,WAAW,QAAQ,CAAC;AAChG,MAAI,OAAO,WAAW,GAAG;AACvB,WAAO;EACT;AAEA,MAAI,OAAO;AACX,MAAI,OAAO;AACX,aAAW,CAAC,SAAS,KAAK,UAAU;AAClC,WAAO,KA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QAAM,CAAC,UAAU,SAAS,QAAI,2BAAa,WAAW,IAAI,CAAC;AAC3D,SAAO,CAAC,WAAW,QAAQ;AAC7B;AAEA,SAAS,cAAc,MAAc;AACnC,aAAO,6BAAe,WAAW,IAAI,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC,WAAW,QAAQ,MAAM;IAC3E;IACA;GACD;AACH;AAEA,SAAS,sBAAsB,OAAa;AAC1C,SAAO,OAAO,KAAK,gBAAgB,KAAK,CAAC,EAAE;AAC7C;AAEA,SAAS,gBAAgB,OAAa;AACpC,SAAO,MAAM,WAAW,IAAI,KAAK,MAAM,WAAW,IAAI,IAAI,MAAM,MAAM,CAAC,IAAI;AAC7E;",
5
+ "names": ["cellToBoundary"]
6
+ }
package/dist/h3.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { H3Decoder } from "./h3-decoder.js";
2
+ //# sourceMappingURL=h3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"h3.d.ts","sourceRoot":"","sources":["../src/h3.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,SAAS,EAAC,wBAAqB"}
package/dist/h3.js ADDED
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export { H3Decoder } from "./h3-decoder.js";
5
+ //# sourceMappingURL=h3.js.map
package/dist/h3.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"h3.js","sourceRoot":"","sources":["../src/h3.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,SAAS,EAAC,wBAAqB"}