@@ -19,11 +19,19 @@ export type H3TileIndex = {i: string};
19
19
20
20
const MAX_LATITUDE = 85.051128 ;
21
21
22
- // `polygonToCells()` fills based on hexagon center, this function will
23
- // pad the bounds such that all cells that overlap the bounds will be included
22
+ /**
23
+ * `polygonToCells()` fills based on hexagon center, this function will
24
+ * pad the bounds such that all cells that overlap the bounds will be included.
25
+ *
26
+ * @param bbox - The bounding box to pad.
27
+ * @param resolution - The resolution of the hexagons.
28
+ * @param scale - The scale of the buffer. 1 is to pad by the max edge length of the tile cell.
29
+ * @returns The padded bounding box.
30
+ */
24
31
function padBoundingBox (
25
32
{ west, north, east, south} : GeoBoundingBox ,
26
- resolution : number
33
+ resolution : number ,
34
+ scale : number = 1.0
27
35
) : GeoBoundingBox {
28
36
const corners = [
29
37
[ north , east ] ,
@@ -35,7 +43,7 @@ function padBoundingBox(
35
43
const cornerEdgeLengths = cornerCells . map (
36
44
c => ( Math . max ( ...originToDirectedEdges ( c ) . map ( e => edgeLength ( e , UNITS . rads ) ) ) * 180 ) / Math . PI
37
45
) ;
38
- const bufferLat = Math . max ( ...cornerEdgeLengths ) ;
46
+ const bufferLat = Math . max ( ...cornerEdgeLengths ) * scale ;
39
47
const bufferLon = Math . min ( 180 , bufferLat / Math . cos ( ( ( ( north + south ) / 2 ) * Math . PI ) / 180 ) ) ;
40
48
41
49
return {
@@ -84,7 +92,12 @@ function tileToBoundingBox(index: string): GeoBoundingBox {
84
92
const south = Math . min ( ...latitudes ) ;
85
93
const east = Math . max ( ...longitudes ) ;
86
94
const north = Math . max ( ...latitudes ) ;
87
- return { west, south, east, north} ;
95
+ const bbox = { west, south, east, north} ;
96
+
97
+ // H3 child cells extend beyond their parent's boundary forming a "snowflake"
98
+ // fractal pattern. The required buffer is approximately 10% of the
99
+ // edge length of the tile cell, add a bit more to be safe.
100
+ return padBoundingBox ( bbox , getResolution ( index ) , 0.12 ) ;
88
101
}
89
102
90
103
// Resolution conversion function. Takes a WebMercatorViewport and returns
0 commit comments