Search code examples
pythonpython-3.xpopupmapsfolium

Python Folium: how to create a folium.map.Marker() with multiple popup text lines?


Is there an possibility to create a second or third line for the popup text including adjustment of the width and height of the popup box?

Found something on GitHub, but is that the only way? https://github.com/python-visualization/folium/pull/294


Solution

  • You can put html code inside a popup by means of IFrame:

    import folium
    
    m = folium.Map(location=[43.775, 11.254],
                   zoom_start=5)
    
    html = '''1st line<br>
    2nd line<br>
    3rd line'''
    
    iframe = folium.IFrame(html,
                           width=100,
                           height=100)
    
    popup = folium.Popup(iframe,
                         max_width=100)
    
    marker = folium.Marker([43.775, 11.254],
                           popup=popup).add_to(m)
    m
    

    and you get:

    enter image description here