From 3f5b258982e4acd38ad38f3dea8cb6a92af6f37f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Fri, 26 Jul 2024 22:16:50 -0500 Subject: [PATCH] [vt] Make sure a VT layer gets a proper Swiss extent on an empty project (if the project is not empty, we'll leave the current extent untouched, since chances are users have already the extent they want) --- .../core/filters/swiss_locator_filter.py | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/swiss_locator/core/filters/swiss_locator_filter.py b/swiss_locator/core/filters/swiss_locator_filter.py index ee5669e..85a0899 100644 --- a/swiss_locator/core/filters/swiss_locator_filter.py +++ b/swiss_locator/core/filters/swiss_locator_filter.py @@ -443,9 +443,7 @@ def triggerResult(self, result: QgsLocatorResult): if not ch_layer.isValid(): msg = self.tr( - "Cannot load Vector Tiles layer: {}".format( - swiss_result.title - ) + "Cannot load Vector Tiles layer: {}".format(swiss_result.title) ) level = Qgis.MessageLevel.Warning self.info(msg, level) @@ -453,14 +451,14 @@ def triggerResult(self, result: QgsLocatorResult): ch_layer.setLabelsEnabled(True) ch_layer.loadDefaultMetadata() - error, warnings = '', [] + error, warnings = "", [] res, sublayers = ch_layer.loadDefaultStyleAndSubLayers(error, warnings) if sublayers: msg = self.tr( "Sublayers found ({}): {}".format( swiss_result.title, - "; ".join([sublayer.name() for sublayer in sublayers]) + "; ".join([sublayer.name() for sublayer in sublayers]), ) ) level = Qgis.MessageLevel.Info @@ -468,24 +466,27 @@ def triggerResult(self, result: QgsLocatorResult): if error or warnings: msg = self.tr( "Error/warning found while loading default styles and sublayers for layer {}. Error: {} Warning: {}".format( - swiss_result.title, - error, - "; ".join(warnings) + swiss_result.title, error, "; ".join(warnings) ) ) level = Qgis.MessageLevel.Warning self.info(msg, level) - msg = self.tr( - "Layer added to the map: {}".format( - swiss_result.title - ) - ) + msg = self.tr("Layer added to the map: {}".format(swiss_result.title)) level = Qgis.MessageLevel.Info self.info(msg, level) # Load basemap layers at the bottom of the layer tree root = QgsProject.instance().layerTreeRoot() + empty_project = not QgsProject.instance().mapLayers() + + if empty_project: + # Set the Swiss extent in EPSG:3857 (VT's CRS) + extent = QgsRectangle(624991, 5725825, 1209826, 6089033) + ch_layer.setExtent(extent) + for _layer in sublayers: + _layer.setExtent(extent) + if sublayers: # Sublayers should be loaded on top of the vector tile # layer. We group them to keep them all together.