Skip to content

Commit 1ad2336

Browse files
ozakocefpaf
authored andcommitted
Added default options to tile_layer
1 parent cb2d627 commit 1ad2336

File tree

4 files changed

+95
-23
lines changed

4 files changed

+95
-23
lines changed

folium/folium.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ def __init__(self, location=None, width='100%', height='100%',
9090
9191
Examples
9292
--------
93-
>>>map = folium.Map(location=[45.523, -122.675], width=750, height=500)
94-
>>>map = folium.Map(location=[45.523, -122.675],
95-
tiles='Mapbox Control Room')
96-
>>>map = folium.Map(location=(45.523, -122.675), max_zoom=20,
97-
tiles='Cloudmade', API_key='YourKey')
98-
>>>map = folium.Map(location=[45.523, -122.675], zoom_start=2,
99-
tiles=('http://{s}.tiles.mapbox.com/v3/'
93+
>>> map = folium.Map(location=[45.523, -122.675], width=750,
94+
... height=500)
95+
>>> map = folium.Map(location=[45.523, -122.675],
96+
tiles='Mapbox Control Room')
97+
>>> map = folium.Map(location=(45.523, -122.675), max_zoom=20,
98+
tiles='Cloudmade', API_key='YourKey')
99+
>>> map = folium.Map(location=[45.523, -122.675], zoom_start=2,
100+
tiles=('http://{s}.tiles.mapbox.com/v3/'
100101
'mapbox.control-room/{z}/{x}/{y}.png'),
101102
attr='Mapbox attribution')
102103
@@ -209,24 +210,46 @@ def __init__(self, location=None, width='100%', height='100%',
209210
self.template_vars.setdefault('image_layers', [])
210211

211212
@iter_obj('simple')
212-
def add_tile_layer(self, tile_name=None, tile_url=None, active=False):
213-
"""Adds a simple tile layer.
213+
def add_tile_layer(self, tile_name=None, tile_url=None, **kw):
214+
"""
215+
Adds a simple tile layer.
214216
215217
Parameters
216218
----------
217219
tile_name: string
218220
name of the tile layer
219221
tile_url: string
220222
url location of the tile layer
221-
active: boolean
222-
should the layer be active when added
223+
224+
For the available options see:
225+
http://leafletjs.com/reference.html#tilelayer
226+
223227
"""
228+
# Same defaults.
229+
tms = kw.pop('tms', 'false')
230+
minZoom = kw.pop('minZoom', 0)
231+
opacity = kw.pop('opacity', 1)
232+
maxZoom = kw.pop('maxZoom', 18)
233+
noWrap = kw.pop('noWrap', 'false')
234+
zoomOffset = kw.pop('zoomOffset', 0)
235+
zoomReverse = kw.pop('zoomReverse', 'false')
236+
continuousWorld = kw.pop('continuousWorld', 'false')
237+
224238
if tile_name not in self.added_layers:
225239
tile_name = tile_name.replace(" ", "_")
226240
tile_temp = self.env.get_template('tile_layer.js')
227-
228-
tile = tile_temp.render({'tile_name': tile_name,
229-
'tile_url': tile_url})
241+
tile = tile_temp.render({
242+
'tile_name': tile_name,
243+
'tile_url': tile_url,
244+
'minZoom': minZoom,
245+
'maxZoom': maxZoom,
246+
'tms': str(tms).lower(),
247+
'continuousWorld': str(continuousWorld).lower(),
248+
'noWrap': str(noWrap).lower(),
249+
'zoomOffset': zoomOffset,
250+
'zoomReverse': str(zoomReverse).lower(),
251+
'opacity': opacity,
252+
})
230253

231254
self.template_vars.setdefault('tile_layers', []).append((tile))
232255

@@ -305,8 +328,8 @@ def simple_marker(self, location=None, popup=None,
305328
306329
Example
307330
-------
308-
>>>map.simple_marker(location=[45.5, -122.3], popup='Portland, OR')
309-
>>>map.simple_marker(location=[45.5, -122.3], popup=(vis, 'vis.json'))
331+
>>> map.simple_marker(location=[45.5, -122.3], popup='Portland, OR')
332+
>>> map.simple_marker(location=[45.5, -122.3], popup=(vis, 'vis.json'))
310333
311334
"""
312335
count = self.mark_cnt['simple']
@@ -364,8 +387,8 @@ def line(self, locations,
364387
365388
Example
366389
-------
367-
>>>map.line(locations=[(45.5, -122.3), (42.3, -71.0)])
368-
>>>map.line(locations=[(45.5, -122.3), (42.3, -71.0)],
390+
>>> map.line(locations=[(45.5, -122.3), (42.3, -71.0)])
391+
>>> map.line(locations=[(45.5, -122.3), (42.3, -71.0)],
369392
line_color='red', line_opacity=1.0)
370393
371394
"""
@@ -409,7 +432,6 @@ def multiline(self, locations, line_color=None, line_opacity=None,
409432
410433
Example
411434
-------
412-
# FIXME: Add another example.
413435
>>> m.multiline(locations=[[(45.5236, -122.675), (45.5236, -122.675)],
414436
[(45.5237, -122.675), (45.5237, -122.675)],
415437
[(45.5238, -122.675), (45.5238, -122.675)]])
@@ -467,9 +489,9 @@ def circle_marker(self, location=None, radius=500, popup=None,
467489
468490
Example
469491
-------
470-
>>>map.circle_marker(location=[45.5, -122.3],
492+
>>> map.circle_marker(location=[45.5, -122.3],
471493
radius=1000, popup='Portland, OR')
472-
>>>map.circle_marker(location=[45.5, -122.3],
494+
>>> map.circle_marker(location=[45.5, -122.3],
473495
radius=1000, popup=(bar_chart, 'bar_data.json'))
474496
475497
"""
@@ -584,7 +606,7 @@ def click_for_marker(self, popup=None):
584606
585607
Example
586608
-------
587-
>>>map.click_for_marker(popup='Your Custom Text')
609+
>>> map.click_for_marker(popup='Your Custom Text')
588610
589611
"""
590612
latlng = '"Latitude: " + lat + "<br>Longitude: " + lng '

folium/templates/leaflet-dvf.markers.min.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

folium/templates/tile_layer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
var {{ tile_name }} = L.tileLayer('{{ tile_url }}');
1+
var {{ tile_name }} = L.tileLayer('{{ tile_url }}',{
2+
'minZoom': {{minZoom}},
3+
'maxZoom': {{maxZoom}},
4+
'tms': {{tms}},
5+
'continuousWorld': {{continuousWorld}},
6+
'noWrap': {{noWrap}},
7+
'zoomOffset': {{zoomOffset}},
8+
'zoomReverse': {{zoomReverse}},
9+
'opacity': {{opacity}}
10+
});

tests/folium_tests.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,41 @@ def test_wms_layer(self):
138138
'wms_transparent': 'true'})
139139
assert map.template_vars['wms_layers'][0] == wms
140140

141+
def test_add_tile_layer(self):
142+
"""Test add_layer URLs."""
143+
144+
map = folium.Map(location=[44, -73], zoom_start=3)
145+
tile_name = "Temperature"
146+
tile_url = 'http://gis.srh.noaa.gov/arcgis/services/NDFDTemps/'
147+
tile_url += 'MapServer/WMSServer'
148+
minZoom = 1
149+
maxZoom = 5
150+
tms = True
151+
continuousWorld = False
152+
noWrap = True
153+
zoomOffset = 1
154+
zoomReverse = True
155+
opacity = 2
156+
map.add_tile_layer(tile_name=tile_name, tile_url=tile_url, active=True,
157+
minZoom=minZoom, maxZoom=maxZoom, tms=tms,
158+
continuousWorld=continuousWorld, noWrap=noWrap,
159+
zoomOffset=zoomOffset, zoomReverse=zoomReverse,
160+
opacity=opacity, attribution='Leaflet')
161+
tile_temp = self.env.get_template('tile_layer.js')
162+
tile = tile_temp.render({
163+
'tile_name': tile_name,
164+
'tile_url': tile_url,
165+
'minZoom': minZoom,
166+
'maxZoom': maxZoom,
167+
'tms': str(tms).lower(),
168+
'continuousWorld': str(continuousWorld).lower(),
169+
'noWrap': str(noWrap).lower(),
170+
'zoomOffset': zoomOffset,
171+
'zoomReverse': str(zoomReverse).lower(),
172+
'opacity': opacity,
173+
})
174+
assert map.template_vars['tile_layers'][0] == tile
175+
141176
def test_simple_marker(self):
142177
"""Test simple marker addition."""
143178

0 commit comments

Comments
 (0)