Skip to content

Commit

Permalink
Scale up buffer sizes when converting, in order to better match actua…
Browse files Browse the repository at this point in the history
…l MapBox rendering
  • Loading branch information
nyalldawson committed Sep 14, 2020
1 parent 37471e5 commit 09ea6be
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/vectortile/qgsmapboxglstyleconverter.cpp
Expand Up @@ -859,25 +859,29 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,
}

double bufferSize = 0.0;
// the pixel based text buffers appear larger when rendered on the web - so automatically scale
// them up when converting to a QGIS style
// (this number is based on trial-and-error comparisons only!)
constexpr double BUFFER_SIZE_SCALE = 2.0;
if ( jsonPaint.contains( QStringLiteral( "text-halo-width" ) ) )
{
const QVariant jsonHaloWidth = jsonPaint.value( QStringLiteral( "text-halo-width" ) );
switch ( jsonHaloWidth.type() )
{
case QVariant::Int:
case QVariant::Double:
bufferSize = jsonHaloWidth.toDouble() * context.pixelSizeConversionFactor();
bufferSize = jsonHaloWidth.toDouble() * context.pixelSizeConversionFactor() * BUFFER_SIZE_SCALE;
break;

case QVariant::Map:
bufferSize = 1;
ddLabelProperties.setProperty( QgsPalLayerSettings::BufferSize, parseInterpolateByZoom( jsonHaloWidth.toMap(), context, context.pixelSizeConversionFactor(), &bufferSize ) );
ddLabelProperties.setProperty( QgsPalLayerSettings::BufferSize, parseInterpolateByZoom( jsonHaloWidth.toMap(), context, context.pixelSizeConversionFactor() * BUFFER_SIZE_SCALE, &bufferSize ) );
break;

case QVariant::List:
case QVariant::StringList:
bufferSize = 1;
ddLabelProperties.setProperty( QgsPalLayerSettings::BufferSize, parseValueList( jsonHaloWidth.toList(), PropertyType::Numeric, context, context.pixelSizeConversionFactor(), 255, nullptr, &bufferSize ) );
ddLabelProperties.setProperty( QgsPalLayerSettings::BufferSize, parseValueList( jsonHaloWidth.toList(), PropertyType::Numeric, context, context.pixelSizeConversionFactor() * BUFFER_SIZE_SCALE, 255, nullptr, &bufferSize ) );
break;

default:
Expand Down

0 comments on commit 09ea6be

Please sign in to comment.