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

From: Don Dietrick <dfdietrick_at_gmail.com>
Date: Mon, 31 Oct 2011 20:42:25 -0400

Hi Carsten,

Sorry for taking so long getting back to you, I've lost
power at my house so I'm typing this on my phone.

If you don't have a declutter matrix in your application it
shouldn't be affecting the position of the location objects.
The Location objects and text would stay where you placed
them. It looks like Java puts one-letter strings with center-justification
at the same place as left-justification. Seems like prepareForRender should
test for the boundary edge and slide the text placement over to the left
as necessary. It would be interesting to see if all odd-number length strings
are one half letter too much to the right, and if font choice plays a role in
this behavior.

-- Don

On Oct 29, 2011, at 10:56 AM, "Carsten Ø. Madsen" <com_at_navicon.dk> wrote:

> Hi Don
>
> I got bitten by the fact that my location cluster is a BasicLocation which is implies that the OMText is decluttered so I had to do:
>
> _at_Override
> public boolean generate(Projection proj, DeclutterMatrix declutterMatrix) {
> return generate(proj);
> }
>
> In the picture below the magenta rects are the center(s) of my calculation. It seems nearly correct for two digits but not for single digits.
>
> int height = g.getFontMetrics().getAscent();
> Rectangle2D strBounds = fm.getStringBounds(label.getData(), g);
> double cX = label.getMapLocation().getX()
> + strBounds.getWidth() / 2;
> double cY = label.getMapLocation().getY() + ((height / 2) - 2);
> int w = 4;
> int h = 4;
> rec.setLocation((int) cX - w / 2, (int) cY - h / 2, (int) cX
> + w / 2, (int) cY + h / 2);
> rec.setVisible(clustered);
> setLocationMarker(rec);
>
> Is there anything else in Location/BasicLocation that alters the position of the OMText during generate?
> <cehedgfc.png>
> BR
> Carsten
>
> On 10/28/2011 11:31 PM, Don Dietrick wrote:
>>
>> 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
>> <mime-attachment.png>
>>


--
[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 Mon Oct 31 2011 - 20:44:25 EDT

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