Re: Centreing and Rotating Text

From: Paul Chisholm <paulch@bigpond.com>
Date: Tue Oct 23 2001 - 19:09:15 EDT

HI Don,

thanks for the info. I have looked at it a bit further and I think there may
be a small defect in the OMText class. You say the rotation point is the
defined lat/lon point. Below is a snippet from the 'render' method:

 if (g instanceof Graphics2D && rotationAngle != DEFAULT_ROTATIONANGLE) {
     computeBounds();
     Rectangle rect = polyBounds.getBounds();

     rx = rect.getX();
     ry = rect.getY();
     rw = rect.getWidth();
     rh = rect.getHeight();
     woffset = 0.0;

     ....some code to set woffset....

     //rotate about our text anchor point
     ((Graphics2D)g).rotate(rotationAngle, rx+woffset, ry);
 }

Note in the call to 'rotate' the y point is 'ry' where 'ry' is set to the y
co-ordinate of the bounding box. Looking at the javadoc page for class
Recangle it states

"A Rectangle specifies an area in a coordinate space that is enclosed by the
Rectangle object's top-left point (x, y) in the coordinate space, its width,
and its height."

So OMText is based on the bottom of the bounding box while Rectangle is
based on the top. This would explain why my testing suggested rotation was
taking place about the top of the text. I subclassed OMText providing an
alternate 'render' method that sets 'ry' to the bottom of the bounding box
and got a satisfactory result.

Paul

----- Original Message -----
From: "Donald Dietrick" <dietrick@bbn.com>
To: "Paul Chisholm" <paulch@bigpond.com>
Cc: <openmap-users@bbn.com>
Sent: Tuesday, October 23, 2001 9:51 PM
Subject: Re: Centreing and Rotating Text

Hi Paul,

The rotation point is the defined lat/lon point, so if you want to
control where your text is relative to that point, you can use a offset
render type, where you give a pixel offset as well as the lat/lon
point. I don't think you'd have to give a horizontal offset if you
choose center justification, but you might have to supply a vertical
offset to put the center of the text on the lat/lon point. You also may
have to create the OMText object, generate it to figure out how tall it
is (pixelwise), and then reset the vertical offset and regenerate().
You should only have to do that once, though.

Cheers,

Don

On Monday, October 22, 2001, at 11:05 PM, Paul Chisholm wrote:

> I am struggling a bit with a problem. I want to place a piece of text
> in a layer with the text centred on a point. That is the centre of the
> text, not the mid-point of the baseline. I then want to rotate the text
> about the centre point.
>
> I have tried some things but cant seem to come up with an acceptable
> solution. The point I want to centre the text on is expressed as a
> Lat/Long.
>
> From my testing it seems the text is rotated about the top of the text.
>
> Paul
>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Donald Dietrick, dietrick@bbn.com
BBN Technologies, Cambridge, MA
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
[To unsubscribe to this list send an email to "majdart@bbn.com"
with the following text in the BODY of the message "unsubscribe
openmap-users"]
--
[To unsubscribe to this list send an email to "majdart@bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Tue Oct 23 19:11:10 2001

This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:32 EDT