Skip to content

Commit e42bd87

Browse files
committed
[labeling] Fix data defined placement with rotated maps
For layers requiring reprojection and with rotated maps any labels with data defined x/y would not be rendered Fix #14236 (cherry-picked from d36fb61)
1 parent 23a0984 commit e42bd87

File tree

1 file changed

+7
-28
lines changed

1 file changed

+7
-28
lines changed

src/core/qgspallabeling.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,35 +2803,14 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
28032803
ydiff = yd;
28042804
}
28052805

2806-
//project xPos and yPos from layer to map CRS
2807-
double z = 0;
2808-
if ( ct )
2806+
//project xPos and yPos from layer to map CRS, handle rotation
2807+
QgsGeometry ddPoint( new QgsPointV2( xPos, yPos ) );
2808+
if ( QgsPalLabeling::geometryRequiresPreparation( &ddPoint, context, ct ) )
28092809
{
2810-
try
2811-
{
2812-
ct->transformInPlace( xPos, yPos, z );
2813-
}
2814-
catch ( QgsCsException &e )
2815-
{
2816-
Q_UNUSED( e );
2817-
QgsDebugMsgLevel( QString( "Ignoring feature %1 due transformation exception on data-defined position" ).arg( f.id() ), 4 );
2818-
return;
2819-
}
2820-
}
2821-
2822-
//rotate position with map if data-defined
2823-
if ( dataDefinedPosition && m2p.mapRotation() )
2824-
{
2825-
const QgsPoint& center = context.extent().center();
2826-
QTransform t = QTransform::fromTranslate( center.x(), center.y() );
2827-
t.rotate( -m2p.mapRotation() );
2828-
t.translate( -center.x(), -center.y() );
2829-
qreal xPosR, yPosR;
2830-
qreal xPos_qreal = xPos, yPos_qreal = yPos;
2831-
t.map( xPos_qreal, yPos_qreal, &xPosR, &yPosR );
2832-
xPos = xPosR;
2833-
yPos = yPosR;
2834-
2810+
QgsGeometry* newPoint = QgsPalLabeling::prepareGeometry( &ddPoint, context, ct );
2811+
xPos = static_cast< QgsPointV2* >( newPoint->geometry() )->x();
2812+
yPos = static_cast< QgsPointV2* >( newPoint->geometry() )->y();
2813+
delete newPoint;
28352814
}
28362815

28372816
xPos += xdiff;

0 commit comments

Comments
 (0)