Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Always read tilemaps from source when loading vtpk/arcgis vector tile
layers
  • Loading branch information
nyalldawson committed May 16, 2023
1 parent 7ee5e32 commit a121e40
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
Expand Up @@ -72,6 +72,11 @@ QgsArcGisVectorTileServiceDataProvider::QgsArcGisVectorTileServiceDataProvider(
mLayerMetadata = other.mLayerMetadata;
}

Qgis::VectorTileProviderFlags QgsArcGisVectorTileServiceDataProvider::providerFlags() const
{
return QgsXyzVectorTileDataProviderBase::providerFlags() | Qgis::VectorTileProviderFlag::AlwaysUseTileMatrixSetFromProvider;
}

Qgis::VectorTileProviderCapabilities QgsArcGisVectorTileServiceDataProvider::providerCapabilities() const
{
return Qgis::VectorTileProviderCapability::ReadLayerMetadata;
Expand Down
Expand Up @@ -41,6 +41,7 @@ class CORE_EXPORT QgsArcGisVectorTileServiceDataProvider : public QgsXyzVectorTi
*/
QgsArcGisVectorTileServiceDataProvider &operator=( const QgsArcGisVectorTileServiceDataProvider &other ) = delete;

Qgis::VectorTileProviderFlags providerFlags() const override;
Qgis::VectorTileProviderCapabilities providerCapabilities() const override;
QString name() const override;
QString description() const override;
Expand Down
1 change: 0 additions & 1 deletion src/core/vectortile/qgsvectortilelayer.cpp
Expand Up @@ -184,7 +184,6 @@ bool QgsVectorTileLayer::writeXml( QDomNode &layerNode, QDomDocument &doc, const
mapLayerNode.appendChild( mMatrixSet.writeXml( doc, context ) );
}


// add provider node
if ( mDataProvider )
{
Expand Down
5 changes: 5 additions & 0 deletions src/core/vectortile/qgsvtpkvectortiledataprovider.cpp
Expand Up @@ -83,6 +83,11 @@ QgsVtpkVectorTileDataProvider::QgsVtpkVectorTileDataProvider( const QgsVtpkVecto
mSpriteImage = other.mSpriteImage;
}

Qgis::VectorTileProviderFlags QgsVtpkVectorTileDataProvider::providerFlags() const
{
return Qgis::VectorTileProviderFlag::AlwaysUseTileMatrixSetFromProvider;
}

Qgis::VectorTileProviderCapabilities QgsVtpkVectorTileDataProvider::providerCapabilities() const
{
return Qgis::VectorTileProviderCapability::ReadLayerMetadata;
Expand Down
1 change: 1 addition & 0 deletions src/core/vectortile/qgsvtpkvectortiledataprovider.h
Expand Up @@ -45,6 +45,7 @@ class CORE_EXPORT QgsVtpkVectorTileDataProvider : public QgsVectorTileDataProvid
*/
QgsVtpkVectorTileDataProvider &operator=( const QgsVtpkVectorTileDataProvider &other ) = delete;

Qgis::VectorTileProviderFlags providerFlags() const override;
Qgis::VectorTileProviderCapabilities providerCapabilities() const override;
QString name() const override;
QString description() const override;
Expand Down
43 changes: 32 additions & 11 deletions tests/src/python/test_qgsvtpk.py
Expand Up @@ -10,12 +10,15 @@
__copyright__ = 'Copyright 2022, The QGIS Project'

import qgis # NOQA
from qgis.PyQt.QtXml import QDomDocument

from qgis.core import (
QgsCoordinateTransformContext,
QgsVectorTileLayer,
QgsVtpkTiles,
QgsTileRange,
QgsTileXYZ
QgsTileXYZ,
QgsReadWriteContext
)
from qgis.testing import start_app, unittest

Expand Down Expand Up @@ -162,22 +165,40 @@ def testVectorTileLayerTileMap(self):
# note that this is only the "shell" of a vtpk -- there's no tiles here
# as the file is just for tilemap handling tests
layer = QgsVectorTileLayer(f"type=vtpk&url={unitTestDataPath() + '/vector_tile/vtpk_indexed.vtpk'}", 'tiles')
layer.setOpacity(0.5)
self.assertTrue(layer.isValid())

tiles = layer.tileMatrixSet().tilesInRange(QgsTileRange(0, 1023, 0, 1023), 10)
# we want to see the zoom level 9 tiles here, as the tilemap indicates
# that they should be used instead of zoom level 10 tiles for their
# extents
self.assertCountEqual(tiles, [QgsTileXYZ(274, 52, 9),
QgsTileXYZ(275, 52, 9),
QgsTileXYZ(548, 106, 10),
QgsTileXYZ(549, 106, 10),
QgsTileXYZ(550, 106, 10),
QgsTileXYZ(551, 106, 10),
QgsTileXYZ(548, 107, 10),
QgsTileXYZ(549, 107, 10),
QgsTileXYZ(550, 107, 10),
QgsTileXYZ(551, 107, 10)])
expected = [QgsTileXYZ(274, 52, 9),
QgsTileXYZ(275, 52, 9),
QgsTileXYZ(548, 106, 10),
QgsTileXYZ(549, 106, 10),
QgsTileXYZ(550, 106, 10),
QgsTileXYZ(551, 106, 10),
QgsTileXYZ(548, 107, 10),
QgsTileXYZ(549, 107, 10),
QgsTileXYZ(550, 107, 10),
QgsTileXYZ(551, 107, 10)]
self.assertCountEqual(tiles, expected)

# ensure that tilemap is correctly handled when restoring layers
doc = QDomDocument("testdoc")
elem = doc.createElement("maplayer")
self.assertTrue(layer.writeLayerXml(elem, doc, QgsReadWriteContext()))

layer2 = QgsVectorTileLayer(f"type=vtpk&url={unitTestDataPath() + '/vector_tile/vtpk_indexed.vtpk'}", 'tiles')
tiles = layer2.tileMatrixSet().tilesInRange(
QgsTileRange(0, 1023, 0, 1023), 10)
self.assertCountEqual(tiles, expected)

self.assertTrue(layer2.readLayerXml(elem, QgsReadWriteContext()))
self.assertEqual(layer2.opacity(), 0.5)
tiles = layer2.tileMatrixSet().tilesInRange(
QgsTileRange(0, 1023, 0, 1023), 10)
self.assertCountEqual(tiles, expected)


if __name__ == '__main__':
Expand Down

0 comments on commit a121e40

Please sign in to comment.