Skip to content

Fix broken prefer_canvas option #1133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions folium/folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,14 @@ class GlobalSwitches(Element):

_template = Template("""
<script>
L_PREFER_CANVAS = {{ this.prefer_canvas|tojson }};
L_NO_TOUCH = {{ this.no_touch |tojson}};
L_DISABLE_3D = {{ this.disable_3d|tojson }};
</script>
""")

def __init__(self, prefer_canvas=False, no_touch=False, disable_3d=False):
def __init__(self, no_touch=False, disable_3d=False):
super(GlobalSwitches, self).__init__()
self._name = 'GlobalSwitches'
self.prefer_canvas = prefer_canvas
self.no_touch = no_touch
self.disable_3d = disable_3d

Expand Down Expand Up @@ -269,11 +267,11 @@ def __init__(
max_bounds=max_bounds_array,
zoom=zoom_start,
zoom_control=zoom_control,
prefer_canvas=prefer_canvas,
**kwargs
)

self.global_switches = GlobalSwitches(
prefer_canvas,
no_touch,
disable_3d
)
Expand Down
19 changes: 13 additions & 6 deletions tests/test_folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def test_init(self):
assert self.m.width == (900, 'px')
assert self.m.left == (0, '%')
assert self.m.top == (0, '%')
assert self.m.global_switches.prefer_canvas is False
assert self.m.global_switches.no_touch is False
assert self.m.global_switches.disable_3d is False
assert self.m.to_dict() == {
Expand Down Expand Up @@ -278,7 +277,7 @@ def test_fit_bounds(self):
'padding': (3, 3), },
sort_keys=True),
'this': fitbounds,
})
})

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

Expand Down Expand Up @@ -310,22 +309,30 @@ def test_custom_icon(self):

def test_global_switches(self):
m = folium.Map(prefer_canvas=True)
assert m.global_switches.prefer_canvas
out = m._parent.render()
out_str = ''.join(out.split())
assert "preferCanvas:true" in out_str
assert not m.global_switches.no_touch
assert not m.global_switches.disable_3d

m = folium.Map(no_touch=True)
assert not m.global_switches.prefer_canvas
out = m._parent.render()
out_str = ''.join(out.split())
assert "preferCanvas:false" in out_str
assert m.global_switches.no_touch
assert not m.global_switches.disable_3d

m = folium.Map(disable_3d=True)
assert not m.global_switches.prefer_canvas
out = m._parent.render()
out_str = ''.join(out.split())
assert "preferCanvas:false" in out_str
assert not m.global_switches.no_touch
assert m.global_switches.disable_3d

m = folium.Map(prefer_canvas=True, no_touch=True, disable_3d=True)
assert m.global_switches.prefer_canvas
out = m._parent.render()
out_str = ''.join(out.split())
assert "preferCanvas:true" in out_str
assert m.global_switches.no_touch
assert m.global_switches.disable_3d

Expand Down