Skip to content

Commit

Permalink
Correctly handle some MapBox GL default values
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 14, 2020
1 parent f791674 commit 37471e5
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/core/vectortile/qgsmapboxglstyleconverter.cpp
Expand Up @@ -195,6 +195,11 @@ bool QgsMapBoxGlStyleConverter::parseFillLayer( const QVariantMap &jsonLayer, Qg
}
}
}
else
{
// defaults to #000000
fillColor = QColor( 0, 0, 0 );
}

QColor fillOutlineColor;
if ( !jsonPaint.contains( QStringLiteral( "fill-outline-color" ) ) )
Expand Down Expand Up @@ -322,6 +327,10 @@ bool QgsMapBoxGlStyleConverter::parseFillLayer( const QVariantMap &jsonLayer, Qg

const QVariant fillPatternJson = jsonPaint.value( QStringLiteral( "fill-pattern" ) );

// fill-pattern disabled dillcolor
fillColor = QColor();
fillOutlineColor = QColor();

// fill-pattern can be String or Object
// String: {"fill-pattern": "dash-t"}
// Object: {"fill-pattern":{"stops":[[11,"wetland8"],[12,"wetland16"]]}}
Expand Down Expand Up @@ -420,6 +429,11 @@ bool QgsMapBoxGlStyleConverter::parseLineLayer( const QVariantMap &jsonLayer, Qg
break;
}
}
else
{
// defaults to #000000
lineColor = QColor( 0, 0, 0 );
}


double lineWidth = 1.0;
Expand Down Expand Up @@ -626,7 +640,7 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,

QgsPropertyCollection ddLabelProperties;

double textSize = 16.0;
double textSize = 16.0 * context.pixelSizeConversionFactor();
QString textSizeProperty;
if ( jsonLayout.contains( QStringLiteral( "text-size" ) ) )
{
Expand Down Expand Up @@ -689,6 +703,11 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,
break;
}
}
else
{
// defaults to 10
textMaxWidth = 10 * EM_TO_CHARS;
}

double textLetterSpacing = -1;
if ( jsonLayout.contains( QStringLiteral( "text-letter-spacing" ) ) )
Expand Down Expand Up @@ -765,6 +784,22 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,
}
}
}
else
{
// Defaults to ["Open Sans Regular","Arial Unicode MS Regular"].
if ( QgsFontUtils::fontFamilyHasStyle( QStringLiteral( "Open Sans" ), QStringLiteral( "Regular" ) ) )
{
textFont = QFont( QStringLiteral( "Open Sans" ) );
textFont.setStyleName( QStringLiteral( "Regular" ) );
foundFont = true;
}
else if ( QgsFontUtils::fontFamilyHasStyle( QStringLiteral( "Arial Unicode MS" ), QStringLiteral( "Regular" ) ) )
{
textFont = QFont( QStringLiteral( "Arial Unicode MS" ) );
textFont.setStyleName( QStringLiteral( "Regular" ) );
foundFont = true;
}
}

// text color
QColor textColor;
Expand All @@ -791,6 +826,11 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,
break;
}
}
else
{
// defaults to #000000
textColor = QColor( 0, 0, 0 );
}

// buffer color
QColor bufferColor;
Expand Down Expand Up @@ -1278,6 +1318,11 @@ bool QgsMapBoxGlStyleConverter::parseSymbolLayerAsRenderer( const QVariantMap &j
break;
}
}
else
{
// defaults to 250
spacing = 250 * context.pixelSizeConversionFactor();
}

bool rotateMarkers = true;
if ( jsonLayout.contains( QStringLiteral( "icon-rotation-alignment" ) ) )
Expand Down Expand Up @@ -1323,7 +1368,7 @@ bool QgsMapBoxGlStyleConverter::parseSymbolLayerAsRenderer( const QVariantMap &j
QgsMarkerLineSymbolLayer *lineSymbol = new QgsMarkerLineSymbolLayer( rotateMarkers, spacing > 0 ? spacing : 1 );
lineSymbol->setOutputUnit( context.targetUnit() );
lineSymbol->setDataDefinedProperties( ddProperties );
if ( spacing <= 0 )
if ( spacing < 1 )
{
// if spacing isn't specified, it's a central point marker only
lineSymbol->setPlacement( QgsTemplatedLineSymbolLayerBase::CentralPoint );
Expand Down

0 comments on commit 37471e5

Please sign in to comment.