Created
February 9, 2019 13:44
-
-
Save Gordonei/6f40b6d15e1a00fce8281f5e3165ece6 to your computer and use it in GitHub Desktop.
Styling folium (Leaflet) tooltips
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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