12
12
13
13
from folium .map import FitBounds
14
14
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
+ )
16
21
17
22
from jinja2 import Environment , PackageLoader , Template
18
23
@@ -132,6 +137,9 @@ class Map(MacroElement):
132
137
rare environments) even if they're supported.
133
138
zoom_control : bool, default True
134
139
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
135
143
136
144
Returns
137
145
-------
@@ -173,25 +181,14 @@ class Map(MacroElement):
173
181
{% endmacro %}
174
182
175
183
{% 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
-
185
184
var {{ this.get_name() }} = L.map(
186
185
{{ this.get_name()|tojson }},
187
186
{
188
187
center: {{ this.location|tojson }},
189
- zoom: {{ this.zoom_start|tojson }},
190
- maxBounds: bounds,
191
- layers: [],
192
- worldCopyJump: {{ this.world_copy_jump|tojson }},
193
188
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 %}
195
192
}
196
193
);
197
194
@@ -237,6 +234,7 @@ def __init__(
237
234
disable_3d = False ,
238
235
png_enabled = False ,
239
236
zoom_control = True ,
237
+ ** kwargs
240
238
):
241
239
super (Map , self ).__init__ ()
242
240
self ._name = 'Map'
@@ -248,10 +246,9 @@ def __init__(
248
246
if location is None :
249
247
# If location is not passed we center and zoom out.
250
248
self .location = [0 , 0 ]
251
- self . zoom_start = 1
249
+ zoom_start = 1
252
250
else :
253
251
self .location = validate_location (location )
254
- self .zoom_start = zoom_start
255
252
256
253
Figure ().add_child (self )
257
254
@@ -262,17 +259,18 @@ def __init__(
262
259
self .top = _parse_size (top )
263
260
self .position = position
264
261
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
272
264
273
265
self .crs = crs
274
266
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
+ )
276
274
277
275
self .global_switches = GlobalSwitches (
278
276
prefer_canvas ,
0 commit comments