undocumented hit testing behavior on 10.2

1517
1
12-13-2013 02:17 PM
DanaMaher
Occasional Contributor
As requested in the 10.2 sticky thread, I am posting a test harness (see attached .zip) that shows undocumented hit testing behavior changes in 10.2. The test harness creates a basic map with one AGSTiledMapServiceLayer and one AGSGraphicsLayer. The AGSGraphicsLayer contains a single rectangular test graphic that is initially symbolized/filled with the default system color [UIColor redColor] and an alpha value of 1.0. A segmented control is provided that will toggle the alpha value to several values falling between 1.0 and 0.0, and some simple hit testing feedback is provided via on-screen labels, the presentation of a callout, and NSLog statements.

In using this test harness with 10.2, I see the following behavior:

  • Case of alpha = 1.0 OR 0.01 : Hits detected on perimeter and interior of test graphic.

  • Case of alpha = 0.0001 OR 0.0 : Hits detected on perimeter but not on interior of test graphic.


So, it appears that at some value approaching 0.0, the SDK decides that the alpha is effectively 0.0 and also starts passing hits through without assigning them to the graphic. Also, even at very low alpha values that still intercept touches, the fill is very slightly visible. I would like to be able to use a truly transparent fill (and outline, actually) and still catch interior taps.

Prior to 10.2, invisible areas of graphics caught hits and tehcnobrat's comment from the 10.2 sticky thread indicates this is unexpected behavior:
[INDENT]"We haven't changed the hit-testing mechanism to ignore transparent fills. I am unable to reproduce the behavior you described.
Could you please start a new thread and provide some code to repro?"[/INDENT]


Ideally, it seems like developers should be able to set a flag causing hit testing to either use or ignore the alpha value. On the project that led me to report this behavior, I would really like "invisible" graphics to still catch touches because they are sitting over a tiled map service that gives the user a really good idea of where they would like to tap and looks a lot better than a collection of visible graphics. However, I can see myself wanting the opposite behavior for a different use case involving city boundaries or the like.

Thanks, and apologies for the belated response; I've been swamped at work and am trying to maintain some semblance of work-life balance 😛
0 Kudos
1 Reply
NimeshJarecha
Esri Regular Contributor
Hi Dana,

Thanks for providing reproducible case. The problem is, you are creating graphic with envelope. If you create, graphic with polygon everything will work.

        NSMutableDictionary *atts = [[NSMutableDictionary alloc] init];
        AGSSimpleFillSymbol *symbol = [self fillSymbolForOpacity:_currentFillOpacity];
        //AGSEnvelope *testPoly = [[AGSEnvelope alloc] initWithXmin:-13701208.361324 ymin:5471547.949196 xmax:-13699472.062330 ymax:5473284.248190 spatialReference:_mapView.spatialReference];
        AGSMutablePolygon *polygon = [[AGSMutablePolygon alloc] initWithSpatialReference:_mapView.spatialReference];
        [polygon addRingToPolygon];
        [polygon addPointToRing:[AGSPoint pointWithX:-13701208.361324 y:5471547.949196 spatialReference:nil]];
        [polygon addPointToRing:[AGSPoint pointWithX:-13701208.361324 y:5473284.248190 spatialReference:nil]];
        [polygon addPointToRing:[AGSPoint pointWithX:-13699472.062330 y:5473284.248190 spatialReference:nil]];
        [polygon addPointToRing:[AGSPoint pointWithX:-13699472.062330 y:5471547.949196 spatialReference:nil]];
       
        _testGraphic = [[AGSGraphic alloc] initWithGeometry:polygon symbol:symbol attributes:atts];
        [_gLayer addGraphic:_testGraphic];

We'll see if if we can fix the hit test issue with envelope geometry.

Regards,
Nimesh
0 Kudos