Skip to content

Commit

Permalink
Mapbox GL style converter: allow attribute defined value for icon-rot…
Browse files Browse the repository at this point in the history
…ate and other properties (fixes #45021)
  • Loading branch information
rouault authored and nyalldawson committed Oct 4, 2021
1 parent a0af938 commit 5b47d46
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/core/vectortile/qgsmapboxglstyleconverter.cpp
Expand Up @@ -2334,8 +2334,7 @@ QgsProperty QgsMapBoxGlStyleConverter::parseValueList( const QVariantList &json,
}
else
{
context.pushWarning( QObject::tr( "%1: Could not interpret value list with method %2" ).arg( context.layerId(), method ) );
return QgsProperty();
return QgsProperty::fromExpression( parseExpression( json, context ) );
}
}

Expand Down
28 changes: 27 additions & 1 deletion tests/src/python/test_qgsmapboxglconverter.py
Expand Up @@ -12,9 +12,11 @@

import qgis # NOQA

from qgis.PyQt.QtGui import (QColor)
from qgis.PyQt.QtCore import QSize
from qgis.PyQt.QtGui import (QColor, QImage)
from qgis.core import (QgsMapBoxGlStyleConverter,
QgsMapBoxGlStyleConversionContext,
QgsSymbolLayer,
QgsWkbTypes,
QgsEffectStack
)
Expand Down Expand Up @@ -586,6 +588,30 @@ def testConvertLabels(self):
self.assertEqual(labeling.labelSettings().fieldName, '''lower(concat(concat("name_en",' - ',"name_fr"),"bar"))''')
self.assertTrue(labeling.labelSettings().isExpression)

def testDataDefinedIconRotate(self):
""" Test icon-rotate property that depends on a data attribute """
context = QgsMapBoxGlStyleConversionContext()

image = QImage(QSize(1, 1), QImage.Format_ARGB32)
context.setSprites(image, {"foo": {"x": 0, "y": 0, "width": 1, "height": 1, "pixelRatio": 1}})
style = {
"layout": {
"icon-image": "{foo}",
"icon-rotate": ["get", "ROTATION"],
"text-size": 11,
"icon-size": 1
},
"type": "symbol",
"id": "poi_label",
"source-layer": "poi_label"
}
renderer, has_renderer, labeling, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer(style, context)
self.assertTrue(has_renderer)
self.assertFalse(has_labeling)
dd_props = renderer.symbol().symbolLayers()[0].dataDefinedProperties()
prop = dd_props.property(QgsSymbolLayer.PropertyAngle)
self.assertEqual(prop.asExpression(), '"ROTATION"')

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

0 comments on commit 5b47d46

Please sign in to comment.