Skip to content
Permalink
Browse files

Support replacement of layer names in GetFeatureInfo with the element…

…s WMSFeatureInfoAliasLayers and WMSFeatureInfoLayerAliases
  • Loading branch information
mhugent committed Jan 18, 2012
1 parent 98876da commit 828ee7ec419e91214a626766484c5c13fe1c6835
@@ -113,6 +113,9 @@ class QgsConfigParser
/**Appends service metadata to the capabilities document*/
virtual void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

/**Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias*/
virtual QHash<QString, QString> featureInfoLayerAliasMap() const { return QHash<QString, QString>(); }

protected:
/**Parser to forward not resolved requests (e.g. SLD parser based on user request might have a fallback parser with admin configuration)*/
QgsConfigParser* mFallbackParser;
@@ -1353,6 +1353,50 @@ void QgsProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocu
parentElement.appendChild( serviceElem );
}

QHash<QString, QString> QgsProjectParser::featureInfoLayerAliasMap() const
{
QHash<QString, QString> aliasMap;
QDomElement propertiesElem = mXMLDoc->documentElement().firstChildElement( "properties" );
if ( propertiesElem.isNull() )
{
return aliasMap;
}

//WMSFeatureInfoAliasLayers
QStringList aliasLayerStringList;
QDomElement featureInfoAliasLayersElem = propertiesElem.firstChildElement( "WMSFeatureInfoAliasLayers" );
if ( featureInfoAliasLayersElem.isNull() )
{
return aliasMap;
}
QDomNodeList aliasLayerValueList = featureInfoAliasLayersElem.elementsByTagName( "value" );
for ( int i = 0; i < aliasLayerValueList.size(); ++i )
{
aliasLayerStringList << aliasLayerValueList.at( i ).toElement().text();
}

//WMSFeatureInfoLayerAliases
QStringList layerAliasStringList;
QDomElement featureInfoLayerAliasesElem = propertiesElem.firstChildElement( "WMSFeatureInfoLayerAliases" );
if ( featureInfoLayerAliasesElem.isNull() )
{
return aliasMap;
}
QDomNodeList layerAliasesValueList = featureInfoLayerAliasesElem.elementsByTagName( "value" );
for ( int i = 0; i < layerAliasesValueList.size(); ++i )
{
layerAliasStringList << layerAliasesValueList.at( i ).toElement().text();
}

int nMapEntries = qMin( aliasLayerStringList.size(), layerAliasStringList.size() );
for ( int i = 0; i < nMapEntries; ++i )
{
aliasMap.insert( aliasLayerStringList.at( i ), layerAliasStringList.at( i ) );
}

return aliasMap;
}

QString QgsProjectParser::convertToAbsolutePath( const QString& file ) const
{
if ( !file.startsWith( "./" ) && !file.startsWith( "../" ) )
@@ -101,6 +101,9 @@ class QgsProjectParser: public QgsConfigParser
/**Reads service metadata from projectfile or falls back to parent class method if not there*/
void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

/**Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias*/
virtual QHash<QString, QString> featureInfoLayerAliasMap() const;

private:

//forbidden
@@ -1564,6 +1564,15 @@ bool QgsSLDParser::featureInfoWithWktGeometry() const
return false;
}

QHash<QString, QString> QgsSLDParser::featureInfoLayerAliasMap() const
{
if ( mFallbackParser )
{
return mFallbackParser->featureInfoLayerAliasMap();
}
return QHash<QString, QString>();
}

#ifdef DIAGRAMSERVER
int QgsSLDParser::overlaysFromUserStyle( const QDomElement& userStyleElement, QgsVectorLayer* vec ) const
{
@@ -79,6 +79,9 @@ class QgsSLDParser: public QgsConfigParser
/**True if the feature info response should contain the wkt geometry for vector features*/
virtual bool featureInfoWithWktGeometry() const;

/**Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias*/
virtual QHash<QString, QString> featureInfoLayerAliasMap() const;

private:
/**Don't use the default constructor*/
QgsSLDParser();
@@ -810,6 +810,9 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
QMap< QString, QMap< int, QString > > aliasInfo = mConfigParser->layerAliasInfo();
QMap< QString, QSet<QString> > hiddenAttributes = mConfigParser->hiddenAttributes();

//layers can have assigned a different name for GetCapabilities
QHash<QString, QString> layerAliasMap = mConfigParser->featureInfoLayerAliasMap();

QList<QgsMapLayer*> layerList;
QgsMapLayer* currentLayer = 0;
QStringList::const_iterator layerIt;
@@ -838,7 +841,15 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
}

QDomElement layerElement = result.createElement( "Layer" );
layerElement.setAttribute( "name", currentLayer->name() );
QString layerName = currentLayer->name();

//check if the layer is given a different name for GetFeatureInfo output
QHash<QString, QString>::const_iterator layerAliasIt = layerAliasMap.find( layerName );
if ( layerAliasIt != layerAliasMap.constEnd() )
{
layerName = layerAliasIt.value();
}
layerElement.setAttribute( "name", layerName );
getFeatureInfoElement.appendChild( layerElement );

//switch depending on vector or raster

0 comments on commit 828ee7e

Please sign in to comment.
You can’t perform that action at this time.