Skip to content

Instantly share code, notes, and snippets.

@Gordonei
Created February 9, 2019 13:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gordonei/6f40b6d15e1a00fce8281f5e3165ece6 to your computer and use it in GitHub Desktop.
Save Gordonei/6f40b6d15e1a00fce8281f5e3165ece6 to your computer and use it in GitHub Desktop.
Styling folium (Leaflet) tooltips
import folium
# Map pointing at Cape Town
m = folium.Map(
location=[-33.918861, 18.423300],
zoom_start=12
)
# HTML Div with style information
desc_html = f'<div style="white-space: normal"> This is a line,<br> this is another line </div>'
# Adding it to the map via a Transparent Rectangle
folium.vector_layers.Rectangle(
bounds=[[-33.90916303, 18.388831778], [-34.075691, 18.843266]],
fill=True,
opacity=0,
fill_opacity=0,
tooltip=folium.map.Tooltip(
# note that the width still has to be set on the HTML object is still set
text=folium.Html(desc_html, script=True, width=300).render(),
)
).add_to(m)
m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment