Skip to content

Commit 724813a

Browse files
committedJan 28, 2019
GeoServer compatibility
1 parent df75801 commit 724813a

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed
 

‎src/core/qgsjsonutils.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,7 @@ QString QgsJsonExporter::exportFeatures( const QgsFeatureList &features ) const
243243
featureJSON << exportFeature( feature );
244244
}
245245

246-
QString layerName;
247-
if ( mIncludeName )
248-
layerName = QStringLiteral( "\n \"name\": \"%1\",\n" ).arg( mLayer->name() );
249-
250-
return QStringLiteral( "{%1 \"type\": \"FeatureCollection\",\n \"features\":[\n%2\n]}" ).arg( layerName, featureJSON.join( QStringLiteral( ",\n" ) ) );
246+
return QStringLiteral( "{\"type\": \"FeatureCollection\",\n \"features\":[\n%2\n]}" ).arg( featureJSON.join( QStringLiteral( ",\n" ) ) );
251247
}
252248

253249

‎src/core/qgsjsonutils.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,6 @@ class CORE_EXPORT QgsJsonExporter
7575
*/
7676
bool includeGeometry() const { return mIncludeGeometry; }
7777

78-
/**
79-
* Sets whether to include layer's name in the JSON exports.
80-
* \param includeName set to false to prevent name inclusion
81-
* \see includeName()
82-
* \since QGIS 3.6
83-
*/
84-
void setIncludeName( bool includeName ) { mIncludeName = includeName; }
85-
86-
/**
87-
* Returns whether layer's name will be included in the JSON exports.
88-
* \see setIncludeName()
89-
* \since QGIS 3.6
90-
*/
91-
bool includeName() const { return mIncludeName; }
92-
9378
/**
9479
* Sets whether to include attributes in the JSON exports.
9580
* \param includeAttributes set to false to prevent attribute inclusion

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,8 @@ namespace QgsWms
22812281
QByteArray QgsRenderer::convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc ) const
22822282
{
22832283
QString json;
2284-
json.append( QStringLiteral( "{\n\"layers\":[" ) );
2284+
json.append( QStringLiteral( "{\"type\": \"FeatureCollection\",\n" ) );
2285+
json.append( QStringLiteral( " \"features\":[\n" ) );
22852286

22862287
const bool withGeometry = ( QgsServerProjectUtils::wmsFeatureInfoAddWktGeometry( *mProject ) && mWmsParameters.withGeometry() );
22872288

@@ -2340,17 +2341,24 @@ namespace QgsWms
23402341
exporter.setAttributeDisplayName( true );
23412342
exporter.setAttributes( attributes );
23422343
exporter.setIncludeGeometry( withGeometry );
2343-
exporter.setIncludeName( true );
23442344

2345-
if ( i > 0 )
2346-
json.append( QStringLiteral( "," ) );
2345+
for ( const auto feature : features )
2346+
{
2347+
if ( json.right( 1 ).compare( QStringLiteral( "}" ) ) == 0 )
2348+
{
2349+
json.append( QStringLiteral( "," ) );
2350+
}
23472351

2348-
json.append( exporter.exportFeatures( features ) );
2352+
const QString id = QStringLiteral( "%1.%2" ).arg( layer->name(), QgsJsonUtils::encodeValue( feature.id() ) );
2353+
json.append( exporter.exportFeature( feature, QVariantMap(), id ) );
2354+
}
23492355
}
23502356
else // raster layer
23512357
{
23522358
json.append( QStringLiteral( "{" ) );
2353-
json.append( QStringLiteral( "\n \"name\": \"%1\",\n" ).arg( layer->name() ) );
2359+
json.append( QStringLiteral( "\"type\":\"Feature\",\n" ) );
2360+
json.append( QStringLiteral( "\"id\":\"%1\",\n" ).arg( layer->name() ) );
2361+
json.append( QStringLiteral( "\"properties\":{\n" ) );
23542362

23552363
const QDomNodeList attributesNode = layerElem.elementsByTagName( QStringLiteral( "Attribute" ) );
23562364
for ( int j = 0; j < attributesNode.size(); ++j )
@@ -2362,10 +2370,10 @@ namespace QgsWms
23622370
if ( j > 0 )
23632371
json.append( QStringLiteral( ",\n" ) );
23642372

2365-
json.append( QStringLiteral( "\"%1\": \"%2\"" ).arg( name, value ) );
2373+
json.append( QStringLiteral( " \"%1\": \"%2\"" ).arg( name, value ) );
23662374
}
23672375

2368-
json.append( QStringLiteral( "\n}" ) );
2376+
json.append( QStringLiteral( "\n}\n}" ) );
23692377
}
23702378
}
23712379

0 commit comments

Comments
 (0)
Please sign in to comment.