/// <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(); } }
/// <summary> /// Initialisation /// </summary> /// <param name="mapView"></param> /// <param name="GPSButton"></param> /// <param name="AddMapGeometryButton"></param> /// <param name="navigation"></param> public MapPageVM(Mapsui.UI.Forms.MapView mapView, Button GPSButton, Button AddMapGeometryButton, INavigation navigation) { GPSButtonCommand = new Command(GPSButtonPressed, GPSActivated); LayersButtonCommand = new LayersButtonCommand(this); CancelGeomCommand = new Command(CancelNewGeom, CanCancelNewGeom); SaveGeomCommand = new Command(SaveNewGeom, CanSaveNewGeom); SaveMapCommand = new Command(SaveMaps, CanSaveMaps); AddMapGeometryCommand = new Command(AllowAddNewGeom, AllowAddNewGeomButtonActivated); CancelSaveCommand = new Command(CancelSave, AllowCancelSave); CanAddMapGeometry = false; Navigation = navigation; VMGPSButton = GPSButton; VMGeomEditButton = AddMapGeometryButton; VMGeomEditButton.BackgroundColor = (Color)Application.Current.Resources["BioDivGrey"]; GeometryType = String.Empty; Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged; ConfigureMap(); mapView.Map = Map; mapView.Refresh(); mapView.IsNorthingButtonVisible = false; mapView.IsMyLocationButtonVisible = false; mapView.IsZoomButtonVisible = false; mapView.MyLocationLayer.IsMoving = true; mapView.MyLocationFollow = false; mapView.RotationLock = true; mapView.MyLocationEnabled = true; mapView.Info += MapOnInfo; OSAppTheme currentTheme = Application.Current.RequestedTheme; if (currentTheme == OSAppTheme.Dark) { mapView.Map.BackColor = Mapsui.Styles.Color.Black; } else { mapView.Map.BackColor = Mapsui.Styles.Color.White; } VMMapView = mapView; VMMapView.TouchMove += MapView_TouchMove; VMMapView.ViewportInitialized += VMMapView_ViewportInitialized; TempCoordinates = new List <Mapsui.Geometries.Point>(); var positionLat = Preferences.Get("LastPositionLatitude", 47.36); var positionLong = Preferences.Get("LastPositionLongitude", 8.54); Mapsui.Geometries.Point centre = new Mapsui.Geometries.Point(positionLong, positionLat); var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(centre.X, centre.Y); VMMapView.MyLocationLayer.UpdateMyLocation(new Mapsui.UI.Forms.Position(centre.Y, centre.X), false); VMMapView.Map.Limiter = new ViewportLimiterKeepWithin { PanLimits = new BoundingBox(SphericalMercator.FromLonLat(-180, -90), SphericalMercator.FromLonLat(180, 90)) }; try { MapLayers = MapModel.MakeArrayOfLayers(); } catch (Exception e) { Console.WriteLine(e); } finally { Map.Widgets.Add(new Mapsui.Widgets.ScaleBar.ScaleBarWidget(Map) { TextAlignment = Mapsui.Widgets.Alignment.Center, HorizontalAlignment = Mapsui.Widgets.HorizontalAlignment.Left, VerticalAlignment = Mapsui.Widgets.VerticalAlignment.Bottom }); } MessagingCenter.Subscribe <Application, string>(App.Current, "TileSaved", (sender, arg1) => { SaveCountText = (string)arg1; }); SaveCountText = String.Empty; MessagingCenter.Subscribe <Application>(App.Current, "PermissionsChanged", (sender) => { Device.BeginInvokeOnMainThread(() => { GPSButtonCommand.ChangeCanExecute(); }); }); MessagingCenter.Subscribe <MapPageVM>(this, "ShapeDrawingUndone", (sender) => { RefreshShapes(); TempLayer = MapModel.CreateTempLayer(TempCoordinates); Map.Layers.Insert(Map.Layers.Count, TempLayer); //SaveGeomCommand.ChangeCanExecute(); }); DeviceDisplay.MainDisplayInfoChanged += HandleRotationChange; }