Skip to content
Permalink
Browse files

Add layers tag and their names in exported json

  • Loading branch information
pblottiere committed Jan 28, 2019
1 parent e4cdd7c commit f9eba37b1071f6e716456ccad11653e05dd93e9b
Showing with 19 additions and 1 deletion.
  1. +5 −1 src/core/qgsjsonutils.cpp
  2. +5 −0 src/core/qgsjsonutils.h
  3. +9 −0 src/server/services/wms/qgswmsrenderer.cpp
@@ -237,7 +237,11 @@ QString QgsJsonExporter::exportFeatures( const QgsFeatureList &features ) const
featureJSON << exportFeature( feature );
}

return QStringLiteral( "{ \"type\": \"FeatureCollection\",\n \"features\":[\n%1\n]}" ).arg( featureJSON.join( QStringLiteral( ",\n" ) ) );
QString layerName;
if ( mIncludeLayerName )
layerName.append( QStringLiteral( "\n \"name\": \"%1\",\n" ).arg( mLayer->name() ) );

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


@@ -75,6 +75,10 @@ class CORE_EXPORT QgsJsonExporter
*/
bool includeGeometry() const { return mIncludeGeometry; }

void setIncludeLayerName( bool includeLayerName ) { mIncludeLayerName = includeLayerName; }

bool includeLayerName() const { return mIncludeLayerName; }

/**
* Sets whether to include attributes in the JSON exports.
* \param includeAttributes set to false to prevent attribute inclusion
@@ -223,6 +227,7 @@ class CORE_EXPORT QgsJsonExporter

QgsCoordinateTransform mTransform;

bool mIncludeLayerName = false;
};

/**
@@ -2281,6 +2281,8 @@ namespace QgsWms
QByteArray QgsRenderer::convertFeatureInfoToJson( const QList<QgsMapLayer *> &layers, const QDomDocument &doc ) const
{
QString json;
json.append( "{" );
json.append( ( "\"layers\":[" ) );

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

@@ -2338,13 +2340,20 @@ namespace QgsWms
QgsJsonExporter exporter( vl );
exporter.setAttributes( attributes );
exporter.setIncludeGeometry( withGeometry );
exporter.setIncludeLayerName( true );

if ( i > 0 )
json.append( "," );

json.append( exporter.exportFeatures( features ) );
}
else // raster layer
{
}
}

json.append( ( "]}" ) );

return json.toUtf8();
}

0 comments on commit f9eba37

Please sign in to comment.
You can’t perform that action at this time.