ArcGis Map не исчезает в навигации Xamarin.Forms - PullRequest
0 голосов
/ 30 мая 2018

Здравствуйте, ребята: D У меня проблема с андроидной частью Xamarin.Forms

Когда я перемещаюсь из AbsoluteLayout с картой и TabbleView ( введите описание изображения здесь ), чтобыa Сетка только с картой, карта с предыдущей страницы остается статичной поверх второй ( введите описание изображения здесь ).Эта проблема не проявляется в iOS, только в Android.Если кто-нибудь из вас знает проблему, пожалуйста, скажите мне, чтобы я мог быстро исправить: D

Страница с первой картой

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="SGPI.Intervencao.CriarIntervencao"
         xmlns:local="clr-namespace:SGPI.Shared"
         xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
         Padding="5,5">
<ContentPage.Resources>
    <ResourceDictionary>
        <local:MapViewModel x:Key="MapViewModel" />
    </ResourceDictionary>
</ContentPage.Resources>
<AbsoluteLayout>
    <esriUI:MapView Map="{Binding Map, Source={StaticResource MapViewModel}}" x:Name="map" AbsoluteLayout.LayoutBounds="0,0, 1, 0.6" AbsoluteLayout.LayoutFlags="All"/>
    <TableView Intent="Form" HasUnevenRows="True" AbsoluteLayout.LayoutBounds="0,1, 1, 0.4" AbsoluteLayout.LayoutFlags="All">
        <TableRoot>
            <TableSection Title="Information">
                <EntryCell Label="Nome" Text="{Binding Name}" Placeholder="Nome"/>
                <EntryCell Label="Codigo" Text="{Binding Code}" Placeholder="Codigo"/>
                <ViewCell>
                    <StackLayout Orientation="Horizontal">
                        <Label Text="Status" HorizontalOptions="Start" VerticalOptions="Center"/>
                        <Picker x:Name="pick" SelectedIndex="{Binding Index}" SelectedItem="{Binding Status}" Title="Status" HorizontalOptions="FillAndExpand">
                            <Picker.Items>
                                <x:String>Em Construção</x:String>
                                <x:String>Construido</x:String>
                            </Picker.Items>
                        </Picker>
                    </StackLayout>
                </ViewCell>
                <ViewCell>
                    <Button Image="editMap.png" Clicked="Button_Clicked" />
                </ViewCell>
            </TableSection>
        </TableRoot>
    </TableView>
</AbsoluteLayout>
<ContentPage.ToolbarItems>
    <ToolbarItem Icon="dan.png" Order="Primary" x:Name="done" Clicked="Done"/>
</ContentPage.ToolbarItems>

Код за

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;


     using Xamarin.Forms;
       using Xamarin.Forms.Xaml;
       namespace SGPI.Intervencao

   {



    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class CriarIntervencao : ContentPage
    {

    public event EventHandler<IntervencaoClass> IntervencaoAdded;
    public event EventHandler<IntervencaoClass> IntervencaoUpdated;

        public CriarIntervencao(IntervencaoClass intervencao)
        {

            if(intervencao == null)
                throw new ArgumentNullException(nameof(intervencao));

            InitializeComponent();
            BindingContext = new IntervencaoClass
            {
                Code = intervencao.Code,
                Name = intervencao.Name,
                Status = intervencao.Status,
                Index = intervencao.Index,
                Id = intervencao.Id,
                Polygons = intervencao.Polygons
            };
            if(intervencao.Polygons != null)
                map.GraphicsOverlays.Add(intervencao.Polygons);
        }

        private async void Done(object sender, EventArgs e)
         {
            var intervencao = BindingContext as IntervencaoClass;
            if (filled())
            {
                await DisplayAlert("Erro", "Preenche tudo", "OK");
                return;
            }
            map.GraphicsOverlays.Clear();
            if (!intervencao.Id.HasValue)
            {
                intervencao.Id = 1;
                IntervencaoAdded?.Invoke(this, intervencao);
            }
            else
            {
                IntervencaoUpdated?.Invoke(this, intervencao);
            }

            await Navigation.PopAsync();
        }

        public bool filled()
        {
            var intervencao = BindingContext as IntervencaoClass;
            return String.IsNullOrEmpty(intervencao.Name) || String.IsNullOrEmpty(intervencao.Code) || pick.SelectedIndex == -1;
        }

        private async void Button_Clicked(object sender, EventArgs e)
        {
            map.GraphicsOverlays.Clear();
            var page = new MapPages.MapPage((BindingContext as IntervencaoClass).Polygons);
            page.AcceptedMap += (send, graphics) => {
                var intervencao = BindingContext as IntervencaoClass;
                intervencao.Polygons = graphics;
                map.GraphicsOverlays.Add(graphics);
                Navigation.PopAsync();
            };
            await Navigation.PushAsync(page);
        }

    }
}

Вторая страница

    <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:SGPI.Shared"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             x:Class="SGPI.MapPages.MapPage">
    <ContentPage.Resources>
        <ResourceDictionary>
            <local:MapViewModel x:Key="MapViewModel" />
        </ResourceDictionary>
    </ContentPage.Resources>
    <Grid>
            <esriUI:MapView Map="{Binding Map, Source={StaticResource MapViewModel}}" x:Name="map" GeoViewTapped="Map_GeoViewTapped"/>
    </Grid>
    <ContentPage.ToolbarItems>
        <ToolbarItem Icon="dan.png" Clicked="Done"/>
    </ContentPage.ToolbarItems>
</ContentPage>

Код второй страницы позади

using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Symbology;
using System.Collections.Generic;
using Xamarin.Forms;
using Esri.ArcGISRuntime.UI;
using System;
using System.Threading;

namespace SGPI.MapPages
{
    public partial class MapPage : ContentPage
    {

        public event EventHandler<GraphicsOverlay> AcceptedMap;
        List<MapPoint> points;
        static SimpleLineSymbol symbol = new SimpleLineSymbol()
        {
            Style = SimpleLineSymbolStyle.Dash,
            Color = System.Drawing.Color.Black,
            Width = 1
        };
        static SimpleMarkerSymbol marker = new SimpleMarkerSymbol()
        {
            Color = System.Drawing.Color.Pink,
            Outline = symbol,
            Style = SimpleMarkerSymbolStyle.Diamond,
            Size = 10
        };
        static SimpleLineSymbol line = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.CadetBlue, 1);
        static SimpleFillSymbol fill = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, System.Drawing.Color.Black, line);

        public MapPage(GraphicsOverlay graphic)
        {
            InitializeComponent();
            map.Map = new SGPI.Shared.MapViewModel().Map;
            if(graphic == null)
                graphic = new GraphicsOverlay();
            map.GraphicsOverlays.Add(graphic);
            points = new List<MapPoint>();
        }



        private Graphic AddPolygonInMap(MapPoint[] points)
        {
            var pointCollection = new PointCollection(points[0].SpatialReference);
            foreach (MapPoint p in points)
                pointCollection.Add(p);

            var sPolygon = new Polygon(pointCollection);

            return new Graphic(sPolygon, fill);
        }

        private void AddPointinMap(MapPoint point)
        {
            Graphic graphic = new Graphic(point, marker);
            map.GraphicsOverlays[0].Graphics.Add(graphic);
        }


        private async void Map_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            var tolerance = 10d; // Use larger tolerance for touch
            var maximumResults = 1; // Only return one graphic  
            var onlyReturnPopups = false; // Don't return only popups

            // Use the following method to identify graphics in a specific graphics overlay
            IdentifyGraphicsOverlayResult identifyResults = await map.IdentifyGraphicsOverlayAsync(
                 map.GraphicsOverlays[0],
                 e.Position,
                 tolerance,
                 onlyReturnPopups,
                 maximumResults);

            // Check if we got results
            if (identifyResults.Graphics.Count > 0)
            {
                // Make sure that the UI changes are done in the UI thread
                Device.BeginInvokeOnMainThread(async () => {
                    await DisplayAlert("", "Tapped on graphic", "OK");
                });
            } else
            {
                points.Add(e.Location);
                AddPointinMap(e.Location);
            }
        }

    private async void Done(object sender, EventArgs e)
        {
            if(points.Count > 2) { 
                GraphicsOverlay graphics = new GraphicsOverlay();
                graphics.Graphics.Add(AddPolygonInMap(points.ToArray()));
                map.GraphicsOverlays.Add(graphics);
                Thread.Sleep(500);
                var accepted = await DisplayAlert("Aviso", "Este é o polígono certo?", "Sim", "Não");
                if (accepted)
                {
                    GraphicsOverlay graph = graphics;
                    map.GraphicsOverlays.Clear();
                    AcceptedMap?.Invoke(this, graph);
                }
                else
                {
                    for(int i = 1; i < map.GraphicsOverlays.Count; i++)
                        map.GraphicsOverlays[i] = new GraphicsOverlay();
                }
            }
        }
    }
}
...