Skip to content

Commit d539b9c

Browse files
fix(QgsMapBoxGlStyleConverter): also handle visibility when it is defined in "layout" (#59974)
Co-authored-by: bdm-oslandia <benoit.de.mezzo@oslandia.com>
1 parent 581e564 commit d539b9c

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

src/core/vectortile/qgsmapboxglstyleconverter.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,18 @@ void QgsMapBoxGlStyleConverter::parseLayers( const QVariantList &layers, QgsMapB
149149
if ( maxZoom != -1 )
150150
maxZoom--;
151151

152-
const bool enabled = jsonLayer.value( QStringLiteral( "visibility" ) ).toString() != QLatin1String( "none" );
152+
QString visibilyStr;
153+
if ( jsonLayer.contains( QStringLiteral( "visibility" ) ) )
154+
{
155+
visibilyStr = jsonLayer.value( QStringLiteral( "visibility" ) ).toString();
156+
}
157+
else if ( jsonLayer.contains( QStringLiteral( "layout" ) ) && jsonLayer.value( QStringLiteral( "layout" ) ).userType() == QMetaType::Type::QVariantMap )
158+
{
159+
const QVariantMap jsonLayout = jsonLayer.value( QStringLiteral( "layout" ) ).toMap();
160+
visibilyStr = jsonLayout.value( QStringLiteral( "visibility" ) ).toString();
161+
}
162+
163+
const bool enabled = visibilyStr != QLatin1String( "none" );
153164

154165
QString filterExpression;
155166
if ( jsonLayer.contains( QStringLiteral( "filter" ) ) )

tests/src/python/test_qgsmapboxglconverter.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,88 @@ def testLabelRotation(self):
22032203
'"direction"',
22042204
)
22052205

2206+
def test_parse_visibility(self):
2207+
context = QgsMapBoxGlStyleConversionContext()
2208+
style = {
2209+
"sources": {"Basemaps": {"type": "vector", "url": "https://xxxxxx"}},
2210+
"layers": [
2211+
{
2212+
"id": "at-layout-level-true",
2213+
"source": "streets",
2214+
"source-layer": "water",
2215+
"type": "fill",
2216+
"paint": {"fill-color": "#00ffff"},
2217+
"layout": {
2218+
"visibility": "visible",
2219+
"text-field": "{substance}",
2220+
},
2221+
},
2222+
{
2223+
"id": "at-layout-level-other",
2224+
"source": "streets",
2225+
"source-layer": "water",
2226+
"type": "fill",
2227+
"paint": {"fill-color": "#00ffff"},
2228+
"layout": {
2229+
"visibility": "anOtherText",
2230+
"text-field": "{substance}",
2231+
},
2232+
},
2233+
{
2234+
"id": "at-layout-level-false",
2235+
"source": "streets",
2236+
"source-layer": "water",
2237+
"type": "fill",
2238+
"paint": {"fill-color": "#00ffff"},
2239+
"layout": {
2240+
"visibility": "none",
2241+
"text-field": "{substance}",
2242+
},
2243+
},
2244+
{
2245+
"id": "at-root-level-true",
2246+
"source": "streets",
2247+
"source-layer": "water",
2248+
"type": "fill",
2249+
"paint": {"fill-color": "#00ffff"},
2250+
"visibility": "visible",
2251+
},
2252+
{
2253+
"id": "at-root-level-other",
2254+
"source": "streets",
2255+
"source-layer": "water",
2256+
"type": "fill",
2257+
"paint": {"fill-color": "#00ffff"},
2258+
"visibility": "anOtherText",
2259+
},
2260+
{
2261+
"id": "at-root-level-false",
2262+
"source": "streets",
2263+
"source-layer": "water",
2264+
"type": "fill",
2265+
"paint": {"fill-color": "#00ffff"},
2266+
"visibility": "none",
2267+
},
2268+
],
2269+
}
2270+
2271+
converter = QgsMapBoxGlStyleConverter()
2272+
converter.convert(style, context)
2273+
2274+
renderer = converter.renderer()
2275+
style = renderer.style(0)
2276+
self.assertEqual(style.isEnabled(), True)
2277+
style = renderer.style(1)
2278+
self.assertEqual(style.isEnabled(), True)
2279+
style = renderer.style(2)
2280+
self.assertEqual(style.isEnabled(), False)
2281+
style = renderer.style(3)
2282+
self.assertEqual(style.isEnabled(), True)
2283+
style = renderer.style(4)
2284+
self.assertEqual(style.isEnabled(), True)
2285+
style = renderer.style(5)
2286+
self.assertEqual(style.isEnabled(), False)
2287+
22062288
def test_parse_zoom_levels(self):
22072289
context = QgsMapBoxGlStyleConversionContext()
22082290
style = {

0 commit comments

Comments
 (0)