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

[Backport release-3_40] [vector tiles] Fix handling of zoom levels for mbtiles datasets #60395

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
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
23 changes: 17 additions & 6 deletions src/core/vectortile/qgsmbtilesvectortiledataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,26 @@ QgsMbTilesVectorTileDataProvider::QgsMbTilesVectorTileDataProvider( const QStrin

QgsDebugMsgLevel( QStringLiteral( "name: " ) + reader.metadataValue( QStringLiteral( "name" ) ), 2 );

mMatrixSet = QgsVectorTileMatrixSet::fromWebMercator();

bool minZoomOk, maxZoomOk;
const int minZoom = reader.metadataValue( QStringLiteral( "minzoom" ) ).toInt( &minZoomOk );
const int maxZoom = reader.metadataValue( QStringLiteral( "maxzoom" ) ).toInt( &maxZoomOk );
if ( minZoomOk )
mMatrixSet.dropMatricesOutsideZoomRange( minZoom, 99 );
if ( maxZoomOk )
mMatrixSet.dropMatricesOutsideZoomRange( 0, maxZoom );
if ( minZoomOk && maxZoomOk )
{
mMatrixSet = QgsVectorTileMatrixSet::fromWebMercator( minZoom, maxZoom );
}
else if ( minZoomOk )
{
mMatrixSet = QgsVectorTileMatrixSet::fromWebMercator( minZoom, 99 );
}
else if ( maxZoomOk )
{
mMatrixSet = QgsVectorTileMatrixSet::fromWebMercator( 0, maxZoom );
}
else
{
mMatrixSet = QgsVectorTileMatrixSet::fromWebMercator();
}

QgsDebugMsgLevel( QStringLiteral( "zoom range: %1 - %2" ).arg( mMatrixSet.minimumZoom() ).arg( mMatrixSet.maximumZoom() ), 2 );

QgsRectangle r = reader.extent();
Expand Down
12 changes: 12 additions & 0 deletions tests/src/core/testqgsvectortilelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class TestQgsVectorTileLayer : public QgsTest
void testMbtilesProviderMetadata();
void test_relativePathsMbTiles();
void test_absoluteRelativeUriMbTiles();
void test_mbtilesZoom16();

void test_relativePathsXyz();
void test_absoluteRelativeUriXyz();
Expand Down Expand Up @@ -371,6 +372,17 @@ void TestQgsVectorTileLayer::test_absoluteRelativeUriMbTiles()
QCOMPARE( vectorTileMetadata->relativeToAbsoluteUri( relativeUri, context ), absoluteUri );
}

void TestQgsVectorTileLayer::test_mbtilesZoom16()
{
const QString srcMbtiles = QStringLiteral( "type=mbtiles&url=%1/vector_tile/z16.mbtiles" ).arg( TEST_DATA_DIR );

std::unique_ptr<QgsVectorTileLayer> layer = std::make_unique<QgsVectorTileLayer>( srcMbtiles );
QVERIFY( layer->isValid() );
QCOMPARE( layer->providerType(), QStringLiteral( "mbtilesvectortiles" ) );
QCOMPARE( layer->sourceMinZoom(), 16 );
QCOMPARE( layer->sourceMaxZoom(), 16 );
}

void TestQgsVectorTileLayer::test_relativePathsXyz()
{
QgsReadWriteContext contextRel;
Expand Down
Binary file added tests/testdata/vector_tile/z16.mbtiles
Binary file not shown.
Loading