Query on ArcGISDynamicMapServiceLayer

4361
4
Jump to solution
05-18-2013 12:11 PM
GakuminKato
New Contributor III
Hello,

I am trying to query a point data on ArcGISDynamicMapServiceLayer with a single tap.
However, FeatureSet "fs_view" does not seem to catch anything with "queryTask.execute(query)"...
And the program goes to the line of "catch"(Exception e).

I have checked the followings with debugging.
- "env_v" has 2D envelope
- "queryTask" and "query" have values in them
- ???e??? has values. Please see attached jpg file

For now, in order to make code simple, only one element of "resultGraphic" is dealt with.

I am very new to development of applications, so I may miss very simple and fundamental components in my code. Please excuse me.
I am very grateful if anybody helped me out. I do not know around me any android developers who are familiar with ArcGIS Android SDK...

Thank you in advance,
Gakumin


 public void setDefaultTapActions_popup(){   Map_view.setOnSingleTapListener(new OnSingleTapListener() {    private static final long serialVersionUID = 1L;    private Context context;        @Override    public void onSingleTap(float x_v, float y_v) {     Point point = Map_view.toMapPoint(x_v, y_v);          // Tolerance: 20 pixel     Envelope env_v = new Envelope(point,20*Map_view.getResolution(), 20*Map_view.getResolution());           //Set query task     QueryTask queryTask = new QueryTask("****/MapServer/0");          //Set Spatial Reference     SpatialReference sr;     sr = dmsl_v.getSpatialReference();          //Set query parameters     Query query = new Query();     query.setInSpatialReference(sr);     query.setOutSpatialReference(sr);     query.setGeometry(env_v);     //For now, max number of returned features is 10.     query.setMaxFeatures(10);     query.setOutFields(new String[] { "*" });          //Execute query task     try {      FeatureSet fs_view = queryTask.execute(query);      //Get an array of graphics of the query result FeatureSet      Graphic[] resultGraphic = fs_view.getGraphics();      View popupView = createPopupView(resultGraphic[0]);            callout.show(point, popupView);      } catch (Exception e) {      // TODO Auto-generated catch block      e.printStackTrace();     } 
0 Kudos
1 Solution

Accepted Solutions
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
You are trying to execute a query on the main UI Thread.  This is not allowed.  Try using an AsyncTask. 
http://developer.android.com/reference/android/os/AsyncTask.html

Y
ou can also import the QueryTask Android Sample in Eclipse. This will point you in the right direction.

View solution in original post

0 Kudos
4 Replies
deleted-user-ATjHIWsdQYmT
Occasional Contributor III
You are trying to execute a query on the main UI Thread.  This is not allowed.  Try using an AsyncTask. 
http://developer.android.com/reference/android/os/AsyncTask.html

Y
ou can also import the QueryTask Android Sample in Eclipse. This will point you in the right direction.
0 Kudos
GakuminKato
New Contributor III
Hi andrewb,
Thank you for your comments. I will try that with the AsyncTask.
And, I will let you know how it went once I am done.
Thank you,
Gakumin

You are trying to execute a query on the main UI Thread.  This is not allowed.  Try using an AsyncTask. 
http://developer.android.com/reference/android/os/AsyncTask.html

Y
ou can also import the QueryTask Android Sample in Eclipse. This will point you in the right direction.
0 Kudos
GakuminKato
New Contributor III
Hi andrewb,

My code worked fine (grabbed a point successfully) after I used AsyncTask!
Thank you so much for your help.
For reference, I will put my new code here (the code does not good at all, but for somebody's references...).
Gakumin

You are trying to execute a query on the main UI Thread.  This is not allowed.  Try using an AsyncTask. 
http://developer.android.com/reference/android/os/AsyncTask.html

Y
ou can also import the QueryTask Android Sample in Eclipse. This will point you in the right direction.


@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
//Set a default tap action as pop-up
  Map_view.setOnSingleTapListener(new OnSingleTapListener() {
   private static final long serialVersionUID = 1L;
   public void onSingleTap(float x_v, float y_v) {
    Point point = Map_view.toMapPoint(x_v, y_v);
    // Tolerance: 20 pixel
    Envelope env_v = new Envelope(point,20*Map_view.getResolution(), 20*Map_view.getResolution()); 
    new setDefaultTapActions_popup(env_v, dmsl_v.getSpatialReference(), point).execute(".../MapServer/0");
   }
   
  });

//Query dynamic map service layer by QueryTask(Modified from "PopupInWebmapForViewing.java")
 private class setDefaultTapActions_popup extends AsyncTask<String, Void, FeatureSet> {
  
  private Envelope env_v;
  private SpatialReference sr;
  private Point point;
  
  public setDefaultTapActions_popup(Envelope env_v, SpatialReference sr, Point point) { 
   super();
   this.env_v = env_v;
   this.sr = sr;
   this.point = point;
  }
  
  @Override
  protected FeatureSet doInBackground(String... params) {
   //Set query parameters
   Query query = new Query();
   query.setInSpatialReference(sr);
   query.setOutSpatialReference(sr);
   query.setGeometry(env_v);
   //For now, max number of returned features is 10.
   query.setMaxFeatures(10);
   query.setOutFields(new String[] { "*" });
   
   QueryTask queryTask = new QueryTask("..../MapServer/0");
   
   //Execute query task
   try {
    FeatureSet fs_view = queryTask.execute(query);
    //Get an array of graphics of the query result FeatureSet
    Graphic[] resultGraphic = fs_view.getGraphics();
    View popupView = createPopupView(resultGraphic[0]);
    
    callout.show(point, popupView);

   } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } 
   
   
   
   // TODO Auto-generated method stub
   return null;
  }

0 Kudos
AkshayAnpat
New Contributor

Can u shre ur whole code.

I need to show callout for a layer.

0 Kudos