Increase FeatureLayer click tolerance

1496
6
10-24-2016 06:59 AM
JustinGreco
Occasional Contributor

Is there any way to increase the click tolerance for point features in a FeatureLayer?  It can take 4 or 5 times to get a popup to appear.  I believe there was a way in the 3.x version.

6 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Justin,

   There was not a way to do this in 3.x either.

0 Kudos
JustinGreco
Occasional Contributor

Not officially, but there was actually was a way to increase it.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

I would love to see that if there was.

0 Kudos
JustinGreco
Occasional Contributor

Not sure where I had seen this for 3.x, been a while since I have used the API since I went with Leaflet for a while.  Anyways, it would be great if the tolerance could be increased, its way to low for tapping on points on touch devices.  Ended up finding a workaround though.

0 Kudos
JoelBennett
Occasional Contributor II

In 3.x, you can do this by overriding the "_calculateClickTolerance" function of the map's popupManager property. For example:

map.popupManager._calculateClickTolerance = function(graphicsLayers) {
    return 10;
};

That is a very simplistic example, but you could implement whatever logic you want inside that function as long as you return an integer (preferably non-negative).

The "graphicsLayers" parameter is an array of GraphicsLayer instances (this includes classes that inherit GraphicsLayer, like FeatureLayer). The returned value is the tolerance in pixels.

The default implementation basically does this: for each SimpleRenderer, ClassBreaksRenderer, or UniqueValuesRenderer found in the input GraphicsLayer array, it looks at each symbol in the renderer and finds the one with the greatest offset value (this includes "xoffset" and "yoffset" values). If the greatest offset it finds is greater than 6, it returns that. Otherwise, it returns 6 by default.

0 Kudos
PeteVitt
Occasional Contributor II

I agree, this would be very useful -- it can take 4 + clicks to get the pop-up to appear for points on mobile devices

0 Kudos