Skip to content

allow passing TileLayer to Map #1624

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

Merged
merged 2 commits into from
Nov 8, 2022
Merged
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
9 changes: 6 additions & 3 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ class Map(JSCSSMixin, MacroElement):
Width of the map.
height: pixel int or percentage string (default: '100%')
Height of the map.
tiles: str, default 'OpenStreetMap'
tiles: str or TileLayer, default 'OpenStreetMap'
Map tileset to use. Can choose from a list of built-in tiles,
pass a custom URL or pass `None` to create a map without tiles.
pass a custom URL, pass a TileLayer object,
or pass `None` to create a map without tiles.
For more advanced tile layer options, use the `TileLayer` class.
min_zoom: int, default 0
Minimum allowed zoom level for the tile layer that is created.
Expand Down Expand Up @@ -282,7 +283,9 @@ def __init__(

self.objects_to_stay_in_front = []

if tiles:
if isinstance(tiles, TileLayer):
self.add_child(tiles)
elif tiles:
tile_layer = TileLayer(tiles=tiles, attr=attr,
min_zoom=min_zoom, max_zoom=max_zoom)
self.add_child(tile_layer, name=tile_layer.tile_name)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import branca.element

import folium
from folium import TileLayer
from folium.features import GeoJson, Choropleth

import jinja2
Expand Down Expand Up @@ -148,6 +149,13 @@ def test_custom_tile(self):
bounds = m.get_bounds()
assert bounds == [[None, None], [None, None]], bounds

def test_tilelayer_object(self):
url = "http://{s}.custom_tiles.org/{z}/{x}/{y}.png"
attr = "Attribution for custom tiles"
m = folium.Map(location=[45.52, -122.67], tiles=TileLayer(url, attr=attr))
assert next(iter(m._children.values())).tiles == url
assert attr in m._parent.render()

def test_feature_group(self):
"""Test FeatureGroup."""

Expand Down