From fad13f407d9efbef5689fda54e5a730ce0eace6c Mon Sep 17 00:00:00 2001 From: Marco Hugentobler Date: Sun, 1 Apr 2012 17:26:47 +0200 Subject: [PATCH] [FEATURE]: possibility to set MaxWidth and MaxHeight for GetMap request --- src/app/qgsprojectproperties.cpp | 33 +++ src/mapserver/qgsconfigparser.cpp | 2 + src/mapserver/qgsconfigparser.h | 7 + src/mapserver/qgsprojectparser.cpp | 47 +++++ src/mapserver/qgsprojectparser.h | 2 + src/mapserver/qgswmsserver.cpp | 32 +++ src/mapserver/qgswmsserver.h | 4 + src/ui/qgsprojectpropertiesbase.ui | 310 ++++++++++++++++------------- 8 files changed, 294 insertions(+), 143 deletions(-) diff --git a/src/app/qgsprojectproperties.cpp b/src/app/qgsprojectproperties.cpp index 8fec88120f7..9d90fc97bd8 100644 --- a/src/app/qgsprojectproperties.cpp +++ b/src/app/qgsprojectproperties.cpp @@ -229,6 +229,20 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa bool addWktGeometry = QgsProject::instance()->readBoolEntry( "WMSAddWktGeometry", "/" ); mAddWktGeometryCheckBox->setChecked( addWktGeometry ); + //WMS maxWidth / maxHeight + mMaxWidthLineEdit->setValidator( new QIntValidator( mMaxWidthLineEdit ) ); + int maxWidth = QgsProject::instance()->readNumEntry( "WMSMaxWidth", "/", -1 ); + if ( maxWidth != -1 ) + { + mMaxWidthLineEdit->setText( QString::number( maxWidth ) ); + } + mMaxHeightLineEdit->setValidator( new QIntValidator( mMaxHeightLineEdit ) ); + int maxHeight = QgsProject::instance()->readNumEntry( "WMSMaxHeight", "/", -1 ); + if ( maxHeight != -1 ) + { + mMaxHeightLineEdit->setText( QString::number( maxHeight ) ); + } + QStringList wfsLayerIdList = QgsProject::instance()->readListEntry( "WFSLayers", "/" ); twWFSLayers->setColumnCount( 2 ); @@ -460,6 +474,25 @@ void QgsProjectProperties::apply() QgsProject::instance()->writeEntry( "WMSAddWktGeometry", "/", mAddWktGeometryCheckBox->isChecked() ); + QString maxWidthText = mMaxWidthLineEdit->text(); + if ( maxWidthText.isEmpty() ) + { + QgsProject::instance()->removeEntry( "WMSMaxWidth", "/" ); + } + else + { + QgsProject::instance()->writeEntry( "WMSMaxWidth", "/", maxWidthText.toInt() ); + } + QString maxHeightText = mMaxHeightLineEdit->text(); + if ( maxHeightText.isEmpty() ) + { + QgsProject::instance()->removeEntry( "WMSMaxHeight", "/" ); + } + else + { + QgsProject::instance()->writeEntry( "WMSMaxHeight", "/", maxHeightText.toInt() ); + } + QStringList wfsLayerList; for ( int i = 0; i < twWFSLayers->rowCount(); i++ ) { diff --git a/src/mapserver/qgsconfigparser.cpp b/src/mapserver/qgsconfigparser.cpp index e8398baf3e9..3209ad883be 100644 --- a/src/mapserver/qgsconfigparser.cpp +++ b/src/mapserver/qgsconfigparser.cpp @@ -31,6 +31,8 @@ QgsConfigParser::QgsConfigParser() : mFallbackParser( 0 ) , mScaleDenominator( 0 ) , mOutputUnits( QgsMapRenderer::Millimeters ) + , mMaxWidth( -1 ) + , mMaxHeight( -1 ) { setDefaultLegendSettings(); mSelectionColor = QColor( 255, 255, 0 ); //yellow opaque is default selection color diff --git a/src/mapserver/qgsconfigparser.h b/src/mapserver/qgsconfigparser.h index a165e8bf3e6..682463db6a1 100644 --- a/src/mapserver/qgsconfigparser.h +++ b/src/mapserver/qgsconfigparser.h @@ -121,6 +121,9 @@ class QgsConfigParser QColor selectionColor() const { return mSelectionColor; } void setSelectionColor( const QColor& c ) { mSelectionColor = c; } + int maxWidth() const { return mMaxWidth; } + int maxHeight() const { return mMaxHeight; } + protected: /**Parser to forward not resolved requests (e.g. SLD parser based on user request might have a fallback parser with admin configuration)*/ QgsConfigParser* mFallbackParser; @@ -160,6 +163,10 @@ class QgsConfigParser QColor mSelectionColor; + //maximum width/height for the GetMap request. Disabled by default (-1) + int mMaxWidth; + int mMaxHeight; + /**Transforms layer extent to epsg 4326 and appends ExGeographicBoundingBox and BoundingBox elements to the layer element*/ void appendLayerBoundingBoxes( QDomElement& layerElem, QDomDocument& doc, const QgsRectangle& layerExtent, const QgsCoordinateReferenceSystem& layerCRS ) const; diff --git a/src/mapserver/qgsprojectparser.cpp b/src/mapserver/qgsprojectparser.cpp index e1dfdbb8b6f..d4fe7737e27 100644 --- a/src/mapserver/qgsprojectparser.cpp +++ b/src/mapserver/qgsprojectparser.cpp @@ -45,6 +45,7 @@ QgsProjectParser::QgsProjectParser( QDomDocument* xmlDoc, const QString& filePat mOutputUnits = QgsMapRenderer::Millimeters; setLegendParametersFromProject(); setSelectionColor(); + setMaxWidthHeight(); //accelerate search for layers and groups if ( mXMLDoc ) @@ -1439,6 +1440,27 @@ void QgsProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocu } serviceElem.appendChild( contactInfoElem ); + + //MaxWidth / MaxHeight for WMS 1.3 + QString version = doc.documentElement().attribute( "version" ); + if ( version != "1.1.1" ) + { + if ( mMaxWidth != -1 ) + { + QDomElement maxWidthElem = doc.createElement( "MaxWidth" ); + QDomText maxWidthText = doc.createTextNode( QString::number( mMaxWidth ) ); + maxWidthElem.appendChild( maxWidthText ); + serviceElem.appendChild( maxWidthElem ); + } + if ( mMaxHeight != -1 ) + { + QDomElement maxHeightElem = doc.createElement( "MaxHeight" ); + QDomText maxHeightText = doc.createTextNode( QString::number( mMaxHeight ) ); + maxHeightElem.appendChild( maxHeightText ); + serviceElem.appendChild( maxHeightElem ); + } + } + parentElement.appendChild( serviceElem ); } @@ -1541,6 +1563,31 @@ void QgsProjectParser::setSelectionColor() mSelectionColor = QColor( red, green, blue, alpha ); } +void QgsProjectParser::setMaxWidthHeight() +{ + if ( mXMLDoc ) + { + QDomElement qgisElem = mXMLDoc->documentElement(); + if ( !qgisElem.isNull() ) + { + QDomElement propertiesElem = qgisElem.firstChildElement( "properties" ); + if ( !propertiesElem.isNull() ) + { + QDomElement maxWidthElem = propertiesElem.firstChildElement( "WMSMaxWidth" ); + if ( !maxWidthElem.isNull() ) + { + mMaxWidth = maxWidthElem.text().toInt(); + } + QDomElement maxHeightElem = propertiesElem.firstChildElement( "WMSMaxHeight" ); + if ( !maxHeightElem.isNull() ) + { + mMaxHeight = maxHeightElem.text().toInt(); + } + } + } + } +} + const QgsCoordinateReferenceSystem& QgsProjectParser::projectCRS() const { //mapcanvas->destinationsrs->spatialrefsys->authid diff --git a/src/mapserver/qgsprojectparser.h b/src/mapserver/qgsprojectparser.h index d4152a92610..b5138005a46 100644 --- a/src/mapserver/qgsprojectparser.h +++ b/src/mapserver/qgsprojectparser.h @@ -167,6 +167,8 @@ class QgsProjectParser: public QgsConfigParser /**Reads selection color from project and sets it to QgsConfigParser::mSelectionColor*/ void setSelectionColor(); + /**Reads maxWidth / maxHeight from project and sets it to QgsConfigParser::mMaxWidth / mMaxHeight*/ + void setMaxWidthHeight(); }; #endif // QGSPROJECTPARSER_H diff --git a/src/mapserver/qgswmsserver.cpp b/src/mapserver/qgswmsserver.cpp index 1de6a91099c..9cd9074c2d2 100644 --- a/src/mapserver/qgswmsserver.cpp +++ b/src/mapserver/qgswmsserver.cpp @@ -669,6 +669,10 @@ QImage* QgsWMSServer::printCompositionToImage( QgsComposition* c ) const QImage* QgsWMSServer::getMap() { + if ( !checkMaximumWidthHeight() ) + { + throw QgsMapServiceException( "Size error", "The requested map size is too large" ); + } QStringList layersList, stylesList, layerIdList; QImage* theImage = initializeRendering( layersList, stylesList, layerIdList ); @@ -1994,3 +1998,31 @@ void QgsWMSServer::clearFeatureSelections( const QStringList& layerIds ) const return; } + +bool QgsWMSServer::checkMaximumWidthHeight() const +{ + //test if maxWidth / maxHeight set and WIDTH / HEIGHT parameter is in the range + if ( mConfigParser->maxWidth() != -1 ) + { + QMap::const_iterator widthIt = mParameterMap.find( "WIDTH" ); + if ( widthIt != mParameterMap.constEnd() ) + { + if ( widthIt->toInt() > mConfigParser->maxWidth() ) + { + return false; + } + } + } + if ( mConfigParser->maxHeight() != -1 ) + { + QMap::const_iterator heightIt = mParameterMap.find( "HEIGHT" ); + if ( heightIt != mParameterMap.constEnd() ) + { + if ( heightIt->toInt() > mConfigParser->maxHeight() ) + { + return false; + } + } + } + return true; +} diff --git a/src/mapserver/qgswmsserver.h b/src/mapserver/qgswmsserver.h index 79ef589331a..a87cd2f2bcb 100644 --- a/src/mapserver/qgswmsserver.h +++ b/src/mapserver/qgswmsserver.h @@ -163,6 +163,10 @@ class QgsWMSServer void appendFormats( QDomDocument &doc, QDomElement &elem, const QStringList &formats ); + /**Checks WIDTH/HEIGHT values agains MaxWidth and MaxHeight + @return true if width/height values are okay*/ + bool checkMaximumWidthHeight() const; + /**Map containing the WMS parameters*/ QMap mParameterMap; QgsConfigParser* mConfigParser; diff --git a/src/ui/qgsprojectpropertiesbase.ui b/src/ui/qgsprojectpropertiesbase.ui index cd58ba453c9..ff758a5ff4a 100644 --- a/src/ui/qgsprojectpropertiesbase.ui +++ b/src/ui/qgsprojectpropertiesbase.ui @@ -6,8 +6,8 @@ 0 0 - 676 - 522 + 571 + 448 @@ -368,7 +368,7 @@ OWS Server - + true @@ -377,13 +377,13 @@ 0 - 0 - 616 - 538 + -271 + 526 + 668 - - + + Service Capabilitities @@ -483,148 +483,158 @@ - + WMS Capabilitities - - - - Advertised Extent - - - true - - - false - - - - - - Min. X - - - mWMSExtMinX - - - - - - - - - - - - - Min. Y + + + Advertised Extent - - mWMSExtMinY + + true + + false + + + + + + Min. X + + + mWMSExtMinX + + + + + + + + + + + + + + Min. Y + + + mWMSExtMinY + + + + + + + + + + + + + + Max. X + + + mWMSExtMaxX + + + + + + + + + + + + + + Max. Y + + + mWMSExtMaxY + + + + + + + + + + + + + + Use Current Canvas Extent + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + - - - + + + Coordinate Systems Restrictions + + true + + + false + + + + + + + + + Add + + + + + + + Remove + + + + + + + Used + + + + - + - Max. X - - - mWMSExtMaxX - - - - - - - - - - - - - - Max. Y - - - mWMSExtMaxY - - - - - - - - - - - - - - Use Current Canvas Extent - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - Coordinate Systems Restrictions - - - true - - - false - - - - - - - - - Add - - - - - - - Remove - - - - - - - Used + Add WKT geometry to feature info response @@ -632,16 +642,30 @@ - - - Add WKT geometry to feature info response - - + + + + + Maximum width + + + + + + + + + + Maximum height + + + + + + + - - - - + WFS Capabilitities