Skip to content
Permalink
Browse files

Fix some ArcGis VectorTileServer urls cannot be directly loaded

Some services don't default to returning JSON for the capabilities,
so explicitly request it

Fixes #42314
  • Loading branch information
nyalldawson authored and github-actions committed Mar 22, 2021
1 parent 6239efc commit 61fcbbcc171bfab7c8d73011c9be5e7c5d5dfbb4
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/core/vectortile/qgsvectortilelayer.cpp
@@ -34,6 +34,7 @@
#include "qgsmaplayerfactory.h"

#include <QUrl>
#include <QUrlQuery>

QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseName )
: QgsMapLayer( QgsMapLayerType::VectorTileLayer, baseName )
@@ -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 ) )
@@ -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 ) )
{
@@ -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 ) )

0 comments on commit 61fcbbc

Please sign in to comment.