Skip to content

Commit 89c76a0

Browse files
authored
Merge pull request #623 from damselem/subdomains
Add subdomains option for TileLayer
2 parents ba45248 + 328e124 commit 89c76a0

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.4.0
2+
~~~~~
3+
- Added support for subdomains options in TileLayer (damselem #623)
4+
15
0.3.0
26
~~~~~
37

folium/map.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def __init__(self, location=None, width='100%', height='100%',
152152
no_wrap=False, attr=None, min_lat=-90, max_lat=90,
153153
min_lon=-180, max_lon=180, max_bounds=True,
154154
detect_retina=False, crs='EPSG3857', control_scale=False,
155-
prefer_canvas=False, no_touch=False, disable_3d=False):
155+
prefer_canvas=False, no_touch=False, disable_3d=False,
156+
subdomains='abc'):
156157
super(LegacyMap, self).__init__()
157158
self._name = 'Map'
158159
self._env = ENV
@@ -192,7 +193,8 @@ def __init__(self, location=None, width='100%', height='100%',
192193
self.add_tile_layer(
193194
tiles=tiles, min_zoom=min_zoom, max_zoom=max_zoom,
194195
continuous_world=continuous_world, no_wrap=no_wrap, attr=attr,
195-
API_key=API_key, detect_retina=detect_retina
196+
API_key=API_key, detect_retina=detect_retina,
197+
subdomains=subdomains
196198
)
197199

198200
self._template = Template(u"""
@@ -247,7 +249,8 @@ def _repr_html_(self, **kwargs):
247249
def add_tile_layer(self, tiles='OpenStreetMap', name=None,
248250
API_key=None, max_zoom=18, min_zoom=1,
249251
continuous_world=False, attr=None, active=False,
250-
detect_retina=False, no_wrap=False, **kwargs):
252+
detect_retina=False, no_wrap=False, subdomains='abc',
253+
**kwargs):
251254
"""
252255
Add a tile layer to the map. See TileLayer for options.
253256
@@ -257,6 +260,7 @@ def add_tile_layer(self, tiles='OpenStreetMap', name=None,
257260
attr=attr, API_key=API_key,
258261
detect_retina=detect_retina,
259262
continuous_world=continuous_world,
263+
subdomains=subdomains,
260264
no_wrap=no_wrap)
261265
self.add_child(tile_layer, name=tile_layer.tile_name)
262266

@@ -374,11 +378,13 @@ class TileLayer(Layer):
374378
Adds the layer as an optional overlay (True) or the base layer (False).
375379
control : bool, default True
376380
Whether the Layer will be included in LayerControls.
381+
subdomains: string, default 'abc'
382+
Subdomains of the tile service.
377383
"""
378384
def __init__(self, tiles='OpenStreetMap', min_zoom=1, max_zoom=18,
379385
attr=None, API_key=None, detect_retina=False,
380386
continuous_world=False, name=None, overlay=False,
381-
control=True, no_wrap=False):
387+
control=True, no_wrap=False, subdomains='abc'):
382388
self.tile_name = (name if name is not None else
383389
''.join(tiles.lower().strip().split()))
384390
super(TileLayer, self).__init__(name=self.tile_name, overlay=overlay,
@@ -390,6 +396,7 @@ def __init__(self, tiles='OpenStreetMap', min_zoom=1, max_zoom=18,
390396
self.max_zoom = max_zoom
391397
self.no_wrap = no_wrap
392398
self.continuous_world = continuous_world
399+
self.subdomains = subdomains
393400

394401
self.detect_retina = detect_retina
395402

@@ -424,7 +431,8 @@ def __init__(self, tiles='OpenStreetMap', min_zoom=1, max_zoom=18,
424431
continuousWorld: {{this.continuous_world.__str__().lower()}},
425432
noWrap: {{this.no_wrap.__str__().lower()}},
426433
attribution: '{{this.attr}}',
427-
detectRetina: {{this.detect_retina.__str__().lower()}}
434+
detectRetina: {{this.detect_retina.__str__().lower()}},
435+
subdomains: '{{this.subdomains}}'
428436
}
429437
).addTo({{this._parent.get_name()}});
430438

folium/templates/fol_template.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
continuousWorld: {{tile['continuous_world'].__str__().lower()}},
8080
noWrap: {{tile['no_wrap'].__str__().lower()}},
8181
attribution: '{{tile['attr']}}',
82-
detectRetina: {{tile['detect_retina'].__str__().lower()}}
82+
detectRetina: {{tile['detect_retina'].__str__().lower()}},
83+
subdomains: '{{tile['subdomains']}}'
8384
}
8485
).addTo({{ map_id }});
8586
{% endfor %}

tests/test_folium.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ def test_custom_tile(self):
147147
bounds = map.get_bounds()
148148
assert bounds == [[None, None], [None, None]], bounds
149149

150+
def test_custom_tile_subdomains(self):
151+
"""Test custom tile subdomains."""
152+
153+
url = 'http://{s}.custom_tiles.org/{z}/{x}/{y}.png'
154+
map = folium.Map(location=[45.52, -122.67], tiles=url,
155+
attr='attribution',
156+
subdomains='1234')
157+
158+
url_with_name = 'http://{s}.custom_tiles-subdomains.org/{z}/{x}/{y}.png'
159+
tile_layer = folium.map.TileLayer(url,
160+
name='subdomains2',
161+
attr='attribution',
162+
subdomains='5678')
163+
map.add_child(tile_layer)
164+
map.add_tile_layer(tiles=url_with_name, attr='attribution',
165+
subdomains='9012')
166+
167+
out = map._parent.render()
168+
assert '1234' in out
169+
assert '5678' in out
170+
assert '9012' in out
171+
150172
def test_feature_group(self):
151173
"""Test FeatureGroup."""
152174

@@ -320,7 +342,8 @@ def test_map_build(self):
320342
'min_zoom': 1,
321343
'detect_retina': False,
322344
'no_wrap': False,
323-
'continuous_world': False
345+
'continuous_world': False,
346+
'subdomains': 'abc'
324347
}]
325348
tmpl = {'map_id': 'map_' + '0' * 32,
326349
'lat': 45.5236, 'lon': -122.675,

0 commit comments

Comments
 (0)