package com.esri.android.editdemo; import com.esri.android.map.GraphicsLayer; import com.esri.android.map.MapView; import com.esri.android.map.ags.ArcGISTiledMapServiceLayer; import com.esri.android.map.event.OnSingleTapListener; import com.esri.core.geometry.Envelope; import com.esri.core.geometry.GeometryEngine; import com.esri.core.geometry.Point; import com.esri.core.geometry.SpatialReference; import com.esri.core.map.Graphic; import com.esri.core.symbol.SimpleMarkerSymbol; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; import android.widget.Toast; public class EditDemoActivity extends Activity { LinearLayout linearLayout = null; MapView map = null; GraphicsLayer graphicsLayer = null; SpatialReference webMercator = SpatialReference.create(102100); public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Context context = this; boolean useLinearLayout = true; // <-- mapView fails, but has button // boolean useLinearLayout = false; // <-- mapView works, but no button if (useLinearLayout) { linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); setContentView(linearLayout); Button testButton = new Button(this); testButton.setText("Hello"); testButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Toast.makeText(context, "Test", Toast.LENGTH_SHORT).show(); } }); linearLayout.addView(testButton); map = new MapView(this); linearLayout.addView(map); } else { map = new MapView(this); setContentView(map); } // Add the ArcGIS Online layer to the map. map.addLayer(new ArcGISTiledMapServiceLayer("" + "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer")); map.setOnSingleTapListener(new OnSingleTapListener() { public void onSingleTap(float x, float y) { Point newPoint = map.toMapPoint(new Point(x, y)); SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(Color.RED, 20, SimpleMarkerSymbol.STYLE.CIRCLE); graphicsLayer.addGraphic(new Graphic(newPoint, simpleMarkerSymbol)); } }); // Set the extent to ESRI Redlands Campus Point minPoint = GeometryEngine.project(-117.200, 34.057, webMercator); Point maxPoint = GeometryEngine.project(-117.198, 34.059, webMercator); Envelope extent = new Envelope(minPoint.getX(), minPoint.getY(), maxPoint.getX(), maxPoint.getY()); extent.inflate(10000, 10000); map.setExtent(extent); // Create a graphics layer and add it to the map. graphicsLayer = new GraphicsLayer(); map.addLayer(graphicsLayer); } protected void onPause() { super.onPause(); map.pause(); } protected void onResume() { super.onResume(); map.unpause(); } }
Solved! Go to Solution.
package com.esri.android.editdemo; import com.esri.android.map.GraphicsLayer; import com.esri.android.map.MapView; import com.esri.android.map.ags.ArcGISTiledMapServiceLayer; import com.esri.android.map.event.OnSingleTapListener; import com.esri.core.geometry.Envelope; import com.esri.core.geometry.GeometryEngine; import com.esri.core.geometry.Point; import com.esri.core.geometry.SpatialReference; import com.esri.core.map.Graphic; import com.esri.core.symbol.SimpleMarkerSymbol; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.Toast; public class EditDemoActivity extends Activity { MapView map = null; GraphicsLayer graphicsLayer = null; SpatialReference webMercator = SpatialReference.create(102100); PopupWindow popupWindow = null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); map = new MapView(this); setContentView(map); // Add the ArcGIS Online layer to the map. map.addLayer(new ArcGISTiledMapServiceLayer("" + "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer")); map.setOnSingleTapListener(new OnSingleTapListener() { public void onSingleTap(float x, float y) { Point newPoint = map.toMapPoint(new Point(x, y)); SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(Color.RED, 20, SimpleMarkerSymbol.STYLE.CIRCLE); graphicsLayer.addGraphic(new Graphic(newPoint, simpleMarkerSymbol)); } }); // Set the extent to ESRI Redlands Campus Point minPoint = GeometryEngine.project(-117.200, 34.057, webMercator); Point maxPoint = GeometryEngine.project(-117.198, 34.059, webMercator); Envelope extent = new Envelope(minPoint.getX(), minPoint.getY(), maxPoint.getX(), maxPoint.getY()); extent.inflate(10000, 10000); map.setExtent(extent); // Create a graphics layer and add it to the map. graphicsLayer = new GraphicsLayer(); map.addLayer(graphicsLayer); // Post create PopupWindow since it created during onCreate(). final Context context = this; map.post( new Runnable() { public void run() { popupWindow = new PopupWindow(context); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.HORIZONTAL); Button button = new Button(context); button.setText("Clear"); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { graphicsLayer.removeAll(); Toast.makeText(context, "Graphics Layer Cleared", Toast.LENGTH_SHORT).show(); } }); linearLayout.addView(button); popupWindow.setContentView(linearLayout); popupWindow.showAtLocation(linearLayout, Gravity.LEFT | Gravity.BOTTOM, 10, 10); popupWindow.update(64, 64); } } ); } protected void onPause() { super.onPause(); map.pause(); } protected void onResume() { super.onResume(); map.unpause(); } }
package com.esri.android.editdemo; import com.esri.android.map.GraphicsLayer; import com.esri.android.map.MapView; import com.esri.android.map.ags.ArcGISTiledMapServiceLayer; import com.esri.android.map.event.OnSingleTapListener; import com.esri.core.geometry.Envelope; import com.esri.core.geometry.GeometryEngine; import com.esri.core.geometry.Point; import com.esri.core.geometry.SpatialReference; import com.esri.core.map.Graphic; import com.esri.core.symbol.SimpleMarkerSymbol; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.Toast; public class EditDemoActivity extends Activity { MapView map = null; GraphicsLayer graphicsLayer = null; SpatialReference webMercator = SpatialReference.create(102100); PopupWindow popupWindow = null; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); map = new MapView(this); setContentView(map); // Add the ArcGIS Online layer to the map. map.addLayer(new ArcGISTiledMapServiceLayer("" + "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer")); map.setOnSingleTapListener(new OnSingleTapListener() { public void onSingleTap(float x, float y) { Point newPoint = map.toMapPoint(new Point(x, y)); SimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(Color.RED, 20, SimpleMarkerSymbol.STYLE.CIRCLE); graphicsLayer.addGraphic(new Graphic(newPoint, simpleMarkerSymbol)); } }); // Set the extent to ESRI Redlands Campus Point minPoint = GeometryEngine.project(-117.200, 34.057, webMercator); Point maxPoint = GeometryEngine.project(-117.198, 34.059, webMercator); Envelope extent = new Envelope(minPoint.getX(), minPoint.getY(), maxPoint.getX(), maxPoint.getY()); extent.inflate(10000, 10000); map.setExtent(extent); // Create a graphics layer and add it to the map. graphicsLayer = new GraphicsLayer(); map.addLayer(graphicsLayer); // Post create PopupWindow since it created during onCreate(). final Context context = this; map.post( new Runnable() { public void run() { popupWindow = new PopupWindow(context); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.HORIZONTAL); Button button = new Button(context); button.setText("Clear"); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { graphicsLayer.removeAll(); Toast.makeText(context, "Graphics Layer Cleared", Toast.LENGTH_SHORT).show(); } }); linearLayout.addView(button); popupWindow.setContentView(linearLayout); popupWindow.showAtLocation(linearLayout, Gravity.LEFT | Gravity.BOTTOM, 10, 10); popupWindow.update(64, 64); } } ); } protected void onPause() { super.onPause(); map.pause(); } protected void onResume() { super.onResume(); map.unpause(); } }
import java.util.ArrayList; import java.util.concurrent.atomic.AtomicInteger; import android.app.Activity; import android.app.Dialog; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Color; import android.os.AsyncTask; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.widget.Button; import android.widget.LinearLayout; import android.widget.PopupWindow; import com.esri.android.map.Layer; import com.esri.android.map.MapView; import com.esri.android.map.PopupContainer; import com.esri.android.map.PopupView; import com.esri.android.map.ags.ArcGISDynamicMapServiceLayer; import com.esri.android.map.ags.ArcGISFeatureLayer; import com.esri.android.map.ags.ArcGISLayerInfo; import com.esri.android.map.event.OnSingleTapListener; import com.esri.core.geometry.Envelope; import com.esri.core.geometry.SpatialReference; import com.esri.core.map.FeatureSet; import com.esri.core.map.Graphic; import com.esri.core.map.popup.PopupInfo; import com.esri.core.tasks.ags.query.Query; import com.esri.core.tasks.ags.query.QueryTask; public class MapscreenMain extends Activity { private MapView map; private PopupContainer popupContainer; private PopupDialog popupDialog; private ProgressDialog progressDialog; private AtomicInteger count; PopupWindow popupWindow = null; /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load a webmap. map = new MapView(this, "http://www.arcgis.com/home/item.html?id=ec84873154cf4d7f07", "", ""); setContentView(map); // Post create PopupWindow since it created during onCreate(). final Context context = this; map.post( new Runnable() { public void run() { popupWindow = new PopupWindow(context); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.HORIZONTAL); Button button = new Button(context); button.setText("Clear"); linearLayout.addView(button); popupWindow.setContentView(linearLayout); popupWindow.showAtLocation(linearLayout, Gravity.LEFT | Gravity.BOTTOM, 10, 10); popupWindow.update(64, 64); } }); // Tap on the map and show popups for selected features. map.setOnSingleTapListener(new OnSingleTapListener() { private static final long serialVersionUID = 1L;.....................ect. public void onSingleTap(float x, float y) {