Leaflet: newline in tooltip on polyline

Using leaflet to show data on a map, if I use the html
markup in the tooltip on a marker (using the ‘tooltip’ column in a dataframe), it correctly inserts a newline.

However, if I use it in a Tooltip that is a child of a Polyline, it just prints the actual ‘
’.

Is there a way to insert a newline in a tooltip on a Polyline?

FWIW, I tried ‘
’ as well as ‘

You can put html in tooltips and popups,

for example I have it in one of my projects like:

event_html = f"""<div style='text-align: left; margin-bottom: 10px;'>
                            <b style='color: {incident_color};'>{incident_type}</b><br>
                            <b>Title:</b> {event['declarationTitle']}<br>
                            <b>Location:</b> {clean_county} County, {state}<br>
                            <b>Date:</b> {event['declarationDate'].strftime('%Y-%m-%d')}
                        </div>"""

Then you just need to put it in a content not in children like how I set it up:

marker = dl.Marker(
                    position=coordinates,
                    children=[dl.Tooltip(
                        content=combined_tooltip,
                        permanent=False,
                        direction="auto",
                    )],
                    icon=custom_icon
                )

which allows me to display map context like so:

THanks!
Yeah, the ‘content’ property solves my issue.

1 Like