How do you set the pixel tolerance on a hitTestOverlay

2934
4
Jump to solution
10-01-2015 02:24 PM
JerrySchultz
New Contributor III

I want to change the pixel tolerance on the HitTestOverlay for a graphics layer containing TextSymbols. There is a reference to this in one of the graphics layer HitTestOverlay discussions but I have been unable to find a method or property where I can increase the number of pixels so that if the user gets pretty close it will select the textsymbol that they are trying to select.

0 Kudos
1 Solution

Accepted Solutions
ColinAnderson2
New Contributor

This isn't available in the overlay but the source is available for the toolkit so you could to modify the hit test overlay to do what you want. In HitTestOverlay.java modify the following lines in public void onMouseClicked(MouseEvent event)

int[] _hitGraphicsIDs = hitLayer.getGraphicIDs(event.getX(), event.getY(), 0);

long[] _hitGraphicsIDs = hitLayer.getFeatureIDs(event.getX(), event.getY(), 0);

the last argument is the tolerance in pixels. It sounds like you would probably be better add a property on the overlay so that you can set the tolerance from your application code.

View solution in original post

0 Kudos
4 Replies
JeremieJoalland
New Contributor II

You should try this :

public final static int TOLERANCE_PIXEL = 5;

...

public void onMouseClicked(final MouseEvent event) {

...

     final int[] hitGraphicsIDs = myGraphicLayer.getGraphicIDs(event.getX(), event.getY(), TOLERANCE_PIXEL);

where TOLERANCE_PIXEL is your tolerance, in my exemple = 5.

you have code sample in argcis toolkit for the Selection Overlay.

0 Kudos
JerrySchultz
New Contributor III

Thanks Jeremie, I did implement this as a mouselistener but decided against it as I wanted to have HitTestOverlays for several GraphicLayers not just one. Adding mutilple HitTestOverlays to the map, one for each graphicslayer works but I am not able to set the tolerance on the HitTestOverlay. The mouse has to be very close to the attachment point in order to pick it up. If anyone knows how to set the tolerance on the HitTestOverlay please let me know.

0 Kudos
JeremieJoalland
New Contributor II

Could you provide some code sample of what you are trying to do ?

because in my project we have selection tool base on a single HitTestOverlay for several GraphicLayers with different kind of graphics (Point, Polyline, Polygon) and it's working fine.

0 Kudos
ColinAnderson2
New Contributor

This isn't available in the overlay but the source is available for the toolkit so you could to modify the hit test overlay to do what you want. In HitTestOverlay.java modify the following lines in public void onMouseClicked(MouseEvent event)

int[] _hitGraphicsIDs = hitLayer.getGraphicIDs(event.getX(), event.getY(), 0);

long[] _hitGraphicsIDs = hitLayer.getFeatureIDs(event.getX(), event.getY(), 0);

the last argument is the tolerance in pixels. It sounds like you would probably be better add a property on the overlay so that you can set the tolerance from your application code.

0 Kudos