python-visualization / folium

Python Data. Leaflet.js Maps.
https://python-visualization.github.io/folium/
MIT License
6.94k stars 2.23k forks source link

Issue 1943 allow jscode in options #2029

Closed hansthen closed 1 week ago

hansthen commented 2 weeks ago

Boring but big. The leaflet class hierarchy allows all classes to have optional arguments. These optional arguments can contain JavaScript code or references to other Leaflet elements.

To support this in Folium I replaced (almost) all instances of parse_options in the constructors with this.options | tojavascript in the templates. I left the parse_options in case someone outside of Folium uses it.

hansthen commented 1 week ago

@Conengmo Perhaps you can also have a look at the raster_layers.WmsTileLayer class. I still use {{ this.options|tojson }} there because there is an option that should remain lowercase. The inconsistency bugs me (a bit). I could not think of a way to make it consistent. But perhaps you have suggestions on how we could use tojavascript here?

Conengmo commented 1 week ago

Yes, I noticed that one as well. Can't think of a good, simple solution right now, so maybe what you did is best for now.