AnsweredAssumed Answered

Problems with using MapView.setMapOptions() or MapView.centerAndZoom()

Question asked by dani.g@bnmsp.de on Jul 27, 2016
Latest reply on Jul 28, 2016 by ANohe-esristaff

Hallo everybody,

i just made some Tutorials with the Esri Android API including the "Use ArcGIS basemaps" and everything worked fine. Now I want to implement a MapView into my own App and there are some problems with it:

 

What I have done:

I declared the MapView in my XML-Layout File and refer to it per "R.id". In my java-File Irefer to it and set some additional parameters like "mMapView.setEsriLogoVisible(true);" etc. and everything works fine until I reach the point where I want to change the initial View of the Map dynamically. So I tried ".setMapOptions" as well as ".centerAndZoom" nothing works here.

 

What I tried:

I remembered, that it was working fine in the Tutorial so I tried a few things out and saw, that the View changed if I wait a few seconds after initializing the MapView in java code. I created a timer and it worked. Also with a Button it worked fine. But if I try it directly after the initialisation it wont.

 

After that i tried to use the "OnStatusChangedListener" because I thougt it might work if the Map will be completely initialized, but here happens nothing as well. Tha map just appears at the initial point declared in the xml file. If I delete the initial coordinates in my Layout-File the hole MapView won't beinitialized (referring to the Callback).

 

Main question short:

How do I know, when I can use MapView.setMapOptions to change the initial center and appearence of the Map?

 

My Code:

 

.java:

public class MissionControlActivity extends AppCompatActivity{

     private MapView mMapView = null;

     private MapOptions mMapOptionsSat = new MapOptions(MapType.SATELLITE, 43.971873, 6.161288, 9);

    

     @Override

     protected void onCreate(Bundle savedInstanceState) {

     super.onCreate(savedInstanceState);

     setContentView(R.layout.activity_mission_control);

     initUI();

     }

    

     private void initUI(){

          mMapView = (MapView) findViewById(R.id.esriMapView);

          mMapView.enableWrapAround(true);

          mMapView.setAllowRotationByPinch(true);

          mMapView.setMapOptions(mMapOptionsSat);            //This here doesn't work

}

 

.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:custom="http://schemas.android.com/apk/res-auto"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

 

       <com.esri.android.map.MapView
             android:id="@+id/esriMapView"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             mapoptions.MapType="Topo"
             mapoptions.ZoomLevel="13"
             mapoptions.center="33.666354, -117.903557"/>

 

</RelativeLayout>

Outcomes