Skip to content

Commit

Permalink
GeoServer compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Jan 28, 2019
1 parent df75801 commit 724813a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
6 changes: 1 addition & 5 deletions src/core/qgsjsonutils.cpp
Expand Up @@ -243,11 +243,7 @@ QString QgsJsonExporter::exportFeatures( const QgsFeatureList &features ) const
featureJSON << exportFeature( feature );
}

QString layerName;
if ( mIncludeName )
layerName = QStringLiteral( "\n \"name\": \"%1\",\n" ).arg( mLayer->name() );

return QStringLiteral( "{%1 \"type\": \"FeatureCollection\",\n \"features\":[\n%2\n]}" ).arg( layerName, featureJSON.join( QStringLiteral( ",\n" ) ) );
return QStringLiteral( "{\"type\": \"FeatureCollection\",\n \"features\":[\n%2\n]}" ).arg( featureJSON.join( QStringLiteral( ",\n" ) ) );
}


Expand Down
15 changes: 0 additions & 15 deletions src/core/qgsjsonutils.h
Expand Up @@ -75,21 +75,6 @@ class CORE_EXPORT QgsJsonExporter
*/
bool includeGeometry() const { return mIncludeGeometry; }

/**
* Sets whether to include layer's name in the JSON exports.
* \param includeName set to false to prevent name inclusion
* \see includeName()
* \since QGIS 3.6
*/
void setIncludeName( bool includeName ) { mIncludeName = includeName; }

/**
* Returns whether layer's name will be included in the JSON exports.
* \see setIncludeName()
* \since QGIS 3.6
*/
bool includeName() const { return mIncludeName; }

/**
* Sets whether to include attributes in the JSON exports.
* \param includeAttributes set to false to prevent attribute inclusion
Expand Down
24 changes: 16 additions & 8 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -2281,7 +2281,8 @@ namespace QgsWms
QByteArray QgsRenderer::convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc ) const
{
QString json;
json.append( QStringLiteral( "{\n\"layers\":[" ) );
json.append( QStringLiteral( "{\"type\": \"FeatureCollection\",\n" ) );
json.append( QStringLiteral( " \"features\":[\n" ) );

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

Expand Down Expand Up @@ -2340,17 +2341,24 @@ namespace QgsWms
exporter.setAttributeDisplayName( true );
exporter.setAttributes( attributes );
exporter.setIncludeGeometry( withGeometry );
exporter.setIncludeName( true );

if ( i > 0 )
json.append( QStringLiteral( "," ) );
for ( const auto feature : features )
{
if ( json.right( 1 ).compare( QStringLiteral( "}" ) ) == 0 )
{
json.append( QStringLiteral( "," ) );
}

json.append( exporter.exportFeatures( features ) );
const QString id = QStringLiteral( "%1.%2" ).arg( layer->name(), QgsJsonUtils::encodeValue( feature.id() ) );
json.append( exporter.exportFeature( feature, QVariantMap(), id ) );
}
}
else // raster layer
{
json.append( QStringLiteral( "{" ) );
json.append( QStringLiteral( "\n \"name\": \"%1\",\n" ).arg( layer->name() ) );
json.append( QStringLiteral( "\"type\":\"Feature\",\n" ) );
json.append( QStringLiteral( "\"id\":\"%1\",\n" ).arg( layer->name() ) );
json.append( QStringLiteral( "\"properties\":{\n" ) );

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

json.append( QStringLiteral( "\"%1\": \"%2\"" ).arg( name, value ) );
json.append( QStringLiteral( " \"%1\": \"%2\"" ).arg( name, value ) );
}

json.append( QStringLiteral( "\n}" ) );
json.append( QStringLiteral( "\n}\n}" ) );
}
}

Expand Down

0 comments on commit 724813a

Please sign in to comment.