@@ -1571,7 +1571,7 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
1571
1571
1572
1572
QDomElement attributeElement = infoDocument.createElement ( " Attribute" );
1573
1573
attributeElement.setAttribute ( " name" , attributeName );
1574
- attributeElement.setAttribute ( " value" , QgsExpression::replaceExpressionText ( featureAttributes[i].toString (), &feature, layer ) );
1574
+ attributeElement.setAttribute ( " value" , replaceValueMapAndRelation ( layer, i, QgsExpression::replaceExpressionText ( featureAttributes[i].toString (), &feature, layer ) ) );
1575
1575
featureElement.appendChild ( attributeElement );
1576
1576
}
1577
1577
@@ -1590,7 +1590,7 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
1590
1590
// also append the wkt geometry as an attribute
1591
1591
if ( addWktGeometry && hasGeometry )
1592
1592
{
1593
- QgsGeometry* geom = feature.geometry ();
1593
+ QgsGeometry* geom = feature.geometry ();
1594
1594
if ( layer->crs () != outputCrs )
1595
1595
{
1596
1596
const QgsCoordinateTransform *transform = mapRender->transformation ( layer );
@@ -2558,42 +2558,42 @@ QDomElement QgsWMSServer::createFeatureGML(
2558
2558
typeNameElement.setAttribute ( " fid" , typeName + " ." + QString::number ( feat->id () ) );
2559
2559
2560
2560
const QgsCoordinateTransform* transform = 0 ;
2561
- if ( layer && layer->crs () != crs)
2561
+ if ( layer && layer->crs () != crs )
2562
2562
{
2563
2563
transform = mMapRenderer ->transformation ( layer );
2564
2564
}
2565
2565
2566
2566
QgsGeometry* geom = feat->geometry ();
2567
2567
2568
2568
// always add bounding box info if feature contains geometry
2569
- if ( geom && geom->type () != QGis::UnknownGeometry && geom->type () != QGis::NoGeometry)
2570
- {
2571
- QgsRectangle box = feat->geometry ()->boundingBox ();
2572
- if ( transform )
2573
- {
2574
- box = transform->transformBoundingBox ( box );
2575
- }
2576
-
2577
- QDomElement bbElem = doc.createElement ( " gml:boundedBy" );
2578
- QDomElement boxElem;
2579
- if ( version < 3 )
2580
- {
2581
- boxElem = QgsOgcUtils::rectangleToGMLBox ( &box, doc );
2582
- }
2583
- else
2584
- {
2585
- boxElem = QgsOgcUtils::rectangleToGMLEnvelope ( &box, doc );
2586
- }
2587
-
2588
- if ( crs.isValid () )
2589
- {
2590
- boxElem.setAttribute ( " srsName" , crs.authid () );
2591
- }
2592
- bbElem.appendChild ( boxElem );
2593
- typeNameElement.appendChild ( bbElem );
2594
- }
2595
-
2596
- if ( withGeom)
2569
+ if ( geom && geom->type () != QGis::UnknownGeometry && geom->type () != QGis::NoGeometry )
2570
+ {
2571
+ QgsRectangle box = feat->geometry ()->boundingBox ();
2572
+ if ( transform )
2573
+ {
2574
+ box = transform->transformBoundingBox ( box );
2575
+ }
2576
+
2577
+ QDomElement bbElem = doc.createElement ( " gml:boundedBy" );
2578
+ QDomElement boxElem;
2579
+ if ( version < 3 )
2580
+ {
2581
+ boxElem = QgsOgcUtils::rectangleToGMLBox ( &box, doc );
2582
+ }
2583
+ else
2584
+ {
2585
+ boxElem = QgsOgcUtils::rectangleToGMLEnvelope ( &box, doc );
2586
+ }
2587
+
2588
+ if ( crs.isValid () )
2589
+ {
2590
+ boxElem.setAttribute ( " srsName" , crs.authid () );
2591
+ }
2592
+ bbElem.appendChild ( boxElem );
2593
+ typeNameElement.appendChild ( bbElem );
2594
+ }
2595
+
2596
+ if ( withGeom )
2597
2597
{
2598
2598
// add geometry column (as gml)
2599
2599
@@ -2634,7 +2634,7 @@ QDomElement QgsWMSServer::createFeatureGML(
2634
2634
QString fieldTextString = featureAttributes[i].toString ();
2635
2635
if ( layer )
2636
2636
{
2637
- fieldTextString = QgsExpression::replaceExpressionText ( fieldTextString, feat, layer );
2637
+ fieldTextString = replaceValueMapAndRelation ( layer, i, QgsExpression::replaceExpressionText ( fieldTextString, feat, layer ) );
2638
2638
}
2639
2639
QDomText fieldText = doc.createTextNode ( fieldTextString );
2640
2640
fieldElem.appendChild ( fieldText );
@@ -2643,3 +2643,31 @@ QDomElement QgsWMSServer::createFeatureGML(
2643
2643
2644
2644
return typeNameElement;
2645
2645
}
2646
+
2647
+ QString QgsWMSServer::replaceValueMapAndRelation ( QgsVectorLayer* vl, int idx, const QString& attributeVal )
2648
+ {
2649
+ if ( !vl )
2650
+ {
2651
+ return attributeVal;
2652
+ }
2653
+
2654
+ QgsVectorLayer::EditType type = vl->editType ( idx );
2655
+ if ( type == QgsVectorLayer::ValueMap )
2656
+ {
2657
+ QMap<QString, QVariant> valueMap = vl->valueMap ( idx );
2658
+ QMap<QString, QVariant>::const_iterator vmapIt = valueMap.constBegin ();
2659
+ for ( ; vmapIt != valueMap.constEnd (); ++vmapIt )
2660
+ {
2661
+ if ( vmapIt.value ().toString () == attributeVal )
2662
+ {
2663
+ return vmapIt.key ();
2664
+ }
2665
+ }
2666
+ }
2667
+ else if ( type == QgsVectorLayer::ValueRelation )
2668
+ {
2669
+ QgsVectorLayer::ValueRelationData vrdata = vl->valueRelation ( idx );
2670
+ // todo...
2671
+ }
2672
+ return attributeVal;
2673
+ }
0 commit comments