@@ -85,19 +85,17 @@ bool QgsVectorTileLayer::loadDataSource()
85
85
const QgsDataProvider::ReadFlags flags;
86
86
87
87
mSourceType = dsUri.param ( QStringLiteral ( " type" ) );
88
- mSourcePath = dsUri.param ( QStringLiteral ( " url" ) );
88
+ const QString sourcePath = dsUri.param ( QStringLiteral ( " url" ) );
89
89
if ( mSourceType == QLatin1String ( " xyz" ) && dsUri.param ( QStringLiteral ( " serviceType" ) ) == QLatin1String ( " arcgis" ) )
90
90
{
91
- if ( !setupArcgisVectorTileServiceConnection ( mSourcePath , dsUri ) )
91
+ if ( !setupArcgisVectorTileServiceConnection ( sourcePath , dsUri ) )
92
92
return false ;
93
-
94
- mDataProvider = std::make_unique< QgsArcGisVectorTileServiceDataProvider >( providerOptions, flags );
95
93
}
96
94
else if ( mSourceType == QLatin1String ( " xyz" ) )
97
95
{
98
- if ( !QgsVectorTileUtils::checkXYZUrlTemplate ( mSourcePath ) )
96
+ if ( !QgsVectorTileUtils::checkXYZUrlTemplate ( sourcePath ) )
99
97
{
100
- QgsDebugMsg ( QStringLiteral ( " Invalid format of URL for XYZ source: " ) + mSourcePath );
98
+ QgsDebugMsg ( QStringLiteral ( " Invalid format of URL for XYZ source: " ) + sourcePath );
101
99
return false ;
102
100
}
103
101
@@ -113,14 +111,14 @@ bool QgsVectorTileLayer::loadDataSource()
113
111
mMatrixSet = QgsVectorTileMatrixSet::fromWebMercator ( zMin, zMax );
114
112
setExtent ( QgsRectangle ( -20037508.3427892 , -20037508.3427892 , 20037508.3427892 , 20037508.3427892 ) );
115
113
116
- mDataProvider = std::make_unique< QgsXyzVectorTileDataProvider >( providerOptions, flags );
114
+ mDataProvider = std::make_unique< QgsXyzVectorTileDataProvider >( mDataSource , providerOptions, flags );
117
115
}
118
116
else if ( mSourceType == QLatin1String ( " mbtiles" ) )
119
117
{
120
- QgsMbTiles reader ( mSourcePath );
118
+ QgsMbTiles reader ( sourcePath );
121
119
if ( !reader.open () )
122
120
{
123
- QgsDebugMsg ( QStringLiteral ( " failed to open MBTiles file: " ) + mSourcePath );
121
+ QgsDebugMsg ( QStringLiteral ( " failed to open MBTiles file: " ) + sourcePath );
124
122
return false ;
125
123
}
126
124
@@ -148,14 +146,14 @@ bool QgsVectorTileLayer::loadDataSource()
148
146
r = ct.transformBoundingBox ( r );
149
147
setExtent ( r );
150
148
151
- mDataProvider = std::make_unique< QgsMbTilesVectorTileDataProvider >( providerOptions, flags );
149
+ mDataProvider = std::make_unique< QgsMbTilesVectorTileDataProvider >( mDataSource , providerOptions, flags );
152
150
}
153
151
else if ( mSourceType == QLatin1String ( " vtpk" ) )
154
152
{
155
- QgsVtpkTiles reader ( mSourcePath );
153
+ QgsVtpkTiles reader ( sourcePath );
156
154
if ( !reader.open () )
157
155
{
158
- QgsDebugMsg ( QStringLiteral ( " failed to open VTPK file: " ) + mSourcePath );
156
+ QgsDebugMsg ( QStringLiteral ( " failed to open VTPK file: " ) + sourcePath );
159
157
return false ;
160
158
}
161
159
@@ -171,7 +169,7 @@ bool QgsVectorTileLayer::loadDataSource()
171
169
setCrs ( mMatrixSet .crs () );
172
170
setExtent ( reader.extent ( transformContext () ) );
173
171
174
- mDataProvider = std::make_unique< QgsVtpkVectorTileDataProvider >( providerOptions, flags );
172
+ mDataProvider = std::make_unique< QgsVtpkVectorTileDataProvider >( mDataSource , providerOptions, flags );
175
173
}
176
174
else
177
175
{
@@ -281,10 +279,10 @@ bool QgsVectorTileLayer::setupArcgisVectorTileServiceConnection( const QString &
281
279
}
282
280
}
283
281
284
- mSourcePath = tileServiceUri + ' /' + mArcgisLayerConfiguration .value ( QStringLiteral ( " tiles" ) ).toList ().value ( 0 ).toString ();
285
- if ( !QgsVectorTileUtils::checkXYZUrlTemplate ( mSourcePath ) )
282
+ const QString sourcePath = tileServiceUri + ' /' + mArcgisLayerConfiguration .value ( QStringLiteral ( " tiles" ) ).toList ().value ( 0 ).toString ();
283
+ if ( !QgsVectorTileUtils::checkXYZUrlTemplate ( sourcePath ) )
286
284
{
287
- QgsDebugMsg ( QStringLiteral ( " Invalid format of URL for XYZ source: " ) + mSourcePath );
285
+ QgsDebugMsg ( QStringLiteral ( " Invalid format of URL for XYZ source: " ) + sourcePath );
288
286
return false ;
289
287
}
290
288
@@ -336,6 +334,10 @@ bool QgsVectorTileLayer::setupArcgisVectorTileServiceConnection( const QString &
336
334
}
337
335
}
338
336
337
+ const QgsDataProvider::ProviderOptions providerOptions { mTransformContext };
338
+ const QgsDataProvider::ReadFlags flags;
339
+ mDataProvider = std::make_unique< QgsArcGisVectorTileServiceDataProvider >( mDataSource , sourcePath, providerOptions, flags );
340
+
339
341
return true ;
340
342
}
341
343
@@ -622,10 +624,10 @@ bool QgsVectorTileLayer::loadDefaultStyleAndSubLayersPrivate( QString &error, QS
622
624
623
625
if ( mSourceType == QLatin1String ( " vtpk" ) )
624
626
{
625
- QgsVtpkTiles reader ( mSourcePath );
627
+ QgsVtpkTiles reader ( sourcePath () );
626
628
if ( !reader.open () )
627
629
{
628
- QgsDebugMsg ( QStringLiteral ( " failed to open VTPK file: " ) + mSourcePath );
630
+ QgsDebugMsg ( QStringLiteral ( " failed to open VTPK file: " ) + sourcePath () );
629
631
return false ;
630
632
}
631
633
@@ -796,10 +798,10 @@ QString QgsVectorTileLayer::loadDefaultMetadata( bool &resultFlag )
796
798
}
797
799
else if ( mSourceType == QLatin1String ( " vtpk" ) )
798
800
{
799
- QgsVtpkTiles reader ( mSourcePath );
801
+ QgsVtpkTiles reader ( sourcePath () );
800
802
if ( !reader.open () )
801
803
{
802
- QgsDebugMsg ( QStringLiteral ( " failed to open VTPK file: " ) + mSourcePath );
804
+ QgsDebugMsg ( QStringLiteral ( " failed to open VTPK file: " ) + sourcePath () );
803
805
resultFlag = false ;
804
806
}
805
807
else
@@ -891,9 +893,20 @@ QString QgsVectorTileLayer::htmlMetadata() const
891
893
return info;
892
894
}
893
895
896
+ QString QgsVectorTileLayer::sourcePath () const
897
+ {
898
+ if ( QgsVectorTileDataProvider *vtProvider = qobject_cast< QgsVectorTileDataProvider * >( mDataProvider .get () ) )
899
+ return vtProvider->sourcePath ();
900
+
901
+ return QString ();
902
+ }
903
+
894
904
QByteArray QgsVectorTileLayer::getRawTile ( QgsTileXYZ tileID )
895
905
{
896
906
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
907
+ QgsVectorTileDataProvider *vtProvider = qobject_cast< QgsVectorTileDataProvider * >( mDataProvider .get () );
908
+ if ( !vtProvider )
909
+ return QByteArray ();
897
910
898
911
const QgsTileMatrix tileMatrix = mMatrixSet .tileMatrix ( tileID.zoomLevel () );
899
912
const QgsTileRange tileRange ( tileID.column (), tileID.column (), tileID.row (), tileID.row () );
@@ -902,7 +915,7 @@ QByteArray QgsVectorTileLayer::getRawTile( QgsTileXYZ tileID )
902
915
dsUri.setEncodedUri ( mDataSource );
903
916
const QString authcfg = dsUri.authConfigId ();
904
917
905
- QList<QgsVectorTileRawData> rawTiles = QgsVectorTileLoader::blockingFetchTileRawData ( mSourceType , mSourcePath , tileMatrix, QPointF (), tileRange, authcfg, dsUri.httpHeaders () );
918
+ QList<QgsVectorTileRawData> rawTiles = QgsVectorTileLoader::blockingFetchTileRawData ( mSourceType , vtProvider-> sourcePath () , tileMatrix, QPointF (), tileRange, authcfg, dsUri.httpHeaders () );
906
919
if ( rawTiles.isEmpty () )
907
920
return QByteArray ();
908
921
return rawTiles.first ().data ;
@@ -1312,10 +1325,10 @@ void QgsVectorTileLayer::removeSelection()
1312
1325
// QgsVectorTileDataProvider
1313
1326
//
1314
1327
// /@cond PRIVATE
1315
- QgsVectorTileDataProvider::QgsVectorTileDataProvider (
1316
- const ProviderOptions &options,
1317
- QgsDataProvider::ReadFlags flags )
1318
- : QgsDataProvider( QString() , options, flags )
1328
+ QgsVectorTileDataProvider::QgsVectorTileDataProvider ( const QString &uri,
1329
+ const ProviderOptions &options,
1330
+ QgsDataProvider::ReadFlags flags )
1331
+ : QgsDataProvider( uri , options, flags )
1319
1332
{}
1320
1333
1321
1334
QgsCoordinateReferenceSystem QgsVectorTileDataProvider::crs () const
@@ -1367,42 +1380,69 @@ bool QgsVectorTileDataProvider::renderInPreview( const PreviewContext &context )
1367
1380
// QgsXyzVectorTileDataProvider
1368
1381
//
1369
1382
1370
- QgsXyzVectorTileDataProvider::QgsXyzVectorTileDataProvider ( const ProviderOptions &providerOptions, ReadFlags flags )
1371
- : QgsVectorTileDataProvider( providerOptions, flags )
1383
+ QgsXyzVectorTileDataProvider::QgsXyzVectorTileDataProvider ( const QString &uri, const ProviderOptions &providerOptions, ReadFlags flags )
1384
+ : QgsVectorTileDataProvider( uri, providerOptions, flags )
1372
1385
{
1373
1386
1374
1387
}
1375
1388
1389
+ QString QgsXyzVectorTileDataProvider::sourcePath () const
1390
+ {
1391
+ QgsDataSourceUri dsUri;
1392
+ dsUri.setEncodedUri ( dataSourceUri () );
1393
+ return dsUri.param ( QStringLiteral ( " url" ) );
1394
+ }
1395
+
1376
1396
//
1377
1397
// QgsMbTilesVectorTileDataProvider
1378
1398
//
1379
1399
1380
- QgsMbTilesVectorTileDataProvider::QgsMbTilesVectorTileDataProvider ( const ProviderOptions &providerOptions, ReadFlags flags )
1381
- : QgsVectorTileDataProvider( providerOptions, flags )
1400
+ QgsMbTilesVectorTileDataProvider::QgsMbTilesVectorTileDataProvider ( const QString &uri, const ProviderOptions &providerOptions, ReadFlags flags )
1401
+ : QgsVectorTileDataProvider( uri, providerOptions, flags )
1382
1402
{
1383
1403
1384
1404
}
1385
1405
1406
+ QString QgsMbTilesVectorTileDataProvider::sourcePath () const
1407
+ {
1408
+ QgsDataSourceUri dsUri;
1409
+ dsUri.setEncodedUri ( dataSourceUri () );
1410
+ return dsUri.param ( QStringLiteral ( " url" ) );
1411
+ }
1412
+
1386
1413
//
1387
1414
// QgsVtpkVectorTileDataProvider
1388
1415
//
1389
1416
1390
- QgsVtpkVectorTileDataProvider::QgsVtpkVectorTileDataProvider ( const ProviderOptions &providerOptions, ReadFlags flags )
1391
- : QgsVectorTileDataProvider( providerOptions, flags )
1417
+ QgsVtpkVectorTileDataProvider::QgsVtpkVectorTileDataProvider ( const QString &uri, const ProviderOptions &providerOptions, ReadFlags flags )
1418
+ : QgsVectorTileDataProvider( uri, providerOptions, flags )
1392
1419
{
1393
1420
1394
1421
}
1395
1422
1423
+ QString QgsVtpkVectorTileDataProvider::sourcePath () const
1424
+ {
1425
+ QgsDataSourceUri dsUri;
1426
+ dsUri.setEncodedUri ( dataSourceUri () );
1427
+ return dsUri.param ( QStringLiteral ( " url" ) );
1428
+ }
1429
+
1396
1430
//
1397
1431
// QgsArcGisVectorTileServiceDataProvider
1398
1432
//
1399
1433
1400
- QgsArcGisVectorTileServiceDataProvider::QgsArcGisVectorTileServiceDataProvider ( const ProviderOptions &providerOptions, ReadFlags flags )
1401
- : QgsVectorTileDataProvider( providerOptions, flags )
1434
+ QgsArcGisVectorTileServiceDataProvider::QgsArcGisVectorTileServiceDataProvider ( const QString &uri, const QString &sourcePath, const ProviderOptions &providerOptions, ReadFlags flags )
1435
+ : QgsVectorTileDataProvider( uri, providerOptions, flags )
1436
+ , mSourcePath( sourcePath )
1402
1437
{
1403
1438
1404
1439
}
1405
1440
1441
+ QString QgsArcGisVectorTileServiceDataProvider::sourcePath () const
1442
+ {
1443
+ return mSourcePath ;
1444
+ }
1445
+
1406
1446
// /@endcond
1407
1447
1408
1448
0 commit comments