[OpenMap Users] Potential bug in Location.java when decluttering

From: Stéphane Wasserhardt <swasserhardt_at_cls.fr>
Date: Mon, 03 Apr 2006 17:37:48 +0200
Hi again !

In com.bbn.openmap.layer.location.Location.declutterLabel :
When the label has to be decluttered, the following code is used :

// Get the bounds of the label to declutter
Rectangle bounds = label.getPolyBounds().getBounds();
int height = (int) ((float) (bounds.getHeight() - currentFontDescent / 2));
int width = (int) bounds.getWidth();

Point p =
label.getMapLocation();

int limit;
// [...] Compute limit

// Find a position for the label
Point newpoint = declutter.setNextOpen(p, width, height, limit);


But if you look carefully at the DeclutterMatrix code, you'll see that it naturally uses AWT coordinate system :
it considers the origin to be the upper-left corner.
When you use "label.getMapLocation()", you retrieve the lower-left corner of the label.
In order to use the DeclutterMatrix properly, you should use the upper-left corner ! (available via "bounds.getLocation()").
Since we usually draw labels having all the same height, there is no visible problem. But when you have labels with different heights (or when you use the same DeclutterMatrix for other things than labels), decluttering bugs may appear !

I must tell that I didn't found this using the LocationLayer, but using my own layer. My layer uses a copy of the Location's declutterLabel() method declutter its labels, but accepts more complex OMGraphics as labels. Then I saw that decluttering didn't work properly... That's how I found the bug, but I didn't really test if it happens on the Location layer... So maybe the Location's code is fine and I'm missing something!

Stephane -- [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 Apr 03 2006 - 11:38:55 EDT

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