Callout for a selected point

546
3
Jump to solution
05-22-2013 05:10 PM
GakuminKato
New Contributor III
Hello,

I am trying to show Callout for a selected(queried by a single tap) point data (Map service).
I believe query part works fine, as I checked that attribute values of a point data are assigned to valuables.
That is, "myPopupInfo" has an expected value. However, nothing show up after that.

I am not sure whether "popupContent"(TextView) and "rat"(LinearLayout) are correct.

I would really appreciate if anybody helped me out...
Thank you in advance,
Gakumin

 @Override  protected void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   setContentView(R.layout.map_view);    //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]);          Map_view.getCallout().show(point, popupView);     } catch (Exception e) {     // TODO Auto-generated catch block     e.printStackTrace();    }     // TODO Auto-generated method stub    return null;   }    private View createPopupView(Graphic graphic) {    //Employ "createReportView" of "MyWater" sample of ESRI    LinearLayout ret = new LinearLayout(context);    ret.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,      LayoutParams.WRAP_CONTENT));        Object attribute;        attribute = graphic.getAttributeValue("Type_Store");    String Type_Store = null;    if (attribute != null){     Type_Store = (String)attribute;    }        attribute = graphic.getAttributeValue("Name_Store");    String Name_Store = null;    if (attribute != null){     Name_Store = (String)attribute;    }        attribute = graphic.getAttributeValue("Open_Close");    String Open_Close = null;    if (attribute != null){     Open_Close = (String)attribute;    }        attribute = graphic.getAttributeValue("Service");    String Service = null;    if (attribute != null){     Service = (String)attribute;    }        attribute = graphic.getAttributeValue("AmountSup");    Integer AmountSup = 0;    if (attribute != null){     AmountSup = (Integer)attribute;    }        StringBuilder myPopupInfo = new StringBuilder();    myPopupInfo.append("Type of Store:\t" + Type_Store);    myPopupInfo.append("\nName of Store:\t" + Name_Store);    myPopupInfo.append("\nOpen or Close?:\t" + Open_Close);    myPopupInfo.append("\nService:\t" + Service);    myPopupInfo.append("\nAmount of Supply:\t" + AmountSup);        TextView popupContent = new TextView(context);    popupContent.setText(myPopupInfo.toString());    popupContent.setTextColor(Color.WHITE);    popupContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 9);    popupContent.setPadding(1, 0, 1, 0);    ret.addView(popupContent);        // TODO Auto-generated method stub    return ret;   }     } 
0 Kudos
1 Solution

Accepted Solutions
JeffSmith8
New Contributor II
Try moving the lines that follow the "queryTask.execute" statement from the "doInBackground" method to the "onPostExecute" method of your AsyncTask. Hopefully the problem is limited to the issue of needing to update the GUI from only the main thread, which is performed by onPostExecute. Your sample code is missing the onPostExecute method with a FeatureSet as the incoming parameter, something like:
 
  @Override   protected void onPostExecute(final FeatureSet result) {    //Get an array of graphics of the query result FeatureSet    Graphic[] resultGraphic = result.getGraphics();    View popupView = createPopupView(resultGraphic[0]);        Map_view.getCallout().show(point, popupView);    }



I currently cannot verify what is going on in the PopupInWebmapForViewing sample as my machine is throwing errors - hopefully this will gain you some progress.

View solution in original post

0 Kudos
3 Replies
JeffSmith8
New Contributor II
Try moving the lines that follow the "queryTask.execute" statement from the "doInBackground" method to the "onPostExecute" method of your AsyncTask. Hopefully the problem is limited to the issue of needing to update the GUI from only the main thread, which is performed by onPostExecute. Your sample code is missing the onPostExecute method with a FeatureSet as the incoming parameter, something like:
 
  @Override   protected void onPostExecute(final FeatureSet result) {    //Get an array of graphics of the query result FeatureSet    Graphic[] resultGraphic = result.getGraphics();    View popupView = createPopupView(resultGraphic[0]);        Map_view.getCallout().show(point, popupView);    }



I currently cannot verify what is going on in the PopupInWebmapForViewing sample as my machine is throwing errors - hopefully this will gain you some progress.

View solution in original post

0 Kudos
GakuminKato
New Contributor III
Hi jsmithgisguy2,

Thank you so much for your advice! I will definitely give it a try shortly! (I am currently running into another issue in different part as well...) Then, I will report the result to you and community here.

Gakumin


Try moving the lines that follow the "queryTask.execute" statement from the "doInBackground" method to the "onPostExecute" method of your AsyncTask. Hopefully the problem is limited to the issue of needing to update the GUI from only the main thread, which is performed by onPostExecute. Your sample code is missing the onPostExecute method with a FeatureSet as the incoming parameter, something like:
 
  @Override
  protected void onPostExecute(final FeatureSet result) {
   //Get an array of graphics of the query result FeatureSet
   Graphic[] resultGraphic = result.getGraphics();
   View popupView = createPopupView(resultGraphic[0]);
  
   Map_view.getCallout().show(point, popupView);

  }



I currently cannot verify what is going on in the PopupInWebmapForViewing sample as my machine is throwing errors - hopefully this will gain you some progress.
0 Kudos
GakuminKato
New Contributor III
Hi jsmithgisguy2,

Thank you so much for your help! Your advise worked in my code!
My updated code does query in "doInBackground" and pass the result, view, to "doInBackground".
Then, callout showed up! I really appreciate your help!
I attached the updated code here for reference.

Gakumin


//Query dynamic map service layer by QueryTask(Modified from "PopupInWebmapForViewing.java")
private class setDefaultTapActions_popup extends AsyncTask<String, Void, View> {
 
  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 View 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]);
   } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   // TODO Auto-generated method stub
   return null;
  }
 
  @Override
  protected void onPostExecute(View popupView) {
   // TODO Auto-generated method stub
   super.onPostExecute(popupView);
   Callout callout = Map_view.getCallout();
   callout.setStyle(R.xml.callout_style);
   callout.setContent(popupView);
   callout.show(point);
  }
0 Kudos