Skip to content
Permalink
Browse files

When editing vector tile symbols, correctly populate the @zoom_level

variable to match the current canvas zoom level

Makes it easier to write and debug data defined expressions based
on zoom level.
  • Loading branch information
nyalldawson committed Sep 9, 2020
1 parent 92c3a88 commit 5df98cfb67ca7db0cf009fa51e4dcadf195f4b9a
@@ -396,6 +396,16 @@ void QgsVectorTileBasicLabelingWidget::editStyleAtIndex( const QModelIndex &prox
context.setMapCanvas( mMapCanvas );
context.setMessageBar( mMessageBar );

if ( mMapCanvas )
{
const int zoom = QgsVectorTileUtils::scaleToZoomLevel( mMapCanvas->scale(), 0, 99 );
QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
QgsExpressionContextScope tileScope;
tileScope.setVariable( "zoom_level", zoom, true );
scopes << tileScope;
context.setAdditionalExpressionContextScopes( scopes );
}

QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?

QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
@@ -410,6 +410,16 @@ void QgsVectorTileBasicRendererWidget::editStyleAtIndex( const QModelIndex &prox
context.setMapCanvas( mMapCanvas );
context.setMessageBar( mMessageBar );

if ( mMapCanvas )
{
const int zoom = QgsVectorTileUtils::scaleToZoomLevel( mMapCanvas->scale(), 0, 99 );
QList<QgsExpressionContextScope> scopes = context.additionalExpressionContextScopes();
QgsExpressionContextScope tileScope;
tileScope.setVariable( "zoom_level", zoom, true );
scopes << tileScope;
context.setAdditionalExpressionContextScopes( scopes );
}

QgsVectorLayer *vectorLayer = nullptr; // TODO: have a temporary vector layer with sub-layer's fields?

QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );

0 comments on commit 5df98cf

Please sign in to comment.
You can’t perform that action at this time.