Select to view content in your preferred language

InfoTemplate doesn't work when tapped on Graphic

1864
5
12-27-2011 01:21 PM
SwatiGadey
Emerging Contributor
When I tap on any graphic, it's InfoTemplate doesn't show up. Following is the snippet of code showing how I am creating the Graphic and setting it's parameters.

     /*
      * Here, I am getting the results from the QueryTask (in FeatureSet queryResult)
      */
     Graphic graphics[] = queryResult.getGraphics();
     Symbol symbol = new PictureMarkerSymbol(getResources()
      .getDrawable(R.drawable.xyz));
     InfoTemplate infoTemplate = new InfoTemplate("Address",
     (String) graphics[0].getAttributeValue(queryResult
       .getDisplayFieldName()));

     Graphic gr = new Graphic(graphics[0].getGeometry(), symbol, graphics[0].getAttributes(), infoTemplate);
     GraphicsLayer gLayer = new GraphicsLayer();
     gLayer.addGraphic(gr);

If anyone came across this problem or has any suggestion on resolving this issue, please respond to this thread.

Thanks.
0 Kudos
5 Replies
ArchanaAgarwal
Occasional Contributor
Hello,

For the infotemplate information to show please add it to a android view.

Thanks.
0 Kudos
SwatiGadey
Emerging Contributor
Do you mean add the information I am providing in my InfoTemplate (includes title and content) to a View object (like a label)?

In case of multiple Graphics, I would like to show the InfoTemplate only upon tapping on that Graphic (instead of a label like view).

Please correct me if my understanding is incorrect. Thanks.
0 Kudos
ArchanaAgarwal
Occasional Contributor
You can use the graphicsLayer.getGraphic(...) method to get the graphic you just tapped on, then show the info template contents in a callout (MapView.getCallout())

map.setOnSingleTapListener(new OnSingleTapListener() {
  
   @Override
   public void onSingleTap(float x, float y) {
    gl.addGraphic(new Graphic(map.toMapPoint(x,y), new SimpleMarkerSymbol(Color.RED, 15, STYLE.CIRCLE)));
    int[] ids = gl.getGraphicIDs(x, y, 15, 1);
   
   
    InfoTemplate infoTemp = new InfoTemplate();
    infoTemp.setContentTemplate("Where is the data ${type}");
    try {
     HashMap<String, Object> attrs = new HashMap<String, Object>();
     attrs.put("type", "Point");
     Graphic gg = new Graphic(map.toMapPoint(x,y),new SimpleMarkerSymbol(Color.YELLOW, 25, STYLE.DIAMOND),attrs, infoTemp);
     gl.addGraphic(gg);
    
     Log.d(TAG,""+gg.getInfoTemplate().getContent(gg));
     Callout callout = map.getCallout();
     callout.setContent(createContent(ContactInfoTemplate.this, gl.getGraphic(ids[0]).getInfoTemplate(),gg));
     callout.show(map.toMapPoint(x,y));
    } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   
   
   }
  });


public View createContent(Context context, InfoTemplate info, Graphic gg)
{
  LinearLayout layout = new LinearLayout(context);
  TextView txt = new TextView(context);
  txt.setText("Content: "+gg.getInfoTemplate().getContent(gg));
 
 
  TextView txtAttr = new TextView(context);
  txt.setText("Attr: "+(String)gg.getAttributeValue("type"));
 
                layout.addView(txt);
  layout.addView(txtAttr);
 
  return layout;
}
0 Kudos
SwatiGadey
Emerging Contributor
Great! That works.
I appreciate your help.
0 Kudos
ArchanaAgarwal
Occasional Contributor
Awesome!
Its great to hear back from users when stuff works.
0 Kudos