folium icon indicating copy to clipboard operation
folium copied to clipboard

Polyline highlight color

Open fm-sys opened this issue 1 year ago • 5 comments

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.

fm-sys avatar May 22 '23 07:05 fm-sys

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

Conengmo avatar May 22 '23 09:05 Conengmo

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

Thanks for letting me know about the workaround, exactly what I need 👍

fm-sys avatar May 22 '23 10:05 fm-sys

@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
   

IndigoWizard avatar Aug 12 '23 23:08 IndigoWizard

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.

fm-sys avatar Aug 13 '23 10:08 fm-sys

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.

Conengmo avatar Aug 15 '23 08:08 Conengmo