mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-10 00:08:20 -05:00
Move source path handling to vector tile provider subclasses
This commit is contained in:
parent
097b2ca646
commit
e3fda27d66
@ -85,19 +85,17 @@ bool QgsVectorTileLayer::loadDataSource()
|
|||||||
const QgsDataProvider::ReadFlags flags;
|
const QgsDataProvider::ReadFlags flags;
|
||||||
|
|
||||||
mSourceType = dsUri.param( QStringLiteral( "type" ) );
|
mSourceType = dsUri.param( QStringLiteral( "type" ) );
|
||||||
mSourcePath = dsUri.param( QStringLiteral( "url" ) );
|
const QString sourcePath = dsUri.param( QStringLiteral( "url" ) );
|
||||||
if ( mSourceType == QLatin1String( "xyz" ) && dsUri.param( QStringLiteral( "serviceType" ) ) == QLatin1String( "arcgis" ) )
|
if ( mSourceType == QLatin1String( "xyz" ) && dsUri.param( QStringLiteral( "serviceType" ) ) == QLatin1String( "arcgis" ) )
|
||||||
{
|
{
|
||||||
if ( !setupArcgisVectorTileServiceConnection( mSourcePath, dsUri ) )
|
if ( !setupArcgisVectorTileServiceConnection( sourcePath, dsUri ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
mDataProvider = std::make_unique< QgsArcGisVectorTileServiceDataProvider >( providerOptions, flags );
|
|
||||||
}
|
}
|
||||||
else if ( mSourceType == QLatin1String( "xyz" ) )
|
else if ( mSourceType == QLatin1String( "xyz" ) )
|
||||||
{
|
{
|
||||||
if ( !QgsVectorTileUtils::checkXYZUrlTemplate( mSourcePath ) )
|
if ( !QgsVectorTileUtils::checkXYZUrlTemplate( sourcePath ) )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QStringLiteral( "Invalid format of URL for XYZ source: " ) + mSourcePath );
|
QgsDebugMsg( QStringLiteral( "Invalid format of URL for XYZ source: " ) + sourcePath );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,14 +111,14 @@ bool QgsVectorTileLayer::loadDataSource()
|
|||||||
mMatrixSet = QgsVectorTileMatrixSet::fromWebMercator( zMin, zMax );
|
mMatrixSet = QgsVectorTileMatrixSet::fromWebMercator( zMin, zMax );
|
||||||
setExtent( QgsRectangle( -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892 ) );
|
setExtent( QgsRectangle( -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892 ) );
|
||||||
|
|
||||||
mDataProvider = std::make_unique< QgsXyzVectorTileDataProvider >( providerOptions, flags );
|
mDataProvider = std::make_unique< QgsXyzVectorTileDataProvider >( mDataSource, providerOptions, flags );
|
||||||
}
|
}
|
||||||
else if ( mSourceType == QLatin1String( "mbtiles" ) )
|
else if ( mSourceType == QLatin1String( "mbtiles" ) )
|
||||||
{
|
{
|
||||||
QgsMbTiles reader( mSourcePath );
|
QgsMbTiles reader( sourcePath );
|
||||||
if ( !reader.open() )
|
if ( !reader.open() )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QStringLiteral( "failed to open MBTiles file: " ) + mSourcePath );
|
QgsDebugMsg( QStringLiteral( "failed to open MBTiles file: " ) + sourcePath );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,14 +146,14 @@ bool QgsVectorTileLayer::loadDataSource()
|
|||||||
r = ct.transformBoundingBox( r );
|
r = ct.transformBoundingBox( r );
|
||||||
setExtent( r );
|
setExtent( r );
|
||||||
|
|
||||||
mDataProvider = std::make_unique< QgsMbTilesVectorTileDataProvider >( providerOptions, flags );
|
mDataProvider = std::make_unique< QgsMbTilesVectorTileDataProvider >( mDataSource, providerOptions, flags );
|
||||||
}
|
}
|
||||||
else if ( mSourceType == QLatin1String( "vtpk" ) )
|
else if ( mSourceType == QLatin1String( "vtpk" ) )
|
||||||
{
|
{
|
||||||
QgsVtpkTiles reader( mSourcePath );
|
QgsVtpkTiles reader( sourcePath );
|
||||||
if ( !reader.open() )
|
if ( !reader.open() )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QStringLiteral( "failed to open VTPK file: " ) + mSourcePath );
|
QgsDebugMsg( QStringLiteral( "failed to open VTPK file: " ) + sourcePath );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +169,7 @@ bool QgsVectorTileLayer::loadDataSource()
|
|||||||
setCrs( mMatrixSet.crs() );
|
setCrs( mMatrixSet.crs() );
|
||||||
setExtent( reader.extent( transformContext() ) );
|
setExtent( reader.extent( transformContext() ) );
|
||||||
|
|
||||||
mDataProvider = std::make_unique< QgsVtpkVectorTileDataProvider >( providerOptions, flags );
|
mDataProvider = std::make_unique< QgsVtpkVectorTileDataProvider >( mDataSource, providerOptions, flags );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -281,10 +279,10 @@ bool QgsVectorTileLayer::setupArcgisVectorTileServiceConnection( const QString &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mSourcePath = tileServiceUri + '/' + mArcgisLayerConfiguration.value( QStringLiteral( "tiles" ) ).toList().value( 0 ).toString();
|
const QString sourcePath = tileServiceUri + '/' + mArcgisLayerConfiguration.value( QStringLiteral( "tiles" ) ).toList().value( 0 ).toString();
|
||||||
if ( !QgsVectorTileUtils::checkXYZUrlTemplate( mSourcePath ) )
|
if ( !QgsVectorTileUtils::checkXYZUrlTemplate( sourcePath ) )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QStringLiteral( "Invalid format of URL for XYZ source: " ) + mSourcePath );
|
QgsDebugMsg( QStringLiteral( "Invalid format of URL for XYZ source: " ) + sourcePath );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,6 +334,10 @@ bool QgsVectorTileLayer::setupArcgisVectorTileServiceConnection( const QString &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QgsDataProvider::ProviderOptions providerOptions { mTransformContext };
|
||||||
|
const QgsDataProvider::ReadFlags flags;
|
||||||
|
mDataProvider = std::make_unique< QgsArcGisVectorTileServiceDataProvider >( mDataSource, sourcePath, providerOptions, flags );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,10 +624,10 @@ bool QgsVectorTileLayer::loadDefaultStyleAndSubLayersPrivate( QString &error, QS
|
|||||||
|
|
||||||
if ( mSourceType == QLatin1String( "vtpk" ) )
|
if ( mSourceType == QLatin1String( "vtpk" ) )
|
||||||
{
|
{
|
||||||
QgsVtpkTiles reader( mSourcePath );
|
QgsVtpkTiles reader( sourcePath() );
|
||||||
if ( !reader.open() )
|
if ( !reader.open() )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QStringLiteral( "failed to open VTPK file: " ) + mSourcePath );
|
QgsDebugMsg( QStringLiteral( "failed to open VTPK file: " ) + sourcePath() );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -796,10 +798,10 @@ QString QgsVectorTileLayer::loadDefaultMetadata( bool &resultFlag )
|
|||||||
}
|
}
|
||||||
else if ( mSourceType == QLatin1String( "vtpk" ) )
|
else if ( mSourceType == QLatin1String( "vtpk" ) )
|
||||||
{
|
{
|
||||||
QgsVtpkTiles reader( mSourcePath );
|
QgsVtpkTiles reader( sourcePath() );
|
||||||
if ( !reader.open() )
|
if ( !reader.open() )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( QStringLiteral( "failed to open VTPK file: " ) + mSourcePath );
|
QgsDebugMsg( QStringLiteral( "failed to open VTPK file: " ) + sourcePath() );
|
||||||
resultFlag = false;
|
resultFlag = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -891,9 +893,20 @@ QString QgsVectorTileLayer::htmlMetadata() const
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsVectorTileLayer::sourcePath() const
|
||||||
|
{
|
||||||
|
if ( QgsVectorTileDataProvider *vtProvider = qobject_cast< QgsVectorTileDataProvider * >( mDataProvider.get() ) )
|
||||||
|
return vtProvider->sourcePath();
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray QgsVectorTileLayer::getRawTile( QgsTileXYZ tileID )
|
QByteArray QgsVectorTileLayer::getRawTile( QgsTileXYZ tileID )
|
||||||
{
|
{
|
||||||
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
|
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
|
||||||
|
QgsVectorTileDataProvider *vtProvider = qobject_cast< QgsVectorTileDataProvider * >( mDataProvider.get() );
|
||||||
|
if ( !vtProvider )
|
||||||
|
return QByteArray();
|
||||||
|
|
||||||
const QgsTileMatrix tileMatrix = mMatrixSet.tileMatrix( tileID.zoomLevel() );
|
const QgsTileMatrix tileMatrix = mMatrixSet.tileMatrix( tileID.zoomLevel() );
|
||||||
const QgsTileRange tileRange( tileID.column(), tileID.column(), tileID.row(), tileID.row() );
|
const QgsTileRange tileRange( tileID.column(), tileID.column(), tileID.row(), tileID.row() );
|
||||||
@ -902,7 +915,7 @@ QByteArray QgsVectorTileLayer::getRawTile( QgsTileXYZ tileID )
|
|||||||
dsUri.setEncodedUri( mDataSource );
|
dsUri.setEncodedUri( mDataSource );
|
||||||
const QString authcfg = dsUri.authConfigId();
|
const QString authcfg = dsUri.authConfigId();
|
||||||
|
|
||||||
QList<QgsVectorTileRawData> rawTiles = QgsVectorTileLoader::blockingFetchTileRawData( mSourceType, mSourcePath, tileMatrix, QPointF(), tileRange, authcfg, dsUri.httpHeaders() );
|
QList<QgsVectorTileRawData> rawTiles = QgsVectorTileLoader::blockingFetchTileRawData( mSourceType, vtProvider->sourcePath(), tileMatrix, QPointF(), tileRange, authcfg, dsUri.httpHeaders() );
|
||||||
if ( rawTiles.isEmpty() )
|
if ( rawTiles.isEmpty() )
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
return rawTiles.first().data;
|
return rawTiles.first().data;
|
||||||
@ -1312,10 +1325,10 @@ void QgsVectorTileLayer::removeSelection()
|
|||||||
// QgsVectorTileDataProvider
|
// QgsVectorTileDataProvider
|
||||||
//
|
//
|
||||||
///@cond PRIVATE
|
///@cond PRIVATE
|
||||||
QgsVectorTileDataProvider::QgsVectorTileDataProvider(
|
QgsVectorTileDataProvider::QgsVectorTileDataProvider( const QString &uri,
|
||||||
const ProviderOptions &options,
|
const ProviderOptions &options,
|
||||||
QgsDataProvider::ReadFlags flags )
|
QgsDataProvider::ReadFlags flags )
|
||||||
: QgsDataProvider( QString(), options, flags )
|
: QgsDataProvider( uri, options, flags )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QgsCoordinateReferenceSystem QgsVectorTileDataProvider::crs() const
|
QgsCoordinateReferenceSystem QgsVectorTileDataProvider::crs() const
|
||||||
@ -1367,42 +1380,69 @@ bool QgsVectorTileDataProvider::renderInPreview( const PreviewContext &context )
|
|||||||
// QgsXyzVectorTileDataProvider
|
// QgsXyzVectorTileDataProvider
|
||||||
//
|
//
|
||||||
|
|
||||||
QgsXyzVectorTileDataProvider::QgsXyzVectorTileDataProvider( const ProviderOptions &providerOptions, ReadFlags flags )
|
QgsXyzVectorTileDataProvider::QgsXyzVectorTileDataProvider( const QString &uri, const ProviderOptions &providerOptions, ReadFlags flags )
|
||||||
: QgsVectorTileDataProvider( providerOptions, flags )
|
: QgsVectorTileDataProvider( uri, providerOptions, flags )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsXyzVectorTileDataProvider::sourcePath() const
|
||||||
|
{
|
||||||
|
QgsDataSourceUri dsUri;
|
||||||
|
dsUri.setEncodedUri( dataSourceUri() );
|
||||||
|
return dsUri.param( QStringLiteral( "url" ) );
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// QgsMbTilesVectorTileDataProvider
|
// QgsMbTilesVectorTileDataProvider
|
||||||
//
|
//
|
||||||
|
|
||||||
QgsMbTilesVectorTileDataProvider::QgsMbTilesVectorTileDataProvider( const ProviderOptions &providerOptions, ReadFlags flags )
|
QgsMbTilesVectorTileDataProvider::QgsMbTilesVectorTileDataProvider( const QString &uri, const ProviderOptions &providerOptions, ReadFlags flags )
|
||||||
: QgsVectorTileDataProvider( providerOptions, flags )
|
: QgsVectorTileDataProvider( uri, providerOptions, flags )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsMbTilesVectorTileDataProvider::sourcePath() const
|
||||||
|
{
|
||||||
|
QgsDataSourceUri dsUri;
|
||||||
|
dsUri.setEncodedUri( dataSourceUri() );
|
||||||
|
return dsUri.param( QStringLiteral( "url" ) );
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// QgsVtpkVectorTileDataProvider
|
// QgsVtpkVectorTileDataProvider
|
||||||
//
|
//
|
||||||
|
|
||||||
QgsVtpkVectorTileDataProvider::QgsVtpkVectorTileDataProvider( const ProviderOptions &providerOptions, ReadFlags flags )
|
QgsVtpkVectorTileDataProvider::QgsVtpkVectorTileDataProvider( const QString &uri, const ProviderOptions &providerOptions, ReadFlags flags )
|
||||||
: QgsVectorTileDataProvider( providerOptions, flags )
|
: QgsVectorTileDataProvider( uri, providerOptions, flags )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsVtpkVectorTileDataProvider::sourcePath() const
|
||||||
|
{
|
||||||
|
QgsDataSourceUri dsUri;
|
||||||
|
dsUri.setEncodedUri( dataSourceUri() );
|
||||||
|
return dsUri.param( QStringLiteral( "url" ) );
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// QgsArcGisVectorTileServiceDataProvider
|
// QgsArcGisVectorTileServiceDataProvider
|
||||||
//
|
//
|
||||||
|
|
||||||
QgsArcGisVectorTileServiceDataProvider::QgsArcGisVectorTileServiceDataProvider( const ProviderOptions &providerOptions, ReadFlags flags )
|
QgsArcGisVectorTileServiceDataProvider::QgsArcGisVectorTileServiceDataProvider( const QString &uri, const QString &sourcePath, const ProviderOptions &providerOptions, ReadFlags flags )
|
||||||
: QgsVectorTileDataProvider( providerOptions, flags )
|
: QgsVectorTileDataProvider( uri, providerOptions, flags )
|
||||||
|
, mSourcePath( sourcePath )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsArcGisVectorTileServiceDataProvider::sourcePath() const
|
||||||
|
{
|
||||||
|
return mSourcePath;
|
||||||
|
}
|
||||||
|
|
||||||
///@endcond
|
///@endcond
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -188,7 +188,7 @@ class CORE_EXPORT QgsVectorTileLayer : public QgsMapLayer
|
|||||||
//! Returns type of the data source
|
//! Returns type of the data source
|
||||||
QString sourceType() const { return mSourceType; }
|
QString sourceType() const { return mSourceType; }
|
||||||
//! Returns URL/path of the data source (syntax different to each data source type)
|
//! Returns URL/path of the data source (syntax different to each data source type)
|
||||||
QString sourcePath() const { return mSourcePath; }
|
QString sourcePath() const;
|
||||||
|
|
||||||
//! Returns minimum zoom level at which source has any valid tiles (negative = unconstrained)
|
//! Returns minimum zoom level at which source has any valid tiles (negative = unconstrained)
|
||||||
int sourceMinZoom() const { return mMatrixSet.minimumZoom(); }
|
int sourceMinZoom() const { return mMatrixSet.minimumZoom(); }
|
||||||
@ -290,8 +290,6 @@ class CORE_EXPORT QgsVectorTileLayer : public QgsMapLayer
|
|||||||
private:
|
private:
|
||||||
//! Type of the data source
|
//! Type of the data source
|
||||||
QString mSourceType;
|
QString mSourceType;
|
||||||
//! URL/Path of the data source
|
|
||||||
QString mSourcePath;
|
|
||||||
|
|
||||||
QgsVectorTileMatrixSet mMatrixSet;
|
QgsVectorTileMatrixSet mMatrixSet;
|
||||||
|
|
||||||
@ -334,7 +332,8 @@ class QgsVectorTileDataProvider : public QgsDataProvider
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QgsVectorTileDataProvider( const QgsDataProvider::ProviderOptions &providerOptions,
|
QgsVectorTileDataProvider( const QString &uri,
|
||||||
|
const QgsDataProvider::ProviderOptions &providerOptions,
|
||||||
QgsDataProvider::ReadFlags flags );
|
QgsDataProvider::ReadFlags flags );
|
||||||
QgsCoordinateReferenceSystem crs() const override;
|
QgsCoordinateReferenceSystem crs() const override;
|
||||||
QString name() const override;
|
QString name() const override;
|
||||||
@ -343,6 +342,8 @@ class QgsVectorTileDataProvider : public QgsDataProvider
|
|||||||
bool isValid() const override;
|
bool isValid() const override;
|
||||||
bool renderInPreview( const QgsDataProvider::PreviewContext &context ) override;
|
bool renderInPreview( const QgsDataProvider::PreviewContext &context ) override;
|
||||||
|
|
||||||
|
virtual QString sourcePath() const = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class QgsXyzVectorTileDataProvider : public QgsVectorTileDataProvider
|
class QgsXyzVectorTileDataProvider : public QgsVectorTileDataProvider
|
||||||
@ -350,9 +351,12 @@ class QgsXyzVectorTileDataProvider : public QgsVectorTileDataProvider
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QgsXyzVectorTileDataProvider( const QgsDataProvider::ProviderOptions &providerOptions,
|
QgsXyzVectorTileDataProvider( const QString &uri,
|
||||||
|
const QgsDataProvider::ProviderOptions &providerOptions,
|
||||||
QgsDataProvider::ReadFlags flags );
|
QgsDataProvider::ReadFlags flags );
|
||||||
|
|
||||||
|
QString sourcePath() const override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class QgsMbTilesVectorTileDataProvider : public QgsVectorTileDataProvider
|
class QgsMbTilesVectorTileDataProvider : public QgsVectorTileDataProvider
|
||||||
@ -360,9 +364,12 @@ class QgsMbTilesVectorTileDataProvider : public QgsVectorTileDataProvider
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QgsMbTilesVectorTileDataProvider( const QgsDataProvider::ProviderOptions &providerOptions,
|
QgsMbTilesVectorTileDataProvider( const QString &uri,
|
||||||
|
const QgsDataProvider::ProviderOptions &providerOptions,
|
||||||
QgsDataProvider::ReadFlags flags );
|
QgsDataProvider::ReadFlags flags );
|
||||||
|
|
||||||
|
QString sourcePath() const override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class QgsVtpkVectorTileDataProvider : public QgsVectorTileDataProvider
|
class QgsVtpkVectorTileDataProvider : public QgsVectorTileDataProvider
|
||||||
@ -370,8 +377,11 @@ class QgsVtpkVectorTileDataProvider : public QgsVectorTileDataProvider
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QgsVtpkVectorTileDataProvider( const QgsDataProvider::ProviderOptions &providerOptions,
|
QgsVtpkVectorTileDataProvider( const QString &uri,
|
||||||
|
const QgsDataProvider::ProviderOptions &providerOptions,
|
||||||
QgsDataProvider::ReadFlags flags );
|
QgsDataProvider::ReadFlags flags );
|
||||||
|
|
||||||
|
QString sourcePath() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QgsArcGisVectorTileServiceDataProvider : public QgsVectorTileDataProvider
|
class QgsArcGisVectorTileServiceDataProvider : public QgsVectorTileDataProvider
|
||||||
@ -379,8 +389,15 @@ class QgsArcGisVectorTileServiceDataProvider : public QgsVectorTileDataProvider
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QgsArcGisVectorTileServiceDataProvider( const QgsDataProvider::ProviderOptions &providerOptions,
|
QgsArcGisVectorTileServiceDataProvider( const QString &uri,
|
||||||
|
const QString &sourcePath,
|
||||||
|
const QgsDataProvider::ProviderOptions &providerOptions,
|
||||||
QgsDataProvider::ReadFlags flags );
|
QgsDataProvider::ReadFlags flags );
|
||||||
|
QString sourcePath() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QString mSourcePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
///@endcond
|
///@endcond
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user