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

From: Carsten Ø. Madsen <com_at_navicon.dk>
Date: Thu, 27 Oct 2011 16:01:57 +0200

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"]
Received on Thu Oct 27 2011 - 10:04:36 EDT

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