@@ -1367,7 +1367,11 @@ bool QgsVectorTileDataProvider::supportsAsync() const
1367
1367
QgsXyzVectorTileDataProvider::QgsXyzVectorTileDataProvider ( const QString &uri, const ProviderOptions &providerOptions, ReadFlags flags )
1368
1368
: QgsVectorTileDataProvider( uri, providerOptions, flags )
1369
1369
{
1370
+ QgsDataSourceUri dsUri;
1371
+ dsUri.setEncodedUri ( uri );
1370
1372
1373
+ mAuthCfg = dsUri.authConfigId ();
1374
+ mHeaders = dsUri.httpHeaders ();
1371
1375
}
1372
1376
1373
1377
QgsVectorTileDataProvider *QgsXyzVectorTileDataProvider::clone () const
@@ -1409,27 +1413,48 @@ bool QgsXyzVectorTileDataProvider::supportsAsync() const
1409
1413
1410
1414
QByteArray QgsXyzVectorTileDataProvider::readTile ( const QgsTileMatrix &tileMatrix, const QgsTileXYZ &id, QgsFeedback *feedback ) const
1411
1415
{
1412
- QgsDataSourceUri dsUri;
1413
- dsUri.setEncodedUri ( dataSourceUri () );
1414
- const QString authcfg = dsUri.authConfigId ();
1415
-
1416
- const QgsTileRange tileRange ( id.column (), id.column (), id.row (), id.row () );
1417
-
1418
- QList<QgsVectorTileRawData> rawTiles = QgsVectorTileLoader::blockingFetchTileRawData ( QStringLiteral ( " xyz" ),
1419
- dsUri.param ( QStringLiteral ( " url" ) ),
1420
- tileMatrix,
1421
- QPointF (),
1422
- tileRange,
1423
- authcfg,
1424
- dsUri.httpHeaders () );
1425
- if ( rawTiles.isEmpty () )
1426
- return QByteArray ();
1427
- return rawTiles.first ().data ;
1416
+ return loadFromNetwork ( id, tileMatrix, sourcePath (), mAuthCfg , mHeaders , feedback );
1428
1417
}
1429
1418
1430
- QList<QgsVectorTileRawData> QgsXyzVectorTileDataProvider::readTiles ( const QgsTileMatrix &, const QVector<QgsTileXYZ> &tiles, QgsFeedback *feedback ) const
1419
+ QList<QgsVectorTileRawData> QgsXyzVectorTileDataProvider::readTiles ( const QgsTileMatrix &tileMatrix , const QVector<QgsTileXYZ> &tiles, QgsFeedback *feedback ) const
1431
1420
{
1421
+ QList<QgsVectorTileRawData> rawTiles;
1422
+ rawTiles.reserve ( tiles.size () );
1423
+ const QString source = sourcePath ();
1424
+ for ( QgsTileXYZ id : std::as_const ( tiles ) )
1425
+ {
1426
+ if ( feedback && feedback->isCanceled () )
1427
+ break ;
1432
1428
1429
+ const QByteArray rawData = loadFromNetwork ( id, tileMatrix, source, mAuthCfg , mHeaders , feedback );
1430
+ if ( !rawData.isEmpty () )
1431
+ {
1432
+ rawTiles.append ( QgsVectorTileRawData ( id, rawData ) );
1433
+ }
1434
+ }
1435
+ return rawTiles;
1436
+ }
1437
+
1438
+ QByteArray QgsXyzVectorTileDataProvider::loadFromNetwork ( const QgsTileXYZ &id, const QgsTileMatrix &tileMatrix, const QString &requestUrl, const QString &authid, const QgsHttpHeaders &headers, QgsFeedback *feedback )
1439
+ {
1440
+ QString url = QgsVectorTileUtils::formatXYZUrlTemplate ( requestUrl, id, tileMatrix );
1441
+ QNetworkRequest nr;
1442
+ nr.setUrl ( QUrl ( url ) );
1443
+
1444
+ headers.updateNetworkRequest ( nr );
1445
+
1446
+ QgsBlockingNetworkRequest req;
1447
+ req.setAuthCfg ( authid );
1448
+ QgsDebugMsgLevel ( QStringLiteral ( " Blocking request: " ) + url, 2 );
1449
+ QgsBlockingNetworkRequest::ErrorCode errCode = req.get ( nr, false , feedback );
1450
+ if ( errCode != QgsBlockingNetworkRequest::NoError )
1451
+ {
1452
+ QgsDebugMsg ( QStringLiteral ( " Request failed: " ) + url );
1453
+ return QByteArray ();
1454
+ }
1455
+ QgsNetworkReplyContent reply = req.reply ();
1456
+ QgsDebugMsgLevel ( QStringLiteral ( " Request successful, content size %1" ).arg ( reply.content ().size () ), 2 );
1457
+ return reply.content ();
1433
1458
}
1434
1459
1435
1460
//
@@ -1474,7 +1499,7 @@ QgsCoordinateReferenceSystem QgsMbTilesVectorTileDataProvider::crs() const
1474
1499
return QgsCoordinateReferenceSystem ( QStringLiteral ( " EPSG:3857" ) );
1475
1500
}
1476
1501
1477
- QByteArray QgsMbTilesVectorTileDataProvider::readTile ( const QgsTileMatrix &tileMatrix , const QgsTileXYZ &id, QgsFeedback *feedback ) const
1502
+ QByteArray QgsMbTilesVectorTileDataProvider::readTile ( const QgsTileMatrix &, const QgsTileXYZ &id, QgsFeedback *feedback ) const
1478
1503
{
1479
1504
QgsDataSourceUri dsUri;
1480
1505
dsUri.setEncodedUri ( dataSourceUri () );
@@ -1622,7 +1647,7 @@ QByteArray QgsVtpkVectorTileDataProvider::loadFromVtpk( QgsVtpkTiles &vtpkTileRe
1622
1647
//
1623
1648
1624
1649
QgsArcGisVectorTileServiceDataProvider::QgsArcGisVectorTileServiceDataProvider ( const QString &uri, const QString &sourcePath, const ProviderOptions &providerOptions, ReadFlags flags )
1625
- : QgsVectorTileDataProvider ( uri, providerOptions, flags )
1650
+ : QgsXyzVectorTileDataProvider ( uri, providerOptions, flags )
1626
1651
, mSourcePath( sourcePath )
1627
1652
{
1628
1653
@@ -1651,38 +1676,6 @@ bool QgsArcGisVectorTileServiceDataProvider::isValid() const
1651
1676
return true ;
1652
1677
}
1653
1678
1654
- QgsCoordinateReferenceSystem QgsArcGisVectorTileServiceDataProvider::crs () const
1655
- {
1656
- QGIS_PROTECT_QOBJECT_THREAD_ACCESS
1657
-
1658
- return QgsCoordinateReferenceSystem ( QStringLiteral ( " EPSG:3857" ) );
1659
- }
1660
-
1661
- QByteArray QgsArcGisVectorTileServiceDataProvider::readTile ( const QgsTileMatrix &tileMatrix, const QgsTileXYZ &id, QgsFeedback *feedback ) const
1662
- {
1663
- QgsDataSourceUri dsUri;
1664
- dsUri.setEncodedUri ( dataSourceUri () );
1665
- const QString authcfg = dsUri.authConfigId ();
1666
-
1667
- const QgsTileRange tileRange ( id.column (), id.column (), id.row (), id.row () );
1668
-
1669
- QList<QgsVectorTileRawData> rawTiles = QgsVectorTileLoader::blockingFetchTileRawData ( QStringLiteral ( " xyz" ),
1670
- mSourcePath ,
1671
- tileMatrix,
1672
- QPointF (),
1673
- tileRange,
1674
- authcfg,
1675
- dsUri.httpHeaders () );
1676
- if ( rawTiles.isEmpty () )
1677
- return QByteArray ();
1678
- return rawTiles.first ().data ;
1679
- }
1680
-
1681
- QList<QgsVectorTileRawData> QgsArcGisVectorTileServiceDataProvider::readTiles ( const QgsTileMatrix &, const QVector<QgsTileXYZ> &tiles, QgsFeedback *feedback ) const
1682
- {
1683
-
1684
- }
1685
-
1686
1679
// /@endcond
1687
1680
1688
1681
0 commit comments