1+ using CairoMakie
2+ import GeoInterface as GI, GeometryOps as GO
3+ using NaturalEarth
4+
5+
6+ using GeometryOps. SpatialTreeInterface
7+ import GeometryOps. SpatialTreeInterface as STI
8+ using SortTileRecursiveTree
9+
10+ function build_spatial_index_gif (geom, index_constructor, filename; plot_leaves = true , title = splitext (filename)[1 ], axis = (;), figure = (;), record = (;))
11+ fig = Figure (; figure... )
12+ ax = Axis (fig[1 , 1 ]; title = title, axis... )
13+
14+ # Create a spatial index
15+ index = index_constructor (geom)
16+ ext = STI. node_extent (index)
17+ limits! (ax, ext. X[1 ], ext. X[2 ], ext. Y[1 ], ext. Y[2 ])
18+
19+ rects = Rect2f[Rect2f ((NaN , NaN ), (NaN , NaN ))]
20+ colors = RGBAf[to_color (:transparent )]
21+ palette = Makie. wong_colors (0.7 )
22+
23+ plt = poly! (ax, rects; color = colors)
24+
25+ to_rect2 (extent) = Rect2f ((extent. X[1 ], extent. Y[1 ]), (extent. X[2 ] - extent. X[1 ], extent. Y[2 ] - extent. Y[1 ]))
26+
27+ function dive_in (io, plt, node, level)
28+ if STI. isleaf (node) && plot_leaves
29+ push! (rects, to_rect2 (STI. node_extent (node)))
30+ push! (colors, palette[level])
31+ else
32+ for child in STI. getchild (node)
33+ dive_in (io, plt, child, level + 1 )
34+ end
35+ push! (rects, to_rect2 (STI. node_extent (node)))
36+ push! (colors, palette[level])
37+ end
38+ update! (plt, rects; color = colors)
39+ recordframe! (io)
40+ return
41+ end
42+
43+ Makie. record (fig, filename; record... ) do io
44+ empty! (rects)
45+ empty! (colors)
46+ dive_in (io, plt, index, 1 )
47+ end
48+
49+ end
0 commit comments