Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE]: possibility to set MaxWidth and MaxHeight for GetMap request
  • Loading branch information
mhugent committed Apr 1, 2012
1 parent f244373 commit fad13f4
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 142 deletions.
33 changes: 33 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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++ )
{
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgsconfigparser.cpp
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/mapserver/qgsconfigparser.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
47 changes: 47 additions & 0 deletions src/mapserver/qgsprojectparser.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgsprojectparser.h
Expand Up @@ -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
32 changes: 32 additions & 0 deletions src/mapserver/qgswmsserver.cpp
Expand Up @@ -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 );

Expand Down Expand Up @@ -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<QString, QString>::const_iterator widthIt = mParameterMap.find( "WIDTH" );
if ( widthIt != mParameterMap.constEnd() )
{
if ( widthIt->toInt() > mConfigParser->maxWidth() )
{
return false;
}
}
}
if ( mConfigParser->maxHeight() != -1 )
{
QMap<QString, QString>::const_iterator heightIt = mParameterMap.find( "HEIGHT" );
if ( heightIt != mParameterMap.constEnd() )
{
if ( heightIt->toInt() > mConfigParser->maxHeight() )
{
return false;
}
}
}
return true;
}
4 changes: 4 additions & 0 deletions src/mapserver/qgswmsserver.h
Expand Up @@ -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<QString, QString> mParameterMap;
QgsConfigParser* mConfigParser;
Expand Down

0 comments on commit fad13f4

Please sign in to comment.