Skip to content

Commit 62af439

Browse files
talespaivaocefpaf
authored andcommitted
New plugin added: Leaflet.TextPath #451
1 parent 02b7765 commit 62af439

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

examples/polyline_text_path_example.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@
22
import folium
33
from folium import plugins
44

5-
m = folium.Map([30.,0.], zoom_start=3)
6-
wind_locations = [[59.3556, -31.99219], [55.17887, -42.89062], [47.7541, -43.94531], [38.27269, -37.96875],
7-
[27.05913, -41.13281], [16.29905, -36.5625], [8.40717, -30.23437], [1.05463, -22.5],
8-
[-8.75479, -18.28125], [-21.61658, -20.03906], [-31.35364, -24.25781], [-39.90974, -30.9375],
9-
[-43.83453, -41.13281], [-47.7541, -49.92187], [-50.95843, -54.14062], [-55.9738, -56.60156]]
5+
m = folium.Map([30., 0.], zoom_start=3)
6+
wind_locations = [[59.3556, -31.99219], [55.17887, -42.89062], [47.7541, -43.94531],
7+
[38.27269, -37.96875], [27.05913, -41.13281], [16.29905, -36.5625],
8+
[8.40717, -30.23437], [1.05463, -22.5], [-8.75479, -18.28125],
9+
[-21.61658, -20.03906], [-31.35364, -24.25781], [-39.90974, -30.9375],
10+
[-43.83453, -41.13281], [-47.7541, -49.92187], [-50.95843, -54.14062],
11+
[-55.9738, -56.60156]]
1012

1113
wind_line = folium.PolyLine(wind_locations, weight=15, color='#8EE9FF').add_to(m)
1214
attr = {'fill': '#007DEF', 'font-weight': 'bold', 'font-size': '24'}
1315
plugins.PolyLineTextPath(wind_line, ") ", repeat=True, offset=7, attributes=attr).add_to(m)
1416

15-
danger_line = folium.PolyLine([[-40.311, -31.952], [-12.086, -18.727]], weight=10, color='orange', opacity=0.8).add_to(m)
17+
danger_line = folium.PolyLine([[-40.311, -31.952], [-12.086, -18.727]], weight=10, color='orange',
18+
opacity=0.8).add_to(m)
1619
attr = {'fill': 'red'}
1720
plugins.PolyLineTextPath(danger_line, "\u25BA", repeat=True, offset=6, attributes=attr).add_to(m)
1821

19-
plane_line = folium.PolyLine([[-49.38237, -37.26562], [-1.75754, -14.41406], [51.61802, -23.20312]], weight=1, color='black').add_to(m)
20-
attr = {'font-weight':'bold', 'font-size':'24'}
22+
plane_line = folium.PolyLine([[-49.38237, -37.26562], [-1.75754, -14.41406], [51.61802, -23.20312]],
23+
weight=1, color='black').add_to(m)
24+
attr = {'font-weight': 'bold', 'font-size': '24'}
2125
plugins.PolyLineTextPath(plane_line, "\u2708 ", repeat=True, offset=8, attributes=attr).add_to(m)
2226

23-
line_to_new_dehli = folium.PolyLine([[46.67959447, 3.33984375],
27+
line_to_new_delhi = folium.PolyLine([[46.67959447, 3.33984375],
2428
[46.5588603, 29.53125],
2529
[42.29356419, 51.328125],
2630
[35.74651226, 68.5546875],
@@ -31,7 +35,7 @@
3135
[25.68113734, 97.3828125],
3236
[21.24842224, 105.77636719]]).add_to(m)
3337

34-
plugins.PolyLineTextPath(line_to_new_dehli, "To New Delhi", offset=-5).add_to(m)
38+
plugins.PolyLineTextPath(line_to_new_delhi, "To New Delhi", offset=-5).add_to(m)
3539
plugins.PolyLineTextPath(line_to_hanoi, "To Hanoi", offset=-5).add_to(m)
3640

3741
m.save(outfile='polyline_text.html')

folium/plugins/polyline_text_path.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
class PolyLineTextPath(MacroElement):
1818
"""Shows a text along a PolyLine."""
19-
def __init__(self, polyline, text, repeat=False, center=False, below=False, offset=0, orientation=0, attributes={}):
19+
def __init__(self, polyline, text, repeat=False, center=False, below=False,
20+
offset=0, orientation=0, attributes={}):
2021
"""Shows a text along a PolyLine.
2122
2223
Parameters
@@ -44,7 +45,8 @@ def __init__(self, polyline, text, repeat=False, center=False, below=False, offs
4445
4546
attributes: dictionary
4647
Object containing the attributes applied to the text tag.
47-
Check valid attributes here: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/text#Attributes
48+
Check valid attributes here:
49+
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/text#Attributes
4850
Example: {'fill': '#007DEF', 'font-weight': 'bold', 'font-size': '24'}
4951
5052

tests/plugins/test_polyline_text_path.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
Test Terminator
3+
Test PolyLineTextPath
44
---------------
55
"""
66

@@ -13,11 +13,12 @@
1313
def test_polyline_text_path():
1414
m = folium.Map([20., 0.], zoom_start=3)
1515

16-
wind_locations = [[59.3556, -31.99219], [55.17887, -42.89062], [47.7541, -43.94531], [38.27269, -37.96875],
17-
[27.05913, -41.13281], [16.29905, -36.5625], [8.40717, -30.23437], [1.05463, -22.5],
18-
[-8.75479, -18.28125], [-21.61658, -20.03906], [-31.35364, -24.25781], [-39.90974, -30.9375],
19-
[-43.83453, -41.13281], [-47.7541, -49.92187], [-50.95843, -54.14062], [-55.9738, -56.60156]]
20-
16+
wind_locations = [[59.3556, -31.99219], [55.17887, -42.89062], [47.7541, -43.94531],
17+
[38.27269, -37.96875], [27.05913, -41.13281], [16.29905, -36.5625],
18+
[8.40717, -30.23437], [1.05463, -22.5], [-8.75479, -18.28125],
19+
[-21.61658, -20.03906], [-31.35364, -24.25781], [-39.90974, -30.9375],
20+
[-43.83453, -41.13281], [-47.7541, -49.92187], [-50.95843, -54.14062],
21+
[-55.9738, -56.60156]]
2122

2223
wind_line = folium.PolyLine(wind_locations, weight=15, color='#8EE9FF')
2324
attr = {'fill': '#007DEF', 'font-weight': 'bold', 'font-size': '24'}

0 commit comments

Comments
 (0)