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(); }
Solved! Go to Solution.
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
You can also import the QueryTask Android Sample in Eclipse. This will point you in the right direction.
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
You 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;
}
Can u shre ur whole code.
I need to show callout for a layer.