folium
folium copied to clipboard
Polyline highlight color
Polylines currently support showing a tooltip when clicking on them. Maybe it would be worth to add a highlight-color
property, so the line can optionally be colored in a different style while the tooltip is shown.
Alternatively users need to add some custom JS code which might get ugly.
That's a nice suggestion. If somebody is willing to pick this up, that's welcome. I'm thinking it could be an argument for all vector classes, either implemented as a kwarg or as a separate class.
Alternatively, you could convert your data to geojson format and use the highlight_function
argument of the GeoJson
class. We have an example of that here: https://nbviewer.org/github/python-visualization/folium/blob/main/examples/Highlight_Function.ipynb
Alternatively, you could convert your data to geojson format and use the
highlight_function
argument of theGeoJson
class. We have an example of that here
Thanks for letting me know about the workaround, exactly what I need 👍
@fm-sys As @Conengmo said, you can do it through the highlight_function
of folium.features.GeoJson
when using a GeoJSON for your polyline. I encountered the issue before and solved it through this, take a look at the solution I posted a while back:
Folium draw and highlight polylines with distinct colours from unique GeoJSON
Results - before hover | Results - on hover/highlight |
---|---|
![]() |
![]() |
I have successfully used the GeoJson
workaround meanwhile... From my side this issue can be closed, but as I far as I understood @Conengmo we might want to track this idea for normal poly lines as well.
Thanks for your input both. Indeed let's keep this issue open, I like the idea of having this on vector classes as well, as long as it can be done in a simple way.