Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
python-visualization
GitHub Repository: python-visualization/folium
Path: blob/main/tests/plugins/test_polyline_text_path.py
1601 views
1
"""
2
Test PolyLineTextPath
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_polyline_text_path():
13
m = folium.Map([20.0, 0.0], zoom_start=3)
14
15
wind_locations = [
16
[59.355600, -31.99219],
17
[55.178870, -42.89062],
18
[47.754100, -43.94531],
19
[38.272690, -37.96875],
20
[27.059130, -41.13281],
21
[16.299050, -36.56250],
22
[8.4071700, -30.23437],
23
[1.0546300, -22.50000],
24
[-8.754790, -18.28125],
25
[-21.61658, -20.03906],
26
[-31.35364, -24.25781],
27
[-39.90974, -30.93750],
28
[-43.83453, -41.13281],
29
[-47.75410, -49.92187],
30
[-50.95843, -54.14062],
31
[-55.97380, -56.60156],
32
]
33
34
wind_line = folium.PolyLine(wind_locations, weight=15, color="#8EE9FF")
35
attr = {"fill": "#007DEF", "font-weight": "bold", "font-size": "24"}
36
wind_textpath = plugins.PolyLineTextPath(
37
wind_line, ") ", repeat=True, offset=7, attributes=attr
38
)
39
40
m.add_child(wind_line)
41
m.add_child(wind_textpath)
42
43
out = normalize(m._parent.render())
44
45
# We verify that the script import is present.
46
script = '<script src="https://cdn.jsdelivr.net/npm/[email protected]/leaflet.textpath.min.js"></script>' # noqa
47
assert script in out
48
49
# We verify that the script part is correct.
50
tmpl = Template(
51
"""
52
{{ this.polyline.get_name() }}.setText(
53
"{{this.text}}",
54
{{ this.options|tojavascript }}
55
);
56
"""
57
)
58
59
expected = normalize(tmpl.render(this=wind_textpath))
60
assert expected in out
61
62