Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
python-visualization
GitHub Repository: python-visualization/folium
Path: blob/main/tests/plugins/test_semicircle.py
1601 views
1
"""
2
Test SemiCircle
3
---------------
4
5
"""
6
7
import folium
8
from folium import plugins
9
from folium.template import Template
10
from folium.utilities import normalize
11
12
13
def test_semicircle():
14
m = folium.Map([30.0, 0.0], zoom_start=3)
15
sc1 = plugins.SemiCircle(
16
(34, -43),
17
radius=400000,
18
arc=300,
19
direction=20,
20
color="red",
21
fill_color="red",
22
opacity=0,
23
popup="Direction - 20 degrees, arc 300 degrees",
24
)
25
sc2 = plugins.SemiCircle(
26
(46, -30),
27
radius=400000,
28
start_angle=10,
29
stop_angle=50,
30
color="red",
31
fill_color="red",
32
opacity=0,
33
popup="Start angle - 10 degrees, Stop angle - 50 degrees",
34
)
35
36
m.add_child(sc1)
37
m.add_child(sc2)
38
m._repr_html_()
39
40
out = normalize(m._parent.render())
41
42
# We verify that the script import is present.
43
script = '<script src="https://cdn.jsdelivr.net/npm/[email protected]/Semicircle.min.js"></script>' # noqa
44
assert script in out
45
46
# We verify that the script part is correct.
47
tmpl_sc1 = Template(
48
"""
49
var {{ this.get_name() }} = L.semiCircle(
50
{{ this.location|tojson }},
51
{{ this.options|tojavascript }}
52
)
53
.setDirection{{ this.direction }}
54
.addTo({{ this._parent.get_name() }});
55
"""
56
)
57
58
tmpl_sc2 = Template(
59
"""
60
var {{ this.get_name() }} = L.semiCircle(
61
{{ this.location|tojson }},
62
{{ this.options|tojavascript }}
63
)
64
.addTo({{ this._parent.get_name() }});
65
"""
66
)
67
assert normalize(tmpl_sc1.render(this=sc1)) in out
68
assert normalize(tmpl_sc2.render(this=sc2)) in out
69
70
bounds = m.get_bounds()
71
assert bounds == [[34, -43], [46, -30]], bounds
72
73