@@ -766,6 +766,8 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
766
766
767
767
// layers can have assigned a different name for GetCapabilities
768
768
QHash<QString, QString> layerAliasMap = mConfigParser ->featureInfoLayerAliasMap ();
769
+ // collect layer name / maplayer for potential later modifications of the xml
770
+ QMap< QString, QgsMapLayer* > layerNameMap;
769
771
770
772
QList<QgsMapLayer*> layerList;
771
773
QgsMapLayer* currentLayer = 0 ;
@@ -805,6 +807,7 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
805
807
}
806
808
layerElement.setAttribute ( " name" , layerName );
807
809
getFeatureInfoElement.appendChild ( layerElement );
810
+ layerNameMap.insert ( layerName, currentLayer );
808
811
809
812
// switch depending on vector or raster
810
813
QgsVectorLayer* vectorLayer = dynamic_cast <QgsVectorLayer*>( currentLayer );
@@ -848,71 +851,8 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
848
851
if ( mConfigParser ->featureInfoFormatSIA2045 ()
849
852
&& mParameterMap .value ( " INFO_FORMAT" ).compare ( " text/xml" , Qt::CaseInsensitive ) == 0 )
850
853
{
851
- // infoFormat = "text/xml; format=sia2045";
852
- QDomDocument outFeatureInfoDoc;
853
- QDomElement infoDocElement = result.documentElement ();
854
- QDomElement outInfoDocElement = outFeatureInfoDoc.importNode ( infoDocElement, false ).toElement ();
855
- outFeatureInfoDoc.appendChild ( outInfoDocElement );
856
-
857
- QString currentAttributeName;
858
- QString currentAttributeValue;
859
- QDomElement currentAttributeElem;
860
- QString currentLayerName;
861
- QDomElement currentLayerElem;
862
- QDomNodeList layerNodeList = infoDocElement.elementsByTagName ( " Layer" );
863
- for ( int i = 0 ; i < layerNodeList.size (); ++i )
864
- {
865
- currentLayerElem = layerNodeList.at ( i ).toElement ();
866
- currentLayerName = currentLayerElem.attribute ( " name" );
867
- QDomElement currentFeatureElem;
868
854
869
- QDomNodeList featureList = currentLayerElem.elementsByTagName ( " Feature" );
870
- if ( featureList.size () < 1 )
871
- {
872
- // raster?
873
- QDomNodeList attributeList = currentLayerElem.elementsByTagName ( " Attribute" );
874
- QDomElement rasterLayerElem;
875
- if ( attributeList.size () > 0 )
876
- {
877
- rasterLayerElem = outFeatureInfoDoc.createElement ( currentLayerName );
878
- }
879
- for ( int j = 0 ; j < attributeList.size (); ++j )
880
- {
881
- currentAttributeElem = attributeList.at ( j ).toElement ();
882
- currentAttributeName = currentAttributeElem.attribute ( " name" );
883
- currentAttributeValue = currentAttributeElem.attribute ( " value" );
884
- QDomElement outAttributeElem = outFeatureInfoDoc.createElement ( currentAttributeName );
885
- QDomText outAttributeText = outFeatureInfoDoc.createTextNode ( currentAttributeValue );
886
- outAttributeElem.appendChild ( outAttributeText );
887
- rasterLayerElem.appendChild ( outAttributeElem );
888
- }
889
- if ( attributeList.size () > 0 )
890
- {
891
- outInfoDocElement.appendChild ( rasterLayerElem );
892
- }
893
- }
894
- else // vector
895
- {
896
- for ( int j = 0 ; j < featureList.size (); ++j )
897
- {
898
- QDomElement outFeatureElem = outFeatureInfoDoc.createElement ( currentLayerName );
899
- currentFeatureElem = featureList.at ( j ).toElement ();
900
- QDomNodeList attributeList = currentFeatureElem.elementsByTagName ( " Attribute" );
901
- for ( int k = 0 ; k < attributeList.size (); ++k )
902
- {
903
- currentAttributeElem = attributeList.at ( k ).toElement ();
904
- currentAttributeName = currentAttributeElem.attribute ( " name" );
905
- currentAttributeValue = currentAttributeElem.attribute ( " value" );
906
- QDomElement outAttributeElem = outFeatureInfoDoc.createElement ( currentAttributeName );
907
- QDomText outAttributeText = outFeatureInfoDoc.createTextNode ( currentAttributeValue );
908
- outAttributeElem.appendChild ( outAttributeText );
909
- outFeatureElem.appendChild ( outAttributeElem );
910
- }
911
- outInfoDocElement.appendChild ( outFeatureElem );
912
- }
913
- }
914
- }
915
- result = outFeatureInfoDoc;
855
+ convertFeatureInfoToSIA2045 ( result, layerNameMap );
916
856
}
917
857
918
858
restoreLayerFilters ( originalLayerFilters );
@@ -2128,3 +2068,120 @@ void QgsWMSServer::addXMLDeclaration( QDomDocument& doc ) const
2128
2068
QDomProcessingInstruction xmlDeclaration = doc.createProcessingInstruction ( " xml" , " version=\" 1.0\" " );
2129
2069
doc.appendChild ( xmlDeclaration );
2130
2070
}
2071
+
2072
+ void QgsWMSServer::convertFeatureInfoToSIA2045 ( QDomDocument& doc, const QMap< QString, QgsMapLayer* >& layerNameMap )
2073
+ {
2074
+ QDomDocument SIAInfoDoc;
2075
+ QDomElement infoDocElement = doc.documentElement ();
2076
+ QDomElement SIAInfoDocElement = SIAInfoDoc.importNode ( infoDocElement, false ).toElement ();
2077
+ SIAInfoDoc.appendChild ( SIAInfoDocElement );
2078
+
2079
+ QString currentAttributeName;
2080
+ QString currentAttributeValue;
2081
+ QDomElement currentAttributeElem;
2082
+ QString currentLayerName;
2083
+ QDomElement currentLayerElem;
2084
+ QDomNodeList layerNodeList = infoDocElement.elementsByTagName ( " Layer" );
2085
+ for ( int i = 0 ; i < layerNodeList.size (); ++i )
2086
+ {
2087
+ currentLayerElem = layerNodeList.at ( i ).toElement ();
2088
+ currentLayerName = currentLayerElem.attribute ( " name" );
2089
+
2090
+ QDomElement currentFeatureElem;
2091
+
2092
+ QDomNodeList featureList = currentLayerElem.elementsByTagName ( " Feature" );
2093
+ if ( featureList.size () < 1 )
2094
+ {
2095
+ // raster?
2096
+ QDomNodeList attributeList = currentLayerElem.elementsByTagName ( " Attribute" );
2097
+ QDomElement rasterLayerElem;
2098
+ if ( attributeList.size () > 0 )
2099
+ {
2100
+ rasterLayerElem = SIAInfoDoc.createElement ( currentLayerName );
2101
+ }
2102
+ for ( int j = 0 ; j < attributeList.size (); ++j )
2103
+ {
2104
+ currentAttributeElem = attributeList.at ( j ).toElement ();
2105
+ currentAttributeName = currentAttributeElem.attribute ( " name" );
2106
+ currentAttributeValue = currentAttributeElem.attribute ( " value" );
2107
+ QDomElement outAttributeElem = SIAInfoDoc.createElement ( currentAttributeName );
2108
+ QDomText outAttributeText = SIAInfoDoc.createTextNode ( currentAttributeValue );
2109
+ outAttributeElem.appendChild ( outAttributeText );
2110
+ rasterLayerElem.appendChild ( outAttributeElem );
2111
+ }
2112
+ if ( attributeList.size () > 0 )
2113
+ {
2114
+ SIAInfoDocElement.appendChild ( rasterLayerElem );
2115
+ }
2116
+ }
2117
+ else // vector
2118
+ {
2119
+
2120
+ // property attributes
2121
+ QSet<QString> layerPropertyAttributes;
2122
+ QMap< QString, QgsMapLayer* >::const_iterator layerNameMapIt = layerNameMap.find ( currentLayerName );
2123
+ if ( layerNameMapIt != layerNameMap.constEnd () )
2124
+ {
2125
+ QgsMapLayer* currentLayer = layerNameMapIt.value ();
2126
+ if ( currentLayer )
2127
+ {
2128
+ QString WMSPropertyAttributesString = currentLayer->customProperty ( " WMSPropertyAttributes" ).toString ();
2129
+ if ( !WMSPropertyAttributesString.isEmpty () )
2130
+ {
2131
+ QStringList propertyList = WMSPropertyAttributesString.split ( " //" );
2132
+ QStringList::const_iterator propertyIt = propertyList.constBegin ();
2133
+ for ( ; propertyIt != propertyList.constEnd (); ++propertyIt )
2134
+ {
2135
+ layerPropertyAttributes.insert ( *propertyIt );
2136
+ }
2137
+ }
2138
+ }
2139
+ }
2140
+
2141
+ QDomElement propertyRefChild; // child to insert the next property after (or
2142
+ for ( int j = 0 ; j < featureList.size (); ++j )
2143
+ {
2144
+ QDomElement SIAFeatureElem = SIAInfoDoc.createElement ( currentLayerName );
2145
+ currentFeatureElem = featureList.at ( j ).toElement ();
2146
+ QDomNodeList attributeList = currentFeatureElem.elementsByTagName ( " Attribute" );
2147
+
2148
+ for ( int k = 0 ; k < attributeList.size (); ++k )
2149
+ {
2150
+ currentAttributeElem = attributeList.at ( k ).toElement ();
2151
+ currentAttributeName = currentAttributeElem.attribute ( " name" );
2152
+ currentAttributeValue = currentAttributeElem.attribute ( " value" );
2153
+ if ( layerPropertyAttributes.contains ( currentAttributeName ) )
2154
+ {
2155
+ QDomElement propertyElem = SIAInfoDoc.createElement ( " property" );
2156
+ QDomElement identifierElem = SIAInfoDoc.createElement ( " identifier" );
2157
+ QDomText identifierText = SIAInfoDoc.createTextNode ( currentAttributeName );
2158
+ identifierElem.appendChild ( identifierText );
2159
+ QDomElement valueElem = SIAInfoDoc.createElement ( " value" );
2160
+ QDomText valueText = SIAInfoDoc.createTextNode ( currentAttributeValue );
2161
+ valueElem.appendChild ( valueText );
2162
+ propertyElem.appendChild ( identifierElem );
2163
+ propertyElem.appendChild ( valueElem );
2164
+ if ( propertyRefChild.isNull () )
2165
+ {
2166
+ SIAFeatureElem.insertBefore ( propertyElem, QDomNode () );
2167
+ propertyRefChild = propertyElem;
2168
+ }
2169
+ else
2170
+ {
2171
+ SIAFeatureElem.insertAfter ( propertyElem, propertyRefChild );
2172
+ }
2173
+ }
2174
+ else
2175
+ {
2176
+ QDomElement SIAAttributeElem = SIAInfoDoc.createElement ( currentAttributeName );
2177
+ QDomText SIAAttributeText = SIAInfoDoc.createTextNode ( currentAttributeValue );
2178
+ SIAAttributeElem.appendChild ( SIAAttributeText );
2179
+ SIAFeatureElem.appendChild ( SIAAttributeElem );
2180
+ }
2181
+ }
2182
+ SIAInfoDocElement.appendChild ( SIAFeatureElem );
2183
+ }
2184
+ }
2185
+ }
2186
+ doc = SIAInfoDoc;
2187
+ }
0 commit comments