Skip to content

Commit 16e4234

Browse files
committed
Adding popup functionality to lines
1 parent f5bdd61 commit 16e4234

6 files changed

Lines changed: 22 additions & 7 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
0.1.5
22
~~~~~
3+
- Popups on lines. (themiurgo)
34
- `fit_bounds` method. (themiurgo)
45
- GeoJSON popup. (ocefpaf 7aad5e0)
56
- Added cartodb positron and dark_matter tiles (ocefpaf d4daee7)

folium/folium.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ def simple_marker(self, location=None, popup='Pop Text', popup_on=True,
363363

364364
@iter_obj('line')
365365
def line(self, locations,
366-
line_color=None, line_opacity=None, line_weight=None):
366+
line_color=None, line_opacity=None, line_weight=None,
367+
popup='Pop Text', popup_on=True, popup_width=300):
367368
"""Add a line to the map with optional styles.
368369
369370
Parameters
@@ -373,6 +374,11 @@ def line(self, locations,
373374
line_color: string, default Leaflet's default ('#03f')
374375
line_opacity: float, default Leaflet's default (0.5)
375376
line_weight: float, default Leaflet's default (5)
377+
popup: string or tuple, default 'Pop Text'
378+
Input text or visualization for object. Can pass either text,
379+
or a tuple of the form (Vincent object, 'vis_path.json')
380+
popup_on: boolean, default True
381+
Pass false for no popup information on the marker
376382
377383
Note: If the optional styles are omitted, they will not be included
378384
in the HTML output and will obtain the Leaflet defaults listed above.
@@ -396,9 +402,13 @@ def line(self, locations,
396402
'locations': locations,
397403
'options': polyline_opts})
398404

405+
popup_out = self._popup_render(popup=popup, mk_name='line_',
406+
count=count, popup_on=popup_on,
407+
width=popup_width)
408+
399409
add_line = 'map.addLayer({});'.format(varname)
400-
self.template_vars.setdefault('lines', []).append((line_rendered,
401-
add_line))
410+
append = (line_rendered, popup_out, add_line)
411+
self.template_vars.setdefault('lines', []).append((append))
402412

403413
@iter_obj('multiline')
404414
def multiline(self, locations, line_color=None, line_opacity=None,

folium/templates/fol_template.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@
134134
{{ add_mark }}
135135
{% endfor %}
136136

137-
{% for line, add_line in lines %}
137+
{% for line, popup, add_line in lines %}
138138
{{ line }}
139+
{{ popup }}
139140
{{ add_line }}
140141
{% endfor %}
141142

folium/templates/geojson_template.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@
103103
{{ add_mark }}
104104
{% endfor %}
105105

106-
{% for line, add_line in lines %}
106+
{% for line, popup, add_line in lines %}
107107
{{ line }}
108+
{{ popup }}
108109
{{ add_line }}
109110
{% endfor %}
110111

folium/templates/ipynb_geojson_repr.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
{{ add_mark }}
5454
{% endfor %}
5555

56-
{% for line, add_line in lines %}
56+
{% for line, popup, add_line in lines %}
5757
{{ line }}
58+
{{ popup }}
5859
{{ add_line }}
5960
{% endfor %}
6061

folium/templates/ipynb_repr.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
{{ add_mark }}
2828
{% endfor %}
2929

30-
{% for line, add_line in lines %}
30+
{% for line, popup, add_line in lines %}
3131
{{ line }}
32+
{{ popup }}
3233
{{ add_line }}
3334
{% endfor %}
3435

0 commit comments

Comments
 (0)