[FEATURE]: possibility to set MaxWidth and MaxHeight for GetMap request

This commit is contained in:
Marco Hugentobler 2012-04-01 17:26:47 +02:00
parent f2443737e0
commit fad13f407d
8 changed files with 294 additions and 143 deletions

View File

@ -229,6 +229,20 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
bool addWktGeometry = QgsProject::instance()->readBoolEntry( "WMSAddWktGeometry", "/" ); bool addWktGeometry = QgsProject::instance()->readBoolEntry( "WMSAddWktGeometry", "/" );
mAddWktGeometryCheckBox->setChecked( addWktGeometry ); 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", "/" ); QStringList wfsLayerIdList = QgsProject::instance()->readListEntry( "WFSLayers", "/" );
twWFSLayers->setColumnCount( 2 ); twWFSLayers->setColumnCount( 2 );
@ -460,6 +474,25 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( "WMSAddWktGeometry", "/", mAddWktGeometryCheckBox->isChecked() ); 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; QStringList wfsLayerList;
for ( int i = 0; i < twWFSLayers->rowCount(); i++ ) for ( int i = 0; i < twWFSLayers->rowCount(); i++ )
{ {

View File

@ -31,6 +31,8 @@ QgsConfigParser::QgsConfigParser()
: mFallbackParser( 0 ) : mFallbackParser( 0 )
, mScaleDenominator( 0 ) , mScaleDenominator( 0 )
, mOutputUnits( QgsMapRenderer::Millimeters ) , mOutputUnits( QgsMapRenderer::Millimeters )
, mMaxWidth( -1 )
, mMaxHeight( -1 )
{ {
setDefaultLegendSettings(); setDefaultLegendSettings();
mSelectionColor = QColor( 255, 255, 0 ); //yellow opaque is default selection color mSelectionColor = QColor( 255, 255, 0 ); //yellow opaque is default selection color

View File

@ -121,6 +121,9 @@ class QgsConfigParser
QColor selectionColor() const { return mSelectionColor; } QColor selectionColor() const { return mSelectionColor; }
void setSelectionColor( const QColor& c ) { mSelectionColor = c; } void setSelectionColor( const QColor& c ) { mSelectionColor = c; }
int maxWidth() const { return mMaxWidth; }
int maxHeight() const { return mMaxHeight; }
protected: protected:
/**Parser to forward not resolved requests (e.g. SLD parser based on user request might have a fallback parser with admin configuration)*/ /**Parser to forward not resolved requests (e.g. SLD parser based on user request might have a fallback parser with admin configuration)*/
QgsConfigParser* mFallbackParser; QgsConfigParser* mFallbackParser;
@ -160,6 +163,10 @@ class QgsConfigParser
QColor mSelectionColor; 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*/ /**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; void appendLayerBoundingBoxes( QDomElement& layerElem, QDomDocument& doc, const QgsRectangle& layerExtent, const QgsCoordinateReferenceSystem& layerCRS ) const;

View File

@ -45,6 +45,7 @@ QgsProjectParser::QgsProjectParser( QDomDocument* xmlDoc, const QString& filePat
mOutputUnits = QgsMapRenderer::Millimeters; mOutputUnits = QgsMapRenderer::Millimeters;
setLegendParametersFromProject(); setLegendParametersFromProject();
setSelectionColor(); setSelectionColor();
setMaxWidthHeight();
//accelerate search for layers and groups //accelerate search for layers and groups
if ( mXMLDoc ) if ( mXMLDoc )
@ -1439,6 +1440,27 @@ void QgsProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocu
} }
serviceElem.appendChild( contactInfoElem ); 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 ); parentElement.appendChild( serviceElem );
} }
@ -1541,6 +1563,31 @@ void QgsProjectParser::setSelectionColor()
mSelectionColor = QColor( red, green, blue, alpha ); 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 const QgsCoordinateReferenceSystem& QgsProjectParser::projectCRS() const
{ {
//mapcanvas->destinationsrs->spatialrefsys->authid //mapcanvas->destinationsrs->spatialrefsys->authid

View File

@ -167,6 +167,8 @@ class QgsProjectParser: public QgsConfigParser
/**Reads selection color from project and sets it to QgsConfigParser::mSelectionColor*/ /**Reads selection color from project and sets it to QgsConfigParser::mSelectionColor*/
void setSelectionColor(); void setSelectionColor();
/**Reads maxWidth / maxHeight from project and sets it to QgsConfigParser::mMaxWidth / mMaxHeight*/
void setMaxWidthHeight();
}; };
#endif // QGSPROJECTPARSER_H #endif // QGSPROJECTPARSER_H

View File

@ -669,6 +669,10 @@ QImage* QgsWMSServer::printCompositionToImage( QgsComposition* c ) const
QImage* QgsWMSServer::getMap() QImage* QgsWMSServer::getMap()
{ {
if ( !checkMaximumWidthHeight() )
{
throw QgsMapServiceException( "Size error", "The requested map size is too large" );
}
QStringList layersList, stylesList, layerIdList; QStringList layersList, stylesList, layerIdList;
QImage* theImage = initializeRendering( layersList, stylesList, layerIdList ); QImage* theImage = initializeRendering( layersList, stylesList, layerIdList );
@ -1994,3 +1998,31 @@ void QgsWMSServer::clearFeatureSelections( const QStringList& layerIds ) const
return; 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;
}

View File

@ -163,6 +163,10 @@ class QgsWMSServer
void appendFormats( QDomDocument &doc, QDomElement &elem, const QStringList &formats ); 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*/ /**Map containing the WMS parameters*/
QMap<QString, QString> mParameterMap; QMap<QString, QString> mParameterMap;
QgsConfigParser* mConfigParser; QgsConfigParser* mConfigParser;

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>676</width> <width>571</width>
<height>522</height> <height>448</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -368,7 +368,7 @@
<string>OWS Server</string> <string>OWS Server</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" rowspan="2"> <item row="0" column="0">
<widget class="QScrollArea" name="scrollArea"> <widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable"> <property name="widgetResizable">
<bool>true</bool> <bool>true</bool>
@ -377,13 +377,13 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>-271</y>
<width>616</width> <width>526</width>
<height>538</height> <height>668</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_7"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2"> <item row="0" column="0">
<widget class="QGroupBox" name="grpOWSServiceCapabilities"> <widget class="QGroupBox" name="grpOWSServiceCapabilities">
<property name="title"> <property name="title">
<string>Service Capabilitities</string> <string>Service Capabilitities</string>
@ -483,148 +483,158 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2"> <item row="1" column="0">
<widget class="QGroupBox" name="grpWMSCapabilities"> <widget class="QGroupBox" name="grpWMSCapabilities">
<property name="title"> <property name="title">
<string>WMS Capabilitities</string> <string>WMS Capabilitities</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_10"> <layout class="QGridLayout" name="gridLayout_10">
<item row="1" column="0">
<widget class="QGroupBox" name="grpWMSExt">
<property name="title">
<string>Advertised Extent</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Min. X</string>
</property>
<property name="buddy">
<cstring>mWMSExtMinX</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="mWMSExtMinX">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_12"> <widget class="QGroupBox" name="grpWMSExt">
<property name="text"> <property name="title">
<string>Min. Y</string> <string>Advertised Extent</string>
</property> </property>
<property name="buddy"> <property name="checkable">
<cstring>mWMSExtMinY</cstring> <bool>true</bool>
</property> </property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Min. X</string>
</property>
<property name="buddy">
<cstring>mWMSExtMinX</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="mWMSExtMinX">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Min. Y</string>
</property>
<property name="buddy">
<cstring>mWMSExtMinY</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mWMSExtMinY">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Max. X</string>
</property>
<property name="buddy">
<cstring>mWMSExtMaxX</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="mWMSExtMaxX">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Max. Y</string>
</property>
<property name="buddy">
<cstring>mWMSExtMaxY</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="mWMSExtMaxY">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="pbnWMSExtCanvas">
<property name="text">
<string>Use Current Canvas Extent</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="mWMSExtMinY"> <widget class="QGroupBox" name="grpWMSList">
<property name="text"> <property name="title">
<string/> <string>Coordinate Systems Restrictions</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0" colspan="3">
<widget class="QListWidget" name="mWMSList"/>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pbnWMSAddSRS">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pbnWMSRemoveSRS">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pbnWMSSetUsedSRS">
<property name="text">
<string>Used</string>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_9"> <widget class="QCheckBox" name="mAddWktGeometryCheckBox">
<property name="text"> <property name="text">
<string>Max. X</string> <string>Add WKT geometry to feature info response</string>
</property>
<property name="buddy">
<cstring>mWMSExtMaxX</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="mWMSExtMaxX">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Max. Y</string>
</property>
<property name="buddy">
<cstring>mWMSExtMaxY</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="mWMSExtMaxY">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="pbnWMSExtCanvas">
<property name="text">
<string>Use Current Canvas Extent</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="grpWMSList">
<property name="title">
<string>Coordinate Systems Restrictions</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0" colspan="3">
<widget class="QListWidget" name="mWMSList"/>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pbnWMSAddSRS">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pbnWMSRemoveSRS">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pbnWMSSetUsedSRS">
<property name="text">
<string>Used</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -632,16 +642,30 @@
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QCheckBox" name="mAddWktGeometryCheckBox"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="text"> <item>
<string>Add WKT geometry to feature info response</string> <widget class="QLabel" name="mMaxWidthLabel">
</property> <property name="text">
</widget> <string>Maximum width</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mMaxWidthLineEdit"/>
</item>
<item>
<widget class="QLabel" name="mMaxHeightLabel">
<property name="text">
<string>Maximum height</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mMaxHeightLineEdit"/>
</item>
</layout>
</item> </item>
</layout> <item row="3" column="0">
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="grpWFSCapabilities"> <widget class="QGroupBox" name="grpWFSCapabilities">
<property name="title"> <property name="title">
<string>WFS Capabilitities</string> <string>WFS Capabilitities</string>