Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid ugly super-narrow annotation balloon callout lines at some angles
  • Loading branch information
nyalldawson committed Apr 30, 2019
1 parent 67271cf commit 43b8a7a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/core/annotations/qgsannotation.cpp
Expand Up @@ -215,7 +215,24 @@ void QgsAnnotation::updateBalloon()
QLineF currentSegment = segmentList.at( i );
QgsPointXY currentMinDistPoint;
double currentMinDist = origin.sqrDistToSegment( currentSegment.x1(), currentSegment.y1(), currentSegment.x2(), currentSegment.y2(), currentMinDistPoint );
if ( currentMinDist < minEdgeDist )
bool isPreferredSegment = false;
if ( qgsDoubleNear( currentMinDist, minEdgeDist ) )
{
// two segments are close - work out which looks nicer
const double angle = fmod( origin.azimuth( currentMinDistPoint ) + 360.0, 360.0 );
if ( angle < 45 || angle > 315 )
isPreferredSegment = i == 0;
else if ( angle < 135 )
isPreferredSegment = i == 3;
else if ( angle < 225 )
isPreferredSegment = i == 2;
else
isPreferredSegment = i == 1;
}
else if ( currentMinDist < minEdgeDist )
isPreferredSegment = true;

if ( isPreferredSegment )
{
minEdgeIndex = i;
minEdgePoint = currentMinDistPoint;
Expand Down

0 comments on commit 43b8a7a

Please sign in to comment.