Skip to content
Permalink
Browse files
[FEATURE:] Consider maptip in GetFeatureInfo
  • Loading branch information
mhugent committed Apr 1, 2014
1 parent 1c3b5e4 commit 9eb4bb6b5b1f33fdd12b1a8152167a137cec51a1
Showing with 40 additions and 1 deletion.
  1. +13 −1 src/mapserver/qgsprojectparser.cpp
  2. +27 −0 src/mapserver/qgswmsserver.cpp
@@ -1546,6 +1546,7 @@ void QgsProjectParser::addLayerProjectSettings( QDomElement& layerElem, QDomDocu
QgsVectorLayer* vLayer = static_cast<QgsVectorLayer*>( currentLayer );
const QSet<QString>& excludedAttributes = vLayer->excludeAttributesWMS();
QString displayField = vLayer->displayField();
int displayFieldIdx = vLayer->fieldNameIndex( displayField );

//attributes
QDomElement attributesElem = doc.createElement( "Attributes" );
@@ -1575,8 +1576,19 @@ void QgsProjectParser::addLayerProjectSettings( QDomElement& layerElem, QDomDocu
attributeElem.setAttribute( "precision", field.precision() );
attributesElem.appendChild( attributeElem );
}

//displayfield
layerElem.setAttribute( "displayField", displayField );
if ( !displayField.isEmpty() )
{
if ( displayFieldIdx >= 0 )
{
layerElem.setAttribute( "displayField", displayField );
}
else
{
layerElem.setAttribute( "displayField", "maptip" );
}
}
layerElem.appendChild( attributesElem );
}
}
@@ -1558,6 +1558,19 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
featureElement.appendChild( attributeElement );
}

//add maptip attribute based on html/expression (in case there is no maptip attribute)
if ( layer->fieldNameIndex( layer->displayField() ) < 0 )
{
QString displayField = layer->displayField();
if ( !displayField.isEmpty() )
{
QDomElement maptipElem = infoDocument.createElement( "Attribute" );
maptipElem.setAttribute( "name", "maptip" );
maptipElem.setAttribute( "value", QgsExpression::replaceExpressionText( displayField, &feature, layer ) );
featureElement.appendChild( maptipElem );
}
}

//append feature bounding box to feature info xml
if ( hasGeometry && mapRender )
{
@@ -2608,6 +2621,20 @@ QDomElement QgsWMSServer::createFeatureGML(
typeNameElement.appendChild( fieldElem );
}

//add maptip attribute based on html/expression (in case there is no maptip attribute)
if ( layer->fieldNameIndex( layer->displayField() ) < 0 )
{
QString displayField = layer->displayField();
if ( !displayField.isEmpty() )
{
QString fieldTextString = QgsExpression::replaceExpressionText( displayField, feat, layer );
QDomElement fieldElem = doc.createElement( "qgs:maptip" );
QDomText maptipText = doc.createTextNode( fieldTextString );
fieldElem.appendChild( maptipText );
typeNameElement.appendChild( fieldElem );
}
}

return typeNameElement;
}

0 comments on commit 9eb4bb6

Please sign in to comment.