Skip to content

Commit 95325c4

Browse files
committed
Added width keyword to simple_popup.
1 parent 4fd9e4f commit 95325c4

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

folium/folium.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def add_layers_to_map(self):
269269
@iter_obj('simple')
270270
def simple_marker(self, location=None, popup='Pop Text', popup_on=True,
271271
marker_color='blue', marker_icon='info-sign',
272-
clustered_marker=False, icon_angle=0):
272+
clustered_marker=False, icon_angle=0, width=300):
273273
'''Create a simple stock Leaflet marker on the map, with optional
274274
popup text or Vincent visualization.
275275
@@ -280,6 +280,8 @@ def simple_marker(self, location=None, popup='Pop Text', popup_on=True,
280280
popup: string or tuple, default 'Pop Text'
281281
Input text or visualization for object. Can pass either text,
282282
or a tuple of the form (Vincent object, 'vis_path.json')
283+
It is possible to adjust the width of text/HTML popups
284+
using the optional keywords `width`. (Leaflet default is 300px.)
283285
popup_on: boolean, default True
284286
Pass false for no popup information on the marker
285287
marker_color
@@ -322,8 +324,8 @@ def simple_marker(self, location=None, popup='Pop Text', popup_on=True,
322324
})
323325

324326
popup_out = self._popup_render(popup=popup, mk_name='marker_',
325-
count=count,
326-
popup_on=popup_on)
327+
count=count, popup_on=popup_on,
328+
width=width)
327329

328330

329331

@@ -545,7 +547,7 @@ def click_for_marker(self, popup=None):
545547
self.template_vars.update({'click_pop': click_str})
546548

547549
def _popup_render(self, popup=None, mk_name=None, count=None,
548-
popup_on=True):
550+
popup_on=True, width=300):
549551
'''Popup renderer: either text or Vincent/Vega.
550552
551553
Parameters
@@ -565,7 +567,8 @@ def _popup_render(self, popup=None, mk_name=None, count=None,
565567
if isinstance(popup, str):
566568
popup_temp = self.env.get_template('simple_popup.js')
567569
return popup_temp.render({'pop_name': mk_name + str(count),
568-
'pop_txt': json.dumps(popup)})
570+
'pop_txt': json.dumps(popup),
571+
'width': width})
569572
elif isinstance(popup, tuple):
570573
#Update template with JS libs
571574
vega_temp = self.env.get_template('vega_ref.txt').render()

folium/templates/simple_popup.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
{{ pop_name }}.bindPopup({{ pop_txt }});
1+
{{ pop_name }}.bindPopup({{ pop_txt }});
2+
{{ pop_name }}._popup.options.maxWidth = {{ width }};

0 commit comments

Comments
 (0)