Skip to content

Commit

Permalink
fix(QgsMapBoxGlStyleConverter): also handle visibility when it is def…
Browse files Browse the repository at this point in the history
…ined in "layout"
  • Loading branch information
benoitdm-oslandia authored and nyalldawson committed Dec 19, 2024
1 parent 80e56a4 commit 149096c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/vectortile/qgsmapboxglstyleconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,18 @@ void QgsMapBoxGlStyleConverter::parseLayers( const QVariantList &layers, QgsMapB
if ( maxZoom != -1 )
maxZoom--;

const bool enabled = jsonLayer.value( QStringLiteral( "visibility" ) ).toString() != QLatin1String( "none" );
QString visibilyStr;
if ( jsonLayer.contains( QStringLiteral( "visibility" ) ) )
{
visibilyStr = jsonLayer.value( QStringLiteral( "visibility" ) ).toString();
}
else if ( jsonLayer.contains( QStringLiteral( "layout" ) ) && jsonLayer.value( QStringLiteral( "layout" ) ).userType() == QMetaType::Type::QVariantMap )
{
const QVariantMap jsonLayout = jsonLayer.value( QStringLiteral( "layout" ) ).toMap();
visibilyStr = jsonLayout.value( QStringLiteral( "visibility" ) ).toString();
}

const bool enabled = visibilyStr != QLatin1String( "none" );

QString filterExpression;
if ( jsonLayer.contains( QStringLiteral( "filter" ) ) )
Expand Down
82 changes: 82 additions & 0 deletions tests/src/python/test_qgsmapboxglconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,88 @@ def testLabelRotation(self):
'"direction"',
)

def test_parse_visibility(self):
context = QgsMapBoxGlStyleConversionContext()
style = {
"sources": {"Basemaps": {"type": "vector", "url": "https://xxxxxx"}},
"layers": [
{
"id": "at-layout-level-true",
"source": "streets",
"source-layer": "water",
"type": "fill",
"paint": {"fill-color": "#00ffff"},
"layout": {
"visibility": "visible",
"text-field": "{substance}",
},
},
{
"id": "at-layout-level-other",
"source": "streets",
"source-layer": "water",
"type": "fill",
"paint": {"fill-color": "#00ffff"},
"layout": {
"visibility": "anOtherText",
"text-field": "{substance}",
},
},
{
"id": "at-layout-level-false",
"source": "streets",
"source-layer": "water",
"type": "fill",
"paint": {"fill-color": "#00ffff"},
"layout": {
"visibility": "none",
"text-field": "{substance}",
},
},
{
"id": "at-root-level-true",
"source": "streets",
"source-layer": "water",
"type": "fill",
"paint": {"fill-color": "#00ffff"},
"visibility": "visible",
},
{
"id": "at-root-level-other",
"source": "streets",
"source-layer": "water",
"type": "fill",
"paint": {"fill-color": "#00ffff"},
"visibility": "anOtherText",
},
{
"id": "at-root-level-false",
"source": "streets",
"source-layer": "water",
"type": "fill",
"paint": {"fill-color": "#00ffff"},
"visibility": "none",
},
],
}

converter = QgsMapBoxGlStyleConverter()
converter.convert(style, context)

renderer = converter.renderer()
style = renderer.style(0)
self.assertEqual(style.isEnabled(), True)
style = renderer.style(1)
self.assertEqual(style.isEnabled(), True)
style = renderer.style(2)
self.assertEqual(style.isEnabled(), False)
style = renderer.style(3)
self.assertEqual(style.isEnabled(), True)
style = renderer.style(4)
self.assertEqual(style.isEnabled(), True)
style = renderer.style(5)
self.assertEqual(style.isEnabled(), False)

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

0 comments on commit 149096c

Please sign in to comment.