Skip to content

Commit fa5a4cd

Browse files
rafaqzlazarusA
andauthored
bugfix 2d tile depth (#128)
* bugfix 2d tile depth * tests, new numbers for tiles * go back, locals are not like in ci, we need to control this better * rm test manifest * extent test * do less --------- Co-authored-by: Lazaro Alonso <[email protected]>
1 parent 6c2ef96 commit fa5a4cd

File tree

8 files changed

+69
-1368
lines changed

8 files changed

+69
-1368
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ FileIO = "1"
4242
GeoFormatTypes = "0.4"
4343
GeoInterface = "1"
4444
GeoMakie = "0.7.12"
45-
GeometryBasics = "0.4, 0.5"
45+
GeometryBasics = "0.5"
4646
GeometryOps = "0.1"
4747
HTTP = "1"
4848
ImageIO = "0.6"
@@ -51,7 +51,7 @@ LinearAlgebra = "1"
5151
Makie = "0.21.6, 0.22"
5252
MapTiles = "1"
5353
OrderedCollections = "1"
54-
PointClouds = "0.3, 0.4"
54+
PointClouds = "0.3"
5555
Proj = "1"
5656
Scratch = "1"
5757
Statistics = "1"

docs/Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ TileProviders = "263fe934-28e1-4ae9-998a-c2629c5fede6"
2121
Tyler = "e170d443-b9d6-418a-9ee8-061e966341ef"
2222

2323
[sources]
24-
OSMMakie = {url = "https://github.com/lazarusA/OSMMakie.jl/"}
25-
Tyler = {path = ".."}
24+
Tyler = {path = ".."}

docs/src/map-3d.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ delta = 0.008
5454
ext = Rect2f(lon - delta / 2, lat - delta / 2, delta, delta)
5555
provider = Tyler.GeoTilePointCloudProvider()
5656
image = ElevationProvider(nothing)
57-
cfg = Tyler.MeshScatterPlotconfig()
57+
cfg = Tyler.MeshScatterPlotconfig(; markersize=2)
5858
m1 = Tyler.Map3D(ext; provider=provider, plot_config=cfg)
5959
cfg = Tyler.PlotConfig(preprocess=pc -> map(p -> p .* 2, pc), shading=FastShading, colormap=:alpine)
6060
m2 = Tyler.Map3D(m1; provider=image, plot_config=cfg)

src/map.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function Map(extent, extent_crs=wgs84;
134134
# That means we won't plot this tile and it should not be in the queue anymore
135135
delete!(map.should_get_plotted, tile_key(map.provider, tile))
136136
else
137-
create_tile_plot!(map, tile, data)
137+
create_tyler_plot!(map, tile, data)
138138
end
139139
catch e
140140
@warn "error while creating tile" exception = (e, Base.catch_backtrace())

src/tile-fetching.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ function update_tiles!(m::Map, arealike)
5050

5151
# Move all plots to the back, that aren't in the newest tileset anymore
5252
for (key, (plot, tile, bounds)) in m.plots
53-
dist = abs(m.zoom[] - tile.z)
54-
if haskey(m.foreground_tiles, tile)
55-
move_in_front!(plot, dist, bounds)
56-
else
57-
move_to_back!(plot, dist, bounds)
58-
end
53+
move_z(m, plot, tile, bounds)
5954
end
6055

6156
# Remove any item from queue, that isn't in the new set

src/tile-plotting.jl

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function move_in_front!(plot, amount, ::Rect2)
44
if !hasproperty(plot, :depth_shift)
55
translate!(plot, 0, 0, amount)
66
else
7-
plot.depth_shift = -amount / 100f0
7+
plot.depth_shift = -amount / 10000f0
88
end
99
end
1010

@@ -13,10 +13,31 @@ function move_to_back!(plot, amount, ::Rect2)
1313
if !hasproperty(plot, :depth_shift)
1414
translate!(plot, 0, 0, -amount)
1515
else
16-
plot.depth_shift = amount / 100f0
16+
plot.depth_shift = amount / 10000f0
1717
end
1818
end
1919

20+
move_z(m::AbstractMap, plot, tile::Tile, bounds::Rect3) = nothing
21+
function move_z(m::AbstractMap, plot, tile::Tile, bounds::Rect2)
22+
# We want to see everything of the current zoom and more zoomed out,
23+
# to fill gaps until they load
24+
if haskey(m.foreground_tiles, tile)
25+
plot.visible = true
26+
amount = -tile.z
27+
elseif m.zoom[] >= tile.z
28+
# @show "zoom is more or equal tile"
29+
plot.visible = true
30+
# move_to_front!(plot, amount, bounds)
31+
# If we are zoomed in we want to see everything
32+
# of that zoom and more zoomed out, to fill gaps until they load
33+
amount = 30 - tile.z # Flip the order for negative shift
34+
move_to_back!(plot, amount, bounds)
35+
else
36+
plot.visible = false
37+
end
38+
# @show m.zoom[] tile.z amount shift
39+
end
40+
2041
struct PlotConfig <: AbstractPlotConfig
2142
attributes::Dict{Symbol, Any}
2243
preprocess::Function
@@ -126,7 +147,7 @@ function cull_plots!(m::Map)
126147
end
127148
end
128149

129-
function create_tile_plot!(m::AbstractMap, tile::Tile, data)
150+
function create_tyler_plot!(m::AbstractMap, tile::Tile, data)
130151
# For providers which have to map the same data to different tiles
131152
# Or providers that have e.g. additional parameters like a date
132153
# the url is a much better key than the tile itself
@@ -149,16 +170,10 @@ function create_tile_plot!(m::AbstractMap, tile::Tile, data)
149170
cull_plots!(m)
150171

151172
if isempty(m.unused_plots)
152-
mplot = create_tileplot!(cfg, m.axis, data_processed, bounds, (tile, m.crs))
173+
mplot = create_tileplot!(cfg, m.axis, m, data_processed, bounds, (tile, m.crs))
153174
else
154175
mplot = pop!(m.unused_plots)
155-
update_tile_plot!(mplot, cfg, m.axis, data_processed, bounds, (tile, m.crs))
156-
end
157-
158-
if haskey(m.foreground_tiles, tile)
159-
move_in_front!(mplot, abs(m.zoom[] - tile.z), bounds)
160-
else
161-
move_to_back!(mplot, abs(m.zoom[] - tile.z), bounds)
176+
update_tile_plot!(mplot, cfg, m.axis, m, data_processed, bounds, (tile, m.crs))
162177
end
163178

164179
# Always move new plots to the front
@@ -195,7 +210,7 @@ function get_bounds(tile::Tile, data::ElevationData, crs)
195210
end
196211

197212
function create_tileplot!(
198-
config::PlotConfig, axis::AbstractAxis, data::ElevationData, bounds::Rect, tile_crs
213+
config::PlotConfig, axis::AbstractAxis, m, data::ElevationData, bounds::Rect, tile_crs
199214
)
200215
# not so elegant with empty array, we may want to make this a bit nicer going forward
201216
color = isempty(data.color) ? (;) : (color=data.color,)
@@ -215,7 +230,7 @@ function create_tileplot!(
215230
end
216231

217232
function update_tile_plot!(
218-
plot::Surface, ::PlotConfig, ::AbstractAxis, data::ElevationData, bounds::Rect, tile_crs
233+
plot::Surface, ::PlotConfig, ::AbstractAxis, m, data::ElevationData, bounds::Rect, tile_crs
219234
)
220235
mini, maxi = extrema(bounds)
221236
plot.args[1].val = (mini[1], maxi[1])
@@ -234,7 +249,7 @@ end
234249
const ImageData = AbstractMatrix{<:Colorant}
235250

236251
function create_tileplot!(
237-
config::PlotConfig, axis::AbstractAxis, data::ImageData, bounds::Rect, tile_crs
252+
config::PlotConfig, axis::AbstractAxis, m, data::ImageData, bounds::Rect, (tile, crs)
238253
)
239254
mini, maxi = extrema(bounds)
240255
plot = Makie.image!(
@@ -244,11 +259,12 @@ function create_tileplot!(
244259
inspectable=false,
245260
config.attributes...
246261
)
262+
translate!(plot, 0, 0, -10)
247263
return plot
248264
end
249265

250266
function update_tile_plot!(
251-
plot::Makie.Image, ::PlotConfig, axis::AbstractAxis, data::ImageData, bounds::Rect, tile_crs
267+
plot::Makie.Image, ::PlotConfig, axis::AbstractAxis, m, data::ImageData, bounds::Rect, tile_crs
252268
)
253269
mini, maxi = extrema(bounds)
254270
plot[1] = (mini[1], maxi[1])
@@ -280,7 +296,7 @@ function Base.map(f::Function, data::PointCloudData)
280296
end
281297

282298
function create_tileplot!(
283-
config::PlotConfig, axis::AbstractAxis, data::PointCloudData, ::Rect, tile_crs
299+
config::PlotConfig, axis::AbstractAxis, m, data::PointCloudData, ::Rect, tile_crs
284300
)
285301
p = Makie.scatter!(
286302
axis.scene, data.points;
@@ -296,7 +312,7 @@ function create_tileplot!(
296312
end
297313

298314
function update_tile_plot!(
299-
plot::Makie.Scatter, ::PlotConfig, ::AbstractAxis, data::PointCloudData, bounds::Rect, tile_crs
315+
plot::Makie.Scatter, ::PlotConfig, ::AbstractAxis, m, data::PointCloudData, bounds::Rect, tile_crs
300316
)
301317
plot.color.val = data.color
302318
plot[1] = data.points
@@ -312,7 +328,7 @@ get_preprocess(config::AbstractPlotConfig) = get_preprocess(config.plcfg)
312328
get_postprocess(config::AbstractPlotConfig) = get_postprocess(config.plcfg)
313329

314330
function create_tileplot!(
315-
config::MeshScatterPlotconfig, axis::AbstractAxis, data::PointCloudData, ::Rect, tile_crs
331+
config::MeshScatterPlotconfig, axis::AbstractAxis, m, data::PointCloudData, ::Rect, tile_crs
316332
)
317333
m = Rect3f(Vec3f(0), Vec3f(1))
318334
p = Makie.meshscatter!(
@@ -327,7 +343,7 @@ function create_tileplot!(
327343
end
328344

329345
function update_tile_plot!(
330-
plot::Makie.MeshScatter, ::MeshScatterPlotconfig, ::AbstractAxis, data::PointCloudData, bounds::Rect, tile_crs
346+
plot::Makie.MeshScatter, ::MeshScatterPlotconfig, ::AbstractAxis, m, data::PointCloudData, bounds::Rect, tile_crs
331347
)
332348
plot.color = data.color
333349
plot[1] = data.points
@@ -347,7 +363,7 @@ DebugPlotConfig(; plot_attributes...) =
347363
DebugPlotConfig(Dict{Symbol,Any}(plot_attributes))
348364

349365
function create_tileplot!(
350-
config::DebugPlotConfig, axis::AbstractAxis, data::ImageData, bounds::Rect, tile_crs
366+
config::DebugPlotConfig, axis::AbstractAxis, m, data::ImageData, bounds::Rect, tile_crs
351367
)
352368
plot = Makie.poly!(
353369
axis.scene,
@@ -363,7 +379,7 @@ function create_tileplot!(
363379
end
364380

365381
function update_tile_plot!(
366-
plot::Makie.Poly, ::DebugPlotConfig, axis::AbstractAxis, data::ImageData, bounds::Rect, tile_crs
382+
plot::Makie.Poly, ::DebugPlotConfig, axis::AbstractAxis, m, data::ImageData, bounds::Rect, tile_crs
367383
)
368384
plot[1] = bounds
369385
plot.color = reverse(data; dims=1)

0 commit comments

Comments
 (0)