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
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with QGIS
Index

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...