Skip to content

Commit

Permalink
[vt] Make sure a VT layer gets a proper Swiss extent on an empty proj…
Browse files Browse the repository at this point in the history
…ect (if the project is not empty, we'll leave the current extent untouched, since chances are users have already the extent they want) (#97)
  • Loading branch information
gacarrillor authored Jul 28, 2024
1 parent 0c34fb3 commit ed91042
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions swiss_locator/core/filters/swiss_locator_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,49 +443,50 @@ 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)
else:
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
self.info(msg, level)
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.
Expand Down

0 comments on commit ed91042

Please sign in to comment.