Skip to content

className not propagated to leaflet path options on markers as otherwise indicated by folium docs #2024

@klausfrandsen

Description

@klausfrandsen

For Markers, CircleMarkers, etc. if adding className as an extra kwarg, it is not propagated to the js-code initializing the leaflet map, even though the documentation somewhat suggests it:
**kwargs
Other valid (possibly inherited) options. See:
https://leafletjs.com/reference.html#circlemarker

Having the possibility to add class-strings to the generated map, greatly improves the usability of Folium (at least for me), as it allows the developer to add extra interactivity client-side in javascript via simple css selectors, e.g. hiding showing selected stuff on the map on js-events.

To Reproduce
Add className='my_class_str' to any Marker.
Inspect map in browser and e.g. search for my_class_str.
It does not show up.

Expected behavior
class = "my_class_str" added to html elements for Markers

Environment (please complete the following information):

  • chrome
  • html files
  • Python version: 3.9
  • folium version: 0.14.0
  • branca version: 0.6.0

Additional context
Seems like this might have been reported before:
#730
But if it was fixed or not seems unclear to me

Possible solutions
Seems like there is a VERY simple fix, by just adding "className": kwargs.pop("className", '') when initializing the default dict in path_options() in vector_layers.py
It works for me, but I do not know if there are use-cases I'm unaware of, or if it results in other unwanted side-effects.

Thanks for a great package!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions