From 8675dce91b85282f12d4e885a6aa7b126737c930 Mon Sep 17 00:00:00 2001 From: SimonSAMPERE <41120579+SimonSAMPERE@users.noreply.github.com> Date: Mon, 18 Dec 2023 14:56:16 +0100 Subject: [PATCH] #437 Add BBOX display to QA version --- modules/search_form.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/search_form.py b/modules/search_form.py index 1390eddc..6cb4372c 100644 --- a/modules/search_form.py +++ b/modules/search_form.py @@ -625,21 +625,25 @@ def get_coords(self, filter: str): # message="{}".format(coord_currentCrs), tag="Isogeo", level=0 # ) - # from qgis.core import QgsGeometry, QgsFeature, QgsRenderContext, QgsVectorLayer - # from qgis.PyQt.QtGui import QColor + from qgis.core import QgsGeometry, QgsFeature, QgsRenderContext, QgsVectorLayer + from qgis.PyQt.QtGui import QColor - # bbox_polygon = QgsFeature() - # bbox_polygon.setGeometry(QgsGeometry.fromRect(extent_wgs84)) - # bbox_layer = QgsVectorLayer("Polygon?crs=epsg:4326", "BoundingBox", "memory") - # bbox_layer.dataProvider().addFeatures([bbox_polygon]) - - # symbols = bbox_layer.renderer().symbols(QgsRenderContext()) - # symbol = symbols[0] - # symbol.setColor(QColor.fromRgb(255, 20, 147)) - # symbol.setOpacity(0.25) - - # qgs_prj.addMapLayer(bbox_layer) - # iface.mapCanvas().refresh() + bbox_layer_name = "BoundingBox {}".format(coord) + if any(lyr.name() == bbox_layer_name for lyr in qgs_prj.mapLayers().values()): + pass + else: + bbox_polygon = QgsFeature() + bbox_polygon.setGeometry(QgsGeometry.fromRect(extent_wgs84)) + bbox_layer = QgsVectorLayer("Polygon?crs=epsg:4326", bbox_layer_name, "memory") + bbox_layer.dataProvider().addFeatures([bbox_polygon]) + + symbols = bbox_layer.renderer().symbols(QgsRenderContext()) + symbol = symbols[0] + symbol.setColor(QColor.fromRgb(255, 20, 147)) + symbol.setOpacity(0.25) + + qgs_prj.addMapLayer(bbox_layer) + iface.mapCanvas().refresh() return coord