Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaflet control #1902

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

hansthen
Copy link
Collaborator

@hansthen hansthen commented Mar 12, 2024

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 #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.

Copy link
Member

@Conengmo Conengmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR contains three separate ideas that I think we should handle separately.

CustomControl is useful I think, and something requested by users. It inherits from Control, but doesn't use anything from it, so it might as well be separate.

I'm not sure what Control is supposed to do. It's a base class for many other classes in this PR, but none of the now child classes use anything from it. No arguments are passed in super().__init__() and the template is overwritten. So it might as well not be there. In which case is shouldn't. Long chains of object inheritance make things difficult to grok.

Then there are also some changes in Realtime that on first glance are not linked to the control change.

So my suggestion would be to take the first and third point and deal with those in separate PRs. And then have a discussion about the second point, how the class structure of Folium should be.

@Conengmo Conengmo removed the waiting for review PR is waiting to be reviewed label May 6, 2024
@hansthen
Copy link
Collaborator Author

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

@hansthen hansthen marked this pull request as draft May 19, 2024 04:16
1. Created a root control class which can load any Leaflet control
2. Made all items that generate a leaflet Control in plugins inherit
   from Control instead of MacroElement.
3. Still TODO:
   It would be nice if Control itself inherited from JSCSSMixin.
   But for that we'd need to revamp loading of css and js.
4. Probably many of the plugins could be rewritten more simply
   by using features from Control and JsCode instead of using custom
   templates.
5. map.LayerControl does not inherit from Control due to issues with
   circular imports. (features import map, so map cannot import features).
   We'd need to move LayerControl for that to work, but that is
   breaking change.
Most of the code of mouse_position has been removed.
Instead it simply calls the constructor of Control with
the typed parameters.
@hansthen
Copy link
Collaborator Author

hansthen commented Jun 2, 2024

@Conengmo I removed the parts that could be handled as separate Pull Requests. I also rewrote the MousePosition control plugin. I think it clarifies why adding Control allows us to simplify a large part of the code base. Let me know what you think.

I would prefer to rewrite the other plugins incrementally. However, that means that for a while there will be inconsistent approaches in the code.

@hansthen hansthen marked this pull request as ready for review June 2, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants