Select to view content in your preferred language

Check if user clicked on graphic

565
1
08-06-2013 12:40 AM
ThomasBinu
Deactivated User
Hi guys,

I need some advice from you on the best practices of using the android API. I have 3 graphic layers and 2 feature layer in my application. Now when the user taps on a graphic in the map, I want to display a callout with relevant details. Going through the ESRI api, there is a function called graphicsLayer.getGraphicIDS(x,y,tolerance) which can give me the graphic, but problem is I have no way on knowing which layer, the graphic belongs to. Now I am doing somthing like this.

map.setOnSingleTapListenere( new onSingleTapListener(pointX,pointY){

if((graphicsLayer1.getGraphicIDs(x,y,tolerance)).length==0){
// inflate callout and show
}else if((graphicsLayer2.getGraphicIDs(x,y,tolerance)).length==0){
// inflate callout and show
}else if((graphicsLayer3.getGraphicIDs(x,y,tolerance)).length==0){
// inflate callout and show
}else  if((featurelayer1.getGraphicIDs(x,y,tolerance)).length==0){
// inflate callout and show
}else  if((featurelayer2.getGraphicIDs(x,y,tolerance)).length==0){
// inflate callout and show
}

});

Is this the best way to handle this situation?Seems like a lot of work for a seemily basic map operation so I feel I am doing something wrong. Please advice.
0 Kudos
1 Reply
AndyGup
Esri Regular Contributor
Thomas,

I think you are very close to the answer. Yes, getGraphicIDs(x,y,tolerance) is the best way to retrieve graphics locally based on an OnSingleTapEvent. The only alternative is you would have make one or multiple round-trip requests to ArcGIS Server depending on how many services you needed to Query.

1) Taking your example, you could create  an Array of all graphics returned and display them in a ListView.

Within your array just make sure to store which layer the info came from such as featureLayer1, graphicsLayer1, etc along with the attributes of the Graphic. This helps you deal with the use case of having multiple graphics returned. It also allows the user to decide which graphic was the one they wanted to view.

2) You could allow the user to toggle layers on/off so that the search is narrowed down to one layer at a time. When working with multiple feature layers this is one of the most common approaches.

-Andy
0 Kudos