.Net Xamarin - Map Shows Blank

1327
10
Jump to solution
06-13-2017 10:01 AM
JimFiddes
Occasional Contributor

Hey Everyone

I'm in the process of building a mobile app and within it I have a map plugin that is utilizing Esri.ArcGISRuntime.Xamarin.Android nuget package (version 100). I have created a C# class which implements a LinearLayout and on Initialize, I construct my Esri.ArcGISRuntime.UI.Controls.MapView and call AddView(_myMapView) followed up with a load layer method that constructs a map consuming a Streets basemap. 

Everything compiles and the layout appears in my app and I see the Powered by ESRI logo; however, nothing displays. The map appears black and no other code fires if I drag or pinch my finger over the control. I did wire up the LoadStatusChanged event for my map and I do achieve a loaded status, again nothing is visible.

Thoughts?

0 Kudos
1 Solution

Accepted Solutions
JimFiddes
Occasional Contributor

So....it appears the issue of the map view never getting a completed status in the DrawStatusChanged event was due to my Post method. In our .net code for windows we Post to another thread to say the map is ready and in the Xamarin Android side, this is not required. By commenting out the post method, my MapReady event is then triggered within the View containing this linear layout which then in turns allows the map view to complete its drawing event.

This thread can now be closed but it is good to know that a MapControlView can be managed within a class that implements a linear layout.

View solution in original post

0 Kudos
10 Replies
dotMorten_esri
Esri Frequent Contributor

Could you share some code that shows how you are setting up the map?

0 Kudos
JimFiddes
Occasional Contributor

Hey there

Here is condensed code from my class:

public class MapControlView : LinearLayout
{
  private readonly MapView _myMapView = new MapView();

  #region Implementors
  public MapControlView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
  {
    Initialize();
  }

  public MapControlView(Context context) : base(context)
  {
    Initialize();
  }

  public MapControlView(Context context, IAttributeSet attrs) : base(context, attrs)
  {
    Initialize();
  }

  public MapControlView(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr)
  {
    Initialize();
  }

  public MapControlView(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes)
  {
    Initialize();
  }
  #endregion

  private void Initialize()
  {
    _myMapView.NavigationCompleted += MyMapView_OnNavigationCompleted;
    AddView(_myMapView);
    LoadLayers();
  }

  private void LoadLayers()
  {
    var mdsMap = new Map(Basemap.CreateImagery());
    mdsMap.LoadStatusChanged += MdsMap_LoadStatusChanged;
    _myMapView.Map = mdsMap;
  }

  private void MdsMap_LoadStatusChanged(object sender, global::Esri.ArcGISRuntime.LoadStatusEventArgs e)
  {
    if (_mapReadyForUse) return;

    if (e.Status.Equals(LoadStatus.Loaded))
    {
      _uiContext.Post(x =>{(sender as Map).LoadStatusChanged -= MdsMap_LoadStatusChanged;

      _mapReadyForUse = true;
      MapReady?.Invoke();
      }, null);
    }
  }
}//end of class

0 Kudos
JimFiddes
Occasional Contributor

Any input on why my map appears blank but still shows Powered by ESRI?

0 Kudos
dotMorten_esri
Esri Frequent Contributor

The two parts are two separate parts to the MapView control. The "Powered by ESRI" text is rendered by the Android Label classes, whereas the map itself is rendered directly by OpenGL and won't start doing rendering until the map is properly loaded.

So it indicates the mapview control is there and loaded, but there's no map it can render, or issues with generating the OpenGL context.

Is the MapView.DrawStatusChanged ever fired?

0 Kudos
JimFiddes
Occasional Contributor

Yes the MapView.DrawStatusChanged event fires as well as the Map.LoadStatusChanged event fires. No exceptions or warnings appear.

0 Kudos
dotMorten_esri
Esri Frequent Contributor

And what are the draw statuses of the layers that are being reported?

0 Kudos
JimFiddes
Occasional Contributor

From what I can see, the map gets a status of loaded in the end and the basemap appears to load without issue. The only thing I do see is that the draw status of the map view is always in progress and never gets to completed.

0 Kudos
dotMorten_esri
Esri Frequent Contributor

Does this map/mapview work outside your custom LinearLayout?

0 Kudos
JimFiddes
Occasional Contributor

So....it appears the issue of the map view never getting a completed status in the DrawStatusChanged event was due to my Post method. In our .net code for windows we Post to another thread to say the map is ready and in the Xamarin Android side, this is not required. By commenting out the post method, my MapReady event is then triggered within the View containing this linear layout which then in turns allows the map view to complete its drawing event.

This thread can now be closed but it is good to know that a MapControlView can be managed within a class that implements a linear layout.

View solution in original post

0 Kudos