[vectortiles] Also expose option to override min/max zoom level

for ESRI vector tile servers
This commit is contained in:
Nyall Dawson 2020-09-25 12:02:31 +10:00
parent d586dda9de
commit 442b721803
5 changed files with 115 additions and 30 deletions

View File

@ -53,7 +53,7 @@ bool QgsVectorTileLayer::loadDataSource()
mSourcePath = dsUri.param( QStringLiteral( "url" ) );
if ( mSourceType == QStringLiteral( "xyz" ) && dsUri.param( QStringLiteral( "serviceType" ) ) == QLatin1String( "arcgis" ) )
{
if ( !setupArcgisVectorTileServiceConnection( mSourcePath ) )
if ( !setupArcgisVectorTileServiceConnection( mSourcePath, dsUri ) )
return false;
}
else if ( mSourceType == QStringLiteral( "xyz" ) )
@ -117,7 +117,7 @@ bool QgsVectorTileLayer::loadDataSource()
return true;
}
bool QgsVectorTileLayer::setupArcgisVectorTileServiceConnection( const QString &uri )
bool QgsVectorTileLayer::setupArcgisVectorTileServiceConnection( const QString &uri, const QgsDataSourceUri &dataSourceUri )
{
QNetworkRequest request = QNetworkRequest( QUrl( uri ) );
@ -159,8 +159,17 @@ bool QgsVectorTileLayer::setupArcgisVectorTileServiceConnection( const QString &
return false;
}
mSourceMinZoom = 0;
mSourceMaxZoom = mArcgisLayerConfiguration.value( QStringLiteral( "maxzoom" ) ).toInt();
// if hardcoded zoom limits aren't specified, take them from the server
if ( !dataSourceUri.hasParam( QStringLiteral( "zmin" ) ) )
mSourceMinZoom = 0;
else
mSourceMinZoom = dataSourceUri.param( QStringLiteral( "zmin" ) ).toInt();
if ( !dataSourceUri.hasParam( QStringLiteral( "zmax" ) ) )
mSourceMaxZoom = mArcgisLayerConfiguration.value( QStringLiteral( "maxzoom" ) ).toInt();
else
mSourceMaxZoom = dataSourceUri.param( QStringLiteral( "zmax" ) ).toInt();
setExtent( QgsRectangle( -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892 ) );
return true;

View File

@ -191,7 +191,7 @@ class CORE_EXPORT QgsVectorTileLayer : public QgsMapLayer
QVariantMap mArcgisLayerConfiguration;
bool setupArcgisVectorTileServiceConnection( const QString &uri );
bool setupArcgisVectorTileServiceConnection( const QString &uri, const QgsDataSourceUri &dataSourceUri );
};

View File

@ -28,6 +28,10 @@ QgsArcgisVectorTileConnectionDialog::QgsArcgisVectorTileConnectionDialog( QWidge
setupUi( this );
QgsGui::enableAutoGeometryRestore( this );
// Behavior for min and max zoom checkbox
connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );
buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
connect( mEditName, &QLineEdit::textChanged, this, &QgsArcgisVectorTileConnectionDialog::updateOkButtonState );
connect( mEditUrl, &QLineEdit::textChanged, this, &QgsArcgisVectorTileConnectionDialog::updateOkButtonState );
@ -40,6 +44,11 @@ void QgsArcgisVectorTileConnectionDialog::setConnection( const QString &name, co
QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( uri );
mEditUrl->setText( conn.url );
mCheckBoxZMin->setChecked( conn.zMin != -1 );
mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
mCheckBoxZMax->setChecked( conn.zMax != -1 );
mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 14 );
mAuthSettings->setUsername( conn.username );
mAuthSettings->setPassword( conn.password );
mEditReferer->setText( conn.referer );
@ -56,6 +65,12 @@ QString QgsArcgisVectorTileConnectionDialog::connectionUri() const
conn.url = conn.url.left( conn.url.length() - 1 );
conn.serviceType = QgsVectorTileProviderConnection::ArcgisVectorTileService;
if ( mCheckBoxZMin->isChecked() )
conn.zMin = mSpinZMin->value();
if ( mCheckBoxZMax->isChecked() )
conn.zMax = mSpinZMax->value();
conn.username = mAuthSettings->username();
conn.password = mAuthSettings->password();
conn.referer = mEditReferer->text();
@ -71,6 +86,16 @@ QString QgsArcgisVectorTileConnectionDialog::connectionName() const
return mEditName->text();
}
void QgsArcgisVectorTileConnectionDialog::accept()
{
if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
{
QMessageBox::warning( this, tr( "Connection Properties" ), tr( "The maximum zoom level (%1) cannot be lower than the minimum zoom level (%2)." ).arg( mSpinZMax->value() ).arg( mSpinZMin->value() ) );
return;
}
QDialog::accept();
}
void QgsArcgisVectorTileConnectionDialog::updateOkButtonState()
{
bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();

View File

@ -35,6 +35,8 @@ class QgsArcgisVectorTileConnectionDialog : public QDialog, public Ui::QgsArcgis
QString connectionUri() const;
QString connectionName() const;
void accept() override;
private slots:
void updateOkButtonState();

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>529</width>
<height>335</height>
<height>386</height>
</rect>
</property>
<property name="windowTitle">
@ -20,21 +20,7 @@
<string>Connection Details</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="2">
<widget class="QLineEdit" name="mEditReferer">
<property name="toolTip">
<string>Optional custom referer</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<item row="8" column="0" colspan="3">
<widget class="QGroupBox" name="mAuthGroupBox">
<property name="title">
<string>Authentication</string>
@ -58,6 +44,26 @@
</layout>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="lblReferer">
<property name="text">
<string>Referer</string>
</property>
<property name="buddy">
<cstring>mEditReferer</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="mCheckBoxZMin">
<property name="text">
<string>Min. Zoom Level</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
@ -65,6 +71,20 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="9" column="2">
<widget class="QLineEdit" name="mEditReferer">
<property name="toolTip">
<string>Optional custom referer</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="mEditUrl">
<property name="toolTip">
@ -75,13 +95,13 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lblReferer">
<property name="text">
<string>Referer</string>
</property>
<property name="buddy">
<cstring>mEditReferer</cstring>
<item row="3" column="2">
<widget class="QSpinBox" name="mSpinZMin">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
@ -92,14 +112,37 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="2">
<widget class="QSpinBox" name="mSpinZMax">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="value">
<number>14</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="mCheckBoxZMax">
<property name="text">
<string>Max. Zoom Level</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Style URL</string>
</property>
</widget>
</item>
<item row="2" column="2">
<item row="6" column="2">
<widget class="QLineEdit" name="mEditStyleUrl">
<property name="toolTip">
<string>If specified, will override the default style defined for the layer with the entered URL</string>
@ -138,6 +181,12 @@
<tabstops>
<tabstop>mEditName</tabstop>
<tabstop>mEditUrl</tabstop>
<tabstop>mCheckBoxZMin</tabstop>
<tabstop>mSpinZMin</tabstop>
<tabstop>mCheckBoxZMax</tabstop>
<tabstop>mSpinZMax</tabstop>
<tabstop>mEditStyleUrl</tabstop>
<tabstop>mEditReferer</tabstop>
</tabstops>
<resources/>
<connections>