Skip to content

adds attribution #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function Map(extent, extent_crs=wgs84;
extent isa Extent || (extent = Extents.extent(extent))
ext_target = MapTiles.project_extent(extent, extent_crs, crs)
figure, axis = setup_figure_and_axis!(figure, axis, ext_target, crs)
setup_attribution!(figure, get_attribution(provider))
end

tiles = TileCache(provider; cache_size_gb=cache_size_gb, max_parallel_downloads=max_parallel_downloads)
Expand Down Expand Up @@ -214,6 +215,19 @@ function setup_axis!(axis::Axis, ext_target, crs)
return
end

function setup_attribution!(figure, attribution)
Box(figure[1,1], color=(:white, 0.85),
tellheight=false, tellwidth=false,
valign=0, halign=0.5,
height=15, cornerradius=2,
strokewidth=0, strokecolor=:transparent
)
Label(figure[1,1], rich("Powered by ", color=:grey15,
rich("Tyler.jl ", color="deepskyblue3", font=:bold),
rich("| Map data - "*attribution, color=:grey8, font=:regular), fontsize=12);
tellheight=false, tellwidth=false, valign=0, halign=0.5)
end

toggle_visibility!(m::Map) = m.axis.scene.visible[] = !m.axis.scene.visible[]

function tile_reloader(map::Map{Axis})
Expand Down Expand Up @@ -250,6 +264,29 @@ Extents.extent(map::Map) = Extents.extent(map.axis.finallimits[])
TileProviders.max_zoom(map::Map) = map.max_zoom
TileProviders.min_zoom(map::Map) = Int(min_zoom(map.provider))

function get_attribution(provider)
_attribution = if hasproperty(provider, :options)
if haskey(provider.options, :attribution)
return provider.options[:attribution]
end
return ""
elseif hasproperty(provider, :color_provider)
if hasproperty(provider.color_provider, :options)
if haskey(provider.color_provider.options, :attribution)
return provider.color_provider.options[:attribution]
end
return ""
else
return ""
end
elseif hasproperty(provider, :baseurl)
return getproperty(provider, :baseurl)
else
return ""
end
return _attribution
end

# Base methods

Base.showable(::MIME"image/png", ::AbstractMap) = true
Expand Down
2 changes: 2 additions & 0 deletions src/map3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ function Map3D(m::Map; kw...)
# Make a copy of the lscene, so we can easier separate the plots.
ax2 = LScene(ax.parent, ax.layoutobservables, ax.blockscene)
ax2.scene = Scene(ax.scene; camera=ax.scene.camera, camera_controls=ax.scene.camera_controls)
provider = get(kw, :provider, m.provider)
setup_attribution!(ax.parent, get_attribution(provider))
return Map3D(nothing, nothing; figure=m.figure, axis=ax2, kw...)
end
function Map3D(extent, extent_crs=wgs84;
Expand Down
Loading