Skip to content

Commit 3008b98

Browse files
FabeGConengmo
authored andcommitted
Fix broken prefer_canvas option (#1133)
Small correction to fix broken prefer_canvas option. Since leaflet 1.0.0, the preferCanvas option is not part of the GlobalSwitch options, but has to be passed as an option to L.Map.
1 parent 3acd373 commit 3008b98

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

folium/folium.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,14 @@ class GlobalSwitches(Element):
5555

5656
_template = Template("""
5757
<script>
58-
L_PREFER_CANVAS = {{ this.prefer_canvas|tojson }};
5958
L_NO_TOUCH = {{ this.no_touch |tojson}};
6059
L_DISABLE_3D = {{ this.disable_3d|tojson }};
6160
</script>
6261
""")
6362

64-
def __init__(self, prefer_canvas=False, no_touch=False, disable_3d=False):
63+
def __init__(self, no_touch=False, disable_3d=False):
6564
super(GlobalSwitches, self).__init__()
6665
self._name = 'GlobalSwitches'
67-
self.prefer_canvas = prefer_canvas
6866
self.no_touch = no_touch
6967
self.disable_3d = disable_3d
7068

@@ -269,11 +267,11 @@ def __init__(
269267
max_bounds=max_bounds_array,
270268
zoom=zoom_start,
271269
zoom_control=zoom_control,
270+
prefer_canvas=prefer_canvas,
272271
**kwargs
273272
)
274273

275274
self.global_switches = GlobalSwitches(
276-
prefer_canvas,
277275
no_touch,
278276
disable_3d
279277
)

tests/test_folium.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def test_init(self):
103103
assert self.m.width == (900, 'px')
104104
assert self.m.left == (0, '%')
105105
assert self.m.top == (0, '%')
106-
assert self.m.global_switches.prefer_canvas is False
107106
assert self.m.global_switches.no_touch is False
108107
assert self.m.global_switches.disable_3d is False
109108
assert self.m.to_dict() == {
@@ -278,7 +277,7 @@ def test_fit_bounds(self):
278277
'padding': (3, 3), },
279278
sort_keys=True),
280279
'this': fitbounds,
281-
})
280+
})
282281

283282
assert ''.join(fit_bounds_rendered.split()) in ''.join(out.split())
284283

@@ -310,22 +309,30 @@ def test_custom_icon(self):
310309

311310
def test_global_switches(self):
312311
m = folium.Map(prefer_canvas=True)
313-
assert m.global_switches.prefer_canvas
312+
out = m._parent.render()
313+
out_str = ''.join(out.split())
314+
assert "preferCanvas:true" in out_str
314315
assert not m.global_switches.no_touch
315316
assert not m.global_switches.disable_3d
316317

317318
m = folium.Map(no_touch=True)
318-
assert not m.global_switches.prefer_canvas
319+
out = m._parent.render()
320+
out_str = ''.join(out.split())
321+
assert "preferCanvas:false" in out_str
319322
assert m.global_switches.no_touch
320323
assert not m.global_switches.disable_3d
321324

322325
m = folium.Map(disable_3d=True)
323-
assert not m.global_switches.prefer_canvas
326+
out = m._parent.render()
327+
out_str = ''.join(out.split())
328+
assert "preferCanvas:false" in out_str
324329
assert not m.global_switches.no_touch
325330
assert m.global_switches.disable_3d
326331

327332
m = folium.Map(prefer_canvas=True, no_touch=True, disable_3d=True)
328-
assert m.global_switches.prefer_canvas
333+
out = m._parent.render()
334+
out_str = ''.join(out.split())
335+
assert "preferCanvas:true" in out_str
329336
assert m.global_switches.no_touch
330337
assert m.global_switches.disable_3d
331338

0 commit comments

Comments
 (0)