AnsweredAssumed Answered

MapView.SetExtent problem

Question asked by hussein on Jul 19, 2015
Latest reply on Aug 7, 2015 by ebader-esristaff

I'm making a simple app to Query Features (Polygons) and then zoom to results , but when it zooms the zoom is too far (no envelope padding in the setExtent method ) , I barely see the feature , and it doesn't zoom more than this even with the manual double tap technique




Here is the code :


public class MainActivity extends ActionBarActivity {


  MapView mMapView;

  ArcGISFeatureLayer mFeatureLayer;

  GraphicsLayer graphicsLayer;

   boolean mIsMapLoaded;

  String mFeatureServiceURL;

  EditText queryText;


   public void onSubmit(View view){

   //reference the values
   queryText = (EditText) findViewById(;

   new QueryFeatureLayer().execute(queryText.getText().toString());



   class QueryFeatureLayer extends AsyncTask<String, Void, FeatureResult> {


   protected FeatureResult doInBackground(String... params) {

  String whereClause = "name ='" + params[0] + "'";


   // Define a new query and set parameters
   QueryParameters mParams = new QueryParameters();




   // Define the new instance of QueryTask
   QueryTask queryTask = new QueryTask(mFeatureServiceURL);

  FeatureResult results;


   try {

   // run the querytask
   results = queryTask.execute(mParams);

   return results;

  } catch (Exception e) {



   return null;



   protected void onPostExecute(FeatureResult results) {


   // Remove the result from previously run query task


   // Define a new marker symbol for the result graphics
   SimpleMarkerSymbol sms = new SimpleMarkerSymbol(Color.BLUE, 10, SimpleMarkerSymbol.STYLE.CIRCLE);

  SimpleFillSymbol fsymbol = new SimpleFillSymbol(Color.RED);


   // Envelope to focus on the map extent on the results
   Envelope extent = new Envelope();

  // iterate through results
   for (Object element : results) {

   // if object is feature cast to feature
   if (element instanceof Feature) {

  Feature feature = (Feature) element;

   // convert feature to graphic
   Graphic graphic = new Graphic(feature.getGeometry(), feature.getSymbol(), feature.getAttributes());


   // add it to the layer








   protected void onCreate(Bundle savedInstanceState) {




   final MapOptions mStreetsBasemap = new MapOptions(MapOptions.MapType.STREETS);



   // Retrieve the map and initial extent from XML layout
   mMapView = (MapView) findViewById(;


   // Get the feature service URL from values->strings.xml
   mFeatureServiceURL = this.getResources().getString(R.string.featureServiceURL);


   // Add Feature layer to the MapView
   mFeatureLayer = new ArcGISFeatureLayer(mFeatureServiceURL, ArcGISFeatureLayer.MODE.ONDEMAND);



   // Add Graphics layer to the MapView

   SimpleRenderer sr = new SimpleRenderer(

   new SimpleFillSymbol(Color.RED));


   //mGraphicsLayer = new GraphicsLayer();




   //add the code below to set a listener that will be called when the MapView is initialized.
  // You will check this in a later step to see if the map is ready for a user to make queries.

   mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

   public void onStatusChanged(Object source, STATUS status) {

   if ((source == mMapView) && (status == OnStatusChangedListener.STATUS.INITIALIZED)) {

   mIsMapLoaded = true;