Skip to content

Commit

Permalink
[FEATURE:] Consider maptip in GetFeatureInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 1, 2014
1 parent 1c3b5e4 commit 9eb4bb6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/mapserver/qgsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down Expand Up @@ -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 );
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/mapserver/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 9eb4bb6

Please sign in to comment.