-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add EventHandler to layer object #1903
Conversation
@Conengmo Can you have a look at this Pull Request? I would like to have this functionality for |
Thanks for the review @ocefpaf. I do have one question. On second thought, maybe it is better to not use a Mixin, but simply define a superclass for Any thoughts on this? |
I don't have a strong opinion on either options. It is mostly a design pattern that we need to choose and stick with it for consistency. With that said, I'd like for you and @Conengmo to agree on one b/c you are the ones maintaining folium the most. I can go with the flow you two dictate here without a problem. |
Makes sense. I will try to contact Frank to discuss. We are actually from the same country, so I am sure we should be able to come up with something. I will convert this one to a draft for the moment. |
Cool. I'd love to restore some dev channel communication. Frank and I used gitter in the past but that is gone now. I'd be ok with direct email or something similar. Mostly I'd like to go over two ideas I have for folium as we move forward with you two. |
Let's hijack this PR to talk about communication :) Would using Github Discussions in this repo work? It's all public, so we can't discuss private things, but I don't mind talking about Folium in the open. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do like the idea in this PR!
I'm thinking though, where in the code we would use this? Or is it a convenience for users who might want to apply additional event handlers?
I'm also wondering where or how we should apply this. Not sure yet what's best.
- Having a mixin that we or that users add where it's needed makes sense. Especially since it only adds an
on
method, so the inheritance complexity is quite low. - If we stick with Folium flavour, we would only provide the EventHandler class, and let users add that as a child directly, without an
on
method. - If this is generally useful, maybe this should be applied to the source, to the
MacroElement
in Branca.
Discussions would be fine for most things. @Conengmo We do work / live very near each other. I would like to meet in person if you are open to that. My e-mail address is in my profile. If you want we can setup a meeting via mail. |
This is indeed meant as an extra capability for users. In my specific case, I would like to use it to autozoom
I don't think this is currently possible to do without changing or extending the Realtime plugin. I chose the |
I guess I started it 🙈
Sure. There are some ideas that I want to pass by you two. We can do that using GD. |
I opened the Discussions feature and added a Collaborators category: https://github.com/python-visualization/folium/discussions/categories/collaborators. It's public, but only maintainers can create posts. I'd love to hear what ideas you have Filipe! |
That does sound fun, but I don't know if I have time for that to be honest :) I'll email you, let's see where that leads! |
Fair enough, sounds good to add!
Both arguments make sense to me, but my thinking is going a bit in another direction. Looking at the three ideas for implementation I posted earlier, I don't think we should go with the mixin. Having it as an optional mixin is confusing I think, because it's not transparent to users when that If possible, I'd like to have Folium be as consistent as possible. Having a single way of working is part of that, and also part of Python. Just having the If you feel strongly about having an What would be your preference? |
I will rewrite it as you suggested. I will also let your comments about |
In combination with JsCode this makes it easier for users to add `on` method calls for event handling without extending Folium itself. The functionality was inspired by PR python-visualization#1866 by @yschopfer19. The PR was not accepted yet, because of concerns with code duplication. In the approach taken in the current PR, python-visualization#1866 would not be necessary anymore, as the requested changes could be added completely in client code space.
We now have github discussions 🥂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, you can merge it if you want!
Two suggestions for your consideration, one small, one bigger:
- Give the class a docstring first line, which is now missing.
- We could consider moving this class as well as
JsCode
to Branca, since they are not Leaflet-specific, but help with any HTML/JS templating. If you agree, we might consider not merging this PR but add the class in Branca directly, as well as adding JsCode there.
Thanks for the review! I added the extra docstring line. About your other suggestion, I would go the other direction (but for the same rationale). In my view, the If we moved it to Branca, I would be afraid that people would be encouraged to add EventHandlers to elements that do not support it, generating questions and increasing our maintenance burden. It is confusing because so many packages (jquery and node) use |
My bad, I didn’t realize the ‘on’ method is Leaflet specific :) totally agree then, it shouldn’t go to Branca. |
Hmm this sounds like something to be mindful of. I guess that’s why you made it a mixin to begin with? To only add it to certain applicable classes? |
Indeed, but now I think it would be better to follow the Leaflet class hierarchy and create an |
Alright, I see your point better now. Can you give me a few days? I want to look at this a bit better now that I get it more. |
I see you made #1959, I'll add a review there 👍 |
Closing since #1959 supersedes this one. |
In combination with JsCode this makes it easier for users to add
on
method calls for event handling without extending Folium itself.The functionality was inspired by PR #1866 by @yschopfer19. The PR was not accepted yet, because of concerns with code duplication. In the approach taken in the current PR, #1866 would not be necessary anymore, as the requested changes could be added completely in client code space.