Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
python-visualization
GitHub Repository: python-visualization/folium
Path: blob/main/tests/plugins/test_scroll_zoom_toggler.py
2533 views
1
"""
2
Test ScrollZoomToggler
3
----------------------
4
"""
5
6
import folium
7
from folium import plugins
8
from folium.template import Template
9
from folium.utilities import normalize
10
11
12
def test_scroll_zoom_toggler():
13
m = folium.Map([45.0, 3.0], zoom_start=4)
14
szt = plugins.ScrollZoomToggler()
15
m.add_child(szt)
16
17
out = normalize(m._parent.render())
18
19
# Verify that the div has been created.
20
tmpl = Template("""
21
<img id="{{this.get_name()}}" alt="scroll"
22
src="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/png/512/arrow-move.png"
23
style="z-index: 999999"
24
onclick="{{this._parent.get_name()}}.toggleScroll()"></img>
25
""")
26
assert "".join(tmpl.render(this=szt).split()) in "".join(out.split())
27
28
# Verify that the style has been created
29
tmpl = Template("""
30
<style>
31
#{{this.get_name()}} {
32
position:absolute;
33
width:35px;
34
bottom:10px;
35
height:35px;
36
left:10px;
37
background-color:#fff;
38
text-align:center;
39
line-height:35px;
40
vertical-align: middle;
41
}
42
</style>
43
""")
44
expected = normalize(tmpl.render(this=szt))
45
assert expected in out
46
47
# Verify that the script is okay.
48
tmpl = Template("""
49
{{this._parent.get_name()}}.scrollEnabled = true;
50
51
{{this._parent.get_name()}}.toggleScroll = function() {
52
if (this.scrollEnabled) {
53
this.scrollEnabled = false;
54
this.scrollWheelZoom.disable();
55
} else {
56
this.scrollEnabled = true;
57
this.scrollWheelZoom.enable();
58
}
59
};
60
61
{{this._parent.get_name()}}.toggleScroll();
62
""")
63
expected = normalize(tmpl.render(this=szt))
64
assert expected in out
65
66
bounds = m.get_bounds()
67
assert bounds == [[None, None], [None, None]], bounds
68
69