Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vt] Make sure a VT layer gets a proper Swiss extent on an empty project #97

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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