Book Image

Building Mapping Applications with QGIS

By : Erik Westra
Book Image

Building Mapping Applications with QGIS

By: Erik Westra

Overview of this book

Table of Contents (16 chapters)
Building Mapping Applications with QGIS
About the Author
About the Reviewers
Free Chapter
Getting Started with QGIS

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 module after the end of your MapExplorer class definition:

class PanTool(QgsMapTool):
    def __init__(self, mapCanvas):
        QgsMapTool.__init__(self, mapCanvas)
        self.dragging = False

    def canvasMoveEvent(self, event):
        if event.buttons() == Qt.LeftButton:
            self.dragging = True