Skip to content

Commit

Permalink
load vector tiles from style only (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored Oct 8, 2024
1 parent 6ab3694 commit 8a77ca3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions swiss_locator/core/filters/swiss_locator_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
QgsFeedback,
QgsRasterLayer,
QgsVectorTileLayer,
QgsVectorTileUtils,
)
from qgis.gui import QgsRubberBand, QgisInterface

Expand Down Expand Up @@ -440,8 +441,9 @@ def triggerResult(self, result: QgsLocatorResult):
# Vector tiles
elif type(swiss_result) == VectorTilesLayerResult:
params = dict()
params["styleUrl"] = swiss_result.style or ""
params["url"] = swiss_result.url
params["styleUrl"] = swiss_result.style
if Qgis.QGIS_VERSION_INT < 33900:
params["url"] = swiss_result.url
params["type"] = "xyz"
# Max and min zoom levels cound be retrieved from metadata JSON files like:
# https://vectortiles.geo.admin.ch/tiles/ch.swisstopo.base.vt/v1.0.0/tiles.json
Expand All @@ -451,6 +453,11 @@ def triggerResult(self, result: QgsLocatorResult):

url_with_params = "&".join([f"{k}={v}" for (k, v) in params.items()])

if Qgis.QGIS_VERSION_INT >= 33900:
url_with_params = QgsVectorTileUtils.updateUriSources(
url_with_params, True
)

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

Expand Down
2 changes: 1 addition & 1 deletion swiss_locator/core/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(
self,
layer,
title,
url,
url: str = None,
style: str = None,
):
self.title = title
Expand Down

0 comments on commit 8a77ca3

Please sign in to comment.