Skip to content

Commit 0f0d64b

Browse files
committed
Simplify option parsing for Map, allow kwargs
1 parent b819b3a commit 0f0d64b

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

folium/folium.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212

1313
from folium.map import FitBounds
1414
from folium.raster_layers import TileLayer
15-
from folium.utilities import _parse_size, _tmp_html, validate_location
15+
from folium.utilities import (
16+
_parse_size,
17+
_tmp_html,
18+
validate_location,
19+
parse_options,
20+
)
1621

1722
from jinja2 import Environment, PackageLoader, Template
1823

@@ -132,6 +137,9 @@ class Map(MacroElement):
132137
rare environments) even if they're supported.
133138
zoom_control : bool, default True
134139
Display zoom controls on the map.
140+
**kwargs
141+
Additional keyword arguments are passed to Leaflets Map class:
142+
https://leafletjs.com/reference-1.4.0.html#map
135143
136144
Returns
137145
-------
@@ -173,25 +181,14 @@ class Map(MacroElement):
173181
{% endmacro %}
174182
175183
{% macro script(this, kwargs) %}
176-
{%- if this.max_bounds %}
177-
var bounds = L.latLngBounds(
178-
[{{ this.min_lat }}, {{ this.min_lon }}],
179-
[{{ this.max_lat }}, {{ this.max_lon }}]
180-
);
181-
{%- else %}
182-
var bounds = null;
183-
{%- endif %}
184-
185184
var {{ this.get_name() }} = L.map(
186185
{{ this.get_name()|tojson }},
187186
{
188187
center: {{ this.location|tojson }},
189-
zoom: {{ this.zoom_start|tojson }},
190-
maxBounds: bounds,
191-
layers: [],
192-
worldCopyJump: {{ this.world_copy_jump|tojson }},
193188
crs: L.CRS.{{ this.crs }},
194-
zoomControl: {{ this.zoom_control|tojson }},
189+
{%- for key, value in this.options.items() %}
190+
{{ key }}: {{ value|tojson }},
191+
{%- endfor %}
195192
}
196193
);
197194
@@ -237,6 +234,7 @@ def __init__(
237234
disable_3d=False,
238235
png_enabled=False,
239236
zoom_control=True,
237+
**kwargs
240238
):
241239
super(Map, self).__init__()
242240
self._name = 'Map'
@@ -248,10 +246,9 @@ def __init__(
248246
if location is None:
249247
# If location is not passed we center and zoom out.
250248
self.location = [0, 0]
251-
self.zoom_start = 1
249+
zoom_start = 1
252250
else:
253251
self.location = validate_location(location)
254-
self.zoom_start = zoom_start
255252

256253
Figure().add_child(self)
257254

@@ -262,17 +259,18 @@ def __init__(
262259
self.top = _parse_size(top)
263260
self.position = position
264261

265-
self.min_lat = min_lat
266-
self.max_lat = max_lat
267-
self.min_lon = min_lon
268-
self.max_lon = max_lon
269-
self.max_bounds = max_bounds
270-
self.no_wrap = no_wrap
271-
self.world_copy_jump = world_copy_jump
262+
max_bounds_array = [[min_lat, min_lon], [max_lat, max_lon]] \
263+
if max_bounds else None
272264

273265
self.crs = crs
274266
self.control_scale = control_scale
275-
self.zoom_control = zoom_control
267+
268+
self.options = parse_options(
269+
max_bounds=max_bounds_array,
270+
zoom=zoom_start,
271+
zoom_control=zoom_control,
272+
**kwargs
273+
)
276274

277275
self.global_switches = GlobalSwitches(
278276
prefer_canvas,

0 commit comments

Comments
 (0)