ARCGis Xamarin - displays MapView from previous pages after navigating to a new page

I have a "master" map from which the user can either add data to the map or click on existing data to see details. This is done with PushModalAsync (), where I navigate to a new page. My problem is with both of these new pages. I have a new map with a new MapView, which is under the "MapView" from the main page. Both MapView and Map are themselves new objects on secondary pages.

After navigating to my new pages, the previous MapView is displayed in the area of ​​the screen where it existed (on the main page), where my new MapView also exists. In other words, on my new map pages, my map differs in different ways and is partially higher in the layout than the "main" map. The part above is the only part of the visible new map that I can interact with. The part that is in the same area is the "main" view of the card and I cannot interact with it and it blocks my new card.

I also tried this with PushAsync (not modal) and nothing changed. How is it supposed to have multiple cards in an application on multiple pages? Is this possible with ArcGIS? This app has been used with Google Maps / Apple and the same layout worked very well.

My main map page in yellow is the area where my future map, on a new page, should display

My new page with a new MapView and a new map covered by the previous map

Edit: Here's the code (with unnecessary parts removed) This page moves from another page with a map where this map is covered if laid out in the same area of ​​the first map. On this page I go to the third page where both cards are displayed. The deletion works successfully, however, when I try to add, I get an error: I cannot add a null child to a group like:

public partial class EventDetails : ContentPage
{
    public Xamarin.Forms.Grid MapGrid = new Xamarin.Forms.Grid()
    {
    RowDefinitions =
    {
        new RowDefinition { Height = 220 },
        new RowDefinition { Height = GridLength.Auto }
    },
    ColumnDefinitions =
    {
        new ColumnDefinition { Width = 500 }
    },
    HorizontalOptions = LayoutOptions.Center
    };
    public Map DetailMap;
    public MapView MyDetailMapView = new MapView();

    public EventDetails(MapLog eventDetails, string strMapType)
    {    
        DetailMap = new Map(BasemapType.ImageryWithLabels, eventDetails.Latitude, eventDetails.Longitude, iMapDetail);
        MyDetailMapView.Map = DetailMap;
        MyDetailMapView.ViewpointChanged += MyMapView_ViewpointChanged;
        var scrollView = new ScrollView
        {
            Content = mainStack
        };
        MapGrid.Children.Add(MyDetailMapView, 0, 0);
        MapGrid.Children.Add(scrollView, 0, 1);
        Content = MapGrid;
    }

#if __ANDROID__ 
protected override void OnAppearing()
{

    if (!MapGrid.Children.Contains(MyDetailMapView))
    {
        try
        {
            MapGrid.Children.Add(MyDetailMapView);
        }
        catch (Exception ex)
        {
            DisplayAlert("Err", ex.Message, "Ok");           
        }

    }
    base.OnAppearing();

 }

protected override void OnDisappearing()
{
    if (MapGrid.Children.Contains(MyDetailMapView))
        MapGrid.Children.Remove(MyDetailMapView);
    base.OnDisappearing();
}
#endif
}

      

EDIT *: I updated the Xamarin Forms version and ARCGIS runtime and now the map remove / add solution actually works without issue.

+3


source to share


1 answer


I had other similar issues with having two maps for android in Xamarin Forms ArcGIS and the solution was removing the MapView from the visual tree when navigating to a new page.
You need to remove the MapView before going to the second page:

[your parent layout].Children.Remove(MyMapView);
await Navigation.PushAsync(new SecondPage());

      

And on the first page, you need to make sure to add the MapView back to the visual tree when you return to the page:



    protected override void OnAppearing()
    {
        if (!GridMap.Children.Contains(MyMapView))
            GridMap.Children.Add(MyMapView);
        base.OnAppearing();
    }

      

This solved all my dual card problems. Thanks to this post on the ESRI forum Navigating between 2 MapViews in Xamarin Android

+1


source







All Articles