Skip to content

Commit fad13f4

Browse files
committedApr 1, 2012
[FEATURE]: possibility to set MaxWidth and MaxHeight for GetMap request
1 parent f244373 commit fad13f4

File tree

8 files changed

+293
-142
lines changed

8 files changed

+293
-142
lines changed
 

‎src/app/qgsprojectproperties.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,20 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
229229
bool addWktGeometry = QgsProject::instance()->readBoolEntry( "WMSAddWktGeometry", "/" );
230230
mAddWktGeometryCheckBox->setChecked( addWktGeometry );
231231

232+
//WMS maxWidth / maxHeight
233+
mMaxWidthLineEdit->setValidator( new QIntValidator( mMaxWidthLineEdit ) );
234+
int maxWidth = QgsProject::instance()->readNumEntry( "WMSMaxWidth", "/", -1 );
235+
if ( maxWidth != -1 )
236+
{
237+
mMaxWidthLineEdit->setText( QString::number( maxWidth ) );
238+
}
239+
mMaxHeightLineEdit->setValidator( new QIntValidator( mMaxHeightLineEdit ) );
240+
int maxHeight = QgsProject::instance()->readNumEntry( "WMSMaxHeight", "/", -1 );
241+
if ( maxHeight != -1 )
242+
{
243+
mMaxHeightLineEdit->setText( QString::number( maxHeight ) );
244+
}
245+
232246
QStringList wfsLayerIdList = QgsProject::instance()->readListEntry( "WFSLayers", "/" );
233247

234248
twWFSLayers->setColumnCount( 2 );
@@ -460,6 +474,25 @@ void QgsProjectProperties::apply()
460474

461475
QgsProject::instance()->writeEntry( "WMSAddWktGeometry", "/", mAddWktGeometryCheckBox->isChecked() );
462476

477+
QString maxWidthText = mMaxWidthLineEdit->text();
478+
if ( maxWidthText.isEmpty() )
479+
{
480+
QgsProject::instance()->removeEntry( "WMSMaxWidth", "/" );
481+
}
482+
else
483+
{
484+
QgsProject::instance()->writeEntry( "WMSMaxWidth", "/", maxWidthText.toInt() );
485+
}
486+
QString maxHeightText = mMaxHeightLineEdit->text();
487+
if ( maxHeightText.isEmpty() )
488+
{
489+
QgsProject::instance()->removeEntry( "WMSMaxHeight", "/" );
490+
}
491+
else
492+
{
493+
QgsProject::instance()->writeEntry( "WMSMaxHeight", "/", maxHeightText.toInt() );
494+
}
495+
463496
QStringList wfsLayerList;
464497
for ( int i = 0; i < twWFSLayers->rowCount(); i++ )
465498
{

‎src/mapserver/qgsconfigparser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ QgsConfigParser::QgsConfigParser()
3131
: mFallbackParser( 0 )
3232
, mScaleDenominator( 0 )
3333
, mOutputUnits( QgsMapRenderer::Millimeters )
34+
, mMaxWidth( -1 )
35+
, mMaxHeight( -1 )
3436
{
3537
setDefaultLegendSettings();
3638
mSelectionColor = QColor( 255, 255, 0 ); //yellow opaque is default selection color

‎src/mapserver/qgsconfigparser.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class QgsConfigParser
121121
QColor selectionColor() const { return mSelectionColor; }
122122
void setSelectionColor( const QColor& c ) { mSelectionColor = c; }
123123

124+
int maxWidth() const { return mMaxWidth; }
125+
int maxHeight() const { return mMaxHeight; }
126+
124127
protected:
125128
/**Parser to forward not resolved requests (e.g. SLD parser based on user request might have a fallback parser with admin configuration)*/
126129
QgsConfigParser* mFallbackParser;
@@ -160,6 +163,10 @@ class QgsConfigParser
160163

161164
QColor mSelectionColor;
162165

166+
//maximum width/height for the GetMap request. Disabled by default (-1)
167+
int mMaxWidth;
168+
int mMaxHeight;
169+
163170
/**Transforms layer extent to epsg 4326 and appends ExGeographicBoundingBox and BoundingBox elements to the layer element*/
164171
void appendLayerBoundingBoxes( QDomElement& layerElem, QDomDocument& doc, const QgsRectangle& layerExtent, const QgsCoordinateReferenceSystem& layerCRS ) const;
165172

‎src/mapserver/qgsprojectparser.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ QgsProjectParser::QgsProjectParser( QDomDocument* xmlDoc, const QString& filePat
4545
mOutputUnits = QgsMapRenderer::Millimeters;
4646
setLegendParametersFromProject();
4747
setSelectionColor();
48+
setMaxWidthHeight();
4849

4950
//accelerate search for layers and groups
5051
if ( mXMLDoc )
@@ -1439,6 +1440,27 @@ void QgsProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocu
14391440
}
14401441

14411442
serviceElem.appendChild( contactInfoElem );
1443+
1444+
//MaxWidth / MaxHeight for WMS 1.3
1445+
QString version = doc.documentElement().attribute( "version" );
1446+
if ( version != "1.1.1" )
1447+
{
1448+
if ( mMaxWidth != -1 )
1449+
{
1450+
QDomElement maxWidthElem = doc.createElement( "MaxWidth" );
1451+
QDomText maxWidthText = doc.createTextNode( QString::number( mMaxWidth ) );
1452+
maxWidthElem.appendChild( maxWidthText );
1453+
serviceElem.appendChild( maxWidthElem );
1454+
}
1455+
if ( mMaxHeight != -1 )
1456+
{
1457+
QDomElement maxHeightElem = doc.createElement( "MaxHeight" );
1458+
QDomText maxHeightText = doc.createTextNode( QString::number( mMaxHeight ) );
1459+
maxHeightElem.appendChild( maxHeightText );
1460+
serviceElem.appendChild( maxHeightElem );
1461+
}
1462+
}
1463+
14421464
parentElement.appendChild( serviceElem );
14431465
}
14441466

@@ -1541,6 +1563,31 @@ void QgsProjectParser::setSelectionColor()
15411563
mSelectionColor = QColor( red, green, blue, alpha );
15421564
}
15431565

1566+
void QgsProjectParser::setMaxWidthHeight()
1567+
{
1568+
if ( mXMLDoc )
1569+
{
1570+
QDomElement qgisElem = mXMLDoc->documentElement();
1571+
if ( !qgisElem.isNull() )
1572+
{
1573+
QDomElement propertiesElem = qgisElem.firstChildElement( "properties" );
1574+
if ( !propertiesElem.isNull() )
1575+
{
1576+
QDomElement maxWidthElem = propertiesElem.firstChildElement( "WMSMaxWidth" );
1577+
if ( !maxWidthElem.isNull() )
1578+
{
1579+
mMaxWidth = maxWidthElem.text().toInt();
1580+
}
1581+
QDomElement maxHeightElem = propertiesElem.firstChildElement( "WMSMaxHeight" );
1582+
if ( !maxHeightElem.isNull() )
1583+
{
1584+
mMaxHeight = maxHeightElem.text().toInt();
1585+
}
1586+
}
1587+
}
1588+
}
1589+
}
1590+
15441591
const QgsCoordinateReferenceSystem& QgsProjectParser::projectCRS() const
15451592
{
15461593
//mapcanvas->destinationsrs->spatialrefsys->authid

‎src/mapserver/qgsprojectparser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ class QgsProjectParser: public QgsConfigParser
167167

168168
/**Reads selection color from project and sets it to QgsConfigParser::mSelectionColor*/
169169
void setSelectionColor();
170+
/**Reads maxWidth / maxHeight from project and sets it to QgsConfigParser::mMaxWidth / mMaxHeight*/
171+
void setMaxWidthHeight();
170172
};
171173

172174
#endif // QGSPROJECTPARSER_H

‎src/mapserver/qgswmsserver.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,10 @@ QImage* QgsWMSServer::printCompositionToImage( QgsComposition* c ) const
669669

670670
QImage* QgsWMSServer::getMap()
671671
{
672+
if ( !checkMaximumWidthHeight() )
673+
{
674+
throw QgsMapServiceException( "Size error", "The requested map size is too large" );
675+
}
672676
QStringList layersList, stylesList, layerIdList;
673677
QImage* theImage = initializeRendering( layersList, stylesList, layerIdList );
674678

@@ -1994,3 +1998,31 @@ void QgsWMSServer::clearFeatureSelections( const QStringList& layerIds ) const
19941998

19951999
return;
19962000
}
2001+
2002+
bool QgsWMSServer::checkMaximumWidthHeight() const
2003+
{
2004+
//test if maxWidth / maxHeight set and WIDTH / HEIGHT parameter is in the range
2005+
if ( mConfigParser->maxWidth() != -1 )
2006+
{
2007+
QMap<QString, QString>::const_iterator widthIt = mParameterMap.find( "WIDTH" );
2008+
if ( widthIt != mParameterMap.constEnd() )
2009+
{
2010+
if ( widthIt->toInt() > mConfigParser->maxWidth() )
2011+
{
2012+
return false;
2013+
}
2014+
}
2015+
}
2016+
if ( mConfigParser->maxHeight() != -1 )
2017+
{
2018+
QMap<QString, QString>::const_iterator heightIt = mParameterMap.find( "HEIGHT" );
2019+
if ( heightIt != mParameterMap.constEnd() )
2020+
{
2021+
if ( heightIt->toInt() > mConfigParser->maxHeight() )
2022+
{
2023+
return false;
2024+
}
2025+
}
2026+
}
2027+
return true;
2028+
}

‎src/mapserver/qgswmsserver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ class QgsWMSServer
163163

164164
void appendFormats( QDomDocument &doc, QDomElement &elem, const QStringList &formats );
165165

166+
/**Checks WIDTH/HEIGHT values agains MaxWidth and MaxHeight
167+
@return true if width/height values are okay*/
168+
bool checkMaximumWidthHeight() const;
169+
166170
/**Map containing the WMS parameters*/
167171
QMap<QString, QString> mParameterMap;
168172
QgsConfigParser* mConfigParser;

0 commit comments

Comments
 (0)
Please sign in to comment.