Skip to content

Commit

Permalink
Merge pull request #5466 from mhugent/maptip_geometry_optional
Browse files Browse the repository at this point in the history
[needs-docs] Make maptip and geometry attribute optional in featureinfo response
  • Loading branch information
mhugent committed Oct 27, 2017
2 parents 26bd6d7 + 52896f5 commit a843df8
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 14 deletions.
24 changes: 24 additions & 0 deletions src/server/services/wms/qgswmsparameters.cpp
Expand Up @@ -462,6 +462,20 @@ namespace QgsWms
QVariant()
};
save( pGridY );

const Parameter pWithGeometry = { ParameterName::WITH_GEOMETRY,
QVariant::Bool,
QVariant( false ),
QVariant()
};
save( pWithGeometry );

const Parameter pWithMapTip = { ParameterName::WITH_MAPTIP,
QVariant::Bool,
QVariant( false ),
QVariant()
};
save( pWithMapTip );
}

QgsWmsParameters::QgsWmsParameters( const QgsServerRequest::Parameters &parameters )
Expand Down Expand Up @@ -1908,6 +1922,16 @@ namespace QgsWms
return wmsUri.encodedUri();
}

bool QgsWmsParameters::withGeometry() const
{
return toBool( ParameterName::WITH_GEOMETRY );
}

bool QgsWmsParameters::withMapTip() const
{
return toBool( ParameterName::WITH_MAPTIP );
}

QString QgsWmsParameters::name( ParameterName name ) const
{
const QMetaEnum metaEnum( QMetaEnum::fromType<ParameterName>() );
Expand Down
16 changes: 15 additions & 1 deletion src/server/services/wms/qgswmsparameters.h
Expand Up @@ -141,7 +141,9 @@ namespace QgsWms
EXTENT,
ROTATION,
GRID_INTERVAL_X,
GRID_INTERVAL_Y
GRID_INTERVAL_Y,
WITH_GEOMETRY,
WITH_MAPTIP
};
Q_ENUM( ParameterName )

Expand Down Expand Up @@ -916,6 +918,18 @@ namespace QgsWms
*/
QString externalWMSUri( const QString &id ) const;

/**
* \brief Returns if the client wants the feature info response with geometry information
* \returns true if geometry information is requested for feature info response
*/
bool withGeometry() const;

/**
* \brief withMapTip
* \returns true if maptip information is requested for feature info response
*/
bool withMapTip() const;

private:
QString name( ParameterName name ) const;
void raiseError( ParameterName name ) const;
Expand Down
6 changes: 3 additions & 3 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -1436,7 +1436,7 @@ namespace QgsWms
int featureCounter = 0;
layer->updateFields();
const QgsFields &fields = layer->pendingFields();
bool addWktGeometry = QgsServerProjectUtils::wmsFeatureInfoAddWktGeometry( *mProject );
bool addWktGeometry = ( QgsServerProjectUtils::wmsFeatureInfoAddWktGeometry( *mProject ) && mWmsParameters.withGeometry() );
bool segmentizeWktGeometry = QgsServerProjectUtils::wmsFeatureInfoSegmentizeWktGeometry( *mProject );
const QSet<QString> &excludedAttributes = layer->excludeAttributesWms();

Expand Down Expand Up @@ -1588,7 +1588,7 @@ namespace QgsWms

//add maptip attribute based on html/expression (in case there is no maptip attribute)
QString mapTip = layer->mapTipTemplate();
if ( !mapTip.isEmpty() )
if ( !mapTip.isEmpty() && mWmsParameters.withMapTip() )
{
QDomElement maptipElem = infoDocument.createElement( QStringLiteral( "Attribute" ) );
maptipElem.setAttribute( QStringLiteral( "name" ), QStringLiteral( "maptip" ) );
Expand Down Expand Up @@ -2236,7 +2236,7 @@ namespace QgsWms
{
QString mapTip = layer->mapTipTemplate();

if ( !mapTip.isEmpty() )
if ( !mapTip.isEmpty() && mWmsParameters.withMapTip() )
{
QString fieldTextString = QgsExpression::replaceExpressionText( mapTip, &expressionContext );
QDomElement fieldElem = doc.createElement( QStringLiteral( "qgs:maptip" ) );
Expand Down
20 changes: 20 additions & 0 deletions tests/src/python/test_qgsserver_wms.py
Expand Up @@ -101,6 +101,26 @@ def test_getfeatureinfo(self):
'query_layers=testlayer%20%C3%A8%C3%A9&X=190&Y=320',
'wms_getfeatureinfo-text-html')

#Test getfeatureinfo response html with geometry
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
'info_format=text%2Fhtml&transparent=true&' +
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
'query_layers=testlayer%20%C3%A8%C3%A9&X=190&Y=320&' +
'with_geometry=true',
'wms_getfeatureinfo-text-html-geometry')

#Test getfeatureinfo response html with maptip
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
'info_format=text%2Fhtml&transparent=true&' +
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
'query_layers=testlayer%20%C3%A8%C3%A9&X=190&Y=320&' +
'with_maptip=true',
'wms_getfeatureinfo-text-html-maptip')

# Test getfeatureinfo response text
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
Expand Down
1 change: 1 addition & 0 deletions tests/testdata/qgis_server/test_project.qgs
Expand Up @@ -356,6 +356,7 @@
<rowstyles/>
<fieldstyles/>
</conditionalstyles>
<mapTip>[% 'Name: ' || "name" %]</mapTip>
</maplayer>
</projectlayers>
<properties>
Expand Down
@@ -0,0 +1,21 @@
Content-Length: 512
Content-Type: text/html; charset=utf-8

<HEAD>
<TITLE> GetFeatureInfo results </TITLE>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</HEAD>
<BODY>
<TABLE border=1 width=100%>
<TR><TH width=25%>Layer</TH><TD>testlayer èé</TD></TR>
</BR><TABLE border=1 width=100%>
<TR><TH>Feature</TH><TD>2</TD></TR>
<TR><TH>id</TH><TD>3</TD></TR>
<TR><TH>name</TH><TD>three</TD></TR>
<TR><TH>utf8nameè</TH><TD>three èé↓</TD></TR>
<TR><TH>geometry</TH><TD>Point (913204.9128 5606011.4565)</TD></TR>
</TABLE>
</BR>
</TABLE>
<BR></BR>
</BODY>
21 changes: 21 additions & 0 deletions tests/testdata/qgis_server/wms_getfeatureinfo-text-html-maptip.txt
@@ -0,0 +1,21 @@
Content-Length: 512
Content-Type: text/html; charset=utf-8

<HEAD>
<TITLE> GetFeatureInfo results </TITLE>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</HEAD>
<BODY>
<TABLE border=1 width=100%>
<TR><TH width=25%>Layer</TH><TD>testlayer èé</TD></TR>
</BR><TABLE border=1 width=100%>
<TR><TH>Feature</TH><TD>2</TD></TR>
<TR><TH>id</TH><TD>3</TD></TR>
<TR><TH>name</TH><TD>three</TD></TR>
<TR><TH>utf8nameè</TH><TD>three èé↓</TD></TR>
<TR><TH>maptip</TH><TD>Name: three</TD></TR>
</TABLE>
</BR>
</TABLE>
<BR></BR>
</BODY>
Expand Up @@ -13,7 +13,6 @@ Content-Type: text/html; charset=utf-8
<TR><TH>id</TH><TD>3</TD></TR>
<TR><TH>name</TH><TD>three</TD></TR>
<TR><TH>utf8nameè</TH><TD>three èé↓</TD></TR>
<TR><TH>geometry</TH><TD>Point (913204.9128 5606011.4565)</TD></TR>
</TABLE>
</BR>
</TABLE>
Expand Down
Expand Up @@ -8,5 +8,4 @@ Feature 2
id = '3'
name = 'three'
utf8nameè = 'three èé↓'
geometry = 'Point (913204.9128 5606011.4565)'

2 changes: 0 additions & 2 deletions tests/testdata/qgis_server/wms_getfeatureinfo-text-xml.txt
Expand Up @@ -7,8 +7,6 @@ Content-Type: text/xml; charset=utf-8
<Attribute value="3" name="id"/>
<Attribute value="three" name="name"/>
<Attribute value="three èé↓" name="utf8nameè"/>
<BoundingBox maxy="5606011.4565" maxx="913204.9128" miny="5606011.4565" CRS="EPSG:3857" minx="913204.9128"/>
<Attribute type="derived" value="Point (913204.9128 5606011.4565)" name="geometry"/>
</Feature>
</Layer>
</GetFeatureInfoResponse>
1 change: 0 additions & 1 deletion tests/testdata/qgis_server/wms_getfeatureinfo_filter.txt
Expand Up @@ -10,7 +10,6 @@ Content-Type: text/xml; charset=utf-8
<Attribute value="two àò" name="utf8nameè"/>
<Attribute value="1" name="orig_ogc_fid"/>
<BoundingBox maxy="5606017.8743" maxx="913214.6741" miny="5606017.8743" CRS="EPSG:3857" minx="913214.6741"/>
<Attribute type="derived" value="Point (913214.6741 5606017.8743)" name="geometry"/>
</Feature>
</Layer>
</GetFeatureInfoResponse>
2 changes: 0 additions & 2 deletions tests/testdata/qgis_server/wms_getfeatureinfo_filter_or.txt
Expand Up @@ -10,15 +10,13 @@ Content-Type: text/xml; charset=utf-8
<Attribute value="two àò" name="utf8nameè"/>
<Attribute value="1" name="orig_ogc_fid"/>
<BoundingBox maxy="5606017.8743" maxx="913214.6741" miny="5606017.8743" CRS="EPSG:3857" minx="913214.6741"/>
<Attribute type="derived" value="Point (913214.6741 5606017.8743)" name="geometry"/>
</Feature>
<Feature id="2">
<Attribute value="3" name="id"/>
<Attribute value="three" name="name"/>
<Attribute value="three èé↓" name="utf8nameè"/>
<Attribute value="2" name="orig_ogc_fid"/>
<BoundingBox maxy="5606011.4565" maxx="913204.9128" miny="5606011.4565" CRS="EPSG:3857" minx="913204.9128"/>
<Attribute type="derived" value="Point (913204.9128 5606011.4565)" name="geometry"/>
</Feature>
</Layer>
</GetFeatureInfoResponse>
Expand Up @@ -10,15 +10,13 @@ Content-Type: text/xml; charset=utf-8
<Attribute value="two àò" name="utf8nameè"/>
<Attribute value="1" name="orig_ogc_fid"/>
<BoundingBox maxy="5606017.8743" maxx="913214.6741" miny="5606017.8743" CRS="EPSG:3857" minx="913214.6741"/>
<Attribute type="derived" value="Point (913214.6741 5606017.8743)" name="geometry"/>
</Feature>
<Feature id="2">
<Attribute value="3" name="id"/>
<Attribute value="three" name="name"/>
<Attribute value="three èé↓" name="utf8nameè"/>
<Attribute value="2" name="orig_ogc_fid"/>
<BoundingBox maxy="5606011.4565" maxx="913204.9128" miny="5606011.4565" CRS="EPSG:3857" minx="913204.9128"/>
<Attribute type="derived" value="Point (913204.9128 5606011.4565)" name="geometry"/>
</Feature>
</Layer>
</GetFeatureInfoResponse>
Expand Up @@ -8,7 +8,6 @@ Content-Type: text/xml; charset=utf-8
<Attribute name="name" value="two"/>
<Attribute name="utf8nameè" value="two àò"/>
<BoundingBox CRS="EPSG:3857" minx="913214.6741" maxx="913214.6741" miny="5606017.8743" maxy="5606017.8743"/>
<Attribute name="geometry" value="Point (913214.6741 5606017.8743)" type="derived"/>
</Feature>
</Layer>
</GetFeatureInfoResponse>

0 comments on commit a843df8

Please sign in to comment.