Skip to content

Commit f48243a

Browse files
authored
Added backward compatibility for dict basemaps (#901)
* Added backward compatibility for dict basemaps Signed-off-by: Kharude, Sachin <[email protected]> * updated as per review comments Signed-off-by: Kharude, Sachin <[email protected]>
1 parent 372a37a commit f48243a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

ipyleaflet/leaflet.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,26 @@ def basemap_to_tiles(basemap, day=yesterday, **kwargs):
4242
4343
Parameters
4444
----------
45-
basemap : class:`xyzservices.lib.TileProvider`
45+
basemap : class:`xyzservices.lib.TileProvider` or Dict
4646
Basemap description coming from ipyleaflet.basemaps.
4747
day: string
4848
If relevant for the chosen basemap, you can specify the day for
4949
the tiles in the "%Y-%m-%d" format. Defaults to yesterday's date.
5050
kwargs: key-word arguments
5151
Extra key-word arguments to pass to the TileLayer constructor.
5252
"""
53-
url = basemap.build_url(time=day, **kwargs)
53+
if isinstance(basemap, xyzservices.lib.TileProvider):
54+
url = basemap.build_url(time=day)
55+
elif isinstance(basemap, dict):
56+
url = basemap.get("url", "")
57+
else:
58+
raise ValueError("Invalid basemap type")
59+
5460
return TileLayer(
5561
url=url,
5662
max_zoom=basemap.get('max_zoom', 19),
5763
min_zoom=basemap.get('min_zoom', 1),
58-
attribution=basemap.get('html_attribution', ''),
64+
attribution=basemap.get('html_attribution', '') or basemap.get('attribution', ''),
5965
name=basemap.get('name', ''),
6066
**kwargs
6167
)

0 commit comments

Comments
 (0)