Skip to content

Commit 7d83263

Browse files
committedMar 1, 2019
[xyz] Optional scaling of XYZ tile layers
This adds "Resolution" configuration flag for XYZ tile layers. It supports several options: - unknown (default) - everything works as before - standard resolution - applies scaling - high resolution - applies scaling, assumes high-res tiles If tiles are made for standard resolution (e.g. 96 DPI) then on high res displays (e.g. 192 DPI) labels and other map features may appear very small if the resolution is not set. When configured as "standard resolution", map tiles will be picked according to this resolution and thus on high res displays the tiles will get scaled up. Similarly for print output, tiles will be scaled up so the printouts will have matching tile resolutions. The "high resolution" option is for tiles 512x512 aimed towards high-resolution displays.
1 parent 334ae0c commit 7d83263

File tree

6 files changed

+114
-49
lines changed

6 files changed

+114
-49
lines changed
 

‎src/providers/wms/qgswmscapabilities.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ struct QgsWmtsTileLayer
423423
QStringList formats;
424424
QStringList infoFormats;
425425
QString defaultStyle;
426+
int dpi = -1; //!< DPI of the tile layer (-1 for unknown DPI)
426427
//! available dimensions (optional, for multi-dimensional data)
427428
QHash<QString, QgsWmtsDimension> dimensions;
428429
QHash<QString, QgsWmtsStyle> styles;

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,10 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
655655
Q_ASSERT( mTileMatrixSet );
656656
Q_ASSERT( !mTileMatrixSet->tileMatrices.isEmpty() );
657657

658+
// if we know both source and output DPI, let's scale the tiles
659+
if ( mDpi != -1 && mTileLayer->dpi != -1 )
660+
vres *= mDpi / mTileLayer->dpi;
661+
658662
// find nearest resolution
659663
tm = mTileMatrixSet->findNearestResolution( vres );
660664
Q_ASSERT( tm );
@@ -1219,6 +1223,22 @@ void QgsWmsProvider::setupXyzCapabilities( const QString &uri )
12191223
tl.tileMode = XYZ;
12201224
tl.identifier = QStringLiteral( "xyz" ); // as set in parseUri
12211225
tl.boundingBoxes << bbox;
1226+
1227+
double tilePixelRatio = 0.; // unknown
1228+
if ( parsedUri.hasParam( QStringLiteral( "tilePixelRatio" ) ) )
1229+
tilePixelRatio = parsedUri.param( QStringLiteral( "tilePixelRatio" ) ).toDouble();
1230+
1231+
if ( tilePixelRatio != 0 )
1232+
{
1233+
// known tile pixel ratio - will be doing auto-scaling of tiles based on output DPI
1234+
tl.dpi = 96 * tilePixelRatio; // TODO: is 96 correct base DPI ?
1235+
}
1236+
else
1237+
{
1238+
// unknown tile pixel ratio - no scaling of tiles based on output DPI
1239+
tilePixelRatio = 1;
1240+
}
1241+
12221242
mCaps.mTileLayersSupported.append( tl );
12231243

12241244
QgsWmtsTileMatrixSet tms;
@@ -1239,7 +1259,7 @@ void QgsWmsProvider::setupXyzCapabilities( const QString &uri )
12391259
QgsWmtsTileMatrix tm;
12401260
tm.identifier = QString::number( zoom );
12411261
tm.topLeft = topLeft;
1242-
tm.tileWidth = tm.tileHeight = 256;
1262+
tm.tileWidth = tm.tileHeight = 256 * tilePixelRatio;
12431263
tm.matrixWidth = tm.matrixHeight = 1 << zoom;
12441264
tm.tres = xspan / ( tm.tileWidth * tm.matrixWidth );
12451265
tm.scaleDenom = 0.0;

‎src/providers/wms/qgsxyzconnection.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ QString QgsXyzConnection::encodedUri() const
3636
uri.setParam( QStringLiteral( "password" ), password );
3737
if ( ! referer.isEmpty() )
3838
uri.setParam( QStringLiteral( "referer" ), referer );
39+
if ( tilePixelRatio != 0 )
40+
uri.setParam( QStringLiteral( "tilePixelRatio" ), QString::number( tilePixelRatio ) );
3941
return uri.encodedUri();
4042
}
4143

@@ -78,6 +80,7 @@ QgsXyzConnection QgsXyzConnectionUtils::connection( const QString &name )
7880
conn.username = settings.value( QStringLiteral( "username" ) ).toString();
7981
conn.password = settings.value( QStringLiteral( "password" ) ).toString();
8082
conn.referer = settings.value( QStringLiteral( "referer" ) ).toString();
83+
conn.tilePixelRatio = settings.value( QStringLiteral( "tilePixelRatio" ), 0 ).toDouble();
8184
conn.hidden = settings.value( QStringLiteral( "hidden" ) ).toBool();
8285
return conn;
8386
}
@@ -120,6 +123,7 @@ void QgsXyzConnectionUtils::addConnection( const QgsXyzConnection &conn )
120123
settings.setValue( QStringLiteral( "username" ), conn.username );
121124
settings.setValue( QStringLiteral( "password" ), conn.password );
122125
settings.setValue( QStringLiteral( "referer" ), conn.referer );
126+
settings.setValue( QStringLiteral( "tilePixelRatio" ), conn.tilePixelRatio );
123127
if ( addHiddenProperty )
124128
{
125129
settings.setValue( QStringLiteral( "hidden" ), false );

‎src/providers/wms/qgsxyzconnection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct QgsXyzConnection
3232
QString password;
3333
// Referer
3434
QString referer;
35+
// tile pixel ratio (0 = unknown (not scaled), 1.0 = 256x256, 2.0 = 512x512)
36+
double tilePixelRatio = 0;
3537
bool hidden = false;
3638

3739
QString encodedUri() const;

‎src/providers/wms/qgsxyzconnectiondialog.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ void QgsXyzConnectionDialog::setConnection( const QgsXyzConnection &conn )
3737
mAuthSettings->setUsername( conn.username );
3838
mAuthSettings->setPassword( conn.password );
3939
mEditReferer->setText( conn.referer );
40+
int index = 0; // default is "unknown"
41+
if ( conn.tilePixelRatio == 2. )
42+
index = 2; // high-res
43+
else if ( conn.tilePixelRatio == 1. )
44+
index = 1; // normal-res
45+
mComboTileResolution->setCurrentIndex( index );
4046
mAuthSettings->setConfigId( conn.authCfg );
4147
}
4248

@@ -52,6 +58,12 @@ QgsXyzConnection QgsXyzConnectionDialog::connection() const
5258
conn.username = mAuthSettings->username();
5359
conn.password = mAuthSettings->password();
5460
conn.referer = mEditReferer->text();
61+
if ( mComboTileResolution->currentIndex() == 1 )
62+
conn.tilePixelRatio = 1.; // normal-res
63+
else if ( mComboTileResolution->currentIndex() == 2 )
64+
conn.tilePixelRatio = 2.; // high-res
65+
else
66+
conn.tilePixelRatio = 0; // unknown
5567
conn.authCfg = mAuthSettings->configId( );
5668
return conn;
5769
}

‎src/ui/qgsxyzconnectiondialog.ui

Lines changed: 74 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>525</width>
10-
<height>332</height>
9+
<width>636</width>
10+
<height>624</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -20,15 +20,18 @@
2020
<string>Connection Details</string>
2121
</property>
2222
<layout class="QGridLayout" name="gridLayout">
23-
<item row="9" column="0" colspan="2">
24-
<widget class="QLabel" name="lblReferer">
25-
<property name="text">
26-
<string>Referer</string>
23+
<item row="10" column="2">
24+
<spacer name="verticalSpacer">
25+
<property name="orientation">
26+
<enum>Qt::Vertical</enum>
2727
</property>
28-
<property name="buddy">
29-
<cstring>mEditReferer</cstring>
28+
<property name="sizeHint" stdset="0">
29+
<size>
30+
<width>20</width>
31+
<height>40</height>
32+
</size>
3033
</property>
31-
</widget>
34+
</spacer>
3235
</item>
3336
<item row="9" column="2">
3437
<widget class="QLineEdit" name="mEditReferer">
@@ -37,13 +40,10 @@
3740
</property>
3841
</widget>
3942
</item>
40-
<item row="8" column="0" colspan="2">
41-
<widget class="QCheckBox" name="mCheckBoxZMax">
43+
<item row="1" column="0">
44+
<widget class="QLabel" name="label_2">
4245
<property name="text">
43-
<string>Max. Zoom Level</string>
44-
</property>
45-
<property name="checked">
46-
<bool>true</bool>
46+
<string>URL</string>
4747
</property>
4848
</widget>
4949
</item>
@@ -60,43 +60,13 @@
6060
</property>
6161
</widget>
6262
</item>
63-
<item row="1" column="2">
64-
<widget class="QLineEdit" name="mEditUrl">
65-
<property name="toolTip">
66-
<string>URL of the connection, {z}, {y}, and {z} will be replaced with actual values. Use {-y} for inverted y axis.</string>
67-
</property>
68-
<property name="placeholderText">
69-
<string>http://example.com/{z}/{x}/{y}.png</string>
70-
</property>
71-
</widget>
72-
</item>
7363
<item row="0" column="0" colspan="2">
7464
<widget class="QLabel" name="label">
7565
<property name="text">
7666
<string>Name</string>
7767
</property>
7868
</widget>
7969
</item>
80-
<item row="0" column="2">
81-
<widget class="QLineEdit" name="mEditName">
82-
<property name="toolTip">
83-
<string>Name of the new connection</string>
84-
</property>
85-
</widget>
86-
</item>
87-
<item row="10" column="2">
88-
<spacer name="verticalSpacer">
89-
<property name="orientation">
90-
<enum>Qt::Vertical</enum>
91-
</property>
92-
<property name="sizeHint" stdset="0">
93-
<size>
94-
<width>20</width>
95-
<height>40</height>
96-
</size>
97-
</property>
98-
</spacer>
99-
</item>
10070
<item row="2" column="0" rowspan="2" colspan="3">
10171
<widget class="QGroupBox" name="mAuthGroupBox">
10272
<property name="title">
@@ -121,10 +91,40 @@
12191
</layout>
12292
</widget>
12393
</item>
124-
<item row="1" column="0">
125-
<widget class="QLabel" name="label_2">
94+
<item row="0" column="2">
95+
<widget class="QLineEdit" name="mEditName">
96+
<property name="toolTip">
97+
<string>Name of the new connection</string>
98+
</property>
99+
</widget>
100+
</item>
101+
<item row="9" column="0" colspan="2">
102+
<widget class="QLabel" name="lblReferer">
126103
<property name="text">
127-
<string>URL</string>
104+
<string>Referer</string>
105+
</property>
106+
<property name="buddy">
107+
<cstring>mEditReferer</cstring>
108+
</property>
109+
</widget>
110+
</item>
111+
<item row="1" column="2">
112+
<widget class="QLineEdit" name="mEditUrl">
113+
<property name="toolTip">
114+
<string>URL of the connection, {z}, {y}, and {z} will be replaced with actual values. Use {-y} for inverted y axis.</string>
115+
</property>
116+
<property name="placeholderText">
117+
<string>http://example.com/{z}/{x}/{y}.png</string>
118+
</property>
119+
</widget>
120+
</item>
121+
<item row="8" column="0" colspan="2">
122+
<widget class="QCheckBox" name="mCheckBoxZMax">
123+
<property name="text">
124+
<string>Max. Zoom Level</string>
125+
</property>
126+
<property name="checked">
127+
<bool>true</bool>
128128
</property>
129129
</widget>
130130
</item>
@@ -148,6 +148,32 @@
148148
</property>
149149
</widget>
150150
</item>
151+
<item row="11" column="0">
152+
<widget class="QLabel" name="label_3">
153+
<property name="text">
154+
<string>Tile Resolution</string>
155+
</property>
156+
</widget>
157+
</item>
158+
<item row="11" column="2">
159+
<widget class="QComboBox" name="mComboTileResolution">
160+
<item>
161+
<property name="text">
162+
<string>Unknown (not scaled)</string>
163+
</property>
164+
</item>
165+
<item>
166+
<property name="text">
167+
<string>Standard (256x256 / 96 DPI)</string>
168+
</property>
169+
</item>
170+
<item>
171+
<property name="text">
172+
<string>High (512x512 / 192 DPI)</string>
173+
</property>
174+
</item>
175+
</widget>
176+
</item>
151177
</layout>
152178
</widget>
153179
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.