Skip to content

Commit

Permalink
cleanup and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Dec 23, 2024
1 parent 1cfc94a commit f5fe863
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/tile-fetching.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,42 @@ function get_tiles_for_area(m::Map{Axis}, scheme::Halo2DTiling, area::Union{Rect
layer_range = max(min_zoom(m), zoom - depth):zoom
# Get the tiles around the mouse first
xpos, ypos = Makie.mouseposition(m.axis.scene)
# Use the closest in-bounds point
xpos = max(min(xpos, area.X[2]), area.X[1])
ypos = max(min(ypos, area.Y[2]), area.Y[1])
# Define a 1% resolution extent around the mouse
xspan = (area.X[2] - area.X[1]) * 0.01
yspan = (area.Y[2] - area.Y[1]) * 0.01
mouse_area = Extents.Extent(; X=(xpos - xspan, xpos + xspan), Y=(ypos - yspan, ypos + yspan))
# Define a halo around the area to download last, so pan/zoom are filled already
halo_area = grow_extent(area, scheme.halo) # We don't mind that the middle tiles are the same, the OrderedSet will remove them

# Set up empty tile lists
foreground = OrderedSet{Tile}()
background = OrderedSet{Tile}()
offscreen = OrderedSet{Tile}()
# Fill tiles for each z layer
for z in layer_range
# Make a halo around the mouse tile to load next,
# intersecting area so we don't download outside the plot
for ext_scale in 1:2:100
# Get rings of tiles around the mouse, intersecting
# area so we don't get tiles outside the plot
for ext_scale in 1:4:100
# Get an extent
mouse_halo_area = grow_extent(mouse_area, ext_scale)
# Check if it intersects the plot area
ext = Extents.intersection(mouse_halo_area, area)
# No intersection so continue
isnothing(ext) && continue
tilegrid = collect(MapTiles.TileGrid(ext, z, m.crs))
tilegrid = MapTiles.TileGrid(ext, z, m.crs)
if z == zoom
union!(foreground, OrderedSet(tilegrid))
union!(foreground, tilegrid)
else
union!(background, tilegrid)
end
end
# Get just the halo ring tiles to load offscreen
# Get the halo ring tiles to load offscreen
area_grid = MapTiles.TileGrid(area, z, m.crs)
halo_grid = MapTiles.TileGrid(halo_area, z, m.crs)
# Remove tiles inside the area grid
halo_tiles = setdiff(halo_grid, area_grid)
union!(offscreen, halo_tiles)
end
Expand Down

0 comments on commit f5fe863

Please sign in to comment.