Skip to content
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

Added backward compatibility for dict basemaps #901

Merged
merged 2 commits into from
Dec 13, 2021
Merged
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
12 changes: 9 additions & 3 deletions ipyleaflet/leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,26 @@ def basemap_to_tiles(basemap, day=yesterday, **kwargs):

Parameters
----------
basemap : class:`xyzservices.lib.TileProvider`
basemap : class:`xyzservices.lib.TileProvider` or Dict
Basemap description coming from ipyleaflet.basemaps.
day: string
If relevant for the chosen basemap, you can specify the day for
the tiles in the "%Y-%m-%d" format. Defaults to yesterday's date.
kwargs: key-word arguments
Extra key-word arguments to pass to the TileLayer constructor.
"""
url = basemap.build_url(time=day, **kwargs)
if isinstance(basemap, xyzservices.lib.TileProvider):
url = basemap.build_url(time=day)
elif isinstance(basemap, dict):
url = basemap.get("url", "")
else:
raise ValueError("Invalid basemap type")

return TileLayer(
url=url,
max_zoom=basemap.get('max_zoom', 19),
min_zoom=basemap.get('min_zoom', 1),
attribution=basemap.get('html_attribution', ''),
attribution=basemap.get('html_attribution', '') or basemap.get('attribution', ''),
name=basemap.get('name', ''),
**kwargs
)
Expand Down