1

I want to put HTML formatting into a folium map popup. How do i format the html popup INSIDE my FOR loop???

My code:

import folium
import pandas
from folium import IFrame

data=pandas.read_csv("addresses.txt")
lat=list(data["LAT"])
lon=list(data["LON"])
name=list(data["NAME"])
desc=list(data["DESCRIPTION"])

map=folium.Map(location=[40.748817,73.985429],zoom_start=14,tiles="stamenterrain")
#folium.TileLayer('cartodbpositron').add_to(map)

for lt,ln,nm,ds in zip(lat,lon,name,desc):
    test = folium.Html('<b>nm<br>desc</b>', script=True)
    fg.add_child(folium.CircleMarker(location=[lt,ln],radius=6,color='grey',fill_color='yellow',
popup=test))

map.add_child(fg)
map.save("Map1.html")
0

folium should handle this correctly by default.

As per the example docs:

import folium
import branca 

m = folium.Map([43, -100], zoom_start=4)

html = """
    <h1> This popup is an Iframe</h1><br>
    With a few lines of code...
    <p>
    <code>
        from numpy import *<br>
        exp(-2*pi)
    </code>
    </p>
    """

iframe = branca.element.IFrame(html=html, width=500, height=300)
popup = folium.Popup(iframe, max_width=500)

folium.Marker([30, -100], popup=popup).add_to(m)

So in your example

for lt,ln,nm,ds in zip(lat,lon,name,desc):
    test = folium.Html('<b>nm<br>desc</b>', script=True) # i'm assuming this bit runs fine
    iframe = branca.element.IFrame(html=test, width=350, height=150)
    popup = folium.Popup(iframe, parse_html=True)
    folium.Marker(location=[lt,ln],radius=6,color='grey',fill_color='yellow', popup=popup)).add_to(map)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.