JaWeilBaum / pyqtlet2

pyqtlet2 extends pyqtlet which initially brought Leaflet maps to PyQt5 and PySide6.
Other
37 stars 19 forks source link

Using chaining in calls to Layer() elements #14

Closed mcondarelli closed 2 years ago

mcondarelli commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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?