From f5fe8635c2badadef66289d9030624fe3910c955 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Mon, 23 Dec 2024 14:29:48 +0100 Subject: [PATCH] cleanup and comments --- src/tile-fetching.jl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/tile-fetching.jl b/src/tile-fetching.jl index f6cc94c..d57bf93 100644 --- a/src/tile-fetching.jl +++ b/src/tile-fetching.jl @@ -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