Esempio n. 1
0
        /// <summary>
        /// Validate whether the new (temp) geometry can be saved - is it valid?
        /// </summary>
        /// <returns>valid/not valid</returns>
        private bool CanSaveNewGeom()
        {
            if (GeometryType == "Punkt")
            {
                return(TempCoordinates.Count > 0);
            }
            else if (GeometryType == "Linie")
            {
                return(TempCoordinates.Count > 1);
            }
            else
            {
                var isValid = MapModel.CheckValidityOfPolygon(TempCoordinates);
                if (TempCoordinates.Count <= 3)
                {
                    CurrentPolygonSelfIntersecting = false;
                }
                if (TempCoordinates.Count > 3 && isValid)
                {
                    CurrentPolygonSelfIntersecting = false;
                    return(true);
                }
                else
                {
                    if (TempCoordinates.Count > 3)
                    {
                        if (!CurrentPolygonSelfIntersecting) //Polyon was not previously self-intersecting
                        {
                            CurrentPolygonSelfIntersecting = true;
                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                bool ok = await App.Current.MainPage.DisplayAlert("Das aktuelle Polygon schneidet sich selbst", "Solange es eine ungültige Geometrie hat kann es nicht gespeichert werden", "Weiter zeichnen", "Rückgängig machen");
                                if (!ok)
                                {
                                    try
                                    {
                                        TempCoordinates.RemoveAt(TempCoordinates.Count - 2);
                                        CurrentPolygonSelfIntersecting = false;
                                        MessagingCenter.Send <MapPageVM>(this, "ShapeDrawingUndone");
                                        SaveGeomCommand.ChangeCanExecute();
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine("Had a problem undoing the shape: " + e.Message);
                                    }
                                }
                            });
                        }
                    }


                    return(false);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Add a temporary geometry to the map
        /// </summary>
        /// <param name="screenPt"></param>
        public void AddTempPoint(Mapsui.UI.Forms.Position screenPt)
        {
            if (CanAddMapGeometry)
            {
                if (TempCoordinates.Count == 0)
                {
                    MessagingCenter.Send <MapPageVM>(this, "SelectGeometryType");
                }
                if (Map.Layers[Map.Layers.Count - 1] == TempLayer)
                {
                    Map.Layers.Remove(TempLayer);
                }
                var mapPt = new Mapsui.Geometries.Point(Convert.ToDouble(screenPt.Longitude), Convert.ToDouble(screenPt.Latitude));
                if (GeometryType == "Punkt")
                {
                    TempCoordinates = new List <Mapsui.Geometries.Point>()
                    {
                        mapPt
                    };
                }
                else if (GeometryType == "Polygon" && TempCoordinates.Count > 0)
                {
                    var prevCoords = new List <Mapsui.Geometries.Point>(TempCoordinates);
                    if (TempCoordinates.Count == 1)
                    {
                        //Complete the polygon
                        TempCoordinates.Add(TempCoordinates[0]);
                    }
                    TempCoordinates.Insert(TempCoordinates.Count - 1, mapPt);
                }
                else
                {
                    TempCoordinates.Add(mapPt);
                }

                TempLayer = MapModel.CreateTempLayer(TempCoordinates);
                Map.Layers.Insert(Map.Layers.Count, TempLayer);
                (SaveGeomCommand as Command).ChangeCanExecute();
            }
        }