Skip to content
Permalink
Browse files

Possible fix for placement of labels with offset from point mode and …

…rotation (refs #12217)
  • Loading branch information
nyalldawson committed Mar 18, 2015
1 parent 9961095 commit fe2db5261cdc6dcbe25872fc13c7bf3eed190487
Showing with 17 additions and 37 deletions.
  1. +17 −37 src/core/pal/feature.cpp
@@ -332,20 +332,26 @@ namespace pal
*lPos = new LabelPosition *[nbp];

// get from feature
double label_x = f->label_x;
double label_y = f->label_y;
double labelW = f->label_x;
double labelH = f->label_y;

double xdiff = 0.0;
double ydiff = 0.0;
double lx = 0.0;
double ly = 0.0;
double cost = 0.0001;
int id = 0;

xdiff -= label_x / 2.0;
ydiff -= label_y / 2.0;
double xdiff = -labelW / 2.0;
double ydiff = -labelH / 2.0;

if ( f->quadOffset )
{
if ( f->quadOffsetX != 0 )
{
xdiff += labelW / 2.0 * f->quadOffsetX;
}
if ( f->quadOffsetY != 0 )
{
ydiff += labelH / 2.0 * f->quadOffsetY;
}
}

if ( ! f->fixedPosition() )
{
@@ -358,32 +364,6 @@ namespace pal
}
}

if ( angle != 0 )
{
// use LabelPosition construction to calculate new rotated label dimensions
pal::LabelPosition* lp = new LabelPosition( 1, lx, ly, label_x, label_y, angle, 0.0, this );

double amin[2], amax[2];
lp->getBoundingBox( amin, amax );
labelW = amax[0] - amin[0];
labelH = amax[1] - amin[1];

delete lp;
}

LabelPosition::Quadrant quadrant = f->quadOffset ? quadrantFromOffset() : LabelPosition::QuadrantOver;
if ( f->quadOffset )
{
if ( f->quadOffsetX != 0 )
{
xdiff += labelW / 2 * f->quadOffsetX;
}
if ( f->quadOffsetY != 0 )
{
ydiff += labelH / 2 * f->quadOffsetY;
}
}

if ( f->offsetPos )
{
if ( f->offsetPosX != 0 )
@@ -396,10 +376,10 @@ namespace pal
}
}

lx = x + xdiff;
ly = y + ydiff;
double lx = x + xdiff;
double ly = y + ydiff;

( *lPos )[0] = new LabelPosition( id, lx, ly, label_x, label_y, angle, cost, this, false, quadrant );
( *lPos )[0] = new LabelPosition( id, lx, ly, labelW, labelH, angle, cost, this );
return nbp;
}

0 comments on commit fe2db52

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