I have a layout with four maps over four pages in QGIS 3.4. I am building a python plugin to simplify map production for non GIS users. I am having difficulty defining the layers I want in each map item, as each map item will have slightly different layers. So far I have the code (I have left out some code above that loads a layout template and yes I have no doubt my code has some ineffeciencies :p ):
project = QgsProject.instance() projectLayoutManager = project.layoutManager() layout = projectLayoutManager.layoutByName("test") iface.openLayoutDesigner(layout) layerList = QgsProject.instance().layerTreeRoot().findLayers() extent = iface.mapCanvas().extent() extent.grow(0.7) map1 = QgsLayoutItemMap(layout) layers = QgsProject.instance().mapLayers() zoning = layers.values(map_layer1) map1.setLayers(zoning) map1.setFrameEnabled(True) map1.setRect(QRectF(20, 20, 20, 100)) map1.setExtent(extent) layout.addLayoutItem(map1)
I have tried a few options but keep getting the same error:
NameError: name 'map_layer1' is not defined
So, I'm not really sure where to go from here. I am just testing with two layers in the map canvas at this point, map layer 1 and map layer 2.