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