Graphics Reference
In-Depth Information
"ogr")
QgsMapLayerRegistry.instance().addMapLayer(
self.landmark_layer)
self.showVisibleMapLayers()
self.mapCanvas.setExtent(QgsRectangle(-127.7, 24.4,
-79.3, 49.1))
This method loads the raster and vector datasets we placed in our data directory. We
then call a new method, showVisibleMapLayers() , to make those layers visible,
and then set the extent of the map canvas to show the continental USA when the applica-
tion first starts up.
Let's implement the showVisibleMapLayers() method:
def showVisibleMapLayers(self):
layers = []
if self.actionShowLandmarkLayer.isChecked():
layers.append(QgsMapCanvasLayer(self.landmark_layer))
if self.actionShowBasemapLayer.isChecked():
layers.append(QgsMapCanvasLayer(self.basemap_layer))
self.mapCanvas.setLayerSet(layers)
As the user can choose to show or hide the basemap and landmark layers individually, we
only display the layers that the user has selected to display. We also put this into a separate
method so that we can call it when the user toggles the visibility of a layer.
There are a few more things to do before our map can be displayed. First off, add the fol-
lowing line to your main() function immediately after the call to window.raise_() :
window.loadMap()
This loads the map once the window has been displayed. Next, add the following to the
end of your main window's __init__() method:
self.actionShowBasemapLayer.setChecked(True)
self.actionShowLandmarkLayer.setChecked(True)
Search WWH ::




Custom Search