Skip to content

Commit

Permalink
fix(QgsMapBoxGlStyleConverter): also handle text-rotate from property…
Browse files Browse the repository at this point in the history
… field
  • Loading branch information
benoitdm-oslandia committed Dec 20, 2024
1 parent 0b60e0f commit 64cc147
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/vectortile/qgsmapboxglstyleconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,19 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,
break;
}

case QMetaType::Type::QVariantMap:
{
QVariantMap rotateMap = jsonTextRotate.toMap();
if ( rotateMap.contains( QStringLiteral( "property" ) ) && rotateMap[QStringLiteral( "type" )].toString() == QStringLiteral( "identity" ) )
{
const QgsProperty property = QgsProperty::fromExpression( rotateMap[QStringLiteral( "property" )].toString() );
ddLabelProperties.setProperty( QgsPalLayerSettings::Property::LabelRotation, property );
}
else
context.pushWarning( QObject::tr( "%1: Skipping unsupported text-rotate map content (%2)" ).arg( context.layerId(), QString( QJsonDocument::fromVariant( rotateMap ).toJson() ) ) );
break;
}

default:
context.pushWarning( QObject::tr( "%1: Skipping unsupported text-rotate type (%2)" ).arg( context.layerId(), QMetaType::typeName( static_cast<QMetaType::Type>( jsonTextRotate.userType() ) ) ) );
break;
Expand Down
27 changes: 27 additions & 0 deletions tests/src/python/test_qgsmapboxglconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,33 @@ def testLabelRotation(self):
'"direction"',
)

context = QgsMapBoxGlStyleConversionContext()
style = {
"layout": {
"visibility": "visible",
"text-field": "{substance}",
"text-rotate": {
"property": "label_angle1",
"default": 0,
"type": "identity",
},
},
"paint": {
"text-color": "rgba(47, 47, 47, 1)",
},
"type": "symbol",
}
rendererStyle, has_renderer, labeling_style, has_labeling = (
QgsMapBoxGlStyleConverter.parseSymbolLayer(style, context)
)
self.assertTrue(has_labeling)
ls = labeling_style.labelSettings()
ddp = ls.dataDefinedProperties()
self.assertEqual(
ddp.property(QgsPalLayerSettings.Property.LabelRotation).asExpression(),
"label_angle1",
)

def test_parse_visibility(self):
context = QgsMapBoxGlStyleConversionContext()
style = {
Expand Down

0 comments on commit 64cc147

Please sign in to comment.