Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
apply style from the input layer to the output vector tiles layer
  • Loading branch information
alexbruy authored and nyalldawson committed May 17, 2023
1 parent 7697ed9 commit 210d9db
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/analysis/processing/qgsalgorithmdownloadvectortiles.cpp
Expand Up @@ -23,6 +23,31 @@

///@cond PRIVATE

class SetStylePostProcessor : public QgsProcessingLayerPostProcessorInterface
{
public:

SetStylePostProcessor( QgsVectorTileLayer *inputLayer )
: mLayer( inputLayer )
{}

void postProcessLayer( QgsMapLayer *layer, QgsProcessingContext &, QgsProcessingFeedback * ) override
{
if ( QgsVectorTileLayer *tileLayer = qobject_cast< QgsVectorTileLayer * >( layer ) )
{
QDomDocument doc( QStringLiteral( "qgis" ) );
QString errorMsg;
mLayer->exportNamedStyle( doc, errorMsg );
tileLayer->importNamedStyle( doc, errorMsg );
tileLayer->triggerRepaint();
}
}

private:

QgsVectorTileLayer *mLayer;
};

QString QgsDownloadVectorTilesAlgorithm::name() const
{
return QStringLiteral( "downloadvectortiles" );
Expand Down Expand Up @@ -171,6 +196,11 @@ QVariantMap QgsDownloadVectorTilesAlgorithm::processAlgorithm( const QVariantMap
it++;
}

if ( context.willLoadLayerOnCompletion( outputFile ) )
{
context.layerToLoadOnCompletionDetails( outputFile ).setPostProcessor( new SetStylePostProcessor( vtLayer ) );
}

QVariantMap results;
results.insert( QStringLiteral( "OUTPUT" ), outputFile );
return results;
Expand Down

0 comments on commit 210d9db

Please sign in to comment.