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, 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.getStyle().setMaxHeight(150); callout.getStyle().setMaxWidth(150); callout.setContent(popupView); callout.show(point); } 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); View popupView = getLayoutInflater().inflate( R.layout.callout_view2, null); TextView popupContent = (TextView) popupView .findViewById(R.id.callout_textview2); popupContent.setText(myPopupInfo.toString()); popupContent.setTextColor(Color.WHITE); popupContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 9); popupContent.setPadding(1, 0, 1, 0); return popupView; // ret.addView(popupContent); // TODO Auto-generated method stub // return ret; } }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/callout_textview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:padding="2dp" android:text="callout" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FF0000" android:textSize="16sp" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <calloutViewStyle titleTextColor="#000000" titleTextSize = "10" titleTextStyle = "0" titleTextTypeFace = "0" frameColor="#FFC7C7C7" backgroundColor="#FF0A0A0A" flat="true" cornerCurve="10" anchor="8" style="app:@style/darkgray_layout"/> </resources>
Solved! Go to Solution.
//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]); //Added this one return popupview; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }
//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]); //Added this one return popupview; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }