Skip to content

Commit

Permalink
Fix raster fill opacity conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 9, 2020
1 parent 68c6e88 commit a1f25da
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/vectortile/qgsmapboxglstyleconverter.cpp
Expand Up @@ -165,6 +165,7 @@ bool QgsMapBoxGlStyleConverter::parseFillLayer( const QVariantMap &jsonLayer, Qg
const QVariantMap jsonPaint = jsonLayer.value( QStringLiteral( "paint" ) ).toMap();

QgsPropertyCollection ddProperties;
QgsPropertyCollection ddRasterProperties;

// fill color
QColor fillColor;
Expand Down Expand Up @@ -232,6 +233,7 @@ bool QgsMapBoxGlStyleConverter::parseFillLayer( const QVariantMap &jsonLayer, Qg
}

double fillOpacity = -1.0;
double rasterOpacity = -1.0;
if ( jsonPaint.contains( QStringLiteral( "fill-opacity" ) ) )
{
const QVariant jsonFillOpacity = jsonPaint.value( QStringLiteral( "fill-opacity" ) );
Expand All @@ -240,6 +242,7 @@ bool QgsMapBoxGlStyleConverter::parseFillLayer( const QVariantMap &jsonLayer, Qg
case QVariant::Int:
case QVariant::Double:
fillOpacity = jsonFillOpacity.toDouble();
rasterOpacity = fillOpacity;
break;

case QVariant::Map:
Expand All @@ -251,6 +254,7 @@ bool QgsMapBoxGlStyleConverter::parseFillLayer( const QVariantMap &jsonLayer, Qg
{
ddProperties.setProperty( QgsSymbolLayer::PropertyFillColor, parseInterpolateOpacityByZoom( jsonFillOpacity.toMap(), fillColor.isValid() ? fillColor.alpha() : 255 ) );
ddProperties.setProperty( QgsSymbolLayer::PropertyStrokeColor, parseInterpolateOpacityByZoom( jsonFillOpacity.toMap(), fillOutlineColor.isValid() ? fillOutlineColor.alpha() : 255 ) );
ddRasterProperties.setProperty( QgsSymbolLayer::PropertyOpacity, parseInterpolateByZoom( jsonFillOpacity.toMap(), context, 100, &rasterOpacity ) );
}
break;

Expand All @@ -264,6 +268,7 @@ bool QgsMapBoxGlStyleConverter::parseFillLayer( const QVariantMap &jsonLayer, Qg
{
ddProperties.setProperty( QgsSymbolLayer::PropertyFillColor, parseInterpolateListByZoom( jsonFillOpacity.toList(), PropertyType::Opacity, context, 1, fillColor.isValid() ? fillColor.alpha() : 255 ) );
ddProperties.setProperty( QgsSymbolLayer::PropertyStrokeColor, parseInterpolateListByZoom( jsonFillOpacity.toList(), PropertyType::Opacity, context, 1, fillOutlineColor.isValid() ? fillOutlineColor.alpha() : 255 ) );
ddRasterProperties.setProperty( QgsSymbolLayer::PropertyOpacity, parseInterpolateListByZoom( jsonFillOpacity.toList(), PropertyType::Numeric, context, 100, 255, nullptr, &rasterOpacity ) );
}
break;

Expand Down Expand Up @@ -341,6 +346,11 @@ bool QgsMapBoxGlStyleConverter::parseFillLayer( const QVariantMap &jsonLayer, Qg
QString path( encoded );
path.prepend( QLatin1String( "base64:" ) );
rasterFill->setImageFilePath( path );
rasterFill->setCoordinateMode( QgsRasterFillSymbolLayer::Viewport );

if ( rasterOpacity >= 0 )
rasterFill->setOpacity( rasterOpacity );
rasterFill->setDataDefinedProperties( ddRasterProperties );

symbol->appendSymbolLayer( rasterFill );
}
Expand Down

0 comments on commit a1f25da

Please sign in to comment.