title: Refresh map loading for Android
body: <p>I am working on an app where the user has to discover places. I am using this to show areas with undiscovered places on a map:
  <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/map/circle-map-overlay" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/map/circle-map-overlay</a></p>
  
  <p>But later while app grew in functionality, it no longer runs well. Here is the link to my github.
  <a href="https://github.com/jakuboles/TDKInz2020/tree/master/TDK" rel="nofollow noreferrer">https://github.com/jakuboles/TDKInz2020/tree/master/TDK</a></p>
  
  <p>After the user login TDK.Android.CustomMapRenderer.OnElementChanged function is called way faster before TDK.MainPage.xaml.cs.DisplayInMap where I set which places should be shown as discovered, and which as undiscovered. In result now app always on TDK.Android.CustomMapRenderer.OnElementChanged line 36 list of places always will have null and on calling OnMapReady to draw circles list is null. </p>
  
  <p>Is there some way to call OnElementChanged once more when DisplayInMap will assign places to list? Or to make OnElementChanged run later, after DisplayInMap will set list.</p>
  
  <p>Sorry if it's a complicated description; didn't know exactly how to properly describe. </p>
  
  <p>Here's my Android renderer:</p>
  
  <pre><code>using Android.Content;
  using Android.Gms.Maps.Model;
  using Java.Lang;
  using MapOverlay;
  using MapOverlay.Droid;
  using System.Collections.Generic;
  using TDK.MapsCustoms;
  using Xamarin.Forms;
  using Xamarin.Forms.Maps.Android;
  
  [assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
  namespace MapOverlay.Droid
  {
      public class CustomMapRenderer : MapRenderer
      {
          List&lt;CustomCircle&gt; circles;
  
          public CustomMapRenderer(Context context) : base(context)
          {
          }
  
          protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs&lt;Xamarin.Forms.Maps.Map&gt; e)
          {
              base.OnElementChanged(e);
  
  
  
              if (e.OldElement != null)
              {
  
              }
  
              if (e.NewElement != null)
              {
                  var formsMap = (CustomMap)e.NewElement;
                  circles = formsMap.CircleList;
              }
          }
  
          protected override void OnMapReady(Android.Gms.Maps.GoogleMap map)
          {
              base.OnMapReady(map);
  
              foreach (var circle in circles)
              {
                  var circleOptions = new CircleOptions();
                  circleOptions.InvokeCenter(new LatLng(circle.Position.Latitude, circle.Position.Longitude));
                  circleOptions.InvokeRadius(circle.Radius);
                  circleOptions.InvokeFillColor(0X66FF0000);
                  circleOptions.InvokeStrokeColor(0X66FF0000);
                  circleOptions.InvokeStrokeWidth(0);
  
                  NativeMap.AddCircle(circleOptions);
              }
          }
      }
  }
  </code></pre>