Skip to content

Commit

Permalink
Address review for Vector Tiles support
Browse files Browse the repository at this point in the history
  • Loading branch information
gacarrillor committed May 14, 2024
1 parent fbf7644 commit 2498d26
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions swiss_locator/core/filters/swiss_locator_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def triggerResult(self, result: QgsLocatorResult):
url_with_params = "&".join([f"{k}={v}" for (k, v) in params.items()])

self.info(f"Loading layer: {url_with_params}")
vt_layer = QgsRasterLayer(url_with_params, result.displayString, "wms")
ch_layer = QgsRasterLayer(url_with_params, result.displayString, "wms")
label = QLabel()
label.setTextFormat(Qt.RichText)
label.setTextInteractionFlags(Qt.TextBrowserInteraction)
Expand All @@ -403,7 +403,7 @@ def triggerResult(self, result: QgsLocatorResult):
)
)

if not vt_layer.isValid():
if not ch_layer.isValid():
msg = self.tr(
"Cannot load Layers layer: {} ({})".format(
swiss_result.title, swiss_result.layer
Expand All @@ -419,7 +419,7 @@ def triggerResult(self, result: QgsLocatorResult):
)
level = Qgis.Info

QgsProject.instance().addMapLayer(vt_layer)
QgsProject.instance().addMapLayer(ch_layer)

self.message_emitted.emit(self.displayName(), msg, level, label)

Expand All @@ -443,9 +443,9 @@ def triggerResult(self, result: QgsLocatorResult):
url_with_params = "&".join([f"{k}={v}" for (k, v) in params.items()])

self.info(f"Loading layer: {url_with_params}")
vt_layer = QgsVectorTileLayer(url_with_params, result.displayString)
ch_layer = QgsVectorTileLayer(url_with_params, result.displayString)

if not vt_layer.isValid():
if not ch_layer.isValid():
msg = self.tr(
"Cannot load Vector Tiles layer: {}".format(
swiss_result.title
Expand All @@ -454,11 +454,11 @@ def triggerResult(self, result: QgsLocatorResult):
level = Qgis.Warning
self.info(msg, level)
else:
vt_layer.setLabelsEnabled(True)
vt_layer.loadDefaultMetadata()
ch_layer.setLabelsEnabled(True)
ch_layer.loadDefaultMetadata()

error, warnings = '', []
res, sublayers = vt_layer.loadDefaultStyleAndSubLayers(error, warnings)
res, sublayers = ch_layer.loadDefaultStyleAndSubLayers(error, warnings)

if sublayers:
msg = self.tr(
Expand Down Expand Up @@ -493,16 +493,16 @@ def triggerResult(self, result: QgsLocatorResult):
if sublayers:
# Sublayers should load on top of the vector tiles layer
# We group them to keep them all together
group = root.insertGroup(-1, vt_layer.name())
group = root.insertGroup(-1, ch_layer.name())
for sublayer in sublayers:
QgsProject.instance().addMapLayer(sublayer, False)
group.addLayer(sublayer)

QgsProject.instance().addMapLayer(vt_layer, False)
group.addLayer(vt_layer)
QgsProject.instance().addMapLayer(ch_layer, False)
group.addLayer(ch_layer)
else:
QgsProject.instance().addMapLayer(vt_layer, False)
root.insertLayer(-1, vt_layer)
QgsProject.instance().addMapLayer(ch_layer, False)
root.insertLayer(-1, ch_layer)

# Location
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def clone(self):
return SwissLocatorFilterVectorTiles(crs=self.crs)

def displayName(self):
return self.tr("Swiss Geoportal Vector Tile Layers")
return self.tr("Swiss Geoportal Vector Tile Base Map Layers")

def prefix(self):
return "chb"
Expand Down
2 changes: 1 addition & 1 deletion swiss_locator/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self):
Enum(
f"{FilterType.Feature.value}_priority",
Scope.Global,
QgsLocatorFilter.Medium,
QgsLocatorFilter.Highest,
)
)
self.add_setting(Integer(f"{FilterType.Feature.value}_limit", Scope.Global, 8))
Expand Down

0 comments on commit 2498d26

Please sign in to comment.