48#include <QRegularExpression>
51#include "moc_qgsmapboxglstyleconverter.cpp"
53using namespace Qt::StringLiterals;
63 if ( style.contains( u
"sources"_s ) )
65 parseSources( style.value( u
"sources"_s ).toMap(), context );
68 if ( style.contains( u
"layers"_s ) )
70 parseLayers( style.value( u
"layers"_s ).toList(), context );
74 mError = QObject::tr(
"Could not find layers list in JSON" );
87 qDeleteAll( mSources );
92 std::unique_ptr< QgsMapBoxGlStyleConversionContext > tmpContext;
95 tmpContext = std::make_unique< QgsMapBoxGlStyleConversionContext >();
96 context = tmpContext.get();
99 QList<QgsVectorTileBasicRendererStyle> rendererStyles;
100 QList<QgsVectorTileBasicLabelingStyle> labelingStyles;
103 bool hasRendererBackgroundStyle =
false;
105 for (
const QVariant &layer : layers )
107 const QVariantMap jsonLayer = layer.toMap();
109 const QString layerType = jsonLayer.value( u
"type"_s ).toString();
110 if ( layerType ==
"background"_L1 )
112 hasRendererBackgroundStyle =
parseFillLayer( jsonLayer, rendererBackgroundStyle, *context,
true );
113 if ( hasRendererBackgroundStyle )
123 const QString styleId = jsonLayer.value( u
"id"_s ).toString();
126 if ( layerType.compare(
"raster"_L1, Qt::CaseInsensitive ) == 0 )
129 const QVariantMap jsonPaint = jsonLayer.value( u
"paint"_s ).toMap();
130 if ( jsonPaint.contains( u
"raster-opacity"_s ) )
132 const QVariant jsonRasterOpacity = jsonPaint.value( u
"raster-opacity"_s );
133 double defaultOpacity = 1;
137 mRasterSubLayers.append( raster );
141 const QString layerName = jsonLayer.value( u
"source-layer"_s ).toString();
143 const int minZoom = jsonLayer.value( u
"minzoom"_s, u
"-1"_s ).toInt();
152 int maxZoom = jsonLayer.value( u
"maxzoom"_s, u
"-1"_s ).toInt();
157 if ( jsonLayer.contains( u
"visibility"_s ) )
159 visibilyStr = jsonLayer.value( u
"visibility"_s ).toString();
161 else if ( jsonLayer.contains( u
"layout"_s ) && jsonLayer.value( u
"layout"_s ).userType() == QMetaType::Type::QVariantMap )
163 const QVariantMap jsonLayout = jsonLayer.value( u
"layout"_s ).toMap();
164 visibilyStr = jsonLayout.value( u
"visibility"_s ).toString();
167 const bool enabled = visibilyStr !=
"none"_L1;
169 QString filterExpression;
170 if ( jsonLayer.contains( u
"filter"_s ) )
172 filterExpression =
parseExpression( jsonLayer.value( u
"filter"_s ).toList(), *context );
178 bool hasRendererStyle =
false;
179 bool hasLabelingStyle =
false;
180 if ( layerType ==
"fill"_L1 )
182 hasRendererStyle =
parseFillLayer( jsonLayer, rendererStyle, *context );
184 else if ( layerType ==
"line"_L1 )
186 hasRendererStyle =
parseLineLayer( jsonLayer, rendererStyle, *context );
188 else if ( layerType ==
"circle"_L1 )
192 else if ( layerType ==
"symbol"_L1 )
194 parseSymbolLayer( jsonLayer, rendererStyle, hasRendererStyle, labelingStyle, hasLabelingStyle, *context );
198 mWarnings << QObject::tr(
"%1: Skipping unknown layer type %2" ).arg( context->
layerId(), layerType );
203 if ( hasRendererStyle )
211 rendererStyles.append( rendererStyle );
214 if ( hasLabelingStyle )
222 labelingStyles.append( labelingStyle );
225 mWarnings.append( context->
warnings() );
229 if ( hasRendererBackgroundStyle )
230 rendererStyles.prepend( rendererBackgroundStyle );
232 auto renderer = std::make_unique< QgsVectorTileBasicRenderer >();
233 renderer->setStyles( rendererStyles );
236 auto labeling = std::make_unique< QgsVectorTileBasicLabeling >();
237 labeling->setStyles( labelingStyles );
243 const QVariantMap jsonPaint = jsonLayer.value( u
"paint"_s ).toMap();
248 bool colorIsDataDefined =
false;
250 std::unique_ptr< QgsSymbol > symbol( std::make_unique< QgsFillSymbol >() );
254 if ( jsonPaint.contains( isBackgroundStyle ? u
"background-color"_s : u
"fill-color"_s ) )
256 const QVariant jsonFillColor = jsonPaint.value( isBackgroundStyle ? u
"background-color"_s : u
"fill-color"_s );
257 switch ( jsonFillColor.userType() )
259 case QMetaType::Type::QVariantMap:
263 case QMetaType::Type::QVariantList:
264 case QMetaType::Type::QStringList:
265 colorIsDataDefined =
true;
269 case QMetaType::Type::QString:
270 fillColor =
parseColor( jsonFillColor.toString(), context );
275 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported fill-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonFillColor.userType() ) ) ) );
283 fillColor = QColor( 0, 0, 0 );
286 QColor fillOutlineColor;
287 if ( !isBackgroundStyle )
289 if ( !jsonPaint.contains( u
"fill-outline-color"_s ) )
291 if ( fillColor.isValid() )
292 fillOutlineColor = fillColor;
300 const QVariant jsonFillOutlineColor = jsonPaint.value( u
"fill-outline-color"_s );
301 switch ( jsonFillOutlineColor.userType() )
303 case QMetaType::Type::QVariantMap:
307 case QMetaType::Type::QVariantList:
308 case QMetaType::Type::QStringList:
312 case QMetaType::Type::QString:
313 fillOutlineColor =
parseColor( jsonFillOutlineColor.toString(), context );
318 QObject::tr(
"%1: Skipping unsupported fill-outline-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonFillOutlineColor.userType() ) ) )
325 double fillOpacity = -1.0;
326 double rasterOpacity = -1.0;
327 if ( jsonPaint.contains( isBackgroundStyle ? u
"background-opacity"_s : u
"fill-opacity"_s ) )
329 const QVariant jsonFillOpacity = jsonPaint.value( isBackgroundStyle ? u
"background-opacity"_s : u
"fill-opacity"_s );
330 switch ( jsonFillOpacity.userType() )
332 case QMetaType::Type::Int:
333 case QMetaType::Type::LongLong:
334 case QMetaType::Type::Double:
335 fillOpacity = jsonFillOpacity.toDouble();
336 rasterOpacity = fillOpacity;
339 case QMetaType::Type::QVariantMap:
352 case QMetaType::Type::QVariantList:
353 case QMetaType::Type::QStringList:
368 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported fill-opacity type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonFillOpacity.userType() ) ) ) );
374 QPointF fillTranslate;
375 if ( jsonPaint.contains( u
"fill-translate"_s ) )
377 const QVariant jsonFillTranslate = jsonPaint.value( u
"fill-translate"_s );
378 switch ( jsonFillTranslate.userType() )
380 case QMetaType::Type::QVariantMap:
384 case QMetaType::Type::QVariantList:
385 case QMetaType::Type::QStringList:
392 QObject::tr(
"%1: Skipping unsupported fill-translate type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonFillTranslate.userType() ) ) )
399 Q_ASSERT( fillSymbol );
402 symbol->setOutputUnit( context.
targetUnit() );
405 if ( !fillTranslate.isNull() )
411 if ( jsonPaint.contains( isBackgroundStyle ? u
"background-pattern"_s : u
"fill-pattern"_s ) )
415 const QVariant fillPatternJson = jsonPaint.value( isBackgroundStyle ? u
"background-pattern"_s : u
"fill-pattern"_s );
418 fillColor = QColor();
419 fillOutlineColor = QColor();
426 QString spriteProperty, spriteSizeProperty;
428 if ( !sprite.isEmpty() )
433 rasterFill->
setWidth( spriteSize.width() );
437 if ( rasterOpacity >= 0 )
442 if ( !spriteProperty.isEmpty() )
449 symbol->appendSymbolLayer( rasterFill );
455 if ( fillOpacity != -1 )
457 symbol->setOpacity( fillOpacity );
468 if ( fillOutlineColor.isValid() && ( fillOutlineColor.alpha() == 255 || fillOutlineColor != fillColor ) )
479 if ( fillColor.isValid() )
483 else if ( colorIsDataDefined )
499 if ( !jsonLayer.contains( u
"paint"_s ) )
501 context.
pushWarning( QObject::tr(
"%1: Style has no paint property, skipping" ).arg( context.
layerId() ) );
506 QString rasterLineSprite;
508 const QVariantMap jsonPaint = jsonLayer.
value( u
"paint"_s ).toMap();
509 if ( jsonPaint.contains( u
"line-pattern"_s ) )
511 const QVariant jsonLinePattern = jsonPaint.value( u
"line-pattern"_s );
512 switch ( jsonLinePattern.userType() )
514 case QMetaType::Type::QVariantMap:
515 case QMetaType::Type::QString:
518 QString spriteProperty, spriteSizeProperty;
524 case QMetaType::Type::QVariantList:
525 case QMetaType::Type::QStringList:
530 if ( rasterLineSprite.isEmpty() )
533 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported line-pattern property" ).arg( context.
layerId() ) );
540 if ( jsonPaint.contains( u
"line-color"_s ) )
542 const QVariant jsonLineColor = jsonPaint.value( u
"line-color"_s );
543 switch ( jsonLineColor.userType() )
545 case QMetaType::Type::QVariantMap:
550 case QMetaType::Type::QVariantList:
551 case QMetaType::Type::QStringList:
556 case QMetaType::Type::QString:
557 lineColor =
parseColor( jsonLineColor.toString(), context );
561 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported line-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonLineColor.userType() ) ) ) );
568 lineColor = QColor( 0, 0, 0 );
574 if ( jsonPaint.contains( u
"line-width"_s ) )
576 const QVariant jsonLineWidth = jsonPaint.value( u
"line-width"_s );
577 switch ( jsonLineWidth.userType() )
579 case QMetaType::Type::Int:
580 case QMetaType::Type::LongLong:
581 case QMetaType::Type::Double:
585 case QMetaType::Type::QVariantMap:
597 case QMetaType::Type::QVariantList:
598 case QMetaType::Type::QStringList:
610 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported fill-width type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonLineWidth.userType() ) ) ) );
615 double lineOffset = 0.0;
616 if ( jsonPaint.contains( u
"line-offset"_s ) )
618 const QVariant jsonLineOffset = jsonPaint.value( u
"line-offset"_s );
619 switch ( jsonLineOffset.userType() )
621 case QMetaType::Type::Int:
622 case QMetaType::Type::LongLong:
623 case QMetaType::Type::Double:
627 case QMetaType::Type::QVariantMap:
632 case QMetaType::Type::QVariantList:
633 case QMetaType::Type::QStringList:
638 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported line-offset type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonLineOffset.userType() ) ) ) );
643 double lineOpacity = -1.0;
645 if ( jsonPaint.contains( u
"line-opacity"_s ) )
647 const QVariant jsonLineOpacity = jsonPaint.value( u
"line-opacity"_s );
648 switch ( jsonLineOpacity.userType() )
650 case QMetaType::Type::Int:
651 case QMetaType::Type::LongLong:
652 case QMetaType::Type::Double:
653 lineOpacity = jsonLineOpacity.toDouble();
656 case QMetaType::Type::QVariantMap:
659 double defaultValue = 1.0;
668 case QMetaType::Type::QVariantList:
669 case QMetaType::Type::QStringList:
672 double defaultValue = 1.0;
683 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported line-opacity type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonLineOpacity.userType() ) ) ) );
688 QVector< double > dashVector;
689 if ( jsonPaint.contains( u
"line-dasharray"_s ) )
691 const QVariant jsonLineDashArray = jsonPaint.value( u
"line-dasharray"_s );
692 switch ( jsonLineDashArray.userType() )
694 case QMetaType::Type::QVariantMap:
696 QString arrayExpression;
699 arrayExpression = u
"array_to_string(array_foreach(%1,@element * (%2)), ';')"_s
704 arrayExpression = u
"array_to_string(%1, ';')"_s.arg(
parseArrayStops( jsonLineDashArray.toMap().value( u
"stops"_s ).toList(), context, lineWidth ) );
708 const QVariantList dashSource = jsonLineDashArray.toMap().value( u
"stops"_s ).toList().first().toList().value( 1 ).toList();
709 for (
const QVariant &v : dashSource )
711 dashVector << v.toDouble() * lineWidth;
716 case QMetaType::Type::QVariantList:
717 case QMetaType::Type::QStringList:
719 const QVariantList dashSource = jsonLineDashArray.toList();
721 if ( dashSource.at( 0 ).userType() == QMetaType::Type::QString )
727 u
"array_to_string(array_foreach(%1,@element * (%2)), ';')"_s
728 .arg( property.asExpression(), lineWidthProperty.
asExpression() )
739 QVector< double > rawDashVectorSizes;
740 rawDashVectorSizes.reserve( dashSource.size() );
741 for (
const QVariant &v : dashSource )
743 rawDashVectorSizes << v.toDouble();
747 if ( rawDashVectorSizes.size() == 1 )
750 rawDashVectorSizes.clear();
752 else if ( rawDashVectorSizes.size() % 2 == 1 )
756 rawDashVectorSizes.append( 0 );
759 if ( !rawDashVectorSizes.isEmpty() && ( !lineWidthProperty.
asExpression().isEmpty() ) )
761 QStringList dashArrayStringParts;
762 dashArrayStringParts.reserve( rawDashVectorSizes.size() );
763 for (
double v : std::as_const( rawDashVectorSizes ) )
768 QString arrayExpression = u
"array_to_string(array_foreach(array(%1),@element * (%2)), ';')"_s
769 .arg( dashArrayStringParts.join(
',' ), lineWidthProperty.
asExpression() );
774 for (
double v : std::as_const( rawDashVectorSizes ) )
776 dashVector << v * lineWidth;
784 QObject::tr(
"%1: Skipping unsupported line-dasharray type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonLineDashArray.userType() ) ) )
790 Qt::PenCapStyle penCapStyle = Qt::FlatCap;
791 Qt::PenJoinStyle penJoinStyle = Qt::MiterJoin;
792 if ( jsonLayer.contains( u
"layout"_s ) )
794 const QVariantMap jsonLayout = jsonLayer.value( u
"layout"_s ).toMap();
795 if ( jsonLayout.contains( u
"line-cap"_s ) )
797 penCapStyle =
parseCapStyle( jsonLayout.value( u
"line-cap"_s ).toString() );
799 if ( jsonLayout.contains( u
"line-join"_s ) )
801 penJoinStyle =
parseJoinStyle( jsonLayout.value( u
"line-join"_s ).toString() );
805 std::unique_ptr< QgsSymbol > symbol( std::make_unique< QgsLineSymbol >() );
806 symbol->setOutputUnit( context.
targetUnit() );
808 if ( !rasterLineSprite.isEmpty() )
818 if ( lineOpacity != -1 )
820 symbol->setOpacity( lineOpacity );
826 symbol->setDataDefinedProperties( ddProperties );
828 if ( lineWidth != -1 )
832 symbol->changeSymbolLayer( 0, lineSymbol );
837 Q_ASSERT( lineSymbol );
847 if ( lineOpacity != -1 )
849 symbol->setOpacity( lineOpacity );
855 symbol->setDataDefinedProperties( ddProperties );
857 if ( lineColor.isValid() )
861 if ( lineWidth != -1 )
865 if ( !dashVector.empty() )
879 if ( !jsonLayer.contains( u
"paint"_s ) )
881 context.
pushWarning( QObject::tr(
"%1: Style has no paint property, skipping" ).arg( context.
layerId() ) );
885 const QVariantMap jsonPaint = jsonLayer.value( u
"paint"_s ).toMap();
890 QColor circleFillColor;
891 if ( jsonPaint.contains( u
"circle-color"_s ) )
893 const QVariant jsonCircleColor = jsonPaint.value( u
"circle-color"_s );
894 switch ( jsonCircleColor.userType() )
896 case QMetaType::Type::QVariantMap:
900 case QMetaType::Type::QVariantList:
901 case QMetaType::Type::QStringList:
905 case QMetaType::Type::QString:
906 circleFillColor =
parseColor( jsonCircleColor.toString(), context );
910 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported circle-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleColor.userType() ) ) ) );
917 circleFillColor = QColor( 0, 0, 0 );
921 double circleDiameter = 10.0;
922 if ( jsonPaint.contains( u
"circle-radius"_s ) )
924 const QVariant jsonCircleRadius = jsonPaint.value( u
"circle-radius"_s );
925 switch ( jsonCircleRadius.userType() )
927 case QMetaType::Type::Int:
928 case QMetaType::Type::LongLong:
929 case QMetaType::Type::Double:
933 case QMetaType::Type::QVariantMap:
938 case QMetaType::Type::QVariantList:
939 case QMetaType::Type::QStringList:
945 QObject::tr(
"%1: Skipping unsupported circle-radius type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleRadius.userType() ) ) )
951 double circleOpacity = -1.0;
952 if ( jsonPaint.contains( u
"circle-opacity"_s ) )
954 const QVariant jsonCircleOpacity = jsonPaint.value( u
"circle-opacity"_s );
955 switch ( jsonCircleOpacity.userType() )
957 case QMetaType::Type::Int:
958 case QMetaType::Type::LongLong:
959 case QMetaType::Type::Double:
960 circleOpacity = jsonCircleOpacity.toDouble();
963 case QMetaType::Type::QVariantMap:
967 case QMetaType::Type::QVariantList:
968 case QMetaType::Type::QStringList:
974 QObject::tr(
"%1: Skipping unsupported circle-opacity type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleOpacity.userType() ) ) )
979 if ( ( circleOpacity != -1 ) && circleFillColor.isValid() )
981 circleFillColor.setAlphaF( circleOpacity );
985 QColor circleStrokeColor;
986 if ( jsonPaint.contains( u
"circle-stroke-color"_s ) )
988 const QVariant jsonCircleStrokeColor = jsonPaint.value( u
"circle-stroke-color"_s );
989 switch ( jsonCircleStrokeColor.userType() )
991 case QMetaType::Type::QVariantMap:
995 case QMetaType::Type::QVariantList:
996 case QMetaType::Type::QStringList:
1000 case QMetaType::Type::QString:
1001 circleStrokeColor =
parseColor( jsonCircleStrokeColor.toString(), context );
1006 QObject::tr(
"%1: Skipping unsupported circle-stroke-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleStrokeColor.userType() ) ) )
1013 double circleStrokeWidth = -1.0;
1014 if ( jsonPaint.contains( u
"circle-stroke-width"_s ) )
1016 const QVariant circleStrokeWidthJson = jsonPaint.value( u
"circle-stroke-width"_s );
1017 switch ( circleStrokeWidthJson.userType() )
1019 case QMetaType::Type::Int:
1020 case QMetaType::Type::LongLong:
1021 case QMetaType::Type::Double:
1025 case QMetaType::Type::QVariantMap:
1026 circleStrokeWidth = -1.0;
1030 case QMetaType::Type::QVariantList:
1031 case QMetaType::Type::QStringList:
1037 QObject::tr(
"%1: Skipping unsupported circle-stroke-width type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( circleStrokeWidthJson.userType() ) ) )
1043 double circleStrokeOpacity = -1.0;
1044 if ( jsonPaint.contains( u
"circle-stroke-opacity"_s ) )
1046 const QVariant jsonCircleStrokeOpacity = jsonPaint.value( u
"circle-stroke-opacity"_s );
1047 switch ( jsonCircleStrokeOpacity.userType() )
1049 case QMetaType::Type::Int:
1050 case QMetaType::Type::LongLong:
1051 case QMetaType::Type::Double:
1052 circleStrokeOpacity = jsonCircleStrokeOpacity.toDouble();
1055 case QMetaType::Type::QVariantMap:
1059 case QMetaType::Type::QVariantList:
1060 case QMetaType::Type::QStringList:
1067 QObject::tr(
"%1: Skipping unsupported circle-stroke-opacity type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleStrokeOpacity.userType() ) ) )
1072 if ( ( circleStrokeOpacity != -1 ) && circleStrokeColor.isValid() )
1074 circleStrokeColor.setAlphaF( circleStrokeOpacity );
1078 QPointF circleTranslate;
1079 if ( jsonPaint.contains( u
"circle-translate"_s ) )
1081 const QVariant jsonCircleTranslate = jsonPaint.value( u
"circle-translate"_s );
1082 switch ( jsonCircleTranslate.userType() )
1084 case QMetaType::Type::QVariantMap:
1088 case QMetaType::Type::QVariantList:
1089 case QMetaType::Type::QStringList:
1096 QObject::tr(
"%1: Skipping unsupported circle-translate type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleTranslate.userType() ) ) )
1102 std::unique_ptr< QgsSymbol > symbol( std::make_unique< QgsMarkerSymbol >() );
1104 Q_ASSERT( markerSymbolLayer );
1107 symbol->setOutputUnit( context.
targetUnit() );
1110 if ( !circleTranslate.isNull() )
1112 markerSymbolLayer->
setOffset( circleTranslate );
1116 if ( circleFillColor.isValid() )
1120 if ( circleDiameter != -1 )
1122 markerSymbolLayer->
setSize( circleDiameter );
1125 if ( circleStrokeColor.isValid() )
1129 if ( circleStrokeWidth != -1 )
1144 hasLabeling =
false;
1145 hasRenderer =
false;
1147 if ( !jsonLayer.contains( u
"layout"_s ) )
1149 context.
pushWarning( QObject::tr(
"%1: Style layer has no layout property, skipping" ).arg( context.
layerId() ) );
1152 const QVariantMap jsonLayout = jsonLayer.value( u
"layout"_s ).toMap();
1153 if ( !jsonLayout.contains( u
"text-field"_s ) )
1159 const QVariantMap jsonPaint = jsonLayer.value( u
"paint"_s ).toMap();
1165 if ( jsonLayout.contains( u
"text-size"_s ) )
1167 const QVariant jsonTextSize = jsonLayout.value( u
"text-size"_s );
1168 switch ( jsonTextSize.userType() )
1170 case QMetaType::Type::Int:
1171 case QMetaType::Type::LongLong:
1172 case QMetaType::Type::Double:
1176 case QMetaType::Type::QVariantMap:
1182 case QMetaType::Type::QVariantList:
1183 case QMetaType::Type::QStringList:
1189 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-size type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextSize.userType() ) ) ) );
1193 if ( textSizeProperty )
1200 constexpr double EM_TO_CHARS = 2.0;
1202 double textMaxWidth = -1;
1203 if ( jsonLayout.contains( u
"text-max-width"_s ) )
1205 const QVariant jsonTextMaxWidth = jsonLayout.value( u
"text-max-width"_s );
1206 switch ( jsonTextMaxWidth.userType() )
1208 case QMetaType::Type::Int:
1209 case QMetaType::Type::LongLong:
1210 case QMetaType::Type::Double:
1211 textMaxWidth = jsonTextMaxWidth.toDouble() * EM_TO_CHARS;
1214 case QMetaType::Type::QVariantMap:
1218 case QMetaType::Type::QVariantList:
1219 case QMetaType::Type::QStringList:
1225 QObject::tr(
"%1: Skipping unsupported text-max-width type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextMaxWidth.userType() ) ) )
1233 textMaxWidth = 10 * EM_TO_CHARS;
1236 double textLetterSpacing = -1;
1237 if ( jsonLayout.contains( u
"text-letter-spacing"_s ) )
1239 const QVariant jsonTextLetterSpacing = jsonLayout.value( u
"text-letter-spacing"_s );
1240 switch ( jsonTextLetterSpacing.userType() )
1242 case QMetaType::Type::Int:
1243 case QMetaType::Type::LongLong:
1244 case QMetaType::Type::Double:
1245 textLetterSpacing = jsonTextLetterSpacing.toDouble();
1248 case QMetaType::Type::QVariantMap:
1252 case QMetaType::Type::QVariantList:
1253 case QMetaType::Type::QStringList:
1259 QObject::tr(
"%1: Skipping unsupported text-letter-spacing type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextLetterSpacing.userType() ) ) )
1266 bool foundFont =
false;
1268 QString fontStyleName;
1270 bool allowOverlap = jsonLayout.contains( u
"text-allow-overlap"_s ) && jsonLayout.
value( u
"text-allow-overlap"_s ).toBool();
1272 if ( jsonLayout.contains( u
"text-font"_s ) )
1274 auto splitFontFamily = [](
const QString &fontName, QString &family, QString &style ) ->
bool {
1275 QString matchedFamily;
1276 const QStringList textFontParts = fontName.split(
' ' );
1277 for (
int i = textFontParts.size() - 1; i >= 1; --i )
1279 const QString candidateFontFamily = textFontParts.mid( 0, i ).join(
' ' );
1280 const QString candidateFontStyle = textFontParts.mid( i ).join(
' ' );
1285 family = processedFontFamily;
1286 style = candidateFontStyle;
1291 if ( processedFontFamily == matchedFamily )
1293 family = processedFontFamily;
1294 style = candidateFontStyle;
1298 family = matchedFamily;
1299 style = processedFontFamily;
1300 style.replace( matchedFamily, QString() );
1301 style = style.trimmed();
1302 if ( !style.isEmpty() && !candidateFontStyle.isEmpty() )
1304 style += u
" %1"_s.arg( candidateFontStyle );
1312 if ( QFontDatabase().hasFamily( processedFontFamily ) )
1315 family = processedFontFamily;
1321 family = matchedFamily;
1328 const QVariant jsonTextFont = jsonLayout.value( u
"text-font"_s );
1329 if ( jsonTextFont.userType() != QMetaType::Type::QVariantList
1330 && jsonTextFont.userType() != QMetaType::Type::QStringList
1331 && jsonTextFont.userType() != QMetaType::Type::QString
1332 && jsonTextFont.userType() != QMetaType::Type::QVariantMap )
1334 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-font type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextFont.userType() ) ) ) );
1338 switch ( jsonTextFont.userType() )
1340 case QMetaType::Type::QVariantList:
1341 case QMetaType::Type::QStringList:
1342 fontName = jsonTextFont.toList().value( 0 ).toString();
1345 case QMetaType::Type::QString:
1346 fontName = jsonTextFont.toString();
1349 case QMetaType::Type::QVariantMap:
1351 QString familyCaseString = u
"CASE "_s;
1352 QString styleCaseString = u
"CASE "_s;
1354 const QVariantList stops = jsonTextFont.toMap().value( u
"stops"_s ).toList();
1357 for (
int i = 0; i < stops.length() - 1; ++i )
1360 const QVariant bz = stops.value( i ).toList().value( 0 );
1361 const QString bv = stops.value( i ).toList().value( 1 ).userType() == QMetaType::Type::QString ? stops.value( i ).toList().value( 1 ).toString()
1362 : stops.value( i ).toList().value( 1 ).toList().value( 0 ).toString();
1363 if ( bz.userType() == QMetaType::Type::QVariantList || bz.userType() == QMetaType::Type::QStringList )
1365 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
1371 const QVariant tz = stops.value( i + 1 ).toList().value( 0 );
1372 if ( tz.userType() == QMetaType::Type::QVariantList || tz.userType() == QMetaType::Type::QStringList )
1374 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
1379 if ( splitFontFamily( bv, fontFamily, fontStyleName ) )
1381 familyCaseString += QStringLiteral(
1382 "WHEN @vector_tile_zoom > %1 AND @vector_tile_zoom <= %2 "
1386 styleCaseString += QStringLiteral(
1387 "WHEN @vector_tile_zoom > %1 AND @vector_tile_zoom <= %2 "
1394 context.
pushWarning( QObject::tr(
"%1: Referenced font %2 is not available on system" ).arg( context.
layerId(), bv ) );
1400 const QString bv = stops.constLast().toList().value( 1 ).userType() == QMetaType::Type::QString ? stops.constLast().toList().value( 1 ).toString()
1401 : stops.constLast().toList().value( 1 ).toList().value( 0 ).toString();
1402 if ( splitFontFamily( bv, fontFamily, fontStyleName ) )
1409 context.
pushWarning( QObject::tr(
"%1: Referenced font %2 is not available on system" ).arg( context.
layerId(), bv ) );
1416 fontName = fontFamily;
1426 if ( splitFontFamily( fontName, fontFamily, fontStyleName ) )
1429 if ( !fontStyleName.isEmpty() )
1430 textFont.setStyleName( fontStyleName );
1440 fontName = u
"Open Sans"_s;
1442 textFont.setStyleName( u
"Regular"_s );
1443 fontStyleName = u
"Regular"_s;
1448 fontName = u
"Arial Unicode MS"_s;
1450 textFont.setStyleName( u
"Regular"_s );
1451 fontStyleName = u
"Regular"_s;
1456 fontName = u
"Open Sans, Arial Unicode MS"_s;
1459 if ( !foundFont && !fontName.isEmpty() )
1461 context.
pushWarning( QObject::tr(
"%1: Referenced font %2 is not available on system" ).arg( context.
layerId(), fontName ) );
1466 if ( jsonPaint.contains( u
"text-color"_s ) )
1468 const QVariant jsonTextColor = jsonPaint.value( u
"text-color"_s );
1469 switch ( jsonTextColor.userType() )
1471 case QMetaType::Type::QVariantMap:
1475 case QMetaType::Type::QVariantList:
1476 case QMetaType::Type::QStringList:
1480 case QMetaType::Type::QString:
1481 textColor =
parseColor( jsonTextColor.toString(), context );
1485 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextColor.userType() ) ) ) );
1492 textColor = QColor( 0, 0, 0 );
1496 QColor bufferColor( 0, 0, 0, 0 );
1497 if ( jsonPaint.contains( u
"text-halo-color"_s ) )
1499 const QVariant jsonBufferColor = jsonPaint.value( u
"text-halo-color"_s );
1500 switch ( jsonBufferColor.userType() )
1502 case QMetaType::Type::QVariantMap:
1506 case QMetaType::Type::QVariantList:
1507 case QMetaType::Type::QStringList:
1511 case QMetaType::Type::QString:
1512 bufferColor =
parseColor( jsonBufferColor.toString(), context );
1517 QObject::tr(
"%1: Skipping unsupported text-halo-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonBufferColor.userType() ) ) )
1523 double bufferSize = 0.0;
1527 constexpr double BUFFER_SIZE_SCALE = 2.0;
1528 if ( jsonPaint.contains( u
"text-halo-width"_s ) )
1530 const QVariant jsonHaloWidth = jsonPaint.value( u
"text-halo-width"_s );
1531 QString bufferSizeDataDefined;
1532 switch ( jsonHaloWidth.userType() )
1534 case QMetaType::Type::Int:
1535 case QMetaType::Type::LongLong:
1536 case QMetaType::Type::Double:
1540 case QMetaType::Type::QVariantMap:
1545 case QMetaType::Type::QVariantList:
1546 case QMetaType::Type::QStringList:
1552 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-halo-width type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonHaloWidth.userType() ) ) ) );
1558 if ( bufferSize > 0 )
1560 if ( textSize > 0 && bufferSizeDataDefined.isEmpty() )
1562 bufferSize = std::min( bufferSize, textSize * BUFFER_SIZE_SCALE / 4 );
1564 else if ( textSize > 0 && !bufferSizeDataDefined.isEmpty() )
1566 bufferSizeDataDefined = u
"min(%1/4, %2)"_s.arg( textSize * BUFFER_SIZE_SCALE ).arg( bufferSizeDataDefined );
1569 else if ( !bufferSizeDataDefined.isEmpty() )
1571 bufferSizeDataDefined = u
"min(%1*%2/4, %3)"_s.arg( textSizeProperty.
asExpression() ).arg( BUFFER_SIZE_SCALE ).arg( bufferSizeDataDefined );
1574 else if ( bufferSizeDataDefined.isEmpty() )
1576 bufferSizeDataDefined = u
"min(%1*%2/4, %3)"_s.arg( textSizeProperty.
asExpression() ).arg( BUFFER_SIZE_SCALE ).arg( bufferSize );
1582 double haloBlurSize = 0;
1583 if ( jsonPaint.contains( u
"text-halo-blur"_s ) )
1585 const QVariant jsonTextHaloBlur = jsonPaint.value( u
"text-halo-blur"_s );
1586 switch ( jsonTextHaloBlur.userType() )
1588 case QMetaType::Type::Int:
1589 case QMetaType::Type::LongLong:
1590 case QMetaType::Type::Double:
1598 QObject::tr(
"%1: Skipping unsupported text-halo-blur type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextHaloBlur.userType() ) ) )
1606 if ( textColor.isValid() )
1608 if ( textSize >= 0 )
1613 if ( !fontStyleName.isEmpty() )
1616 if ( textLetterSpacing > 0 )
1618 QFont f = format.
font();
1619 f.setLetterSpacing( QFont::AbsoluteSpacing, textLetterSpacing );
1623 if ( bufferSize > 0 )
1626 const double opacity = bufferColor.alphaF();
1627 bufferColor.setAlphaF( 1.0 );
1635 if ( haloBlurSize > 0 )
1658 if ( textMaxWidth > 0 )
1664 if ( jsonLayout.contains( u
"text-field"_s ) )
1666 const QVariant jsonTextField = jsonLayout.value( u
"text-field"_s );
1667 switch ( jsonTextField.userType() )
1669 case QMetaType::Type::QString:
1671 labelSettings.
fieldName = processLabelField( jsonTextField.toString(), labelSettings.
isExpression );
1675 case QMetaType::Type::QVariantList:
1676 case QMetaType::Type::QStringList:
1678 const QVariantList textFieldList = jsonTextField.toList();
1686 if ( textFieldList.size() > 2 && textFieldList.at( 0 ).toString() ==
"format"_L1 )
1689 for (
int i = 1; i < textFieldList.size(); ++i )
1691 bool isExpression =
false;
1692 const QString part = processLabelField( textFieldList.at( i ).toString(), isExpression );
1693 if ( !isExpression )
1700 labelSettings.
fieldName = u
"concat(%1)"_s.arg( parts.join(
',' ) );
1715 case QMetaType::Type::QVariantMap:
1717 const QVariantList stops = jsonTextField.toMap().value( u
"stops"_s ).toList();
1718 if ( !stops.empty() )
1725 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-field dictionary" ).arg( context.
layerId() ) );
1731 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-field type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextField.userType() ) ) ) );
1736 if ( jsonLayout.contains( u
"text-rotate"_s ) )
1738 const QVariant jsonTextRotate = jsonLayout.value( u
"text-rotate"_s );
1739 switch ( jsonTextRotate.userType() )
1741 case QMetaType::Type::Double:
1742 case QMetaType::Type::Int:
1744 labelSettings.
angleOffset = jsonTextRotate.toDouble();
1748 case QMetaType::Type::QVariantList:
1749 case QMetaType::Type::QStringList:
1756 case QMetaType::Type::QVariantMap:
1758 QVariantMap rotateMap = jsonTextRotate.toMap();
1759 if ( rotateMap.contains( u
"property"_s ) && rotateMap[u
"type"_s].toString() ==
"identity"_L1 )
1765 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-rotate map content (%2)" ).arg( context.
layerId(), QString( QJsonDocument::fromVariant( rotateMap ).toJson() ) ) );
1770 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-rotate type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextRotate.userType() ) ) ) );
1775 if ( jsonLayout.contains( u
"text-transform"_s ) )
1777 const QString textTransform = jsonLayout.value( u
"text-transform"_s ).toString();
1778 if ( textTransform ==
"uppercase"_L1 )
1782 else if ( textTransform ==
"lowercase"_L1 )
1791 if ( jsonLayout.contains( u
"symbol-placement"_s ) )
1793 const QString symbolPlacement = jsonLayout.value( u
"symbol-placement"_s ).toString();
1794 if ( symbolPlacement ==
"line"_L1 )
1800 if ( jsonLayout.contains( u
"text-rotation-alignment"_s ) )
1802 const QString textRotationAlignment = jsonLayout.value( u
"text-rotation-alignment"_s ).toString();
1803 if ( textRotationAlignment ==
"viewport"_L1 )
1813 if ( jsonLayout.contains( u
"text-offset"_s ) )
1815 const QVariant jsonTextOffset = jsonLayout.value( u
"text-offset"_s );
1818 switch ( jsonTextOffset.userType() )
1820 case QMetaType::Type::QVariantMap:
1821 textOffsetProperty =
parseInterpolatePointByZoom( jsonTextOffset.toMap(), context, !textSizeProperty ? textSize : 1.0, &textOffset );
1822 if ( !textSizeProperty )
1830 u
"with_variable('text_size',%2,abs(array_get(%1,1))*@text_size-@text_size)"_s.arg( textOffsetProperty.
asExpression(), textSizeProperty.
asExpression() )
1836 case QMetaType::Type::QVariantList:
1837 case QMetaType::Type::QStringList:
1838 textOffset = QPointF( jsonTextOffset.toList().value( 0 ).toDouble() * textSize, jsonTextOffset.toList().value( 1 ).toDouble() * textSize );
1843 QObject::tr(
"%1: Skipping unsupported text-offset type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextOffset.userType() ) ) )
1848 if ( !textOffset.isNull() )
1851 labelSettings.
dist = std::abs( textOffset.y() ) - textSize;
1853 if ( textSizeProperty && !textOffsetProperty )
1857 u
"with_variable('text_size',%2,%1*@text_size-@text_size)"_s.arg( std::abs( textOffset.y() / textSize ) ).arg( textSizeProperty.
asExpression() )
1863 if ( textOffset.isNull() )
1871 if ( jsonLayout.contains( u
"text-justify"_s ) )
1873 const QVariant jsonTextJustify = jsonLayout.value( u
"text-justify"_s );
1876 QString textAlign = u
"center"_s;
1878 const QVariantMap conversionMap { { u
"left"_s, u
"left"_s }, { u
"center"_s, u
"center"_s }, { u
"right"_s, u
"right"_s }, { u
"auto"_s, u
"follow"_s } };
1880 switch ( jsonTextJustify.userType() )
1882 case QMetaType::Type::QString:
1883 textAlign = jsonTextJustify.toString();
1886 case QMetaType::Type::QVariantList:
1890 case QMetaType::Type::QVariantMap:
1895 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-justify type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextJustify.userType() ) ) ) );
1899 if ( textAlign ==
"left"_L1 )
1901 else if ( textAlign ==
"right"_L1 )
1903 else if ( textAlign ==
"center"_L1 )
1905 else if ( textAlign ==
"follow"_L1 )
1915 if ( jsonLayout.contains( u
"text-anchor"_s ) )
1917 const QVariant jsonTextAnchor = jsonLayout.value( u
"text-anchor"_s );
1920 const QVariantMap conversionMap {
1926 { u
"top-left"_s, 8 },
1927 { u
"top-right"_s, 6 },
1928 { u
"bottom-left"_s, 2 },
1929 { u
"bottom-right"_s, 0 },
1932 switch ( jsonTextAnchor.userType() )
1934 case QMetaType::Type::QString:
1935 textAnchor = jsonTextAnchor.toString();
1938 case QMetaType::Type::QVariantList:
1942 case QMetaType::Type::QVariantMap:
1947 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-anchor type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextAnchor.userType() ) ) ) );
1951 if ( textAnchor ==
"center"_L1 )
1953 else if ( textAnchor ==
"left"_L1 )
1955 else if ( textAnchor ==
"right"_L1 )
1957 else if ( textAnchor ==
"top"_L1 )
1959 else if ( textAnchor ==
"bottom"_L1 )
1961 else if ( textAnchor ==
"top-left"_L1 )
1963 else if ( textAnchor ==
"top-right"_L1 )
1965 else if ( textAnchor ==
"bottom-left"_L1 )
1967 else if ( textAnchor ==
"bottom-right"_L1 )
1972 if ( jsonLayout.contains( u
"text-offset"_s ) )
1974 const QVariant jsonTextOffset = jsonLayout.value( u
"text-offset"_s );
1977 switch ( jsonTextOffset.userType() )
1979 case QMetaType::Type::QVariantMap:
1983 case QMetaType::Type::QVariantList:
1984 case QMetaType::Type::QStringList:
1985 textOffset = QPointF( jsonTextOffset.toList().value( 0 ).toDouble() * textSize, jsonTextOffset.toList().value( 1 ).toDouble() * textSize );
1989 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-offset type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextOffset.userType() ) ) ) );
1993 if ( !textOffset.isNull() )
1996 labelSettings.
xOffset = textOffset.x();
1997 labelSettings.
yOffset = textOffset.y();
2005 QString spriteProperty, spriteSizeProperty;
2007 if ( !sprite.isEmpty() )
2010 if ( jsonLayout.contains( u
"icon-size"_s ) )
2013 const QVariant jsonIconSize = jsonLayout.
value( u
"icon-size"_s );
2014 switch ( jsonIconSize.userType() )
2016 case QMetaType::Type::Int:
2017 case QMetaType::Type::LongLong:
2018 case QMetaType::Type::Double:
2020 size = jsonIconSize.toDouble();
2021 if ( !spriteSizeProperty.isEmpty() )
2028 case QMetaType::Type::QVariantMap:
2032 case QMetaType::Type::QVariantList:
2033 case QMetaType::Type::QStringList:
2038 QObject::tr(
"%1: Skipping non-implemented icon-size type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconSize.userType() ) ) )
2045 if ( !spriteSizeProperty.isEmpty() )
2058 markerLayer->
setPath( sprite );
2059 markerLayer->
setSize( spriteSize.width() );
2062 if ( !spriteProperty.isEmpty() )
2072 backgroundSettings.
setSize( spriteSize * size );
2080 if ( jsonLayout.contains( u
"symbol-spacing"_s ) )
2083 const QVariant jsonSpacing = jsonLayout.value( u
"symbol-spacing"_s );
2093 switch ( jsonSpacing.userType() )
2095 case QMetaType::Type::Int:
2096 case QMetaType::Type::LongLong:
2097 case QMetaType::Type::Double:
2104 case QMetaType::Type::QVariantMap:
2110 case QMetaType::Type::QVariantList:
2111 case QMetaType::Type::QStringList:
2118 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported symbol-spacing type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonSpacing.userType() ) ) ) );
2126 if ( textSize >= 0 )
2149 if ( !jsonLayer.contains( u
"layout"_s ) )
2151 context.
pushWarning( QObject::tr(
"%1: Style layer has no layout property, skipping" ).arg( context.
layerId() ) );
2154 const QVariantMap jsonLayout = jsonLayer.value( u
"layout"_s ).toMap();
2156 if ( jsonLayout.value( u
"symbol-placement"_s ).toString() ==
"line"_L1 && !jsonLayout.contains( u
"text-field"_s ) )
2160 double spacing = -1.0;
2161 if ( jsonLayout.contains( u
"symbol-spacing"_s ) )
2163 const QVariant jsonSpacing = jsonLayout.value( u
"symbol-spacing"_s );
2164 switch ( jsonSpacing.userType() )
2166 case QMetaType::Type::Int:
2167 case QMetaType::Type::LongLong:
2168 case QMetaType::Type::Double:
2172 case QMetaType::Type::QVariantMap:
2176 case QMetaType::Type::QVariantList:
2177 case QMetaType::Type::QStringList:
2182 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported symbol-spacing type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonSpacing.userType() ) ) ) );
2192 bool rotateMarkers =
true;
2193 if ( jsonLayout.contains( u
"icon-rotation-alignment"_s ) )
2195 const QString alignment = jsonLayout.value( u
"icon-rotation-alignment"_s ).toString();
2196 if ( alignment ==
"map"_L1 || alignment ==
"auto"_L1 )
2198 rotateMarkers =
true;
2200 else if ( alignment ==
"viewport"_L1 )
2202 rotateMarkers =
false;
2207 double rotation = 0.0;
2208 if ( jsonLayout.contains( u
"icon-rotate"_s ) )
2210 const QVariant jsonIconRotate = jsonLayout.value( u
"icon-rotate"_s );
2211 switch ( jsonIconRotate.userType() )
2213 case QMetaType::Type::Int:
2214 case QMetaType::Type::LongLong:
2215 case QMetaType::Type::Double:
2216 rotation = jsonIconRotate.toDouble();
2219 case QMetaType::Type::QVariantMap:
2223 case QMetaType::Type::QVariantList:
2224 case QMetaType::Type::QStringList:
2229 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported icon-rotate type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconRotate.userType() ) ) ) );
2245 QString spriteProperty, spriteSizeProperty;
2247 if ( !sprite.isNull() )
2249 markerLayer->
setPath( sprite );
2250 markerLayer->
setSize( spriteSize.width() );
2253 if ( !spriteProperty.isEmpty() )
2260 if ( jsonLayout.contains( u
"icon-size"_s ) )
2262 const QVariant jsonIconSize = jsonLayout.value( u
"icon-size"_s );
2265 switch ( jsonIconSize.userType() )
2267 case QMetaType::Type::Int:
2268 case QMetaType::Type::LongLong:
2269 case QMetaType::Type::Double:
2271 size = jsonIconSize.toDouble();
2272 if ( !spriteSizeProperty.isEmpty() )
2279 case QMetaType::Type::QVariantMap:
2283 case QMetaType::Type::QVariantList:
2284 case QMetaType::Type::QStringList:
2288 context.
pushWarning( QObject::tr(
"%1: Skipping non-implemented icon-size type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconSize.userType() ) ) ) );
2291 markerLayer->
setSize( size * spriteSize.width() );
2294 if ( !spriteSizeProperty.isEmpty() )
2310 std::unique_ptr< QgsSymbol > symbol = std::make_unique< QgsLineSymbol >(
QgsSymbolLayerList() << lineSymbol );
2313 symbol->setOutputUnit( context.
targetUnit() );
2317 rendererStyle.
setSymbol( symbol.release() );
2320 else if ( jsonLayout.contains( u
"icon-image"_s ) )
2322 const QVariantMap jsonPaint = jsonLayer.value( u
"paint"_s ).toMap();
2325 QString spriteProperty, spriteSizeProperty;
2327 if ( !sprite.isEmpty() || !spriteProperty.isEmpty() )
2330 rasterMarker->
setPath( sprite );
2331 rasterMarker->
setSize( spriteSize.width() );
2335 if ( !spriteProperty.isEmpty() )
2341 if ( jsonLayout.contains( u
"icon-size"_s ) )
2343 const QVariant jsonIconSize = jsonLayout.value( u
"icon-size"_s );
2346 switch ( jsonIconSize.userType() )
2348 case QMetaType::Type::Int:
2349 case QMetaType::Type::LongLong:
2350 case QMetaType::Type::Double:
2352 size = jsonIconSize.toDouble();
2353 if ( !spriteSizeProperty.isEmpty() )
2360 case QMetaType::Type::QVariantMap:
2364 case QMetaType::Type::QVariantList:
2365 case QMetaType::Type::QStringList:
2370 QObject::tr(
"%1: Skipping non-implemented icon-size type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconSize.userType() ) ) )
2374 rasterMarker->
setSize( size * spriteSize.width() );
2377 if ( !spriteSizeProperty.isEmpty() )
2389 double rotation = 0.0;
2390 if ( jsonLayout.contains( u
"icon-rotate"_s ) )
2392 const QVariant jsonIconRotate = jsonLayout.value( u
"icon-rotate"_s );
2393 switch ( jsonIconRotate.userType() )
2395 case QMetaType::Type::Int:
2396 case QMetaType::Type::LongLong:
2397 case QMetaType::Type::Double:
2398 rotation = jsonIconRotate.toDouble();
2401 case QMetaType::Type::QVariantMap:
2405 case QMetaType::Type::QVariantList:
2406 case QMetaType::Type::QStringList:
2412 QObject::tr(
"%1: Skipping unsupported icon-rotate type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconRotate.userType() ) ) )
2418 double iconOpacity = -1.0;
2419 if ( jsonPaint.contains( u
"icon-opacity"_s ) )
2421 const QVariant jsonIconOpacity = jsonPaint.value( u
"icon-opacity"_s );
2422 switch ( jsonIconOpacity.userType() )
2424 case QMetaType::Type::Int:
2425 case QMetaType::Type::LongLong:
2426 case QMetaType::Type::Double:
2427 iconOpacity = jsonIconOpacity.toDouble();
2430 case QMetaType::Type::QVariantMap:
2434 case QMetaType::Type::QVariantList:
2435 case QMetaType::Type::QStringList:
2441 QObject::tr(
"%1: Skipping unsupported icon-opacity type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconOpacity.userType() ) ) )
2448 rasterMarker->
setAngle( rotation );
2449 if ( iconOpacity >= 0 )
2453 rendererStyle.
setSymbol( markerSymbol );
2464 const double base = json.
value( u
"base"_s, u
"1"_s ).toDouble();
2465 const QVariantList stops = json.value( u
"stops"_s ).toList();
2466 if ( stops.empty() )
2469 QString caseString = u
"CASE "_s;
2470 const QString colorComponent(
"color_part(%1,'%2')" );
2472 for (
int i = 0; i < stops.length() - 1; ++i )
2475 const QString bz = stops.at( i ).toList().value( 0 ).toString();
2477 const QString tz = stops.at( i + 1 ).toList().value( 0 ).toString();
2479 const QVariant bcVariant = stops.at( i ).toList().value( 1 );
2480 const QVariant tcVariant = stops.at( i + 1 ).toList().value( 1 );
2482 const QColor bottomColor =
parseColor( bcVariant.toString(), context );
2483 const QColor topColor =
parseColor( tcVariant.toString(), context );
2485 if ( i == 0 && bottomColor.isValid() )
2492 caseString += u
"WHEN @vector_tile_zoom < %1 THEN color_hsla(%2, %3, %4, %5) "_s.arg( bz ).arg( bcHue ).arg( bcSat ).arg( bcLight ).arg( bcAlpha );
2495 if ( bottomColor.isValid() && topColor.isValid() )
2507 caseString += QStringLiteral(
2508 "WHEN @vector_tile_zoom >= %1 AND @vector_tile_zoom < %2 THEN color_hsla("
2521 json.value( u
"x1"_s ).toDouble(),
2522 json.value( u
"y1"_s ).toDouble(),
2523 json.value( u
"x2"_s ).toDouble(),
2524 json.value( u
"y2"_s ).toDouble(),
2535 json.value( u
"x1"_s ).toDouble(),
2536 json.value( u
"y1"_s ).toDouble(),
2537 json.value( u
"x2"_s ).toDouble(),
2538 json.value( u
"y2"_s ).toDouble(),
2549 json.value( u
"x1"_s ).toDouble(),
2550 json.value( u
"y1"_s ).toDouble(),
2551 json.value( u
"x2"_s ).toDouble(),
2552 json.value( u
"y2"_s ).toDouble(),
2563 json.value( u
"x1"_s ).toDouble(),
2564 json.value( u
"y1"_s ).toDouble(),
2565 json.value( u
"x2"_s ).toDouble(),
2566 json.value( u
"y2"_s ).toDouble(),
2577 caseString += QStringLiteral(
2578 "WHEN @vector_tile_zoom >= %1 AND @vector_tile_zoom < %2 THEN color_hsla("
2587 colorComponent.arg( bottomColorExpr ).arg(
"hsl_hue" ),
2588 colorComponent.arg( topColorExpr ).arg(
"hsl_hue" ),
2591 json.value( u
"x1"_s ).toDouble(),
2592 json.value( u
"y1"_s ).toDouble(),
2593 json.value( u
"x2"_s ).toDouble(),
2594 json.value( u
"y2"_s ).toDouble(),
2601 colorComponent.arg( bottomColorExpr ).arg(
"hsl_saturation" ),
2602 colorComponent.arg( topColorExpr ).arg(
"hsl_saturation" ),
2605 json.value( u
"x1"_s ).toDouble(),
2606 json.value( u
"y1"_s ).toDouble(),
2607 json.value( u
"x2"_s ).toDouble(),
2608 json.value( u
"y2"_s ).toDouble(),
2615 colorComponent.arg( bottomColorExpr ).arg(
"lightness" ),
2616 colorComponent.arg( topColorExpr ).arg(
"lightness" ),
2619 json.value( u
"x1"_s ).toDouble(),
2620 json.value( u
"y1"_s ).toDouble(),
2621 json.value( u
"x2"_s ).toDouble(),
2622 json.value( u
"y2"_s ).toDouble(),
2629 colorComponent.arg( bottomColorExpr ).arg(
"alpha" ),
2630 colorComponent.arg( topColorExpr ).arg(
"alpha" ),
2633 json.value( u
"x1"_s ).toDouble(),
2634 json.value( u
"y1"_s ).toDouble(),
2635 json.value( u
"x2"_s ).toDouble(),
2636 json.value( u
"y2"_s ).toDouble(),
2645 const QString tz = stops.last().toList().value( 0 ).toString();
2646 const QVariant tcVariant = stops.last().toList().value( 1 );
2648 if ( tcVariant.userType() == QMetaType::Type::QString )
2651 if ( topColor.isValid() )
2658 caseString += QStringLiteral(
2659 "WHEN @vector_tile_zoom >= %1 THEN color_hsla(%2, %3, %4, %5) "
2660 "ELSE color_hsla(%2, %3, %4, %5) END"
2669 else if ( tcVariant.userType() == QMetaType::QVariantList )
2673 caseString += QStringLiteral(
2674 "WHEN @vector_tile_zoom >= %1 THEN color_hsla(%2, %3, %4, %5) "
2675 "ELSE color_hsla(%2, %3, %4, %5) END"
2678 .arg( colorComponent.arg( topColorExpr ).arg(
"hsl_hue" ) )
2679 .arg( colorComponent.arg( topColorExpr ).arg(
"hsl_saturation" ) )
2680 .arg( colorComponent.arg( topColorExpr ).arg(
"lightness" ) )
2681 .arg( colorComponent.arg( topColorExpr ).arg(
"alpha" ) );
2684 if ( !stops.empty() && defaultColor )
2685 *defaultColor =
parseColor( stops.value( 0 ).toList().value( 1 ).toString(), context );
2692 const double base = json.
value( u
"base"_s, u
"1"_s ).toDouble();
2693 const QVariantList stops = json.value( u
"stops"_s ).toList();
2694 if ( stops.empty() )
2697 QString scaleExpression;
2698 if ( stops.size() <= 2 )
2701 stops.value( 0 ).toList().value( 0 ).toDouble(),
2702 stops.last().toList().value( 0 ).toDouble(),
2703 stops.value( 0 ).toList().value( 1 ),
2704 stops.last().toList().value( 1 ),
2707 json.value( u
"x1"_s ).toDouble(),
2708 json.value( u
"y1"_s ).toDouble(),
2709 json.value( u
"x2"_s ).toDouble(),
2710 json.value( u
"y2"_s ).toDouble(),
2718 =
parseStops( base, stops, multiplier, context, type, json.value( u
"x1"_s ).toDouble(), json.value( u
"y1"_s ).toDouble(), json.value( u
"x2"_s ).toDouble(), json.value( u
"y2"_s ).toDouble() );
2721 if ( !stops.empty() && defaultNumber )
2722 *defaultNumber = stops.value( 0 ).toList().value( 1 ).toDouble() * multiplier;
2732 context = *contextPtr;
2734 const double base = json.value( u
"base"_s, u
"1"_s ).toDouble();
2735 const QVariantList stops = json.value( u
"stops"_s ).toList();
2736 if ( stops.empty() )
2739 QString scaleExpression;
2740 if ( stops.length() <= 2 )
2742 const QVariant bv = stops.value( 0 ).toList().value( 1 );
2743 const QVariant tv = stops.last().toList().value( 1 );
2744 double bottom = 0.0;
2746 const bool numeric = numericArgumentsOnly( bv, tv, bottom, top );
2748 stops.value( 0 ).toList().value( 0 ).toDouble(),
2749 stops.last().toList().value( 0 ).toDouble(),
2750 numeric ? QString::number( bottom * maxOpacity ) : QString(
"(%1) * %2" ).arg( parseValue( bv, context ) ).arg( maxOpacity ),
2751 numeric ? QString::number( top * maxOpacity ) : QString(
"(%1) * %2" ).arg( parseValue( tv, context ) ).arg( maxOpacity ),
2754 json.value( u
"x1"_s ).toDouble(),
2755 json.value( u
"y1"_s ).toDouble(),
2756 json.value( u
"x2"_s ).toDouble(),
2757 json.value( u
"y2"_s ).toDouble(),
2765 =
parseOpacityStops( base, stops, maxOpacity, context, type, json.value( u
"x1"_s ).toDouble(), json.value( u
"y1"_s ).toDouble(), json.value( u
"x2"_s ).toDouble(), json.value( u
"y2"_s ).toDouble() );
2774 QString caseString = u
"CASE WHEN @vector_tile_zoom < %1 THEN set_color_part(@symbol_color, 'alpha', %2)"_s.arg( stops.value( 0 ).toList().value( 0 ).toString() )
2775 .arg( stops.value( 0 ).toList().value( 1 ).toDouble() * maxOpacity );
2777 for (
int i = 0; i < stops.size() - 1; ++i )
2779 const QVariant bv = stops.value( i ).toList().value( 1 );
2780 const QVariant tv = stops.value( i + 1 ).toList().value( 1 );
2781 double bottom = 0.0;
2783 const bool numeric = numericArgumentsOnly( bv, tv, bottom, top );
2785 caseString += QStringLiteral(
2786 " WHEN @vector_tile_zoom >= %1 AND @vector_tile_zoom < %2 "
2787 "THEN set_color_part(@symbol_color, 'alpha', %3)"
2790 stops.value( i ).toList().value( 0 ).toString(),
2791 stops.value( i + 1 ).toList().value( 0 ).toString(),
2793 stops.value( i ).toList().value( 0 ).toDouble(),
2794 stops.value( i + 1 ).toList().value( 0 ).toDouble(),
2795 numeric ? QString::number( bottom * maxOpacity ) : QString(
"(%1) * %2" ).arg( parseValue( bv, context ) ).arg( maxOpacity ),
2796 numeric ? QString::number( top * maxOpacity ) : QString(
"(%1) * %2" ).arg( parseValue( tv, context ) ).arg( maxOpacity ),
2810 bool numeric =
false;
2811 const QVariant vv = stops.last().toList().value( 1 );
2812 double dv = vv.toDouble( &numeric );
2814 caseString += QStringLiteral(
2815 " WHEN @vector_tile_zoom >= %1 "
2816 "THEN set_color_part(@symbol_color, 'alpha', %2) END"
2818 .arg( stops.last().toList().value( 0 ).toString(), numeric ? QString::number( dv * maxOpacity ) : QString(
"(%1) * %2" ).arg( parseValue( vv, context ) ).arg( maxOpacity ) );
2824 const double base = json.
value( u
"base"_s, u
"1"_s ).toDouble();
2825 const QVariantList stops = json.value( u
"stops"_s ).toList();
2826 if ( stops.empty() )
2829 QString scaleExpression;
2830 if ( stops.size() <= 2 )
2832 scaleExpression = u
"array(%1,%2)"_s.arg(
2834 stops.value( 0 ).toList().value( 0 ).toDouble(),
2835 stops.last().toList().value( 0 ).toDouble(),
2836 stops.value( 0 ).toList().value( 1 ).toList().value( 0 ),
2837 stops.last().toList().value( 1 ).toList().value( 0 ),
2840 json.value( u
"x1"_s ).toDouble(),
2841 json.value( u
"y1"_s ).toDouble(),
2842 json.value( u
"x2"_s ).toDouble(),
2843 json.value( u
"y2"_s ).toDouble(),
2848 stops.value( 0 ).toList().value( 0 ).toDouble(),
2849 stops.last().toList().value( 0 ).toDouble(),
2850 stops.value( 0 ).toList().value( 1 ).toList().value( 1 ),
2851 stops.last().toList().value( 1 ).toList().value( 1 ),
2854 json.value( u
"x1"_s ).toDouble(),
2855 json.value( u
"y1"_s ).toDouble(),
2856 json.value( u
"x2"_s ).toDouble(),
2857 json.value( u
"y2"_s ).toDouble(),
2866 =
parsePointStops( base, stops, context, multiplier, type, json.value( u
"x1"_s ).toDouble(), json.value( u
"y1"_s ).toDouble(), json.value( u
"x2"_s ).toDouble(), json.value( u
"y2"_s ).toDouble() );
2869 if ( !stops.empty() && defaultPoint )
2870 *defaultPoint = QPointF( stops.value( 0 ).toList().value( 1 ).toList().value( 0 ).toDouble() * multiplier, stops.value( 0 ).toList().value( 1 ).toList().value( 1 ).toDouble() * multiplier );
2877 const QVariantList stops = json.
value( u
"stops"_s ).toList();
2878 if ( stops.empty() )
2881 const QString scaleExpression =
parseStringStops( stops, context, conversionMap, defaultString );
2890 QString caseString = u
"CASE "_s;
2892 for (
int i = 0; i < stops.length() - 1; ++i )
2895 const QVariant bz = stops.value( i ).toList().value( 0 );
2896 const QVariant bv = stops.value( i ).toList().value( 1 );
2897 if ( bv.userType() != QMetaType::Type::QVariantList && bv.userType() != QMetaType::Type::QStringList )
2899 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported offset interpolation type (%2)." ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( bz.userType() ) ) ) );
2904 const QVariant tz = stops.value( i + 1 ).toList().value( 0 );
2905 const QVariant tv = stops.value( i + 1 ).toList().value( 1 );
2906 if ( tv.userType() != QMetaType::Type::QVariantList && tv.userType() != QMetaType::Type::QStringList )
2908 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported offset interpolation type (%2)." ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( tz.userType() ) ) ) );
2912 caseString += QStringLiteral(
2913 "WHEN @vector_tile_zoom > %1 AND @vector_tile_zoom <= %2 "
2919 interpolateExpression( bz.toDouble(), tz.toDouble(), bv.toList().value( 0 ), tv.toList().value( 0 ), base, multiplier, x1, y1, x2, y2, type, &context ),
2920 interpolateExpression( bz.toDouble(), tz.toDouble(), bv.toList().value( 1 ), tv.toList().value( 1 ), base, multiplier, x1, y1, x2, y2, type, &context )
2923 caseString +=
"END"_L1;
2929 if ( stops.length() < 2 )
2932 QString caseString = u
"CASE"_s;
2934 for (
int i = 0; i < stops.length(); ++i )
2936 caseString +=
" WHEN "_L1;
2937 QStringList conditions;
2940 const QVariant bottomZoom = stops.value( i ).toList().value( 0 );
2941 conditions << u
"@vector_tile_zoom > %1"_s.arg( bottomZoom.toString() );
2943 if ( i < stops.length() - 1 )
2945 const QVariant topZoom = stops.value( i + 1 ).toList().value( 0 );
2946 conditions << u
"@vector_tile_zoom <= %1"_s.arg( topZoom.toString() );
2949 const QVariantList values = stops.value( i ).toList().value( 1 ).toList();
2950 QStringList valuesFixed;
2952 for (
const QVariant &value : values )
2954 const double number = value.toDouble( &ok );
2956 valuesFixed << QString::number( number * multiplier );
2960 caseString += u
"%1 THEN array(%3)"_s.arg( conditions.join(
" AND "_L1 ), valuesFixed.join(
',' ) );
2962 caseString +=
" END"_L1;
2970 QString caseString = u
"CASE "_s;
2972 for (
int i = 0; i < stops.length() - 1; ++i )
2975 const QVariant bz = stops.value( i ).toList().value( 0 );
2976 const QVariant bv = stops.value( i ).toList().value( 1 );
2977 if ( bz.userType() == QMetaType::Type::QVariantList || bz.userType() == QMetaType::Type::QStringList )
2979 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
2984 const QVariant tz = stops.value( i + 1 ).toList().value( 0 );
2985 const QVariant tv = stops.value( i + 1 ).toList().value( 1 );
2986 if ( tz.userType() == QMetaType::Type::QVariantList || tz.userType() == QMetaType::Type::QStringList )
2988 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
2992 const QString lowerComparator = i == 0 ? u
">="_s : u
">"_s;
2994 caseString += QStringLiteral(
2995 "WHEN @vector_tile_zoom %1 %2 AND @vector_tile_zoom <= %3 "
2998 .arg( lowerComparator, bz.toString(), tz.toString(),
interpolateExpression( bz.toDouble(), tz.toDouble(), bv, tv, base, multiplier, x1, y1, x2, y2, type, &context ) );
3001 const QVariant z = stops.last().toList().value( 0 );
3002 const QVariant v = stops.last().toList().value( 1 );
3003 QString vStr = v.toString();
3004 if ( ( QMetaType::Type ) v.userType() == QMetaType::QVariantList )
3007 caseString += QStringLiteral(
3008 "WHEN @vector_tile_zoom > %1 "
3009 "THEN ( ( %2 ) * %3 ) END"
3011 .arg( z.toString() )
3017 caseString += QStringLiteral(
3018 "WHEN @vector_tile_zoom > %1 "
3021 .arg( z.toString() )
3022 .arg( v.toDouble() * multiplier );
3030 QString caseString = u
"CASE "_s;
3032 for (
int i = 0; i < stops.length() - 1; ++i )
3035 const QVariant bz = stops.value( i ).toList().value( 0 );
3036 const QString bv = stops.value( i ).toList().value( 1 ).toString();
3037 if ( bz.userType() == QMetaType::Type::QVariantList || bz.userType() == QMetaType::Type::QStringList )
3039 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
3044 const QVariant tz = stops.value( i + 1 ).toList().value( 0 );
3045 if ( tz.userType() == QMetaType::Type::QVariantList || tz.userType() == QMetaType::Type::QStringList )
3047 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
3051 caseString += QStringLiteral(
3052 "WHEN @vector_tile_zoom > %1 AND @vector_tile_zoom <= %2 "
3057 caseString += u
"ELSE %1 END"_s.arg(
QgsExpression::quotedValue( conversionMap.value( stops.constLast().toList().value( 1 ).toString(), stops.constLast().toList().value( 1 ) ) ) );
3058 if ( defaultString )
3059 *defaultString = stops.constLast().toList().value( 1 ).toString();
3065 QString caseString = u
"CASE "_s;
3067 bool isExpression =
false;
3068 for (
int i = 0; i < stops.length() - 1; ++i )
3071 const QVariant bz = stops.value( i ).toList().value( 0 );
3072 if ( bz.userType() == QMetaType::Type::QVariantList || bz.userType() == QMetaType::Type::QStringList )
3074 context.
pushWarning( QObject::tr(
"%1: Lists in label interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
3079 const QVariant tz = stops.value( i + 1 ).toList().value( 0 );
3080 if ( tz.userType() == QMetaType::Type::QVariantList || tz.userType() == QMetaType::Type::QStringList )
3082 context.
pushWarning( QObject::tr(
"%1: Lists in label interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
3086 QString fieldPart = processLabelField( stops.constLast().toList().value( 1 ).toString(), isExpression );
3087 if ( fieldPart.isEmpty() )
3088 fieldPart = u
"''"_s;
3089 else if ( !isExpression )
3092 caseString += QStringLiteral(
3093 "WHEN @vector_tile_zoom > %1 AND @vector_tile_zoom < %2 "
3096 .arg( bz.toString(), tz.toString(), fieldPart );
3100 const QVariant bz = stops.constLast().toList().value( 0 );
3101 if ( bz.userType() == QMetaType::Type::QVariantList || bz.userType() == QMetaType::Type::QStringList )
3103 context.
pushWarning( QObject::tr(
"%1: Lists in label interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
3107 QString fieldPart = processLabelField( stops.constLast().toList().value( 1 ).toString(), isExpression );
3108 if ( fieldPart.isEmpty() )
3109 fieldPart = u
"''"_s;
3110 else if ( !isExpression )
3113 caseString += QStringLiteral(
3114 "WHEN @vector_tile_zoom >= %1 "
3117 .arg( bz.toString(), fieldPart );
3120 QString defaultPart = processLabelField( stops.constFirst().toList().value( 1 ).toString(), isExpression );
3121 if ( defaultPart.isEmpty() )
3122 defaultPart = u
"''"_s;
3123 else if ( !isExpression )
3125 caseString += u
"ELSE %1 END"_s.arg( defaultPart );
3134 const QString method = json.
value( 0 ).toString();
3135 if ( method ==
"interpolate"_L1 )
3139 else if ( method ==
"match"_L1 )
3141 return parseMatchList( json, type, context, multiplier, maxOpacity, defaultColor, defaultNumber );
3143 else if ( method ==
"step"_L1 )
3145 return parseStepList( json, type, context, multiplier, maxOpacity, defaultColor, defaultNumber );
3157 const QString attribute =
parseExpression( json.value( 1 ).toList(), context );
3158 if ( attribute.isEmpty() )
3160 context.
pushWarning( QObject::tr(
"%1: Could not interpret match list" ).arg( context.
layerId() ) );
3164 QString caseString = u
"CASE "_s;
3166 for (
int i = 2; i < json.length() - 1; i += 2 )
3169 QVariant variantKeys = json.value( i );
3170 if ( variantKeys.userType() == QMetaType::Type::QVariantList || variantKeys.userType() == QMetaType::Type::QStringList )
3171 keys = variantKeys.toList();
3173 keys = { variantKeys };
3175 QStringList matchString;
3176 for (
const QVariant &key : keys )
3181 const QVariant value = json.value( i + 1 );
3183 QString valueString;
3188 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
3194 const QColor color =
parseColor( value, context );
3202 const double v = value.toDouble() * multiplier;
3203 valueString = QString::number( v );
3209 const double v = value.toDouble() * maxOpacity;
3210 valueString = QString::number( v );
3216 valueString = u
"array(%1,%2)"_s.arg( value.toList().value( 0 ).toDouble() * multiplier, value.toList().value( 0 ).toDouble() * multiplier );
3222 if ( value.toList().count() == 2 && value.toList().first().toString() ==
"literal"_L1 )
3224 valueString = u
"array(%1)"_s.arg( value.toList().at( 1 ).toStringList().join(
',' ) );
3228 valueString = u
"array(%1)"_s.arg( value.toStringList().join(
',' ) );
3235 if ( value.toList().count() == 2 && value.toList().first().toString() ==
"literal"_L1 )
3237 QStringList dashValues = value.toList().at( 1 ).toStringList();
3238 if ( dashValues.length() % 2 == 1 )
3240 dashValues << u
"0"_s;
3242 valueString = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3246 QStringList dashValues = value.toStringList();
3247 if ( dashValues.length() % 2 == 1 )
3249 dashValues << u
"0"_s;
3251 valueString = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3257 if ( matchString.count() == 1 )
3259 caseString += u
"WHEN %1 IS %2 THEN %3 "_s.arg( attribute, matchString.at( 0 ), valueString );
3263 caseString += u
"WHEN %1 IN (%2) THEN %3 "_s.arg( attribute, matchString.join(
',' ), valueString );
3267 QVariant lastValue = json.constLast();
3270 switch ( lastValue.userType() )
3272 case QMetaType::Type::QVariantList:
3273 case QMetaType::Type::QStringList:
3274 elseValue =
parseValueList( lastValue.toList(), type, context, multiplier, maxOpacity, defaultColor, defaultNumber ).
asExpression();
3283 const QColor color =
parseColor( lastValue, context );
3285 *defaultColor = color;
3293 const double v = json.constLast().toDouble() * multiplier;
3294 if ( defaultNumber )
3296 elseValue = QString::number( v );
3302 const double v = json.constLast().toDouble() * maxOpacity;
3303 if ( defaultNumber )
3305 elseValue = QString::number( v );
3311 elseValue = u
"array(%1,%2)"_s.arg( json.constLast().toList().value( 0 ).toDouble() * multiplier ).arg( json.constLast().toList().value( 0 ).toDouble() * multiplier );
3317 if ( json.constLast().toList().count() == 2 && json.constLast().toList().first().toString() ==
"literal"_L1 )
3319 elseValue = u
"array(%1)"_s.arg( json.constLast().toList().at( 1 ).toStringList().join(
',' ) );
3323 elseValue = u
"array(%1)"_s.arg( json.constLast().toStringList().join(
',' ) );
3330 if ( json.constLast().toList().count() == 2 && json.constLast().toList().first().toString() ==
"literal"_L1 )
3332 QStringList dashValues = json.constLast().toList().at( 1 ).toStringList();
3333 if ( dashValues.length() % 2 == 1 )
3335 dashValues << u
"0"_s;
3337 elseValue = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3341 QStringList dashValues = json.constLast().toStringList();
3342 if ( dashValues.length() % 2 == 1 )
3344 dashValues << u
"0"_s;
3346 elseValue = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3355 caseString += u
"ELSE %1 END"_s.arg( elseValue );
3363 const QString expression =
parseExpression( json.value( 1 ).toList(), context );
3364 if ( expression.isEmpty() )
3366 context.
pushWarning( QObject::tr(
"%1: Could not interpret step list" ).arg( context.
layerId() ) );
3370 QString caseString = u
"CASE "_s;
3373 for (
int i = json.length() - 2; i > 0; i -= 2 )
3375 const QVariant stepValue = json.value( i + 1 );
3377 QString valueString;
3388 const QColor color =
parseColor( stepValue, context );
3395 const double v = stepValue.toDouble() * multiplier;
3396 valueString = QString::number( v );
3402 const double v = stepValue.toDouble() * maxOpacity;
3403 valueString = QString::number( v );
3409 valueString = u
"array(%1,%2)"_s.arg( stepValue.toList().value( 0 ).toDouble() * multiplier ).arg( stepValue.toList().value( 0 ).toDouble() * multiplier );
3415 if ( stepValue.toList().count() == 2 && stepValue.toList().first().toString() ==
"literal"_L1 )
3417 valueString = u
"array(%1)"_s.arg( stepValue.toList().at( 1 ).toStringList().join(
',' ) );
3421 valueString = u
"array(%1)"_s.arg( stepValue.toStringList().join(
',' ) );
3428 if ( stepValue.toList().count() == 2 && stepValue.toList().first().toString() ==
"literal"_L1 )
3430 QStringList dashValues = stepValue.toList().at( 1 ).toStringList();
3431 if ( dashValues.length() % 2 == 1 )
3433 dashValues << u
"0"_s;
3435 valueString = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3439 QStringList dashValues = stepValue.toStringList();
3440 if ( dashValues.length() % 2 == 1 )
3442 dashValues << u
"0"_s;
3444 valueString = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3454 caseString += u
" WHEN %1 >= %2 THEN (%3) "_s.arg( expression, stepKey, valueString );
3458 caseString += u
"ELSE (%1) END"_s.arg( valueString );
3468 if ( json.value( 0 ).toString() !=
"interpolate"_L1 )
3470 context.
pushWarning( QObject::tr(
"%1: Could not interpret value list" ).arg( context.
layerId() ) );
3474 const QVariantList parts = json.
value( 1 ).toList();
3475 const QString technique = parts.value( 0 ).toString();
3479 if ( technique ==
"linear"_L1 )
3481 props.insert( u
"base"_s, 1 );
3484 else if ( technique ==
"exponential"_L1 )
3486 props.insert( u
"base"_s, parts.value( 1 ).toDouble() );
3489 else if ( technique ==
"cubic-bezier"_L1 )
3493 props.insert( u
"x1"_s, parts.value( 1 ).toDouble() );
3494 props.insert( u
"y1"_s, parts.value( 2 ).toDouble() );
3495 props.insert( u
"x2"_s, parts.value( 3 ).toDouble() );
3496 props.insert( u
"y2"_s, parts.value( 4 ).toDouble() );
3500 context.
pushWarning( QObject::tr(
"%1: Skipping not implemented interpolation method %2" ).arg( context.
layerId(), technique ) );
3504 if ( json.value( 2 ).toList().value( 0 ).toString() !=
"zoom"_L1 )
3506 context.
pushWarning( QObject::tr(
"%1: Skipping not implemented interpolation input %2" ).arg( context.
layerId(), json.value( 2 ).toString() ) );
3512 for (
int i = 3; i < json.length(); i += 2 )
3514 stops.push_back( QVariantList() << json.value( i ).toString() << json.value( i + 1 ) );
3517 props.insert( u
"stops"_s, stops );
3535 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported numeric array in interpolate" ).arg( context.
layerId() ) );
3543 if ( ( QMetaType::Type ) colorExpression.userType() == QMetaType::QVariantList )
3547 return parseValue( colorExpression, context,
true );
3552 if ( color.userType() != QMetaType::Type::QString )
3554 context.
pushWarning( QObject::tr(
"%1: Could not parse non-string color %2, skipping" ).arg( context.
layerId(), color.toString() ) );
3563 hue = std::max( 0, color.hslHue() );
3564 saturation = color.hslSaturation() / 255.0 * 100;
3565 lightness = color.lightness() / 255.0 * 100;
3566 alpha = color.alpha();
3570 double zoomMin,
double zoomMax, QVariant valueMin, QVariant valueMax,
double base,
double multiplier,
double x1,
double y1,
double x2,
double y2,
InterpolationType type,
QgsMapBoxGlStyleConversionContext *contextPtr
3576 context = *contextPtr;
3580 if ( valueMin.canConvert( QMetaType::Double ) && valueMax.canConvert( QMetaType::Double ) )
3582 bool minDoubleOk =
true;
3583 const double min = valueMin.toDouble( &minDoubleOk );
3584 bool maxDoubleOk =
true;
3585 const double max = valueMax.toDouble( &maxDoubleOk );
3586 if ( minDoubleOk && maxDoubleOk &&
qgsDoubleNear( min, max ) )
3588 return QString::number( min * multiplier );
3592 QString minValueExpr = valueMin.toString();
3593 QString maxValueExpr = valueMax.toString();
3594 if ( valueMin.userType() == QMetaType::Type::QVariantList )
3598 if ( valueMax.userType() == QMetaType::Type::QVariantList )
3604 if ( minValueExpr == maxValueExpr )
3606 expression = minValueExpr;
3613 expression = u
"scale_linear(@vector_tile_zoom,%1,%2,%3,%4)"_s.arg( zoomMin ).arg( zoomMax ).arg( minValueExpr ).arg( maxValueExpr );
3618 expression = u
"scale_linear(@vector_tile_zoom,%1,%2,%3,%4)"_s.arg( zoomMin ).arg( zoomMax ).arg( minValueExpr ).arg( maxValueExpr );
3622 expression = u
"scale_exponential(@vector_tile_zoom,%1,%2,%3,%4,%5)"_s.arg( zoomMin ).arg( zoomMax ).arg( minValueExpr ).arg( maxValueExpr ).arg( base );
3627 expression = u
"scale_cubic_bezier(@vector_tile_zoom,%1,%2,%3,%4,%5,%6,%7,%8)"_s.arg( zoomMin ).arg( zoomMax ).arg( minValueExpr ).arg( maxValueExpr ).arg( x1 ).arg( y1 ).arg( x2 ).arg( y2 );
3632 if ( multiplier != 1 )
3633 return u
"(%1) * %2"_s.arg( expression ).arg( multiplier );
3640 if ( style ==
"round"_L1 )
3641 return Qt::RoundCap;
3642 else if ( style ==
"square"_L1 )
3643 return Qt::SquareCap;
3650 if ( style ==
"bevel"_L1 )
3651 return Qt::BevelJoin;
3652 else if ( style ==
"round"_L1 )
3653 return Qt::RoundJoin;
3655 return Qt::MiterJoin;
3660 QString op = expression.value( 0 ).toString();
3661 if ( ( op ==
"%"_L1 || op ==
"/"_L1 || op ==
"-"_L1 || op ==
"^"_L1 ) && expression.size() >= 3 )
3663 if ( expression.size() != 3 )
3665 context.
pushWarning( QObject::tr(
"%1: Operator %2 requires exactly two operands, skipping extra operands" ).arg( context.
layerId() ).arg( op ) );
3667 QString v1 = parseValue( expression.value( 1 ), context, colorExpected );
3668 QString v2 = parseValue( expression.value( 2 ), context, colorExpected );
3669 return u
"(%1 %2 %3)"_s.arg( v1, op, v2 );
3671 else if ( ( op ==
"*"_L1 || op ==
"+"_L1 ) && expression.size() >= 3 )
3673 QStringList operands;
3674 std::transform( std::next( expression.begin() ), expression.end(), std::back_inserter( operands ), [&context, colorExpected](
const QVariant &val ) {
3675 return parseValue( val, context, colorExpected );
3677 return u
"(%1)"_s.arg( operands.join( u
" %1 "_s.arg( op ) ) );
3679 else if ( op ==
"to-number"_L1 )
3681 return u
"to_real(%1)"_s.arg( parseValue( expression.value( 1 ), context ) );
3683 else if ( op ==
"sqrt"_L1 )
3685 return u
"sqrt(%1)"_s.arg( parseValue( expression.value( 1 ), context ) );
3687 else if ( op ==
"literal"_L1 )
3689 return expression.value( 1 ).toString();
3691 else if ( op ==
"all"_L1 || op ==
"any"_L1 || op ==
"none"_L1 )
3694 for (
int i = 1; i < expression.size(); ++i )
3696 const QString part = parseValue( expression.at( i ), context );
3697 if ( part.isEmpty() )
3699 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported expression" ).arg( context.
layerId() ) );
3705 if ( op ==
"none"_L1 )
3706 return u
"NOT (%1)"_s.arg( parts.join(
") AND NOT ("_L1 ) );
3708 QString operatorString;
3709 if ( op ==
"all"_L1 )
3710 operatorString = u
") AND ("_s;
3711 else if ( op ==
"any"_L1 )
3712 operatorString = u
") OR ("_s;
3714 return u
"(%1)"_s.arg( parts.join( operatorString ) );
3716 else if ( op ==
'!' )
3719 QVariantList contraJsonExpr = expression.value( 1 ).toList();
3720 contraJsonExpr[0] = QString( op + contraJsonExpr[0].toString() );
3722 return parseKey( contraJsonExpr, context );
3724 else if ( op ==
"=="_L1 || op ==
"!="_L1 || op ==
">="_L1 || op ==
'>' || op ==
"<="_L1 || op ==
'<' )
3727 if ( op ==
"=="_L1 )
3729 else if ( op ==
"!="_L1 )
3731 return u
"%1 %2 %3"_s.arg( parseKey( expression.value( 1 ), context ), op, parseValue( expression.value( 2 ), context ) );
3733 else if ( op ==
"has"_L1 )
3735 return parseKey( expression.value( 1 ), context ) + u
" IS NOT NULL"_s;
3737 else if ( op ==
"!has"_L1 )
3739 return parseKey( expression.value( 1 ), context ) + u
" IS NULL"_s;
3741 else if ( op ==
"in"_L1 || op ==
"!in"_L1 )
3743 const QString key = parseKey( expression.value( 1 ), context );
3746 QVariantList values = expression.mid( 2 );
3747 if ( expression.size() == 3 && expression.at( 2 ).userType() == QMetaType::Type::QVariantList && expression.at( 2 ).toList().count() > 1 && expression.at( 2 ).toList().at( 0 ).toString() ==
"literal"_L1 )
3749 values = expression.at( 2 ).toList().at( 1 ).toList();
3752 for (
const QVariant &value : std::as_const( values ) )
3754 const QString part = parseValue( value, context );
3755 if ( part.isEmpty() )
3757 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported expression" ).arg( context.
layerId() ) );
3763 if ( parts.size() == 1 )
3765 if ( op ==
"in"_L1 )
3766 return u
"%1 IS %2"_s.arg( key, parts.at( 0 ) );
3768 return u
"(%1 IS NULL OR %1 IS NOT %2)"_s.arg( key, parts.at( 0 ) );
3772 if ( op ==
"in"_L1 )
3773 return u
"%1 IN (%2)"_s.arg( key, parts.join(
", "_L1 ) );
3775 return u
"(%1 IS NULL OR %1 NOT IN (%2))"_s.arg( key, parts.join(
", "_L1 ) );
3778 else if ( op ==
"get"_L1 )
3780 return parseKey( expression.value( 1 ), context );
3782 else if ( op ==
"match"_L1 )
3784 const QString attribute = expression.value( 1 ).toList().value( 1 ).toString();
3786 if ( expression.size() == 5
3787 && expression.at( 3 ).userType() == QMetaType::Type::Bool
3788 && expression.at( 3 ).toBool() ==
true
3789 && expression.at( 4 ).userType() == QMetaType::Type::Bool
3790 && expression.at( 4 ).toBool() ==
false )
3793 if ( expression.at( 2 ).userType() == QMetaType::Type::QVariantList || expression.at( 2 ).userType() == QMetaType::Type::QStringList )
3796 for (
const QVariant &p : expression.at( 2 ).toList() )
3798 parts << parseValue( p, context );
3801 if ( parts.size() > 1 )
3806 else if ( expression.at( 2 ).userType() == QMetaType::Type::QString
3807 || expression.at( 2 ).userType() == QMetaType::Type::Int
3808 || expression.at( 2 ).userType() == QMetaType::Type::Double
3809 || expression.at( 2 ).userType() == QMetaType::Type::LongLong )
3815 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported expression" ).arg( context.
layerId() ) );
3821 QString caseString = u
"CASE "_s;
3822 for (
int i = 2; i < expression.size() - 2; i += 2 )
3824 if ( expression.at( i ).userType() == QMetaType::Type::QVariantList || expression.at( i ).userType() == QMetaType::Type::QStringList )
3827 for (
const QVariant &p : expression.at( i ).toList() )
3832 if ( parts.size() > 1 )
3837 else if ( expression.at( i ).userType() == QMetaType::Type::QString
3838 || expression.at( i ).userType() == QMetaType::Type::Int
3839 || expression.at( i ).userType() == QMetaType::Type::Double
3840 || expression.at( i ).userType() == QMetaType::Type::LongLong )
3845 caseString += u
"THEN %1 "_s.arg( parseValue( expression.at( i + 1 ), context, colorExpected ) );
3847 caseString += u
"ELSE %1 END"_s.arg( parseValue( expression.last(), context, colorExpected ) );
3851 else if ( op ==
"to-string"_L1 )
3853 return u
"to_string(%1)"_s.arg(
parseExpression( expression.value( 1 ).toList(), context ) );
3855 else if ( op ==
"to-boolean"_L1 )
3857 return u
"to_bool(%1)"_s.arg(
parseExpression( expression.value( 1 ).toList(), context ) );
3859 else if ( op ==
"case"_L1 )
3861 QString caseString = u
"CASE"_s;
3862 for (
int i = 1; i < expression.size() - 2; i += 2 )
3864 const QString condition =
parseExpression( expression.value( i ).toList(), context );
3865 const QString value = parseValue( expression.value( i + 1 ), context, colorExpected );
3866 caseString += u
" WHEN (%1) THEN %2"_s.arg( condition, value );
3868 const QString value = parseValue( expression.constLast(), context, colorExpected );
3869 caseString += u
" ELSE %1 END"_s.arg( value );
3872 else if ( op ==
"zoom"_L1 && expression.count() == 1 )
3874 return u
"@vector_tile_zoom"_s;
3876 else if ( op ==
"coalesce"_L1 )
3878 QString coalesceString = u
"coalesce("_s;
3879 for (
int i = 1; i < expression.size(); i++ )
3882 coalesceString +=
", "_L1;
3883 coalesceString += parseValue( expression.value( i ), context );
3885 coalesceString +=
')'_L1;
3886 return coalesceString;
3888 else if ( op ==
"concat"_L1 )
3890 QString concatString = u
"concat("_s;
3891 for (
int i = 1; i < expression.size(); i++ )
3894 concatString +=
", "_L1;
3895 concatString += parseValue( expression.value( i ), context );
3897 concatString +=
')'_L1;
3898 return concatString;
3900 else if ( op ==
"length"_L1 )
3902 return u
"length(%1)"_s.arg(
parseExpression( expression.value( 1 ).toList(), context ) );
3904 else if ( op ==
"step"_L1 )
3906 const QString stepExpression =
parseExpression( expression.value( 1 ).toList(), context );
3907 if ( stepExpression.isEmpty() )
3909 context.
pushWarning( QObject::tr(
"%1: Could not interpret step list" ).arg( context.
layerId() ) );
3913 QString caseString = u
"CASE "_s;
3915 for (
int i = expression.length() - 2; i > 0; i -= 2 )
3917 const QString stepValue = parseValue( expression.value( i + 1 ), context, colorExpected );
3921 caseString += u
" WHEN %1 >= %2 THEN (%3) "_s.arg( stepExpression, stepKey, stepValue );
3925 caseString += u
"ELSE (%1) END"_s.arg( stepValue );
3930 else if ( op ==
"pitch"_L1 )
3936 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported expression \"%2\"" ).arg( context.
layerId(), op ) );
3945 QString actualName = name;
3946 const int categorySeparator = name.indexOf(
':' );
3947 if ( categorySeparator > 0 )
3949 category = name.left( categorySeparator );
3952 actualName = name.mid( categorySeparator + 1 );
3961 if ( category.isEmpty() )
3966 if ( spriteImage.isNull() )
3968 context.
pushWarning( QObject::tr(
"%1: Could not retrieve sprite '%2'" ).arg( context.
layerId(), name ) );
3972 const QVariantMap spriteDefinition = context.
spriteDefinitions( category ).value( actualName ).toMap();
3973 if ( spriteDefinition.size() == 0 )
3975 context.
pushWarning( QObject::tr(
"%1: Could not retrieve sprite '%2'" ).arg( context.
layerId(), name ) );
3980 = spriteImage.copy( spriteDefinition.value( u
"x"_s ).toInt(), spriteDefinition.value( u
"y"_s ).toInt(), spriteDefinition.value( u
"width"_s ).toInt(), spriteDefinition.value( u
"height"_s ).toInt() );
3981 if ( sprite.isNull() )
3983 context.
pushWarning( QObject::tr(
"%1: Could not retrieve sprite '%2'" ).arg( context.
layerId(), name ) );
3987 spriteSize = sprite.size() / spriteDefinition.value( u
"pixelRatio"_s ).toDouble() * context.
pixelSizeConversionFactor();
3997 auto prepareBase64 = [](
const QImage &sprite ) {
3999 if ( !sprite.isNull() )
4002 QBuffer buffer( &blob );
4003 buffer.open( QIODevice::WriteOnly );
4004 sprite.save( &buffer,
"PNG" );
4006 const QByteArray encoded = blob.toBase64();
4007 path = QString( encoded );
4008 path.prepend(
"base64:"_L1 );
4013 switch ( value.userType() )
4015 case QMetaType::Type::QString:
4017 QString spriteName = value.toString();
4018 const thread_local QRegularExpression fieldNameMatch( u
"{([^}]+)}"_s );
4019 QRegularExpressionMatch match = fieldNameMatch.match( spriteName );
4020 if ( match.hasMatch() )
4022 const QString fieldName = match.captured( 1 );
4023 spriteProperty = u
"CASE"_s;
4024 spriteSizeProperty = u
"CASE"_s;
4026 spriteName.replace(
"(",
"\\("_L1 );
4027 spriteName.replace(
")",
"\\)"_L1 );
4028 spriteName.replace( fieldNameMatch, u
"([^\\/\\\\]+)"_s );
4029 const QRegularExpression fieldValueMatch( spriteName );
4031 for (
const QString &name : spriteNames )
4033 match = fieldValueMatch.match( name );
4034 if ( match.hasMatch() )
4038 const QString fieldValue = match.captured( 1 );
4040 path = prepareBase64( sprite );
4041 if ( spritePath.isEmpty() && !path.isEmpty() )
4047 spriteProperty += u
" WHEN \"%1\" = '%2' THEN '%3'"_s.arg( fieldName, fieldValue, path );
4048 spriteSizeProperty += u
" WHEN \"%1\" = '%2' THEN %3"_s.arg( fieldName ).arg( fieldValue ).arg( size.width() );
4052 spriteProperty +=
" END"_L1;
4053 spriteSizeProperty +=
" END"_L1;
4057 spriteProperty.clear();
4058 spriteSizeProperty.clear();
4059 const QImage sprite =
retrieveSprite( spriteName, context, spriteSize );
4060 spritePath = prepareBase64( sprite );
4065 case QMetaType::Type::QVariantMap:
4067 const QVariantList stops = value.toMap().value( u
"stops"_s ).toList();
4068 if ( stops.size() == 0 )
4075 sprite =
retrieveSprite( stops.value( 0 ).toList().value( 1 ).toString(), context, spriteSize );
4076 spritePath = prepareBase64( sprite );
4078 spriteProperty = u
"CASE WHEN @vector_tile_zoom < %1 THEN '%2'"_s.arg( stops.value( 0 ).toList().value( 0 ).toString() ).arg( spritePath );
4079 spriteSizeProperty = u
"CASE WHEN @vector_tile_zoom < %1 THEN %2"_s.arg( stops.value( 0 ).toList().value( 0 ).toString() ).arg( spriteSize.width() );
4081 for (
int i = 0; i < stops.size() - 1; ++i )
4084 sprite =
retrieveSprite( stops.value( 0 ).toList().value( 1 ).toString(), context, size );
4085 path = prepareBase64( sprite );
4087 spriteProperty += QStringLiteral(
4088 " WHEN @vector_tile_zoom >= %1 AND @vector_tile_zoom < %2 "
4091 .arg( stops.value( i ).toList().value( 0 ).toString(), stops.value( i + 1 ).toList().value( 0 ).toString(), path );
4092 spriteSizeProperty += QStringLiteral(
4093 " WHEN @vector_tile_zoom >= %1 AND @vector_tile_zoom < %2 "
4096 .arg( stops.value( i ).toList().value( 0 ).toString(), stops.value( i + 1 ).toList().value( 0 ).toString() )
4097 .arg( size.width() );
4099 sprite =
retrieveSprite( stops.last().toList().value( 1 ).toString(), context, size );
4100 path = prepareBase64( sprite );
4102 spriteProperty += QStringLiteral(
4103 " WHEN @vector_tile_zoom >= %1 "
4106 .arg( stops.last().toList().value( 0 ).toString() )
4108 spriteSizeProperty += QStringLiteral(
4109 " WHEN @vector_tile_zoom >= %1 "
4112 .arg( stops.last().toList().value( 0 ).toString() )
4113 .arg( size.width() );
4117 case QMetaType::Type::QVariantList:
4119 const QVariantList json = value.toList();
4120 const QString method = json.value( 0 ).toString();
4122 if ( method ==
"match"_L1 )
4124 const QString attribute =
parseExpression( json.value( 1 ).toList(), context );
4125 if ( attribute.isEmpty() )
4127 context.
pushWarning( QObject::tr(
"%1: Could not interpret match list" ).arg( context.
layerId() ) );
4131 spriteProperty = u
"CASE"_s;
4132 spriteSizeProperty = u
"CASE"_s;
4134 for (
int i = 2; i < json.length() - 1; i += 2 )
4136 const QVariant matchKey = json.value( i );
4137 const QVariant matchValue = json.value( i + 1 );
4138 QString matchString;
4139 switch ( matchKey.userType() )
4141 case QMetaType::Type::QVariantList:
4142 case QMetaType::Type::QStringList:
4144 const QVariantList keys = matchKey.toList();
4145 QStringList matchStringList;
4146 for (
const QVariant &key : keys )
4150 matchString = matchStringList.join(
',' );
4154 case QMetaType::Type::Bool:
4155 case QMetaType::Type::QString:
4156 case QMetaType::Type::Int:
4157 case QMetaType::Type::LongLong:
4158 case QMetaType::Type::Double:
4165 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported sprite type (%2)." ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( value.userType() ) ) ) );
4169 const QImage sprite =
retrieveSprite( matchValue.toString(), context, spriteSize );
4170 spritePath = prepareBase64( sprite );
4172 spriteProperty += QStringLiteral(
4176 .arg( attribute, matchString, spritePath );
4178 spriteSizeProperty += QStringLiteral(
4182 .arg( attribute, matchString )
4183 .arg( spriteSize.width() );
4186 if ( !json.constLast().toString().isEmpty() )
4188 const QImage sprite =
retrieveSprite( json.constLast().toString(), context, spriteSize );
4189 spritePath = prepareBase64( sprite );
4193 spritePath = QString();
4196 spriteProperty += u
" ELSE '%1' END"_s.arg( spritePath );
4197 spriteSizeProperty += u
" ELSE %3 END"_s.arg( spriteSize.width() );
4200 else if ( method ==
"step"_L1 )
4202 const QString expression =
parseExpression( json.value( 1 ).toList(), context );
4203 if ( expression.isEmpty() )
4205 context.
pushWarning( QObject::tr(
"%1: Could not interpret step list" ).arg( context.
layerId() ) );
4209 spriteProperty = u
"CASE"_s;
4210 spriteSizeProperty = u
"CASE"_s;
4211 for (
int i = json.length() - 2; i > 2; i -= 2 )
4214 const QString stepValue = json.value( i + 1 ).toString();
4216 const QImage sprite =
retrieveSprite( stepValue, context, spriteSize );
4217 spritePath = prepareBase64( sprite );
4219 spriteProperty += u
" WHEN %1 >= %2 THEN '%3' "_s.arg( expression, stepKey, spritePath );
4220 spriteSizeProperty += u
" WHEN %1 >= %2 THEN %3 "_s.arg( expression ).arg( stepKey ).arg( spriteSize.width() );
4223 const QImage sprite =
retrieveSprite( json.at( 2 ).toString(), context, spriteSize );
4224 spritePath = prepareBase64( sprite );
4226 spriteProperty += u
"ELSE '%1' END"_s.arg( spritePath );
4227 spriteSizeProperty += u
"ELSE %3 END"_s.arg( spriteSize.width() );
4230 else if ( method ==
"case"_L1 )
4232 spriteProperty = u
"CASE"_s;
4233 spriteSizeProperty = u
"CASE"_s;
4234 for (
int i = 1; i < json.length() - 2; i += 2 )
4236 const QString caseExpression =
parseExpression( json.value( i ).toList(), context );
4237 const QString caseValue = json.value( i + 1 ).toString();
4239 const QImage sprite =
retrieveSprite( caseValue, context, spriteSize );
4240 spritePath = prepareBase64( sprite );
4242 spriteProperty += u
" WHEN %1 THEN '%2' "_s.arg( caseExpression, spritePath );
4243 spriteSizeProperty += u
" WHEN %1 THEN %2 "_s.arg( caseExpression ).arg( spriteSize.width() );
4245 const QImage sprite =
retrieveSprite( json.last().toString(), context, spriteSize );
4246 spritePath = prepareBase64( sprite );
4248 spriteProperty += u
"ELSE '%1' END"_s.arg( spritePath );
4249 spriteSizeProperty += u
"ELSE %3 END"_s.arg( spriteSize.width() );
4254 context.
pushWarning( QObject::tr(
"%1: Could not interpret sprite value list with method %2" ).arg( context.
layerId(), method ) );
4260 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported sprite type (%2)." ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( value.userType() ) ) ) );
4270 switch ( value.userType() )
4272 case QMetaType::Type::QVariantList:
4273 case QMetaType::Type::QStringList:
4276 case QMetaType::Type::Bool:
4277 case QMetaType::Type::QString:
4278 if ( colorExpected )
4283 return parseValue(
c, context );
4288 case QMetaType::Type::Int:
4289 case QMetaType::Type::LongLong:
4290 case QMetaType::Type::Double:
4291 return value.toString();
4293 case QMetaType::Type::QColor:
4294 c = value.value<QColor>();
4295 return QString(
"color_rgba(%1,%2,%3,%4)" ).arg(
c.red() ).arg(
c.green() ).arg(
c.blue() ).arg(
c.alpha() );
4298 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported expression part" ).arg( context.
layerId() ) );
4306 if ( value.toString() ==
"$type"_L1 )
4308 return u
"_geom_type"_s;
4310 if ( value.toString() ==
"level"_L1 )
4314 else if ( ( value.userType() == QMetaType::Type::QVariantList && value.toList().size() == 1 ) || value.userType() == QMetaType::Type::QStringList )
4316 if ( value.toList().size() > 1 )
4317 return value.toList().at( 1 ).toString();
4320 QString valueString = value.toList().value( 0 ).toString();
4321 if ( valueString ==
"geometry-type"_L1 )
4323 return u
"_geom_type"_s;
4328 else if ( value.userType() == QMetaType::Type::QVariantList && value.toList().size() > 1 )
4335QString QgsMapBoxGlStyleConverter::processLabelField(
const QString &
string,
bool &isExpression )
4339 const thread_local QRegularExpression singleFieldRx( u
"^{([^}]+)}$"_s );
4340 const QRegularExpressionMatch match = singleFieldRx.match(
string );
4341 if ( match.hasMatch() )
4343 isExpression =
false;
4344 return match.captured( 1 );
4347 const thread_local QRegularExpression multiFieldRx( u
"(?={[^}]+})"_s );
4348 const QStringList parts =
string.split( multiFieldRx );
4349 if ( parts.size() > 1 )
4351 isExpression =
true;
4354 for (
const QString &part : parts )
4356 if ( part.isEmpty() )
4359 if ( !part.contains(
'{' ) )
4366 const QStringList split = part.split(
'}' );
4368 if ( !split.at( 1 ).isEmpty() )
4371 return u
"concat(%1)"_s.arg( res.join(
',' ) );
4375 isExpression =
false;
4382 return mRenderer ? mRenderer->
clone() :
nullptr;
4387 return mLabeling ? mLabeling->
clone() :
nullptr;
4397 return mRasterSubLayers;
4402 QList<QgsMapLayer *> subLayers;
4405 const QString sourceName = subLayer.source();
4406 std::unique_ptr< QgsRasterLayer > rl;
4413 rl->pipe()->setDataDefinedProperties( subLayer.dataDefinedProperties() );
4420 subLayers.append( rl.release() );
4429 std::unique_ptr< QgsMapBoxGlStyleConversionContext > tmpContext;
4432 tmpContext = std::make_unique< QgsMapBoxGlStyleConversionContext >();
4433 context = tmpContext.get();
4437 if (
string.compare(
"vector"_L1, Qt::CaseInsensitive ) == 0 )
4439 else if (
string.compare(
"raster"_L1, Qt::CaseInsensitive ) == 0 )
4441 else if (
string.compare(
"raster-dem"_L1, Qt::CaseInsensitive ) == 0 )
4443 else if (
string.compare(
"geojson"_L1, Qt::CaseInsensitive ) == 0 )
4445 else if (
string.compare(
"image"_L1, Qt::CaseInsensitive ) == 0 )
4447 else if (
string.compare(
"video"_L1, Qt::CaseInsensitive ) == 0 )
4449 context->
pushWarning( QObject::tr(
"Invalid source type \"%1\" for source \"%2\"" ).arg(
string, name ) );
4455 const QString name = it.key();
4456 const QVariantMap jsonSource = it.value().toMap();
4457 const QString typeString = jsonSource.value( u
"type"_s ).toString();
4480 std::unique_ptr< QgsMapBoxGlStyleConversionContext > tmpContext;
4483 tmpContext = std::make_unique< QgsMapBoxGlStyleConversionContext >();
4484 context = tmpContext.get();
4487 auto raster = std::make_unique< QgsMapBoxGlStyleRasterSource >( name );
4488 if ( raster->setFromJson( source, context ) )
4489 mSources.append( raster.release() );
4492bool QgsMapBoxGlStyleConverter::numericArgumentsOnly(
const QVariant &bottomVariant,
const QVariant &topVariant,
double &bottom,
double &top )
4494 if ( bottomVariant.canConvert( QMetaType::Double ) && topVariant.canConvert( QMetaType::Double ) )
4496 bool bDoubleOk, tDoubleOk;
4497 bottom = bottomVariant.toDouble( &bDoubleOk );
4498 top = topVariant.toDouble( &tDoubleOk );
4499 return ( bDoubleOk && tDoubleOk );
4510 mWarnings << warning;
4525 return mSizeConversionFactor;
4530 mSizeConversionFactor = sizeConversionFactor;
4535 return mSpriteImage.keys();
4540 return mSpriteImage.contains( category ) ? mSpriteImage[category] : QImage();
4545 return mSpriteDefinitions.contains( category ) ? mSpriteDefinitions[category] : QVariantMap();
4550 mSpriteImage[category] = image;
4551 mSpriteDefinitions[category] = definitions;
4598 mAttribution = json.value( u
"attribution"_s ).toString();
4600 const QString scheme = json.value( u
"scheme"_s, u
"xyz"_s ).toString();
4601 if ( scheme.compare(
"xyz"_L1 ) == 0 )
4607 context->
pushWarning( QObject::tr(
"%1 scheme is not supported for raster source %2" ).arg( scheme,
name() ) );
4611 mMinZoom = json.value( u
"minzoom"_s, u
"0"_s ).toInt();
4612 mMaxZoom = json.value( u
"maxzoom"_s, u
"22"_s ).toInt();
4613 mTileSize = json.value( u
"tileSize"_s, u
"512"_s ).toInt();
4615 const QVariantList
tiles = json.value( u
"tiles"_s ).toList();
4616 for (
const QVariant &tile :
tiles )
4618 mTiles.append( tile.toString() );
4627 parts.insert( u
"type"_s, u
"xyz"_s );
4628 parts.insert( u
"url"_s, mTiles.value( 0 ) );
4630 if ( mTileSize == 256 )
4631 parts.insert( u
"tilePixelRation"_s, u
"1"_s );
4632 else if ( mTileSize == 512 )
4633 parts.insert( u
"tilePixelRation"_s, u
"2"_s );
4635 parts.insert( u
"zmax"_s, QString::number( mMaxZoom ) );
4636 parts.insert( u
"zmin"_s, QString::number( mMinZoom ) );
4639 return rl.release();
@ BelowLine
Labels can be placed below a line feature. Unless MapOrientation is also specified this mode respects...
@ OnLine
Labels can be placed directly over a line feature.
@ AboveLine
Labels can be placed above a line feature. Unless MapOrientation is also specified this mode respects...
@ CentralPoint
Place symbols at the mid point of the line.
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ FollowPlacement
Alignment follows placement of label, e.g., labels to the left of a feature will be drawn with right ...
RenderUnit
Rendering size units.
MapBoxGlStyleSourceType
Available MapBox GL style source types.
@ RasterDem
Raster DEM source.
@ Unknown
Other/unknown source type.
@ Viewport
Relative to the whole viewport/output device.
@ AllowOverlapAtNoCost
Labels may freely overlap other labels, at no cost.
void setPenJoinStyle(Qt::PenJoinStyle style)
Sets the pen join style used to render the line (e.g.
void setPenCapStyle(Qt::PenCapStyle style)
Sets the pen cap style used to render the line (e.g.
static QgsFontManager * fontManager()
Returns the application font manager, which manages available fonts and font installation for the QGI...
A paint effect which blurs a source picture, using a number of different blur methods.
void setBlurUnit(const Qgis::RenderUnit unit)
Sets the units used for the blur level (radius).
@ StackBlur
Stack blur, a fast but low quality blur. Valid blur level values are between 0 - 16.
void setBlurMethod(const BlurMethod method)
Sets the blur method (algorithm) to use for performing the blur.
void setBlurLevel(const double level)
Sets blur level (radius).
A paint effect which consists of a stack of other chained paint effects.
void appendEffect(QgsPaintEffect *effect)
Appends an effect to the end of the stack.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
static QString quotedString(QString text)
Returns a quoted version of a string (in single quotes).
static QString createFieldEqualityExpression(const QString &fieldName, const QVariant &value, QMetaType::Type fieldType=QMetaType::Type::UnknownType)
Create an expression allowing to evaluate if a field is equal to a value.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes).
QString processFontFamilyName(const QString &name) const
Processes a font family name, applying any matching fontFamilyReplacements() to the name.
static QFont createFont(const QString &family, int pointSize=-1, int weight=-1, bool italic=false)
Creates a font with the specified family.
static bool fontFamilyHasStyle(const QString &family, const QString &style)
Check whether font family on system has specific style.
static QVariant parseJson(const std::string &jsonString)
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned and ...
void setPlacementFlags(Qgis::LabelLinePlacementFlags flags)
Returns the line placement flags, which dictate how line labels can be placed above or below the line...
void setFactor(double factor)
Sets the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels,...
Contains general settings related to how labels are placed.
void setOverlapHandling(Qgis::LabelOverlapHandling handling)
Sets the technique used to handle overlapping labels.
void setAllowDegradedPlacement(bool allow)
Sets whether labels can be placed in inferior fallback positions if they cannot otherwise be placed.
void setQuadrant(Qgis::LabelQuadrantPosition quadrant)
Sets the quadrant in which to offset labels from the point.
Contains settings related to how the label engine removes candidate label positions and reduces the n...
void setAllowDuplicateRemoval(bool allow)
Sets whether duplicate label removal is permitted for this layer.
void setMinimumDistanceToDuplicateUnit(Qgis::RenderUnit unit)
Sets the unit for the minimum distance to labels with duplicate text.
virtual void setWidth(double width)
Sets the width of the line symbol layer.
void setOffset(double offset)
Sets the line's offset.
void setOffsetUnit(Qgis::RenderUnit unit)
Sets the unit for the line's offset.
Abstract base class for MapBox GL style sources.
QString name() const
Returns the source's name.
virtual ~QgsMapBoxGlStyleAbstractSource()
QgsMapBoxGlStyleAbstractSource(const QString &name)
Constructor for QgsMapBoxGlStyleAbstractSource.
Context for a MapBox GL style conversion operation.
void setLayerId(const QString &value)
Sets the layer ID of the layer currently being converted.
QStringList warnings() const
Returns a list of warning messages generated during the conversion.
void pushWarning(const QString &warning)
Pushes a warning message generated during the conversion.
QImage spriteImage(const QString &category=QString()) const
Returns the sprite image for a given category to use during conversion, or an invalid image if this i...
double pixelSizeConversionFactor() const
Returns the pixel size conversion factor, used to scale the original pixel sizes when converting styl...
void setTargetUnit(Qgis::RenderUnit targetUnit)
Sets the target unit type.
void setSprites(const QImage &image, const QVariantMap &definitions, const QString &category=QString())
Sets the sprite image and definitions JSON for a given category to use during conversion.
void setPixelSizeConversionFactor(double sizeConversionFactor)
Sets the pixel size conversion factor, used to scale the original pixel sizes when converting styles.
QVariantMap spriteDefinitions(const QString &category=QString()) const
Returns the sprite definitions for a given category to use during conversion.
Qgis::RenderUnit targetUnit() const
Returns the target unit type.
QString layerId() const
Returns the layer ID of the layer currently being converted.
QStringList spriteCategories() const
Returns the list of sprite categories to use during conversion, or an empty list of none is set.
void clearWarnings()
Clears the list of warning messages.
static QgsProperty parseInterpolateByZoom(const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, double *defaultNumber=nullptr, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential)
Parses a numeric value which is interpolated by zoom range.
static QString parseColorExpression(const QVariant &colorExpression, QgsMapBoxGlStyleConversionContext &context)
Converts an expression representing a color to a string (can be color string or an expression where a...
QgsVectorTileRenderer * renderer() const
Returns a new instance of a vector tile renderer representing the converted style,...
static QString parseExpression(const QVariantList &expression, QgsMapBoxGlStyleConversionContext &context, bool colorExpected=false)
Converts a MapBox GL expression to a QGIS expression.
InterpolationType
Interpolation types, for interpolated value conversion.
@ Linear
Linear interpolation.
@ Exponential
Exponential interpolation.
@ CubicBezier
Cubic-bezier interpolation.
static QString parsePointStops(double base, const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential, double x1=0, double y1=0, double x2=0, double y2=0)
Takes values from stops and uses either scale_linear() or scale_exp() functions to interpolate point/...
PropertyType
Property types, for interpolated value conversion.
@ Point
Point/offset property.
@ DashArray
Dash array. Like numeric array, but must be even length array. Odd length arrays are considered as ha...
@ Numeric
Numeric property (e.g. line width, text size).
@ Opacity
Opacity property.
@ NumericArray
Numeric array for dash arrays or such.
QList< QgsMapBoxGlStyleAbstractSource * > sources()
Returns the list of converted sources.
QgsVectorTileLabeling * labeling() const
Returns a new instance of a vector tile labeling representing the converted style,...
QList< QgsMapBoxGlStyleRasterSubLayer > rasterSubLayers() const
Returns a list of raster sub layers contained in the style.
static Qt::PenJoinStyle parseJoinStyle(const QString &style)
Converts a value to Qt::PenJoinStyle enum from JSON value.
static QString interpolateExpression(double zoomMin, double zoomMax, QVariant valueMin, QVariant valueMax, double base, double multiplier=1, double x1=0, double y1=0, double x2=1, double y2=1, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential, QgsMapBoxGlStyleConversionContext *contextPtr=nullptr)
Generates an interpolation for values between valueMin and valueMax, scaled between the ranges zoomMi...
static QgsProperty parseInterpolateStringByZoom(const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, const QVariantMap &conversionMap, QString *defaultString=nullptr)
Interpolates a string by zoom.
static QgsProperty parseStepList(const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, int maxOpacity=255, QColor *defaultColor=nullptr, double *defaultNumber=nullptr)
Parses and converts a match function value list.
static bool parseCircleLayer(const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style, QgsMapBoxGlStyleConversionContext &context)
Parses a circle layer.
Result convert(const QVariantMap &style, QgsMapBoxGlStyleConversionContext *context=nullptr)
Converts a JSON style map, and returns the resultant status of the conversion.
static QgsProperty parseInterpolateListByZoom(const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, int maxOpacity=255, QColor *defaultColor=nullptr, double *defaultNumber=nullptr)
Interpolates a list which starts with the interpolate function.
~QgsMapBoxGlStyleConverter()
QList< QgsMapLayer * > createSubLayers() const
Returns a list of new map layers corresponding to sublayers of the style, e.g.
Result
Result of conversion.
@ Success
Conversion was successful.
@ NoLayerList
No layer list was found in JSON input.
QgsMapBoxGlStyleConverter()
Constructor for QgsMapBoxGlStyleConverter.
static QgsProperty parseInterpolateColorByZoom(const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, QColor *defaultColor=nullptr, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential)
Parses a color value which is interpolated by zoom range.
static QImage retrieveSprite(const QString &name, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize)
Retrieves the sprite image with the specified name, taken from the specified context.
static QString parseLabelStops(const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context)
Parses a list of interpolation stops containing label values.
void parseLayers(const QVariantList &layers, QgsMapBoxGlStyleConversionContext *context=nullptr)
Parse list of layers from JSON.
static QgsProperty parseInterpolateOpacityByZoom(const QVariantMap &json, int maxOpacity, QgsMapBoxGlStyleConversionContext *contextPtr=nullptr, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential)
Interpolates opacity with either scale_linear() or scale_exp() (depending on base value).
static QString retrieveSpriteAsBase64WithProperties(const QVariant &value, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize, QString &spriteProperty, QString &spriteSizeProperty)
Retrieves the sprite image with the specified name, taken from the specified context as a base64 enco...
void parseSources(const QVariantMap &sources, QgsMapBoxGlStyleConversionContext *context=nullptr)
Parse list of sources from JSON.
static QColor parseColor(const QVariant &color, QgsMapBoxGlStyleConversionContext &context)
Parses a color in one of these supported formats:
static bool parseSymbolLayerAsRenderer(const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &rendererStyle, QgsMapBoxGlStyleConversionContext &context)
Parses a symbol layer as a renderer.
static bool parseFillLayer(const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style, QgsMapBoxGlStyleConversionContext &context, bool isBackgroundStyle=false)
Parses a fill layer.
static void parseSymbolLayer(const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &rendererStyle, bool &hasRenderer, QgsVectorTileBasicLabelingStyle &labelingStyle, bool &hasLabeling, QgsMapBoxGlStyleConversionContext &context)
Parses a symbol layer as renderer or labeling.
static QString parseOpacityStops(double base, const QVariantList &stops, int maxOpacity, QgsMapBoxGlStyleConversionContext &context, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential, double x1=0, double y1=0, double x2=1, double y2=1)
Takes values from stops and uses either scale_linear() or scale_exp() functions to interpolate alpha ...
static bool parseLineLayer(const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style, QgsMapBoxGlStyleConversionContext &context)
Parses a line layer.
void parseRasterSource(const QVariantMap &source, const QString &name, QgsMapBoxGlStyleConversionContext *context=nullptr)
Parse a raster source from JSON.
static void colorAsHslaComponents(const QColor &color, int &hue, int &saturation, int &lightness, int &alpha)
Takes a QColor object and returns HSLA components in required format for QGIS color_hsla() expression...
static Qt::PenCapStyle parseCapStyle(const QString &style)
Converts a value to Qt::PenCapStyle enum from JSON value.
static QString parseStringStops(const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, const QVariantMap &conversionMap, QString *defaultString=nullptr)
Parses a list of interpolation stops containing string values.
static QgsProperty parseMatchList(const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, int maxOpacity=255, QColor *defaultColor=nullptr, double *defaultNumber=nullptr)
Parses and converts a match function value list.
static QString parseStops(double base, const QVariantList &stops, double multiplier, QgsMapBoxGlStyleConversionContext &context, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential, double x1=0, double y1=0, double x2=1, double y2=1)
Parses a list of interpolation stops.
static QgsProperty parseValueList(const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, int maxOpacity=255, QColor *defaultColor=nullptr, double *defaultNumber=nullptr)
Parses and converts a value list (e.g.
static QgsProperty parseInterpolatePointByZoom(const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, QPointF *defaultPoint=nullptr, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential)
Interpolates a point/offset with either scale_linear() or scale_exp() (depending on base value).
static QString parseArrayStops(const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier=1)
Takes numerical arrays from stops.
Encapsulates a MapBox GL style raster source.
Qgis::MapBoxGlStyleSourceType type() const override
Returns the source type.
QgsMapBoxGlStyleRasterSource(const QString &name)
Constructor for QgsMapBoxGlStyleRasterSource.
QgsRasterLayer * toRasterLayer() const
Returns a new raster layer representing the raster source, or nullptr if the source cannot be represe...
bool setFromJson(const QVariantMap &json, QgsMapBoxGlStyleConversionContext *context) override
Sets the source's state from a json map.
QStringList tiles() const
Returns the list of tile sources.
Encapsulates a MapBox GL style raster sub layer.
QString source() const
Returns the layer's source.
QString id() const
Returns the layer's ID.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the layer's data defined properties.
QgsMapBoxGlStyleRasterSubLayer(const QString &id, const QString &source)
Constructor for QgsMapBoxGlStyleRasterSubLayer, with the given id and source.
Line symbol layer type which draws repeating marker symbols along a line feature.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
virtual void setSize(double size)
Sets the symbol size.
void setOffsetUnit(Qgis::RenderUnit unit)
Sets the units for the symbol's offset.
void setAngle(double angle)
Sets the rotation angle for the marker.
void setOffset(QPointF offset)
Sets the marker's offset, which is the horizontal and vertical displacement which the rendered marker...
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units for the symbol's size.
A marker symbol type, for rendering Point and MultiPoint geometries.
void setEnabled(bool enabled)
Sets whether the effect is enabled.
Contains settings for how a map layer will be labeled.
double yOffset
Vertical offset of label.
const QgsLabelObstacleSettings & obstacleSettings() const
Returns the label obstacle settings.
const QgsLabelPlacementSettings & placementSettings() const
Returns the label placement settings.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
double xOffset
Horizontal offset of label.
Qgis::LabelPlacement placement
Label placement mode.
Qgis::LabelMultiLineAlignment multilineAlign
Horizontal alignment of multi-line labels.
int priority
Label priority.
double angleOffset
Label rotation, in degrees clockwise.
const QgsLabelThinningSettings & thinningSettings() const
Returns the label thinning settings.
void setThinningSettings(const QgsLabelThinningSettings &settings)
Sets the label thinning settings.
Qgis::RenderUnit offsetUnits
Units for offsets of label.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the label's property collection, used for data defined overrides.
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
void setPlacementSettings(const QgsLabelPlacementSettings &settings)
Sets the label placement settings.
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
double dist
Distance from feature to the label.
Qgis::RenderUnit distUnits
Units the distance from feature to the label.
@ LinePlacementOptions
Line placement flags.
@ LabelRotation
Label rotation.
@ FontStyle
Font style name.
@ RemoveDuplicateLabelDistance
Minimum distance from labels for this feature to other labels with duplicate text.
@ FontLetterSpacing
Letter spacing.
QString fieldName
Name of field (or an expression) to use for label text.
int autoWrapLength
If non-zero, indicates that label text should be automatically wrapped to (ideally) the specified num...
const QgsLabelPointSettings & pointSettings() const
Returns the label point settings, which contain settings related to how the label engine places and f...
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const final
Returns the calculated value of the property with the specified key from within the collection.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
A store for object properties.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
QString expressionString() const
Returns the expression used for the property value.
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
void setExpressionString(const QString &expression)
Sets the expression to use for the property value.
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
void setActive(bool active)
Sets whether the property is currently active.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
A fill symbol layer which fills polygons with a repeated raster image.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the unit for the image's width and height.
void setOpacity(double opacity)
Sets the opacity for the raster image used in the fill.
void setImageFilePath(const QString &imagePath)
Sets the path to the raster image used for the fill.
void setWidth(double width)
Sets the width for scaling the image used in the fill.
void setCoordinateMode(Qgis::SymbolCoordinateReference mode)
Set the coordinate mode for fill.
Represents a raster layer.
Line symbol layer type which draws line sections using a raster image file.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Raster marker symbol layer class.
void setOpacity(double opacity)
Set the marker opacity.
void setPath(const QString &path)
Set the marker raster image path.
@ RendererOpacity
Raster renderer global opacity.
Renders polygons using a single fill and stroke color.
void setBrushStyle(Qt::BrushStyle style)
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void setStrokeWidth(double strokeWidth)
void setStrokeStyle(Qt::PenStyle strokeStyle)
void setOffsetUnit(Qgis::RenderUnit unit)
Sets the unit for the fill's offset.
void setFillColor(const QColor &color) override
Sets the fill color for the symbol layer.
void setOffset(QPointF offset)
Sets an offset by which polygons will be translated during rendering.
void setStrokeColor(const QColor &strokeColor) override
Sets the stroke color for the symbol layer.
A simple line symbol layer, which renders lines using a line in a variety of styles (e....
void setPenCapStyle(Qt::PenCapStyle style)
Sets the pen cap style used to render the line (e.g.
void setUseCustomDashPattern(bool b)
Sets whether the line uses a custom dash pattern.
void setCustomDashVector(const QVector< qreal > &vector)
Sets the custom dash vector, which is the pattern of alternating drawn/skipped lengths used while ren...
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void setPenJoinStyle(Qt::PenJoinStyle style)
Sets the pen join style used to render the line (e.g.
Simple marker symbol layer, consisting of a rendered shape with solid fill color and a stroke.
void setFillColor(const QColor &color) override
Sets the fill color for the symbol layer.
void setStrokeWidthUnit(Qgis::RenderUnit u)
Sets the unit for the width of the marker's stroke.
void setStrokeWidth(double w)
Sets the width of the marker's stroke.
void setStrokeColor(const QColor &color) override
Sets the marker's stroke color.
static QColor parseColor(const QString &colorStr, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes,...
@ File
Filename, eg for svg files.
@ CustomDash
Custom dash pattern.
@ Name
Name, eg shape name for simple markers.
@ StrokeColor
Stroke color.
@ Interval
Line marker interval.
@ StrokeWidth
Stroke width.
@ LayerEnabled
Whether symbol layer is enabled.
virtual void setColor(const QColor &color)
Sets the "representative" color for the symbol layer.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the symbol layer's property collection, used for data defined overrides.
void setPlacements(Qgis::MarkerLinePlacements placements)
Sets the placement of the symbols.
Container for settings relating to a text background object.
void setMarkerSymbol(QgsMarkerSymbol *symbol)
Sets the current marker symbol for the background shape.
void setSizeType(SizeType type)
Sets the method used to determine the size of the background shape (e.g., fixed size or buffer around...
@ ShapeMarkerSymbol
Marker symbol.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units used for the shape's size.
void setType(ShapeType type)
Sets the type of background shape to draw (e.g., square, ellipse, SVG).
void setEnabled(bool enabled)
Sets whether the text background will be drawn.
void setSize(QSizeF size)
Sets the size of the background shape.
void setColor(const QColor &color)
Sets the color for the buffer.
void setOpacity(double opacity)
Sets the buffer opacity.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units used for the buffer size.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the buffer.
void setSize(double size)
Sets the size of the buffer.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setSize(double size)
Sets the size for rendered text.
void setFont(const QFont &font)
Sets the font used for rendering text.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units for the size of rendered text.
void setBackground(const QgsTextBackgroundSettings &backgroundSettings)
Sets the text's background settings.q.
void setNamedStyle(const QString &style)
Sets the named style for the font used for rendering text.
QFont font() const
Returns the font used for rendering text.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
Configuration of a single style within QgsVectorTileBasicLabeling.
void setLayerName(const QString &name)
Sets name of the sub-layer to render (empty layer means that all layers match).
void setMinZoomLevel(int minZoom)
Sets minimum zoom level index (negative number means no limit).
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match).
void setMaxZoomLevel(int maxZoom)
Sets maximum zoom level index (negative number means no limit).
void setStyleName(const QString &name)
Sets human readable name of this style.
void setGeometryType(Qgis::GeometryType geomType)
Sets type of the geometry that will be used (point / line / polygon).
void setLabelSettings(const QgsPalLayerSettings &settings)
Sets labeling configuration of this style.
void setEnabled(bool enabled)
Sets whether this style is enabled (used for rendering).
Definition of map rendering of a subset of vector tile data.
void setEnabled(bool enabled)
Sets whether this style is enabled (used for rendering).
void setMinZoomLevel(int minZoom)
Sets minimum zoom level index (negative number means no limit).
void setLayerName(const QString &name)
Sets name of the sub-layer to render (empty layer means that all layers match).
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match).
void setSymbol(QgsSymbol *sym)
Sets symbol for rendering. Takes ownership of the symbol.
void setStyleName(const QString &name)
Sets human readable name of this style.
void setMaxZoomLevel(int maxZoom)
Sets maximum zoom level index (negative number means no limit).
void setGeometryType(Qgis::GeometryType geomType)
Sets type of the geometry that will be used (point / line / polygon).
Base class for labeling configuration classes for vector tile layers.
virtual QgsVectorTileLabeling * clone() const =0SIP_FACTORY
Returns a new copy of the object.
Abstract base class for all vector tile renderer implementations.
virtual QgsVectorTileRenderer * clone() const =0
Returns a clone of the renderer.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
#define QgsDebugError(str)
QList< QgsSymbolLayer * > QgsSymbolLayerList