Skip to content

Commit

Permalink
Fix some ArcGis VectorTileServer urls cannot be directly loaded
Browse files Browse the repository at this point in the history
Some services don't default to returning JSON for the capabilities,
so explicitly request it

Fixes #42314
  • Loading branch information
nyalldawson committed Mar 23, 2021
1 parent ddd506e commit cb93e3b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/core/vectortile/qgsvectortilelayer.cpp
Expand Up @@ -34,6 +34,7 @@
#include "qgsmaplayerfactory.h"

#include <QUrl>
#include <QUrlQuery>

QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseName )
: QgsMapLayer( QgsMapLayerType::VectorTileLayer, baseName )
Expand Down Expand Up @@ -123,9 +124,16 @@ bool QgsVectorTileLayer::loadDataSource()

bool QgsVectorTileLayer::setupArcgisVectorTileServiceConnection( const QString &uri, const QgsDataSourceUri &dataSourceUri )
{
QNetworkRequest request = QNetworkRequest( QUrl( uri ) );
QUrl url( uri );
// some services don't default to json format, while others do... so let's explicitly request it!
// (refs https://github.com/qgis/QGIS/issues/4231)
QUrlQuery query;
query.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "pjson" ) );
url.setQuery( query );

QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsVectorTileLayer" ) );
QNetworkRequest request = QNetworkRequest( url );

QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsVectorTileLayer" ) )

QgsBlockingNetworkRequest networkRequest;
switch ( networkRequest.get( request ) )
Expand Down Expand Up @@ -416,7 +424,7 @@ bool QgsVectorTileLayer::loadDefaultStyle( QString &error, QStringList &warnings
for ( int resolution = 2; resolution > 0; resolution-- )
{
QNetworkRequest request = QNetworkRequest( QUrl( spriteUriBase + QStringLiteral( "%1.json" ).arg( resolution > 1 ? QStringLiteral( "@%1x" ).arg( resolution ) : QString() ) ) );
QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsVectorTileLayer" ) );
QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsVectorTileLayer" ) )
QgsBlockingNetworkRequest networkRequest;
switch ( networkRequest.get( request ) )
{
Expand All @@ -428,7 +436,7 @@ bool QgsVectorTileLayer::loadDefaultStyle( QString &error, QStringList &warnings
// retrieve sprite images
QNetworkRequest request = QNetworkRequest( QUrl( spriteUriBase + QStringLiteral( "%1.png" ).arg( resolution > 1 ? QStringLiteral( "@%1x" ).arg( resolution ) : QString() ) ) );

QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsVectorTileLayer" ) );
QgsSetRequestInitiatorClass( request, QStringLiteral( "QgsVectorTileLayer" ) )

QgsBlockingNetworkRequest networkRequest;
switch ( networkRequest.get( request ) )
Expand Down

0 comments on commit cb93e3b

Please sign in to comment.