Skip to content

Commit ec0d356

Browse files
Bump Makie compat to v0.21 (#90)
* Bump Makie compat to v0.21 * Try to make Tyler GeoMakie compatible This is not working at the moment because there are some strange interactions. Maybe it would be better to simply use a GeoAxis and let GeoMakie handle the conversion logic, that is currently done in Tyler. * Fix debug_tiles! * Allow Makie 0.21 * Remove show statements * REVERT LATER - let Tyler use any layoutable that can be plotted to * Fix debug tiles * Z-fighting happens more when z axis is scaled to 0 * Remove ImageMagick Compat is a pain and we can do the file type check using the magic bits from FileIO. * Fix tests (`scale` needs to be a float) --------- Co-authored-by: Felix Cremer <fcremer@bgc-jena.mpg.de>
1 parent 866b8fe commit ec0d356

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

Project.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910"
99
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
1010
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
1111
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
12-
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
1312
LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"
1413
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1514
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
@@ -26,12 +25,11 @@ GeometryBasics = "0.4"
2625
HTTP = "1"
2726
LRUCache = "1"
2827
LinearAlgebra = "1"
29-
Makie = "0.20"
28+
Makie = "0.20, 0.21"
3029
MapTiles = "1"
3130
OrderedCollections = "1"
3231
ThreadSafeDicts = "0.1"
3332
TileProviders = "0.1"
34-
ImageMagick = "1.3"
3533
julia = "1"
3634

3735
[extras]

src/Tyler.jl

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ using Extents: Extents, Extent
55
using GeoInterface: GeoInterface
66
using GeometryBasics: GeometryBasics, GLTriangleFace, Point2f, Vec2f, Rect2f, Rect2, Rect, decompose, decompose_uv
77
using HTTP: HTTP
8-
using ImageMagick: ImageMagick
98
using LRUCache: LRUCache, LRU
109
using MapTiles: MapTiles, Tile, TileGrid, web_mercator, wgs84, CoordinateReferenceSystemFormat
11-
using Makie: Makie, Observable, Figure, Axis, RGBAf, on, isopen, meta, mesh!, translate!, scale!
10+
using Makie: Makie, Observable, Figure, Axis, RGBAf, on, isopen, linesegments!, meta, mesh!, translate!, scale!
11+
using Makie: FileIO, ImageIO
1212
using OrderedCollections: OrderedCollections, OrderedSet
1313
using ThreadSafeDicts: ThreadSafeDicts, ThreadSafeDict
1414
using TileProviders: TileProviders, AbstractProvider, geturl, min_zoom, max_zoom
@@ -46,15 +46,15 @@ downloading and plotting more tiles as you zoom and pan.
4646
-`scale`: a tile scaling factor. Low number decrease the downloads but reduce the resolution.
4747
The default is `1.0`.
4848
"""
49-
struct Map
49+
struct Map{A<:Makie.AbstractAxis}
5050
provider::AbstractProvider
5151
crs::CoordinateReferenceSystemFormat
5252
zoom::Observable{Int}
5353
figure::Figure
54-
axis::Axis
54+
axis::A
5555
displayed_tiles::OrderedSet{Tile}
5656
plots::Dict{Tile,Any}
57-
free_tiles::Vector{Makie.Combined}
57+
free_tiles::Vector{Makie.Plot}
5858
fetched_tiles::LRU{Tile,TileImage}
5959
max_parallel_downloads::Int
6060
# TODO, use Channel here
@@ -151,9 +151,15 @@ function Map(extent, extent_crs=wgs84;
151151
ext_target = MapTiles.project_extent(extent, extent_crs, crs)
152152
X = ext_target.X
153153
Y = ext_target.Y
154-
axis.autolimitaspect = 1
155-
Makie.limits!(axis, (X[1], X[2]), (Y[1], Y[2]))
156-
154+
if axis isa Makie.Axis3
155+
Makie.xlims!(axis, X[1], X[2])
156+
Makie.ylims!(axis, Y[1], Y[2])
157+
elseif axis isa Makie.LScene
158+
# do nothing
159+
else # any other axis is 2d
160+
axis.autolimitaspect = 1
161+
Makie.limits!(axis, (X[1], X[2]), (Y[1], Y[2]))
162+
end
157163
plots = Dict{Tile,Any}()
158164
tyler = Map(
159165
provider, crs,
@@ -163,7 +169,7 @@ function Map(extent, extent_crs=wgs84;
163169
max_parallel_downloads, OrderedSet{Tile}(),
164170
tiles_being_added, downloaded_tiles,
165171
display_task, download_task,
166-
depth, halo, scale, max_zoom
172+
depth, Float64(halo), Float64(scale), max_zoom
167173
)
168174
tyler.zoom[] = get_zoom(tyler, extent)
169175
download_task[] = @async begin
@@ -204,16 +210,21 @@ function Map(extent, extent_crs=wgs84;
204210
# Queue tiles to be downloaded & displayed
205211
update_tiles!(tyler, ext_target)
206212

207-
on(axis.scene, axis.finallimits) do extent
208-
stopped_displaying(figure) && return
209-
update_tiles!(tyler, extent)
210-
return
213+
if axis isa Union{Makie.Axis, Makie.Axis3}
214+
on(axis.scene, axis.finallimits) do extent
215+
stopped_displaying(figure) && return
216+
update_tiles!(tyler, extent)
217+
return
218+
end
219+
else
220+
# we can't hook it up so don't do anything.
221+
# the user can zoom manually using `update_tiles!`.
211222
end
212223
return tyler
213224
end
214225

215226
GeoInterface.crs(tyler::Map) = tyler.crs
216-
Extents.extent(tyler::Map) = Extents.extent(tyler.axis.finallimits[])
227+
Extents.extent(tyler::Map) = Extents.extent(Makie.Rect2d(tyler.axis.finallimits[]))
217228

218229
function stop_download!(map::Map, tile::Tile)
219230
# delete!(map.tiles_being_added, tile)
@@ -261,7 +272,7 @@ function place_tile!(tile::Tile, plot, crs)
261272
xmin, xmax = bounds.X
262273
ymin, ymax = bounds.Y
263274
translate!(plot, xmin, ymin, tile.z - 100)
264-
scale!(plot, xmax - xmin, ymax - ymin, 0)
275+
scale!(plot, xmax - xmin, ymax - ymin, 1)
265276
return
266277
end
267278

@@ -283,14 +294,17 @@ function create_tile_plot!(tyler::Map, tile::Tile, image::TileImage)
283294
end
284295

285296
function fetch_tile(tyler::Map, tile::Tile)
297+
#println("Fetching Tile")
286298
return get!(tyler.fetched_tiles, tile) do
287299
fetch_tile(tyler.provider, tile)
288300
end
289301
end
290302
function fetch_tile(provider::AbstractProvider, tile::Tile)
291303
url = TileProviders.geturl(provider, tile.x, tile.y, tile.z)
292304
result = HTTP.get(url; retry=false, readtimeout=4, connect_timeout=4)
293-
return ImageMagick.readblob(result.body)
305+
io = IOBuffer(result.body) # this wraps the byte data in an IO-like type
306+
format = FileIO.query(io) # this interrogates the magic bits to see what file format it is (JPEG, PNG, etc)
307+
return FileIO.load(format) # this actually loads the data using ImageIO.jl or whatever other FileIO loader exists
294308
end
295309

296310
function queue_tile!(tyler::Map, tile)
@@ -412,13 +426,13 @@ function grow_extent(area::Union{Rect,Extent}, factor)
412426
end
413427

414428
function debug_tile!(map::Tyler.Map, tile::Tile)
415-
plot = linesegments!(map.axis, Rect2f(0, 0, 1, 1), color=:red, linewidth=1)
429+
plot = Makie.linesegments!(map.axis, Rect2f(0, 0, 1, 1), color=:red, linewidth=1)
416430
Tyler.place_tile!(tile, plot, web_mercator)
417431
end
418432

419433
function debug_tiles!(map::Tyler.Map)
420-
for tile in m.displayed_tiles
421-
debug_tile!(m, tile)
434+
for tile in map.displayed_tiles
435+
debug_tile!(map, tile)
422436
end
423437
end
424438

0 commit comments

Comments
 (0)