Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] Add WMS parameter value to request only maptip for HTML feature info response #55823

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/server/services/wms/qgswmsparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,7 @@ namespace QgsWms
save( pWithGeometry );

const QgsWmsParameter pWithMapTip( QgsWmsParameter::WITH_MAPTIP,
QVariant::Bool,
QVariant( false ) );
QVariant::String );
save( pWithMapTip );

const QgsWmsParameter pWithDisplayName( QgsWmsParameter::WITH_DISPLAY_NAME,
Expand Down Expand Up @@ -2105,9 +2104,32 @@ namespace QgsWms
return mWmsParameters.value( QgsWmsParameter::WITH_GEOMETRY ).toBool();
}

QString QgsWmsParameters::withMapTipAsString() const
{
return mWmsParameters.value( QgsWmsParameter::WITH_MAPTIP ).toString();
}

bool QgsWmsParameters::withMapTip() const
{
return mWmsParameters.value( QgsWmsParameter::WITH_MAPTIP ).toBool();
const QString mStr = withMapTipAsString();

if ( mStr.startsWith( QLatin1String( "true" ), Qt::CaseInsensitive ) ||
mStr.startsWith( QLatin1String( "on" ), Qt::CaseInsensitive ) ||
mStr.startsWith( QLatin1String( "yes" ), Qt::CaseInsensitive ) ||
mStr.startsWith( QLatin1String( "1" ) ) )
return true;
else
return false;
}

bool QgsWmsParameters::htmlInfoOnlyMapTip() const
{
const QString mStr = withMapTipAsString();

if ( mStr.startsWith( QLatin1String( "html_fi_only_maptip" ), Qt::CaseInsensitive ) )
return true;
else
return false;
}

bool QgsWmsParameters::withDisplayName() const
Expand Down
15 changes: 15 additions & 0 deletions src/server/services/wms/qgswmsparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -1308,12 +1308,27 @@ namespace QgsWms
*/
bool withGeometry() const;

/**
* \brief withMapTipAsString
* \returns WITH_MAPTIP parameter as string
* \since QGIS 3.36
*/
QString withMapTipAsString() const;

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

/**
* Returns TRUE if only maptip information is requested for HTML
* feature info response
* \returns htmlInfoOnlyMapTip
* \since QGIS 3.36
*/
bool htmlInfoOnlyMapTip() const;

/**
* \brief withDisplayName
* \returns TRUE if the display name is requested for feature info response
Expand Down
81 changes: 63 additions & 18 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ namespace QgsWms

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

QByteArray QgsRenderer::convertFeatureInfoToHtml( const QDomDocument &doc ) const
{
QString featureInfoString = QStringLiteral( R"HTML( <!DOCTYPE html>
const bool onlyMapTip = mWmsParameters.htmlInfoOnlyMapTip();
QString featureInfoString = QStringLiteral( " <!DOCTYPE html>" );
if ( !onlyMapTip )
{
featureInfoString.append( QStringLiteral( R"HTML(

<head>
<title>Information</title>
Expand Down Expand Up @@ -2613,7 +2617,8 @@ namespace QgsWms
</head>

<body>
)HTML" );
)HTML" ) );
}

const QDomNodeList layerList = doc.elementsByTagName( QStringLiteral( "Layer" ) );

Expand All @@ -2628,14 +2633,20 @@ namespace QgsWms

if ( !featureNodeList.isEmpty() ) //vector layer
{
const QString featureInfoLayerTitleString = QStringLiteral( " <div class='layer-title'>%1</div>" ).arg( layerElem.attribute( QStringLiteral( "title" ) ).toHtmlEscaped() );
featureInfoString.append( featureInfoLayerTitleString );
if ( !onlyMapTip )
{
const QString featureInfoLayerTitleString = QStringLiteral( " <div class='layer-title'>%1</div>" ).arg( layerElem.attribute( QStringLiteral( "title" ) ).toHtmlEscaped() );
featureInfoString.append( featureInfoLayerTitleString );
}

for ( int j = 0; j < featureNodeList.size(); ++j )
{
const QDomElement featureElement = featureNodeList.at( j ).toElement();
featureInfoString.append( QStringLiteral( R"HTML(
if ( !onlyMapTip )
{
featureInfoString.append( QStringLiteral( R"HTML(
<table>)HTML" ) );
}

//attribute loop
const QDomNodeList attributeNodeList = featureElement.elementsByTagName( QStringLiteral( "Attribute" ) );
Expand All @@ -2649,16 +2660,29 @@ namespace QgsWms
value = value.toHtmlEscaped();
}

const QString featureInfoAttributeString = QStringLiteral( R"HTML(
if ( !onlyMapTip )
{
const QString featureInfoAttributeString = QStringLiteral( R"HTML(
<tr>
<th>%1</th>
<td>%2</td>
</tr>)HTML" ).arg( name, value );

featureInfoString.append( featureInfoAttributeString );
featureInfoString.append( featureInfoAttributeString );
}
else if ( name == QStringLiteral( "maptip" ) )
{
featureInfoString.append( QStringLiteral( R"HTML(
%1)HTML" ).arg( value ) );
break;
}

}
featureInfoString.append( QStringLiteral( R"HTML(
if ( !onlyMapTip )
{
featureInfoString.append( QStringLiteral( R"HTML(
</table>)HTML" ) );
}
}
}
else //no result or raster layer
Expand All @@ -2668,11 +2692,15 @@ namespace QgsWms
// raster layer
if ( !attributeNodeList.isEmpty() )
{
const QString featureInfoLayerTitleString = QStringLiteral( " <div class='layer-title'>%1</div>" ).arg( layerElem.attribute( QStringLiteral( "title" ) ).toHtmlEscaped() );
featureInfoString.append( featureInfoLayerTitleString );
if ( !onlyMapTip )
{
const QString featureInfoLayerTitleString = QStringLiteral( " <div class='layer-title'>%1</div>" ).arg( layerElem.attribute( QStringLiteral( "title" ) ).toHtmlEscaped() );
featureInfoString.append( featureInfoLayerTitleString );

featureInfoString.append( QStringLiteral( R"HTML(
featureInfoString.append( QStringLiteral( R"HTML(
<table>)HTML" ) );
}

for ( int j = 0; j < attributeNodeList.size(); ++j )
{
const QDomElement attributeElement = attributeNodeList.at( j ).toElement();
Expand All @@ -2687,23 +2715,40 @@ namespace QgsWms
value = value.toHtmlEscaped();
}

const QString featureInfoAttributeString = QStringLiteral( R"HTML(
if ( !onlyMapTip )
{
const QString featureInfoAttributeString = QStringLiteral( R"HTML(
<tr>
<th>%1</th>
<td>%2</td>
</tr>)HTML" ).arg( name, value );

featureInfoString.append( featureInfoAttributeString );

featureInfoString.append( featureInfoAttributeString );
}
else if ( name == QStringLiteral( "maptip" ) )
{
featureInfoString.append( QStringLiteral( R"HTML(
%1)HTML" ).arg( value ) );
break;
}

}
featureInfoString.append( QStringLiteral( R"HTML(
if ( !onlyMapTip )
{
featureInfoString.append( QStringLiteral( R"HTML(
</table>)HTML" ) );
}
}
}
}

//end the html body
featureInfoString.append( QStringLiteral( R"HTML(
if ( !onlyMapTip )
{
featureInfoString.append( QStringLiteral( R"HTML(
</body>)HTML" ) );
}

return featureInfoString.toUtf8();
}
Expand Down Expand Up @@ -3048,7 +3093,7 @@ namespace QgsWms
{
QString mapTip = layer->mapTipTemplate();

if ( !mapTip.isEmpty() && mWmsParameters.withMapTip() )
if ( !mapTip.isEmpty() && ( mWmsParameters.withMapTip() || mWmsParameters.htmlInfoOnlyMapTip() ) )
{
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_getfeatureinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ def testGetFeatureInfo(self):
'with_maptip=true',
'wms_getfeatureinfo-text-html-maptip')

# Test getfeatureinfo response html only with maptip for vector layer
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=html_fi_only_maptip',
'wms_getfeatureinfo-html-only-with-maptip-vector')

# Test getfeatureinfo response html with maptip and display name in text mode for vector layer
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
Expand Down Expand Up @@ -271,6 +281,16 @@ def testGetFeatureInfo(self):
'with_maptip=true',
'wms_getfeatureinfo-raster-text-xml-maptip')

# Test GetFeatureInfo on raster layer HTML only with maptip
self.wms_request_compare('GetFeatureInfo',
'&layers=landsat&styles=&' +
'info_format=text%2Fhtml&transparent=true&' +
'width=500&height=500&srs=EPSG%3A3857&' +
'bbox=1989139.6,3522745.0,2015014.9,3537004.5&' +
'query_layers=landsat&X=250&Y=250&' +
'with_maptip=html_fi_only_maptip',
'wms_getfeatureinfo-html-only-with-maptip-raster')

def testGetFeatureInfoValueRelation(self):
"""Test GetFeatureInfo resolves "value relation" widget values. regression 18518"""
mypath = self.testdata_path + "test_project_values.qgz"
Expand Down
6 changes: 4 additions & 2 deletions tests/testdata/qgis_server/test_project.qgs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@
<property value="0" key="embeddedWidgets/count"/>
<property value="Value" key="identify/format"/>
</customproperties>
<mapTip enabled="1">[% 'Value Band 5: ' || raster_value(@layer_id, 5, @layer_cursor_point) %]</mapTip>
<mapTip enabled="1">&lt;title>Maptip&lt;/title>
[% 'Value Band 5: ' || raster_value(@layer_id, 5, @layer_cursor_point) %]</mapTip>
<pipe>
<rasterrenderer opacity="1" type="singlebandgray" grayBand="1" gradient="BlackToWhite" alphaBand="-1">
<rasterTransparency/>
Expand Down Expand Up @@ -561,7 +562,8 @@
<labelOnTop/>
<widgets/>
<previewExpression>"name"</previewExpression>
<mapTip>[% 'Name: ' || represent_value( "name" ) %]</mapTip>
<mapTip enabled="1">&lt;title>Maptip&lt;/title>
[% 'Name: ' || represent_value( "name" ) %]</mapTip>
</maplayer>
<maplayer refreshOnNotifyEnabled="0" maxScale="-4.65661e-10" refreshOnNotifyMessage="" type="vector" minScale="1e+8" labelsEnabled="1" readOnly="0" simplifyMaxScale="1" simplifyDrawingTol="1" styleCategories="AllStyleCategories" geometry="Point" simplifyDrawingHints="0" autoRefreshEnabled="0" hasScaleBasedVisibilityFlag="0" simplifyAlgorithm="0" simplifyLocal="1" autoRefreshTime="0">
<extent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*****
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<title>Maptip</title>
Value Band 5: 90
pathmapper marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*****
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<title>Maptip</title>
Name: three
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Content-Type: text/xml; charset=utf-8
<Attribute value="165" name="Band 7"/>
<Attribute value="217" name="Band 8"/>
<Attribute value="175" name="Band 9"/>
<Attribute value="Value Band 5: 90" name="maptip"/>
<Attribute value="&lt;title>Maptip&lt;/title>&#xa;Value Band 5: 90" name="maptip"/>
</Layer>
</GetFeatureInfoResponse>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Feature 2
id = '3'
name = 'three'
utf8nameè = 'three èé↓'
maptip = 'Name: three'
maptip = '<title>Maptip</title>
Name: three'
displayName = 'three'

Loading
Loading