JaWeilBaum / pyqtlet2

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

marker.setDragging(True) is not work #41

Closed Zhao00Xu closed 1 year ago

Zhao00Xu commented 1 year ago

hello! I want to move the marker in map, but the "bug" happened. I use PySide6=6.2.2 and the master of pyqtlet2, and test with the code in "README.md":

the First problem, I construct a Marker like "self.marker = L.marker([12.934056, 77.610029], {"draggable": True})", then the marker can move by the mouse, but if I do like this "self.marker = L.marker([12.934056, 77.610029]) self.marker.setDragging(True)", the marker cannot move.

the Second problem, if I construct some markers like "self.marker = L.marker([12.934056, 77.610029], {"draggable": True})" before "self.show()", then all the markers can move, but the bug happened when add new markers by right click event. in the right click event slot function, I use " L.marker([12.934056, 77.610029], {"draggable": True}).addTo(self.map)", after the new marker appeared in map, the new marker can move with the mouse, but after move end, all the markers cannot move , even the map cannot move, only map scale function can work.

if I do like "the Second problem" but without the option of "{"draggable": True}", then everything is ok. so how can I solve the problems?

JaWeilBaum commented 1 year ago

In regards to you first problem: Please try the following code. For me both markers seem to be draggable.

class MapWindow(QWidget):
    def __init__(self):
        # Setting up the widgets and layout
        super().__init__()
        self.mapWidget = MapWidget()
        self.layout = QVBoxLayout()
        self.layout.addWidget(self.mapWidget)
        self.setLayout(self.layout)

        # Working with the maps with pyqtlet
        self.map = L.map(self.mapWidget)
        self.map.setView([12.97, 77.59], 10)
        L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(self.map)
        self.marker1 = L.marker([12.934056, 77.610029]).addTo(self.map)
        self.marker1.setDragging(True)

        self.marker2 = L.marker([12.974056, 77.610029], {"draggable": True}).addTo(self.map)

        self.show()

In regards to your second problem, this is a know issues which can't be solved due to the limitations the implementations brings. Most people using this, create a list of unused markers before the self.show() and the use these with the right click event. Basically you link the right click event to moving the marker to the position and making it visible.