I'm discovering Leaflet (especially the equivalent in Python pyqlet), and there is something I do not understand.
I adapted this code from the documentation so when I type the Space bar, the marker present on the map is changed (here I just change the text of the popup)
import sys
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget
from PyQt5.Qt import Qt
from pyqtlet import L, MapWidget
from time import time
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('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_nolabels/{z}/{x}/{y}{r}.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.show()
def keyPressEvent(self, event):
if event.key() == Qt.Key_Space:
self.newMarker()
def newMarker(self):
self.map.removeLayer(self.marker)
self.marker = L.marker([12.934056, 77.610029])
self.marker.bindPopup(str(time())) # put the current time as message
self.map.addLayer(self.marker)
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = MapWindow()
sys.exit(app.exec_())
On the execution, when I use the space bar, the marker is indeed changed but some messages appear in the console (and my research on the web have not been helpful) :
js: Uncaught TypeError: Cannot read property 'mapObject' of null
<*>Registered new object after initialization, existing clients won't be notified!
<*>Registered new object after initialization, existing clients won't be notified!
js: Unhandled signal: l2Object::0
<*>Registered new object after initialization, existing clients won't be notified!
js: Unhandled signal: l3Object::0
The symbol <*> corresponds to when I type the key, it doesn't appear in the terminal.
The first line always appears, but as it is also the case on the code from the documentation, I guess this is not critical.
Is there something I did the wrong way somewhere ?