Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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

(cherry picked from commit 87c7c46)
  • Loading branch information
nyalldawson committed Apr 17, 2021
1 parent 0c8aebe commit e8b7c9e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/vectortile/qgsvectortilelayer.cpp
Expand Up @@ -31,6 +31,9 @@
#include "qgsmapboxglstyleconverter.h"
#include "qgsjsonutils.h"

#include <QUrl>
#include <QUrlQuery>

QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseName )
: QgsMapLayer( QgsMapLayerType::VectorTileLayer, baseName )
{
Expand Down Expand Up @@ -119,9 +122,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 );

QNetworkRequest request = QNetworkRequest( url );

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

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

0 comments on commit e8b7c9e

Please sign in to comment.