JaWeilBaum / pyqtlet2

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

map.fitBounds has no effect #57

Open MarceloBarrosVanegas opened 1 year ago

MarceloBarrosVanegas commented 1 year ago

Hi, I just discovered the pyqtlet2 package. I have tried the basic example, and then try and add the fitBounds method for the map widget but it does not have any effect. I am doing something wrong?

`import os import sys os.environ['QT_API'] = 'pyqt5' from qtpy.QtWidgets import QApplication, QVBoxLayout, QWidget from pyqtlet2 import L, MapWidget

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([-2.8608165094824143, -79.05583521123442], 10)
    self.map.clicked.connect(lambda x: print(x))

    tile_opt = {
        'attribution': 'Map data: &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors',
        'maxZoom': 10000
    }
    _tile = L.tileLayer('http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}', tile_opt)

    _tile.addTo(self.map)
    self.marker = L.marker([12.934056, 77.610029])
    self.marker.bindPopup('Maps are a treasure.')
    self.map.addLayer(self.marker)

    south_west = (-2.8608165094824143, -79.05583521123442)
    north_east = (-2.8520920958914373, -79.03675224795658)
    bounds =(south_west,  north_east)
    self.map.fitBounds(bounds)

    self.show()

if name == 'main': app = QApplication(sys.argv) widget = MapWindow() sys.exit(app.exec_())`

I am trying to make a background layer to display behind a QGrapchisView lines and plots. So the fitBounds method would make the mapwidget scene be the same as the QGrapicsView scene rect.

Thank you for any help.