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

Creating the map canvas


Our Ui_ExplorerWindow class defines an instance variable named centralWidget, which acts as a placeholder for our window's contents. Since we want to place a QGIS map canvas into our window, let's implement the code to create our map canvas and place it into this central widget. Add the following to the end of your MapExplorer window's __init__() method (in lex.py):

        self.mapCanvas = QgsMapCanvas()
        self.mapCanvas.useImageToRender(False)
        self.mapCanvas.setCanvasColor(Qt.white)
        self.mapCanvas.show()

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.mapCanvas)
        self.centralWidget.setLayout(layout)

Next, we want to fill our map canvas with the basemap and landmark map layers. To do this, we'll define a new method called loadMap(), and call this at the appropriate time. Add the following method to your MapExplorer class:

    def loadMap(self):
        cur_dir = os.path.dirname...