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;

‎src/ui/qgsprojectpropertiesbase.ui

Lines changed: 166 additions & 142 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>676</width>
10-
<height>522</height>
9+
<width>571</width>
10+
<height>448</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -368,7 +368,7 @@
368368
<string>OWS Server</string>
369369
</attribute>
370370
<layout class="QGridLayout" name="gridLayout_3">
371-
<item row="0" column="0" rowspan="2">
371+
<item row="0" column="0">
372372
<widget class="QScrollArea" name="scrollArea">
373373
<property name="widgetResizable">
374374
<bool>true</bool>
@@ -377,13 +377,13 @@
377377
<property name="geometry">
378378
<rect>
379379
<x>0</x>
380-
<y>0</y>
381-
<width>616</width>
382-
<height>538</height>
380+
<y>-271</y>
381+
<width>526</width>
382+
<height>668</height>
383383
</rect>
384384
</property>
385-
<layout class="QGridLayout" name="gridLayout_7">
386-
<item row="0" column="0" colspan="2">
385+
<layout class="QGridLayout" name="gridLayout">
386+
<item row="0" column="0">
387387
<widget class="QGroupBox" name="grpOWSServiceCapabilities">
388388
<property name="title">
389389
<string>Service Capabilitities</string>
@@ -483,165 +483,189 @@
483483
</layout>
484484
</widget>
485485
</item>
486-
<item row="1" column="0" colspan="2">
486+
<item row="1" column="0">
487487
<widget class="QGroupBox" name="grpWMSCapabilities">
488488
<property name="title">
489489
<string>WMS Capabilitities</string>
490490
</property>
491491
<layout class="QGridLayout" name="gridLayout_10">
492-
<item row="1" column="0">
493-
<widget class="QGroupBox" name="grpWMSExt">
494-
<property name="title">
495-
<string>Advertised Extent</string>
496-
</property>
497-
<property name="checkable">
498-
<bool>true</bool>
499-
</property>
500-
<property name="checked">
501-
<bool>false</bool>
502-
</property>
503-
<layout class="QGridLayout" name="gridLayout_4">
504-
<item row="0" column="0">
505-
<widget class="QLabel" name="label_11">
506-
<property name="text">
507-
<string>Min. X</string>
508-
</property>
509-
<property name="buddy">
510-
<cstring>mWMSExtMinX</cstring>
511-
</property>
512-
</widget>
513-
</item>
514-
<item row="0" column="1">
515-
<widget class="QLineEdit" name="mWMSExtMinX">
516-
<property name="text">
517-
<string/>
518-
</property>
519-
</widget>
520-
</item>
521492
<item row="1" column="0">
522-
<widget class="QLabel" name="label_12">
523-
<property name="text">
524-
<string>Min. Y</string>
493+
<widget class="QGroupBox" name="grpWMSExt">
494+
<property name="title">
495+
<string>Advertised Extent</string>
525496
</property>
526-
<property name="buddy">
527-
<cstring>mWMSExtMinY</cstring>
497+
<property name="checkable">
498+
<bool>true</bool>
528499
</property>
529-
</widget>
530-
</item>
531-
<item row="1" column="1">
532-
<widget class="QLineEdit" name="mWMSExtMinY">
533-
<property name="text">
534-
<string/>
500+
<property name="checked">
501+
<bool>false</bool>
535502
</property>
503+
<layout class="QGridLayout" name="gridLayout_4">
504+
<item row="0" column="0">
505+
<widget class="QLabel" name="label_11">
506+
<property name="text">
507+
<string>Min. X</string>
508+
</property>
509+
<property name="buddy">
510+
<cstring>mWMSExtMinX</cstring>
511+
</property>
512+
</widget>
513+
</item>
514+
<item row="0" column="1">
515+
<widget class="QLineEdit" name="mWMSExtMinX">
516+
<property name="text">
517+
<string/>
518+
</property>
519+
</widget>
520+
</item>
521+
<item row="1" column="0">
522+
<widget class="QLabel" name="label_12">
523+
<property name="text">
524+
<string>Min. Y</string>
525+
</property>
526+
<property name="buddy">
527+
<cstring>mWMSExtMinY</cstring>
528+
</property>
529+
</widget>
530+
</item>
531+
<item row="1" column="1">
532+
<widget class="QLineEdit" name="mWMSExtMinY">
533+
<property name="text">
534+
<string/>
535+
</property>
536+
</widget>
537+
</item>
538+
<item row="2" column="0">
539+
<widget class="QLabel" name="label_9">
540+
<property name="text">
541+
<string>Max. X</string>
542+
</property>
543+
<property name="buddy">
544+
<cstring>mWMSExtMaxX</cstring>
545+
</property>
546+
</widget>
547+
</item>
548+
<item row="2" column="1">
549+
<widget class="QLineEdit" name="mWMSExtMaxX">
550+
<property name="text">
551+
<string/>
552+
</property>
553+
</widget>
554+
</item>
555+
<item row="3" column="0">
556+
<widget class="QLabel" name="label_10">
557+
<property name="text">
558+
<string>Max. Y</string>
559+
</property>
560+
<property name="buddy">
561+
<cstring>mWMSExtMaxY</cstring>
562+
</property>
563+
</widget>
564+
</item>
565+
<item row="3" column="1">
566+
<widget class="QLineEdit" name="mWMSExtMaxY">
567+
<property name="text">
568+
<string/>
569+
</property>
570+
</widget>
571+
</item>
572+
<item row="4" column="0" colspan="2">
573+
<widget class="QPushButton" name="pbnWMSExtCanvas">
574+
<property name="text">
575+
<string>Use Current Canvas Extent</string>
576+
</property>
577+
</widget>
578+
</item>
579+
<item row="5" column="0" colspan="2">
580+
<spacer name="verticalSpacer">
581+
<property name="orientation">
582+
<enum>Qt::Vertical</enum>
583+
</property>
584+
<property name="sizeHint" stdset="0">
585+
<size>
586+
<width>20</width>
587+
<height>40</height>
588+
</size>
589+
</property>
590+
</spacer>
591+
</item>
592+
</layout>
536593
</widget>
537594
</item>
538-
<item row="2" column="0">
539-
<widget class="QLabel" name="label_9">
540-
<property name="text">
541-
<string>Max. X</string>
542-
</property>
543-
<property name="buddy">
544-
<cstring>mWMSExtMaxX</cstring>
545-
</property>
546-
</widget>
547-
</item>
548-
<item row="2" column="1">
549-
<widget class="QLineEdit" name="mWMSExtMaxX">
550-
<property name="text">
551-
<string/>
552-
</property>
553-
</widget>
554-
</item>
555-
<item row="3" column="0">
556-
<widget class="QLabel" name="label_10">
557-
<property name="text">
558-
<string>Max. Y</string>
559-
</property>
560-
<property name="buddy">
561-
<cstring>mWMSExtMaxY</cstring>
595+
<item row="1" column="1">
596+
<widget class="QGroupBox" name="grpWMSList">
597+
<property name="title">
598+
<string>Coordinate Systems Restrictions</string>
562599
</property>
563-
</widget>
564-
</item>
565-
<item row="3" column="1">
566-
<widget class="QLineEdit" name="mWMSExtMaxY">
567-
<property name="text">
568-
<string/>
600+
<property name="checkable">
601+
<bool>true</bool>
569602
</property>
570-
</widget>
571-
</item>
572-
<item row="4" column="0" colspan="2">
573-
<widget class="QPushButton" name="pbnWMSExtCanvas">
574-
<property name="text">
575-
<string>Use Current Canvas Extent</string>
603+
<property name="checked">
604+
<bool>false</bool>
576605
</property>
606+
<layout class="QGridLayout" name="gridLayout_5">
607+
<item row="0" column="0" colspan="3">
608+
<widget class="QListWidget" name="mWMSList"/>
609+
</item>
610+
<item row="1" column="0">
611+
<widget class="QPushButton" name="pbnWMSAddSRS">
612+
<property name="text">
613+
<string>Add</string>
614+
</property>
615+
</widget>
616+
</item>
617+
<item row="1" column="2">
618+
<widget class="QPushButton" name="pbnWMSRemoveSRS">
619+
<property name="text">
620+
<string>Remove</string>
621+
</property>
622+
</widget>
623+
</item>
624+
<item row="1" column="1">
625+
<widget class="QPushButton" name="pbnWMSSetUsedSRS">
626+
<property name="text">
627+
<string>Used</string>
628+
</property>
629+
</widget>
630+
</item>
631+
</layout>
577632
</widget>
578633
</item>
579-
<item row="5" column="0" colspan="2">
580-
<spacer name="verticalSpacer">
581-
<property name="orientation">
582-
<enum>Qt::Vertical</enum>
583-
</property>
584-
<property name="sizeHint" stdset="0">
585-
<size>
586-
<width>20</width>
587-
<height>40</height>
588-
</size>
589-
</property>
590-
</spacer>
591-
</item>
592-
</layout>
593-
</widget>
594-
</item>
595-
<item row="1" column="1">
596-
<widget class="QGroupBox" name="grpWMSList">
597-
<property name="title">
598-
<string>Coordinate Systems Restrictions</string>
599-
</property>
600-
<property name="checkable">
601-
<bool>true</bool>
602-
</property>
603-
<property name="checked">
604-
<bool>false</bool>
605-
</property>
606-
<layout class="QGridLayout" name="gridLayout_5">
607-
<item row="0" column="0" colspan="3">
608-
<widget class="QListWidget" name="mWMSList"/>
609-
</item>
610-
<item row="1" column="0">
611-
<widget class="QPushButton" name="pbnWMSAddSRS">
612-
<property name="text">
613-
<string>Add</string>
614-
</property>
615-
</widget>
616-
</item>
617-
<item row="1" column="2">
618-
<widget class="QPushButton" name="pbnWMSRemoveSRS">
619-
<property name="text">
620-
<string>Remove</string>
621-
</property>
622-
</widget>
623-
</item>
624-
<item row="1" column="1">
625-
<widget class="QPushButton" name="pbnWMSSetUsedSRS">
634+
<item row="2" column="0">
635+
<widget class="QCheckBox" name="mAddWktGeometryCheckBox">
626636
<property name="text">
627-
<string>Used</string>
637+
<string>Add WKT geometry to feature info response</string>
628638
</property>
629639
</widget>
630640
</item>
631641
</layout>
632642
</widget>
633643
</item>
634644
<item row="2" column="0">
635-
<widget class="QCheckBox" name="mAddWktGeometryCheckBox">
636-
<property name="text">
637-
<string>Add WKT geometry to feature info response</string>
638-
</property>
639-
</widget>
640-
</item>
641-
</layout>
642-
</widget>
645+
<layout class="QHBoxLayout" name="horizontalLayout_2">
646+
<item>
647+
<widget class="QLabel" name="mMaxWidthLabel">
648+
<property name="text">
649+
<string>Maximum width</string>
650+
</property>
651+
</widget>
652+
</item>
653+
<item>
654+
<widget class="QLineEdit" name="mMaxWidthLineEdit"/>
655+
</item>
656+
<item>
657+
<widget class="QLabel" name="mMaxHeightLabel">
658+
<property name="text">
659+
<string>Maximum height</string>
660+
</property>
661+
</widget>
662+
</item>
663+
<item>
664+
<widget class="QLineEdit" name="mMaxHeightLineEdit"/>
665+
</item>
666+
</layout>
643667
</item>
644-
<item row="3" column="0" colspan="2">
668+
<item row="3" column="0">
645669
<widget class="QGroupBox" name="grpWFSCapabilities">
646670
<property name="title">
647671
<string>WFS Capabilitities</string>

0 commit comments

Comments
 (0)
Please sign in to comment.