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

Using chaining in calls to Layer() elements #14

Closed
mcondarelli opened this issue Nov 10, 2021 · 2 comments · Fixed by #15
Closed

Using chaining in calls to Layer() elements #14

mcondarelli opened this issue Nov 10, 2021 · 2 comments · Fixed by #15
Labels
enhancement New feature or request
Milestone

Comments

@mcondarelli
Copy link

mcondarelli commented Nov 10, 2021

Please consider adding something like:

diff --git a/pyqtlet2/leaflet/layer/layer.py b/pyqtlet2/leaflet/layer/layer.py
index 19179cd..478ed8e 100644
--- a/pyqtlet2/leaflet/layer/layer.py
+++ b/pyqtlet2/leaflet/layer/layer.py
@@ -40,9 +40,11 @@ class Layer(Evented):
 
     def addTo(self, map_):
         map_.addLayer(self)
+        return self
 
     def removeFrom(self, map_):
         map_.removeLayer(self)
+        return self
 
     def bindPopup(self, content, options=None):
         js = '{layerName}.bindPopup("{content}"'.format(

to allow for standard chaining like:

    tag = L.polygon([c, a], {'color': color}).addTo(self.map).layerName

instead of the more verbose:

    arrow = L.polygon([c, a], {'color': color})
    arrow.addTo(self.map)
    tag = arrow._ayerName

I can provide a proper pull request, if you want, but this is really trivial ;)

@JaWeilBaum
Copy link
Owner

this seams like a good Idea @mcondarelli ! If you already have this in a fork feel free to make a PR, after this is merged I'll release version 0.5.0 so you can start using it.

@JaWeilBaum JaWeilBaum added the enhancement New feature or request label Nov 10, 2021
@JaWeilBaum JaWeilBaum added this to the Version 0.5.0 milestone Nov 10, 2021
@JaWeilBaum
Copy link
Owner

And I'm not sure if there are other classes where this would make sense. In my uses cases I don't use this chaining at the moment. Are you aware of other use cases?

@JaWeilBaum JaWeilBaum linked a pull request Nov 15, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants