Basemap and layers are displayed only on the second run

200
0
05-22-2020 05:38 AM
MassimoMazzanti
New Contributor III

I'am developing a .NET C# Android app, that start with a SplahAcitivity that calls the MainActivity module.

In the MainAcitivity I load a MapView component, inside a LinearLayout, declared in Main.xml, 

The App compiles correctly, but at first run (in both debug and release version) the basemap and a feature layer are not displayed. The MapView area is completely empty (light blue color).

All the other times I run the application the basemap and the feature layer are displayed correctly.

I have tried to modify the code in various ways but without any positive results.

Do you have any ideas?

A piece of Main.xml:

...

<Esri.ArcGISRuntime.UI.Controls.MapView
       android:id="@+id/MyMapView"
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:layout_weight="1" />

...

Some lines of MainActivity.cs module are shown below:

...

public class MainActivity : AppCompatActivity
{
     MapViewModel _mapViewModel = new MapViewModel();
     MapView _mapView;

     protected override void OnCreate(Bundle bundle)
     {
          base.OnCreate(bundle);

          SetContentView(Resource.Layout.Main);

   

          Initialize();

     }

     private void Initialize()

     {

     ...

          SetContentView(Resource.Layout.Main);

          _mapView = FindViewById<MapView>(Resource.Id.MyMapView);
          _mapView.Map = _mapViewModel.Map;

          Esri.ArcGISRuntime.Mapping.Map myMap = new Esri.ArcGISRuntime.Mapping.Map(Basemap.CreateStreets());
         Envelope initialLocation = new Envelope(720000.0, 4942000.0, 1940000.0, 5900000.0,   SpatialReferences.WebMercator);
         myMap.InitialViewpoint = new Viewpoint(initialLocation);

   // Assign the map to the MapView
         _mapView.Map = myMap;

     ...

     }

...

}

And this is the MapViewModel class declared in MapViewModel.cs

public class MapViewModel : INotifyPropertyChanged
{
     public MapViewModel()
     {

     }

     private Esri.ArcGISRuntime.Mapping.Map _map = new   Esri.ArcGISRuntime.Mapping.Map(Basemap.CreateStreets());

     public Esri.ArcGISRuntime.Mapping.Map Map
     {
          get { return _map; }
          set { _map = value; OnPropertyChanged(); }
     }

     protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
     {
          var propertyChangedHandler = PropertyChanged;
          if (propertyChangedHandler != null)
               propertyChangedHandler(this, new PropertyChangedEventArgs(propertyName));
     }

     public event PropertyChangedEventHandler PropertyChanged;
}

Many thanks.

Best Regards

Massimo

0 Kudos
0 Replies