Skip to content

Commit 4fd9e4f

Browse files
committed
Merge pull request #67 from ocefpaf/zoom
Added max and min zoom keywords.
2 parents 9862c53 + a8a5922 commit 4fd9e4f

File tree

6 files changed

+47
-13
lines changed

6 files changed

+47
-13
lines changed

folium/folium.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ class Map(object):
5656
'''Create a Map with Folium'''
5757

5858
def __init__(self, location=None, width=960, height=500,
59-
tiles='OpenStreetMap', API_key=None, max_zoom=18,
60-
zoom_start=10, attr=None):
59+
tiles='OpenStreetMap', API_key=None, max_zoom=18, min_zoom=1,
60+
zoom_start=10, attr=None, min_lat=-90, max_lat=90,
61+
min_lon=-180, max_lon=180):
6162
'''Create a Map with Folium and Leaflet.js
6263
6364
Generate a base map of given width and height with either default
@@ -139,10 +140,17 @@ def __init__(self, location=None, width=960, height=500,
139140

140141
#Templates
141142
self.env = ENV
142-
self.template_vars = {'lat': location[0], 'lon': location[1],
143-
'size': self._size, 'max_zoom': max_zoom,
144-
'zoom_level': zoom_start,
145-
'map_id': self.map_id}
143+
self.template_vars = dict(lat=location[0],
144+
lon=location[1],
145+
size=self._size,
146+
max_zoom=max_zoom,
147+
zoom_level=zoom_start,
148+
map_id=self.map_id,
149+
min_zoom=min_zoom,
150+
min_lat=min_lat,
151+
max_lat=max_lat,
152+
min_lon=min_lon,
153+
max_lon=max_lon)
146154

147155
#Tiles
148156
self.tiles = ''.join(tiles.lower().strip().split())

folium/templates/fol_template.html

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,22 @@
5858

5959
var base_tile = L.tileLayer('{{ Tiles }}', {
6060
maxZoom: {{ max_zoom }},
61+
minZoom: {{ min_zoom }},
6162
attribution: '{{ attr }}'
6263
});
6364

64-
var baseLayer = {
65+
var baseLayer = {
6566
"Base Layer": base_tile
6667
};
6768

6869
/*
6970
addition of the wms layers
70-
*/
71+
*/
7172

7273
{% for wms in wms_layers %}
7374
{{ wms }}
7475
{% endfor %}
75-
76+
7677
/*
7778
addition of the tile layers
7879
*/
@@ -82,19 +83,27 @@
8283

8384
/*
8485
list of layers to be added
85-
*/
86+
*/
8687
var layer_list = {
8788
{% for data_string in data_layers %}
8889
{{ data_string }}
8990
{% endfor %}
9091
};
9192

93+
/*
94+
Bounding box.
95+
*/
96+
var southWest = L.latLng({{ min_lat }}, {{ min_lon }}),
97+
northEast = L.latLng({{ max_lat }}, {{ max_lon }}),
98+
bounds = L.latLngBounds(southWest, northEast);
99+
92100
/*
93101
Creates the map and adds the selected layers
94102
*/
95103
var map = L.map('{{ map_id }}', {
96104
center:[{{ lat }}, {{ lon }}],
97105
zoom: {{ zoom_level }},
106+
maxBounds: bounds,
98107
layers: [base_tile]
99108
});
100109

folium/templates/geojson_template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474

7575
L.tileLayer('{{ Tiles }}', {
7676
maxZoom: {{ max_zoom }},
77+
minZoom: {{ min_zoom }},
7778
attribution: '{{ attr }}'
7879
}).addTo(map);
7980

folium/templates/ipynb_geojson_repr.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
L.tileLayer('{{ Tiles }}', {
4545
maxZoom: {{ max_zoom }},
46+
minZoom: {{ min_zoom }},
4647
attribution: '{{ attr }}'
4748
}).addTo(map);
4849

folium/templates/ipynb_repr.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
L.tileLayer('{{ Tiles }}', {
1919
maxZoom: {{ max_zoom }},
20+
minZoom: {{ min_zoom }},
2021
attribution: '{{ attr }}'
2122
}).addTo(map);
2223

tests/folium_tests.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,18 @@ def test_init(self):
6464
'attr': ('Map data (c) <a href="http://openstreetmap.org">'
6565
'OpenStreetMap</a> contributors'),
6666
'map_id': 'folium_' + '0' * 32,
67-
'lat': 45.5236, 'lon': -122.675, 'max_zoom': 20,
67+
'lat': 45.5236,
68+
'lon': -122.675,
69+
'max_zoom': 20,
6870
'size': 'style="width: 900px; height: 400px"',
69-
'zoom_level': 4, 'tile_layers': [], 'wms_layers': []}
71+
'zoom_level': 4,
72+
'tile_layers': [],
73+
'wms_layers': [],
74+
'min_zoom': 1,
75+
'min_lat': -90,
76+
'max_lat': 90,
77+
'min_lon': -180,
78+
'max_lon': 180}
7079

7180
assert self.map.template_vars == tmpl
7281

@@ -354,7 +363,12 @@ def test_map_build(self):
354363
'map_id': 'folium_' + '0' * 32,
355364
'lat': 45.5236, 'lon': -122.675, 'max_zoom': 20,
356365
'size': 'style="width: 900px; height: 400px"',
357-
'zoom_level': 4}
366+
'zoom_level': 4,
367+
'min_zoom': 1,
368+
'min_lat': -90,
369+
'max_lat': 90,
370+
'min_lon': -180,
371+
'max_lon': 180}
358372
HTML = html_templ.render(tmpl)
359373

360374
assert self.map.HTML == HTML

0 commit comments

Comments
 (0)