Skip to content

Commit 07ab55d

Browse files
committed
Merge pull request #69 from ocefpaf/set_width
Set width
2 parents 0348cfa + 2fe2ebf commit 07ab55d

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
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

@@ -597,7 +599,7 @@ def click_for_marker(self, popup=None):
597599
self.template_vars.update({'click_pop': click_str})
598600

599601
def _popup_render(self, popup=None, mk_name=None, count=None,
600-
popup_on=True):
602+
popup_on=True, width=300):
601603
'''Popup renderer: either text or Vincent/Vega.
602604
603605
Parameters
@@ -617,7 +619,8 @@ def _popup_render(self, popup=None, mk_name=None, count=None,
617619
if isinstance(popup, str):
618620
popup_temp = self.env.get_template('simple_popup.js')
619621
return popup_temp.render({'pop_name': mk_name + str(count),
620-
'pop_txt': json.dumps(popup)})
622+
'pop_txt': json.dumps(popup),
623+
'width': width})
621624
elif isinstance(popup, tuple):
622625
#Update template with JS libs
623626
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 }};

tests/folium_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ def test_simple_marker(self):
151151
'lon': -122.7,
152152
'icon': "{'icon':marker_1_icon}"})
153153
popup_1 = popup_templ.render({'pop_name': 'marker_1',
154-
'pop_txt': json.dumps('Pop Text')})
154+
'pop_txt': json.dumps('Pop Text'),
155+
'width': 300})
155156
assert self.map.template_vars['custom_markers'][0][1] == mark_1
156157
assert self.map.template_vars['custom_markers'][0][2] == popup_1
157158

@@ -161,7 +162,8 @@ def test_simple_marker(self):
161162
'lon': -122.8,
162163
'icon': "{'icon':marker_2_icon}"})
163164
popup_2 = popup_templ.render({'pop_name': 'marker_2',
164-
'pop_txt': json.dumps('Hi')})
165+
'pop_txt': json.dumps('Hi'),
166+
'width': 300})
165167
assert self.map.mark_cnt['simple'] == 2
166168
assert self.map.template_vars['custom_markers'][1][1] == mark_2
167169
assert self.map.template_vars['custom_markers'][1][2] == popup_2

0 commit comments

Comments
 (0)