Implementing the pan tool
Panning (that is, clicking and dragging on the map to move around) is another area where the QGIS default behavior isn't quite what we want. QGIS includes a classQgsMapToolPan
class, which implements panning; however, it also includes some features that could be quite confusing for users coming from Google Maps. In particular, if the user clicks without dragging, the map is re-centered over the clicked-on point. Instead of using classQgsMapToolPan
, we will implement our own panning map tool. Fortunately, this is simple to do: simply add the following class definition to your lex.py
module after the end of your MapExplorer
class definition:
class PanTool(QgsMapTool): def __init__(self, mapCanvas): QgsMapTool.__init__(self, mapCanvas) self.setCursor(Qt.OpenHandCursor) self.dragging = False def canvasMoveEvent(self, event): if event.buttons() == Qt.LeftButton: self.dragging = True self.canvas().panAction...