python-visualization / folium

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

Leaflet control #1902

Open hansthen opened 2 months ago

hansthen commented 2 months ago

Based on the original draft by @Conengmo

  1. Create a new base class Control, which can be used to more easily create new control based plugins.
  2. Update the original CustomControl so that it also accepts a style parameter.
  3. Change all the plugins that create L.Control subclasses to use Control as a base class.

This is to some extent a work-in-progress. Once https://github.com/python-visualization/folium/pull/1898 is merged I can make Control inherit from JSCSSMixin and remove that class from all the plugins and just use the inherited method from JSCSSMixin inheritance to add stylesheets and javascript.

Furthermore, many of the plugins could be simplified. In the current implementation options are very often coded in the _Template. By using the Control base class and JsCode parameters as part of the specified options we can avoid that. Or, at least, we can move flow code from the Jinja templates into the __init__ method, which is cleaner.

Also, I tried to make map.LayerControl as subclass of Control, but that resulted in circular dependencies.

I did not do everything at once, because I want to take small steps and check if everything stays backward compatible.

hansthen commented 2 weeks ago

Thanks for the review. I will rework it as requested.