Skip to content

Commit

Permalink
Add WMS with_maptip parameter value to request only maptip for HTML f…
Browse files Browse the repository at this point in the history
…eature info response
  • Loading branch information
pathmapper committed Jan 13, 2024
1 parent db7efca commit f4a44dc
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 18 deletions.
25 changes: 22 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,29 @@ 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 ) )
return true;
else
return false;
}

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

if ( mStr.startsWith( QLatin1String( "true_and_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
73 changes: 58 additions & 15 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
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;
if ( !onlyMapTip )
{
featureInfoString.append( QStringLiteral( R"HTML( <!DOCTYPE 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,28 @@ 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( 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 +2691,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 +2714,39 @@ 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( 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
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=true_and_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=true_and_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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*****
Content-Type: text/html; charset=utf-8

Value Band 5: 90
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*****
Content-Type: text/html; charset=utf-8

Name: three

0 comments on commit f4a44dc

Please sign in to comment.