| | |
| | | #!/usr/bin/env |
| | | # -*- coding: utf-8 -*- |
| | | import os |
| | | import math |
| | | from qgis.core import * |
| | |
| | | from qgis.PyQt.QtXml import * |
| | | |
| | | |
| | | # 设置图层可用性 |
| | | def setLayersValid(project, showLayers): |
| | | for layer in project.mapLayers().values(): |
| | | flag = layer.name() in showLayers |
| | |
| | | layer.setValid(flag) |
| | | |
| | | |
| | | # 设置图层可见性 |
| | | def setItemVisibility(root, showLayers): |
| | | print('Group: ' + root.name()) |
| | | print(root.name() + ': Group') |
| | | for node in root.children(): |
| | | # QgsLayerTreeLayer |
| | | if isinstance(node, QgsLayerTreeGroup): |
| | |
| | | else: |
| | | name = node.layer().name() |
| | | flag = name in showLayers |
| | | print(str(flag) + ", " + name) |
| | | print(name + ": " + str(flag)) |
| | | # if not flag: |
| | | # root.removeLayer(node.layer()) |
| | | # node.layer().setValid(False) |
| | |
| | | print('1:' + str(math.ceil(map.scale()))) |
| | | |
| | | # "阀室", "站场", "管道中心线", "矢量注记", "矢量图", "高德影像注记", "高德影像", "影像注记", "影像图" |
| | | showLayers = ["阀室", "管道中心线", "矢量注记", "矢量图"] |
| | | # showLayers = ["阀室", "管道中心线", "矢量注记", "矢量图"] |
| | | showLayers = map.id().split(',') |
| | | root = project.layerTreeRoot() |
| | | # setLayersValid(project, showLayers) |
| | | setItemVisibility(root, showLayers) |