Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Server: respect "use layer ids" option in json getfeatureinfo
Fixes #36262
  • Loading branch information
elpaso committed May 26, 2020
1 parent 24ec1d9 commit 1e54c6b
Show file tree
Hide file tree
Showing 6 changed files with 2,513 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -2279,7 +2279,7 @@ namespace QgsWms

for ( const auto &feature : qgis::as_const( features ) )
{
const QString id = QStringLiteral( "%1.%2" ).arg( layer->name(), QgsJsonUtils::encodeValue( feature.id() ) );
const QString id = QStringLiteral( "%1.%2" ).arg( layerName ).arg( feature.id() );
json["features"].push_back( exporter.exportFeatureToJsonObject( feature, QVariantMap(), id ) );
}
}
Expand All @@ -2298,7 +2298,7 @@ namespace QgsWms
json["features"].push_back(
{
{"type", "Feature" },
{"id", layer->name().toStdString() },
{"id", layerName.toStdString() },
{"properties", properties }
} );
}
Expand Down
35 changes: 34 additions & 1 deletion tests/src/python/test_qgsserver_wms_getfeatureinfo.py
Expand Up @@ -40,7 +40,7 @@
class TestQgsServerWMSGetFeatureInfo(TestQgsServerWMSTestBase):
"""QGIS Server WMS Tests for GetFeatureInfo request"""

# regenerate_reference = True
#regenerate_reference = True

def testGetFeatureInfo(self):
# Test getfeatureinfo response xml
Expand Down Expand Up @@ -752,6 +752,39 @@ def testGetFeatureInfoGroupedLayers(self):
'test_project_wms_grouped_nested_layers.qgs',
normalizeJson=True)

def testGetFeatureInfoJsonUseIdAsLayerName(self):
"""Test GH #36262 where json response + use layer id"""

self.wms_request_compare('GetFeatureInfo',
'&BBOX=44.90139177500000045,8.20335906129666981,44.90148522499999473,8.20364693870333284' +
'&CRS=EPSG:4326' +
'&WIDTH=1568&HEIGHT=509' +
'&LAYERS=testlayer_%C3%A8%C3%A9_cf86cf11_222f_4b62_929c_12cfc82b9774' +
'&STYLES=' +
'&FORMAT=image/jpeg' +
'&QUERY_LAYERS=testlayer_%C3%A8%C3%A9_cf86cf11_222f_4b62_929c_12cfc82b9774' +
'&INFO_FORMAT=application/json' +
'&I=1022&J=269' +
'&FEATURE_COUNT=10',
'wms_getfeatureinfo_json_layer_ids',
'test_project_use_layer_ids.qgs',
normalizeJson=True)

# Raster
self.wms_request_compare('GetFeatureInfo',
'&BBOX=30.1492201749999964,17.81444988978388722,30.2599248249999988,18.15548111021611533' +
'&CRS=EPSG:4326' +
'&WIDTH=1568&HEIGHT=509' +
'&LAYERS=landsat_a7d15b35_ca83_4b23_a9fb_af3fbdd60d15' +
'&STYLES=' +
'&FORMAT=image/jpeg' +
'&QUERY_LAYERS=landsat_a7d15b35_ca83_4b23_a9fb_af3fbdd60d15' +
'&INFO_FORMAT=application/json' +
'&I=769&J=275&FEATURE_COUNT=10',
'wms_getfeatureinfo_json_layer_ids_raster',
'test_project_use_layer_ids.qgs',
normalizeJson=True)

@unittest.skipIf(os.environ.get('TRAVIS', '') == 'true',
"This test cannot run in TRAVIS because it relies on cascading external services")
def testGetFeatureInfoCascadingLayers(self):
Expand Down

0 comments on commit 1e54c6b

Please sign in to comment.