Skip to content

Commit 31bca63

Browse files
author
Martin Journois
committed
Fix issue #206
1 parent 57f2e37 commit 31bca63

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

folium/map.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, location=None, width='100%', height='100%',
2121
left="0%", top="0%", position='relative',
2222
tiles='OpenStreetMap', API_key=None, max_zoom=18, min_zoom=1,
2323
zoom_start=10, attr=None, min_lat=-90, max_lat=90,
24-
min_lon=-180, max_lon=180):
24+
min_lon=-180, max_lon=180, detect_retina=False):
2525
"""Create a Map with Folium and Leaflet.js
2626
2727
Generate a base map of given width and height with either default
@@ -58,6 +58,9 @@ def __init__(self, location=None, width='100%', height='100%',
5858
Initial zoom level for the map.
5959
attr: string, default None
6060
Map tile attribution; only required if passing custom tile URL.
61+
detect_retina: bool, default False
62+
If true and user is on a retina display, it will request four tiles of half the specified
63+
size and a bigger zoom level in place of one to utilize the high resolution.
6164
6265
Returns
6366
-------
@@ -102,7 +105,7 @@ def __init__(self, location=None, width='100%', height='100%',
102105
self.max_lon = max_lon
103106

104107
self.add_tile_layer(tiles=tiles, min_zoom=min_zoom, max_zoom=max_zoom,
105-
attr=attr, API_key=API_key)
108+
attr=attr, API_key=API_key, detect_retina=detect_retina)
106109

107110
self._template = Template(u"""
108111
{% macro header(this, kwargs) %}
@@ -148,7 +151,7 @@ def _repr_html_(self, **kwargs):
148151
def add_tile_layer(self, tiles='OpenStreetMap', name=None,
149152
API_key=None, max_zoom=18, min_zoom=1,
150153
attr=None, tile_name=None, tile_url=None,
151-
active=False, **kwargs):
154+
active=False, detect_retina=False, **kwargs):
152155
if tile_name is not None:
153156
name = tile_name
154157
warnings.warn("'tile_name' is deprecated. Please use 'name' instead.")
@@ -158,12 +161,13 @@ def add_tile_layer(self, tiles='OpenStreetMap', name=None,
158161

159162
tile_layer = TileLayer(tiles=tiles, name=name,
160163
min_zoom=min_zoom, max_zoom=max_zoom,
161-
attr=attr, API_key=API_key)
164+
attr=attr, API_key=API_key, detect_retina=detect_retina)
162165
self.add_children(tile_layer, name=tile_layer.tile_name)
163166

164167
class TileLayer(MacroElement):
165168
def __init__(self, tiles='OpenStreetMap', name=None,
166-
min_zoom=1, max_zoom=18, attr=None, API_key=None, overlay = False):
169+
min_zoom=1, max_zoom=18, attr=None, API_key=None, overlay = False,
170+
detect_retina=False):
167171
"""TODO docstring here
168172
Parameters
169173
----------
@@ -176,6 +180,7 @@ def __init__(self, tiles='OpenStreetMap', name=None,
176180
self.max_zoom = max_zoom
177181

178182
self.overlay = overlay
183+
self.detect_retina = detect_retina
179184

180185
self.tiles = ''.join(tiles.lower().strip().split())
181186
if self.tiles in ('cloudmade', 'mapbox') and not API_key:
@@ -204,7 +209,8 @@ def __init__(self, tiles='OpenStreetMap', name=None,
204209
{
205210
maxZoom: {{this.max_zoom}},
206211
minZoom: {{this.min_zoom}},
207-
attribution: '{{this.attr}}'
212+
attribution: '{{this.attr}}',
213+
detectRetina: {{this.detect_retina.__str__().lower()}}
208214
}
209215
).addTo({{this._parent.get_name()}});
210216

folium/templates/fol_template.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
{
7474
maxZoom: {{tile['max_zoom']}},
7575
minZoom: {{tile['min_zoom']}},
76-
attribution: '{{tile['attr']}}'
76+
attribution: '{{tile['attr']}}',
77+
detectRetina: {{tile['detect_retina'].__str__().lower()}}
7778
}
7879
).addTo({{ map_id }});
7980
{% endfor %}

tests/test_folium.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ def test_map_build(self):
510510
'attr': ('Map data (c) <a href="http://openstreetmap.org">'
511511
'OpenStreetMap</a> contributors'),
512512
'max_zoom': 20,
513-
'min_zoom': 1}
513+
'min_zoom': 1,
514+
'detect_retina': False,
515+
}
514516
]
515517
tmpl = {'map_id': 'map_' + '0' * 32,
516518
'lat': 45.5236, 'lon': -122.675,

0 commit comments

Comments
 (0)