MakieOrg / Tyler.jl

Makie package to plot maptiles from various map providers
https://makieorg.github.io/Tyler.jl/dev/
MIT License
70 stars 9 forks source link

Make it work with GeoAxis #77

Open felixcremer opened 6 months ago

felixcremer commented 6 months ago

It would be nice if it would be possible to use a GeoAxis from GeoMakie in Tyler.Map. When I am trying it, I get the following error:

fig = Figure()
julia> ax = GeoAxis(fig[1,1], dest="+proj=webmerc +datum=WGS84")
GeoAxis()
julia> mgeo = Tyler.Map(ext, m.crs, figure=fig,axis=ax)
ERROR: InexactError: trunc(Int64, NaN)
Stacktrace:
  [1] trunc
    @ ./float.jl:905 [inlined]
  [2] round
    @ ./float.jl:385 [inlined]
  [3] macro expansion
    @ ~/.julia/packages/StaticArrays/EHHaF/src/broadcast.jl:135 [inlined]
  [4] __broadcast
    @ ~/.julia/packages/StaticArrays/EHHaF/src/broadcast.jl:123 [inlined]
  [5] _broadcast
    @ ~/.julia/packages/StaticArrays/EHHaF/src/broadcast.jl:119 [inlined]
  [6] copy
    @ ~/.julia/packages/StaticArrays/EHHaF/src/broadcast.jl:60 [inlined]
  [7] materialize
    @ ./broadcast.jl:903 [inlined]
  [8] round_to_IRect2D(r::GeometryBasics.HyperRectangle{2, Float32})
    @ Makie ~/.julia/packages/Makie/VRavR/src/makielayout/helpers.jl:7
  [9] (::Makie.var"#1456#1457")(bbox::GeometryBasics.HyperRectangle{2, Float32}, limits::Rect2{Float64}, aspect::DataAspect)
    @ Makie ~/.julia/packages/Makie/VRavR/src/makielayout/helpers.jl:49
 [10] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base ./essentials.jl:892
 [11] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base ./essentials.jl:889
 [12] (::Observables.MapCallback)(value::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:436
 [13] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
 [14] invokelatest
    @ ./essentials.jl:889 [inlined]
 [15] notify
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:206 [inlined]
 [16] setindex!(observable::Observable, val::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:123
 [17] adjustlimits!(la::GeoAxis)
    @ Makie ~/.julia/packages/Makie/VRavR/src/makielayout/blocks/axis.jl:1009
 [18] (::GeoMakie.var"#51#53"{GeoAxis})(::GeometryBasics.HyperRectangle{2, Int64}, ::Rect2{Float64})
    @ GeoMakie ~/.julia/packages/GeoMakie/vcMuZ/src/makie-axis.jl:28
 [19] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base ./essentials.jl:892
 [20] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base ./essentials.jl:889
 [21] (::Observables.OnAny)(value::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:420
 [22] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
 [23] invokelatest
    @ ./essentials.jl:889 [inlined]
 [24] notify
    @ ~/.julia/packages/Observables/YdEbO/src/Observables.jl:206 [inlined]
 [25] setindex!(observable::Observable, val::Any)
    @ Observables ~/.julia/packages/Observables/YdEbO/src/Observables.jl:123
 [26] reset_limits!(axis::GeoAxis; xauto::Bool, yauto::Bool)
    @ GeoMakie ~/.julia/packages/GeoMakie/vcMuZ/src/makie-axis.jl:137
 [27] reset_limits!
    @ ~/.julia/packages/GeoMakie/vcMuZ/src/makie-axis.jl:44 [inlined]
 [28] xlims!(ax::GeoAxis, xlims::Tuple{Float32, Float32})
    @ GeoMakie ~/.julia/packages/GeoMakie/vcMuZ/src/makie-axis.jl:449
 [29] limits!
    @ ~/.julia/packages/GeoMakie/vcMuZ/src/makie-axis.jl:471 [inlined]
 [30] Tyler.Map(extent::GeometryBasics.HyperRectangle{…}, extent_crs::MapTiles.WebMercator; resolution::Tuple{…}, figure::Figure, axis::GeoAxis, provider::TileProviders.Provider, crs::MapTiles.WebMercator, max_parallel_downloads::Int64, cache_size_gb::Int64, depth::Int64, halo::Float64, scale::Float64, max_zoom::Int64)
    @ Tyler ~/.julia/packages/Tyler/J1n7N/src/Tyler.jl:146
 [31] top-level scope
    @ REPL[54]:1
Some type information was truncated. Use `show(err)` to see complete types.
felixcremer commented 6 months ago

I got around this issue by setting the source keyword for the GeoAxis to also use webmerc as the source projection. I managed to plot something but it seems that it is only fetching a few tiles and this might be a projection issue.

felixcremer commented 5 months ago

There is some strange interaction between GeoMakie and Tyler. When I construct the Map object it fetches some tiles that I would also expect to be fetched but they are not displayed on the Axis and as soon as I try to interact with the data it fetches only one tile that is on zoomlevel one and at (0,0) and therefore only shows the ocean.

using GeoMakie, Tyler, GLMakie
julia> fig = Figure()

julia> ax = GeoAxis(fig[1,1], dest="+proj=webmerc +datum=WGS84", source="+proj=webmerc +datum=WGS84")
GeoAxis()

julia> nax = Axis(fig[1,2])
Axis with 0 plots:

julia> london = Rect2f(-0.0921, 51.5, 0.04, 0.025)
GeometryBasics.HyperRectangle{2, Float32}(Float32[-0.0921, 51.5], Float32[0.04, 0.025])

julia> m = Tyler.Map(london, figure=fig, axis=nax);
(X[1], X[2]) = (-10252.524915718823, -5799.745763988467)
ext_target = Extent{(:X, :Y), Tuple{Tuple{Float64, Float64}, Tuple{Float64, Float64}}}((X = (-10252.524915718823, -5799.745763988467), Y = (6.710218830581673e6, 6.714690955633332e6)))
area = Extent{(:X, :Y), Tuple{Tuple{Float64, Float64}, Tuple{Float64, Float64}}}((X = (-10252.524915718823, -5799.745763988467), Y = (6.710218830581673e6, 6.714690955633332e6)))
zoom = 16

julia> mgeo = Tyler.Map(extent(m), m.crs, figure=fig,axis=ax);
(X[1], X[2]) = (-10252.525f0, -5799.7456f0)
xlims = (-10252.525f0, -5799.7456f0)
in needs_transform
ylims = (6.709957f6, 6.714953f6)
in needs_transform
extent = GeometryBasics.HyperRectangle{2, Float32}(Float32[-10252.525, 6.7099985f6], Float32[4452.78, 4913.2534])
area = GeometryBasics.HyperRectangle{2, Float32}(Float32[-10252.525, 6.7099985f6], Float32[4452.78, 4913.2534])
zoom = 16
ext_target = Extent{(:X, :Y), Tuple{Tuple{Float32, Float32}, Tuple{Float32, Float32}}}((X = (-10252.525f0, -5799.7456f0), Y = (6.709957f6, 6.714953f6)))
area = Extent{(:X, :Y), Tuple{Tuple{Float32, Float32}, Tuple{Float32, Float32}}}((X = (-10252.525f0, -5799.7456f0), Y = (6.709957f6, 6.714953f6)))
zoom = 16

julia> mgeo.plots
Dict{MapTiles.Tile, Any} with 162 entries:
  Tile(32757, 21789, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32755, 21789, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32756, 21790, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32756, 21791, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(16378, 10893, 15) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32752, 21791, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(16378, 10895, 15) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32757, 21790, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32759, 21794, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32754, 21795, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32753, 21795, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32753, 21789, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(16375, 10895, 15) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(16377, 10897, 15) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32753, 21792, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32751, 21793, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32754, 21791, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32755, 21788, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32753, 21791, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32753, 21794, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  Tile(32757, 21793, 16) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2,…
  ⋮                      => ⋮
julia> mgeo.plots # This is after zooming into the GeoAxis
Dict{MapTiles.Tile, Any} with 1 entry:
  Tile(0, 0, 1) => Mesh{Tuple{Mesh{2, Float32, TriangleP{2, Float32, PointWithUV{2, Float32}}, FaceView{TriangleP{2, Float32,…