diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba5ab731..46896594 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,9 +25,7 @@ jobs: version: 1 arch: x64 - uses: julia-actions/cache@v2 - - run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev libcairo2-dev libfreetype6-dev libffi-dev libjpeg-dev libpng-dev libz-dev - - name: Install pkgs dependencies - run: xvfb-run -s '-screen 0 1024x768x24' julia --project=@. -e 'using Pkg; pkg"add https://github.com/JuliaGeo/TileProviders.jl https://github.com/JuliaGeo/MapTiles.jl"' + - run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev xsettingsd x11-xserver-utils - uses: julia-actions/julia-runtest@v1 with: - prefix: xvfb-run -s '-screen 0 1024x768x24' + prefix: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' diff --git a/docs/src/points_poly_text.md b/docs/src/points_poly_text.md index 56d4e2b3..3ecd1152 100644 --- a/docs/src/points_poly_text.md +++ b/docs/src/points_poly_text.md @@ -39,10 +39,6 @@ show map ````@example plottypes m = Tyler.Map(extent; provider, size=(1000, 600)) -# wait for tiles to fully load -wait(m) -save("map_plottypes.png", current_figure()) # hide -nothing # hide ```` ![](map_plottypes.png) @@ -72,7 +68,4 @@ text!(pts2, text = "Basic Example"; fontsize = 30, color = :darkblue, align = (:center, :center) ) m -save("map_plottypes_all.png", current_figure()) # hide -nothing # hide ```` -![](map_plottypes_all.png) diff --git a/docs/src/whale_shark.md b/docs/src/whale_shark.md index 862cc9dd..626fc875 100644 --- a/docs/src/whale_shark.md +++ b/docs/src/whale_shark.md @@ -56,11 +56,7 @@ fig = Figure(; size = (1200, 600)) ax = Axis(fig[1,1]) m = Tyler.Map(Rect2f(Rect2f(lomn - δlon/2, lamn-δlat/2, 2δlon, 2δlat)); provider, figure=fig, axis=ax) -wait(m) -save("whale_init.png", fig) # hide -nothing # hide ```` -![](whale_init.png) ## Initial point @@ -79,9 +75,7 @@ objscatter = scatter!(ax, whale; markersize = 15, color = :orangered, strokecolor=:white, strokewidth=1.5) hidedecorations!(ax) hidespines!(ax) - -save("whale_init_point.png", fig) # hide -nothing # hide +m ```` ![](whale_init_point.png) @@ -104,4 +98,4 @@ set_theme!() # reset theme (default) ```@raw html -``` \ No newline at end of file +``` diff --git a/src/map.jl b/src/map.jl index c1cfca2d..e8a8583d 100644 --- a/src/map.jl +++ b/src/map.jl @@ -119,7 +119,7 @@ function Map(extent, extent_crs=wgs84; provider=TileProviders.OpenStreetMap(:Mapnik), crs=MapTiles.web_mercator, cache_size_gb=5, - max_parallel_downloads=min(1, Threads.nthreads(:default) ÷ 3), + max_parallel_downloads=max(1, Threads.nthreads(:default) ÷ 3), fetching_scheme=Halo2DTiling(), max_zoom=TileProviders.max_zoom(provider), max_plots=400, @@ -187,24 +187,25 @@ function Map(extent, extent_crs=wgs84; return map end -function Base.wait(m::AbstractMap; time_out=10) +function Base.wait(m::AbstractMap; timeout=50) # The download + plot loops need a screen to do their work! if isnothing(Makie.getscreen(m.figure.scene)) screen = display(m.figure.scene) end screen = Makie.getscreen(m.figure.scene) isnothing(screen) && error("No screen after display.") - wait(m.tiles) + wait(m.tiles; timeout=timeout) start = time() while true tile_keys = Set(tile_key.((m.provider,), keys(m.current_tiles))) if all(k -> haskey(m.plots, k), tile_keys) break end - if time() - start > time_out + if time() - start > timeout @warn "Timeout waiting for all tiles to be plotted" break end + sleep(0.01) end return m end diff --git a/src/tiles.jl b/src/tiles.jl index 644acc9d..6ef06190 100644 --- a/src/tiles.jl +++ b/src/tiles.jl @@ -54,17 +54,19 @@ function run_loop(thread_id, tile_queue, fetched_tiles, downloader, provider, do end end -function TileCache(provider; cache_size_gb=5, max_parallel_downloads=min(1, Threads.nthreads() ÷ 3)) +function TileCache(provider; cache_size_gb=5, max_parallel_downloads=max(1, Threads.nthreads() ÷ 3)) TileFormat = get_tile_format(provider) downloader = [get_downloader(provider) for i in 1:max_parallel_downloads] fetched_tiles = LRU{String,TileFormat}(; maxsize=cache_size_gb * 10^9, by=Base.summarysize) downloaded_tiles = Channel{Tuple{Tile,Union{Nothing, TileFormat}}}(Inf) tile_queue = Channel{Tile}(Inf) async = Threads.nthreads() <= 1 + if async && max_parallel_downloads > 1 @warn "Multiple download threads are not supported with Threads.nthreads()==1, falling back to async. Start Julia with more threads for parallel downloads." async = true end + @assert max_parallel_downloads > 0 for thread in 1:max_parallel_downloads if async @async run_loop(thread, tile_queue, fetched_tiles, downloader, provider, downloaded_tiles) @@ -88,7 +90,7 @@ function load_tile_data(::AbstractProvider, downloaded::AbstractVector{UInt8}) return FileIO.load(format) # this works because we have ImageIO loaded end -function Base.wait(tiles::TileCache; timeout=10) +function Base.wait(tiles::TileCache; timeout=50) # wait for all tiles to get downloaded items = lock(tiles.tile_queue) do copy(tiles.tile_queue.data) diff --git a/test/runtests.jl b/test/runtests.jl index 1f93f368..58549b56 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,7 @@ using GeoInterface # Default london = Rect2f(-0.0921, 51.5, 0.04, 0.025) -m = Tyler.Map(london) +m = Tyler.Map(london); m.figure.scene s = display(m) # waits until all tiles are displayed @test isempty(m.tiles.tile_queue) @test length(m.current_tiles) == 25