JaWeilBaum / pyqtlet2

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

Popup difficulty #33

Closed burkeerr closed 2 years ago

burkeerr commented 2 years ago

Discussed in https://github.com/JaWeilBaum/pyqtlet2/discussions/32

Originally posted by **burkeerr** May 5, 2022 So far this Lib is excellent but i have hit a snag and cant seam to get around it. I want to add a point to the map by clicking a button in QT. This part works fine. But the popup never pops up for the added marker. The marker that was run during init works as expected but the added marker does not. Additionally I added a callback for the click and that works fine for the initial marker but not the added marker. Any suggestions? ` import sys from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget, QPushButton from pyqtlet2 import L, MapWidget class MapWindow(QWidget): marker2 = L.marker def __init__(self): # Setting up the widgets and layout super().__init__() self.mapWidget = MapWidget() self.layout = QVBoxLayout() self.layout.addWidget(self.mapWidget) self.button = QPushButton("Push Me") self.layout.addWidget(self.button) self.setLayout(self.layout) self.button.clicked.connect(self.add_point) # 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.marker = L.marker([12.934056, 77.610029]) self.marker.bindPopup('Maps are a treasure.') self.map.addLayer(self.marker) self.marker.click.connect(self.click_marker) self.drawControl = L.control.draw() self.map.addControl(self.drawControl) self.show() def add_point(self): self.marker2 = L.marker([12.934056, 77.650029]).addTo(self.map).bindPopup("Hi there") self.marker2.click.connect(self.click_marker) print("added point") def click_marker(self, event): print("click", event) if __name__ == '__main__': app = QApplication(sys.argv) widget = MapWindow() sys.exit(app.exec_()) `
burkeerr commented 2 years ago

20

My guess is they are related.

JaWeilBaum commented 2 years ago

Hi @burkeerr

I think you are right. This is an issue I cant resolve. My workaround for this is to create a set of invisible markers at the start of the application and then show or hide them when needed. This requires some housekeeping but I think this is the best possible right now.

Does this solve your issue?

burkeerr commented 2 years ago

Actually that's what i ended up doing. And yes that works. I have not tried to added extras and change them yet but i will. You can definitely add things but the pop-up will not work. I tried even replacing the window with a new one that did do it either. But the work around is good. Thanks for the reply