To let the user move around the map, we'll make use of the PanTool
class we implemented in an earlier chapter. Add the following class definition to the mapTools.py
module:
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(event) def canvasReleaseEvent(self, event): if event.button() == Qt.LeftButton and self.dragging: self.canvas().panActionEnd(event.pos()) self.dragging = False
Back in our forestTrails.py
module, add the following new method:
def setupMapTools(self): self.panTool = PanTool(self.mapCanvas) self.panTool.setAction(self.actionPan)
This method will initialize the various map tools that our application will use; we'll add to this method...