Re: [OpenMap Users] Finding the center (xy) of a OMText?

From: Don Dietrick <dfdietrick_at_gmail.com>
Date: Fri, 28 Oct 2011 17:31:27 -0400

Hi Carsten,

Are you using center justification for the label? If you draw the poly
bounds (I think it shows if matting is turned on), do the bounds look right,
even for one character?

I thought polybounds took font and size into account, but now that you
mention it, I'm not sure if I've looked at it with one character, which
seems to be quite pertinent to you.

- Don

On Thu, Oct 27, 2011 at 10:01 AM, "Carsten Ø. Madsen" <com_at_navicon.dk>wrote:

> Hello
>
> I'm trying to implement clustering of locations a'la google maps marker
> clustering. But I'm having difficulties finding the exact center (xy) of the
> OMText which represents the clustering count. This causes a slight
> misalignment of the icons sitting behind the count.
>
> Here is my code from generate:
>
> label.generate(proj);
> label.prepareForRender(g);
> if (label.getPolyBounds() != null) {
> Rectangle rect = label.getPolyBounds().getBounds();
> rh = (int) ((float) (bounds.getHeight() - currentFontDescent /
> 2));
> rw = (int) rect.getWidth();
> int width = raster.getImage().getWidth(null);
> int height = raster.getImage().getHeight(null);
> raster.setRenderType(OMGraphicConstants.RENDERTYPE_XY);
> double cX = label.getMapLocation().getX() + rw / 2;
> double cY = label.getMapLocation().getY() + currentFontDescent
> / 2;
> raster.setX((int) (cX - width / 2));
> raster.setY((int) (cY - height / 2));
>
> I tried with getCenterX/Y on getPolyBounds but the result varies with the
> font size and length of the string being rendered. It seems to work best
> with string length > 1.
>
> I would like to use
>
> FontMetrics metrics = g.getFontMetrics();
> Rectangle2D rect = metrics.getStringBounds(text, g);
>
> but I guess this does not work with OMText and the way it does text
> rendering.
>
> Any hints?
>
> Thanks
> Carsten
>
>



--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]

gfdcdhdg.png
(image/png attachment: gfdcdhdg.png)

Received on Fri Oct 28 2011 - 17:34:34 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:10 EDT