folium popup width control and icon color

Created on 19 Mar 2019  路  16Comments  路  Source: python-visualization/folium

Hello, trying to make a fixed width for all popups in my data map.

Tried using iframes but the nothing changed when I used different values for width and height.

popuptext = ''
iframe = folium.IFrame(popuptext, width=700, height=1000)
popup = folium.Popup(iframe)
folium.Marker(geo_location, popup = popuptext , icon=folium.Icon(color='black')).add_to(marker_cluster)

Any simple way to set the width for a popup in folium?

bug question

Most helpful comment

This works to set the width:

test = folium.Html(popuptext, script=True)
popup = folium.Popup(test, max_width=300,min_width=300)
icon = folium.Icon(color='red', icon='info-sign')
folium.Marker(geo_location , popup = popup, icon=icon).add_to(marker_cluster)

But now all the icons default to blue and the line:
icon = folium.Icon(color='red', icon='info-sign')
Does not change the color, but it does change the icon itself.

All 16 comments

Have you tried the max_width option of foliums Popup class?

In addition you can also pass it a min_width option. This is not documented in folium, but Leaflet accepts this argument and we pass it on. But you'll need the most recent version on our git master branch for this. You can install it with pip install git+https://github.com/python-visualization/folium.git, but note that it's not available for Python 2.7 which we deprecated recently.

Hello Conengmo, I have been trying for quite a while to set either minWidth or min_width, but with no luck.

popup = folium.Popup(max_width=450,min_width=450)

gives me an error unexpected keyword.

Did you install from our git master branch?

Hello Conengmo, Anaconda user. But i updated folium today. Sorry, new to GitHub, is there a repository I can get a different version?

@spanishinquistion you can install directly from the github source here via pip:

pip install git+https://github.com/python-visualization/folium@master

the conda and pypi packages only get updated on major releases afaik.

Conda don't pip. Work around?
conda install git+https... says package not available.

Conda do pip don鈥檛 it? If you open an Anaconda Prompt you should be able to pip I think.

found a solution for pip on on github, naturally (https://stackoverflow.com/questions/19042389/conda-installing-upgrading-directly-from-github). Thanks for your help, seems to work.

Alright good to hear. I also hope min_width solves your issue, would appreciate you reporting back here.

This works to set the width:

test = folium.Html(popuptext, script=True)
popup = folium.Popup(test, max_width=300,min_width=300)
icon = folium.Icon(color='red', icon='info-sign')
folium.Marker(geo_location , popup = popup, icon=icon).add_to(marker_cluster)

But now all the icons default to blue and the line:
icon = folium.Icon(color='red', icon='info-sign')
Does not change the color, but it does change the icon itself.

Ah that's a bug. I screwed up the markerColor option of the underlying JS class. I'll whip up a PR to fix it.

By the way if you use backticks in your Github comments you can make the code more readible. I edited your last comment.

Should be good now. Can you reinstall and see if everything works alright?

Hey, works like a charm. Appreciate the help. And will backtick next time.

I can start a new issue if you prefer, but I found it odd that I had to set both min_width and max_width to see an effect. I'm inferring that if min_width=foo and max_width is not specified, max_width defaults to some value and constrains the min_width.

In my opinion, intuitive behavior would be that if min_width > default_max_width, then max_width=min_width.

Am I misinterpreting this behavior?

min_width is undocumented behavior, so that's why it doesn't play nice with max_width. See https://github.com/python-visualization/folium/blob/master/folium/map.py#L300

hi I think this can help you

import folium
f = folium.Figure(width=1000, height=1000)
m=folium.Map([39.067758, -94.573534], zoom_start=25).add_to(f)
pp= folium.Html('' + 'popup text' + '', script=True)
popup = folium.Popup(pp, max_width=2650)
folium.Marker(location=[39.067758, -94.573534g], popup=popup).add_to(m)
m=m._repr_html_()

Was this page helpful?
0 / 5 - 0 ratings

Related issues

achourasia picture achourasia  路  15Comments

AntonioLopardo picture AntonioLopardo  路  15Comments

ibayer picture ibayer  路  21Comments

themiurgo picture themiurgo  路  19Comments

wangchenwc picture wangchenwc  路  18Comments