Beispiel #1
0
        public void ChangeSelectedLocationHistory(LocationDTO coordonate)
        {
            // remove the old position if its exist
            if (SelectedLocationHistory != null)
            {
                MapViewControl.RemoveAnnotation(SelectedLocationHistory);
            }

            // if we don't need to select, exit
            if (coordonate == null)
            {
                return;
            }

            // remplacing with the new annotation
            var location = new CLLocationCoordinate2D(coordonate.Latitude, coordonate.Longitude);

            SelectedLocationHistory = new HistoricAnnotation(location
                                                             , " "
                                                             , string.Empty);
            ((HistoricAnnotation)SelectedLocationHistory).Content = coordonate.DateLocationCreation.FormatDateFromNow();
            MapViewControl.AddAnnotation(SelectedLocationHistory);

            // display accuracy if necessary
            CreateAccuracyArea(coordonate.Latitude
                               , coordonate.Longitude
                               , coordonate.Accuracy);

            //// center the new annotation on the map
            //if (!App.Locator.ModeZone.IsOnEditMode)
            //{
            //    if (coordonate.Accuracy == 0)
            //    {
            //        CenterInLocalisation(coordonate.Latitude
            //            , coordonate.Longitude
            //            , 0
            //            , true);
            //    }
            //    else
            //    {
            //        CenterInLocalisation(coordonate.Latitude
            //            , coordonate.Longitude
            //            , 0
            //            , true);
            //        //// display the annotation with accurency and focus on the circle
            //        //_mapViewControl.MapRectThatFits(CreateAccuracyArea(coordonate.Latitude
            //        //, coordonate.Longitude
            //        //, coordonate.Accuracy).BoundingMapRect);
            //    }
            //}

            // display the annotation view
            MapViewControl.SelectAnnotation(SelectedLocationHistory, true);
            //CreateAccuracyArea(coordonate.Latitude
            //    , coordonate.Longitude
            //    , coordonate.Accuracy);
        }
Beispiel #2
0
        public void CreateRouteForeground(List <LocationDTO> coordonates)
        {
            if (PointsOfRoute != null && PointsOfRoute.Count != 0)
            {
                foreach (var annotation in PointsOfRoute)
                {
                    MapViewControl.AddAnnotation(annotation);
                }

                var positionWithSeekios = PointsOfRoute.Select(s => s.Coordinate).ToList();
                if (SelectedAnnotation != null && !positionWithSeekios.Contains(SelectedAnnotation.Coordinate))
                {
                    positionWithSeekios.Add(SelectedAnnotation.Coordinate);
                }
                var polygon = MKPolyline.FromCoordinates(positionWithSeekios.ToArray());
                MapViewControl.AddOverlay(polygon);
                MapViewControl.SetVisibleMapRect(polygon.BoundingMapRect, new UIEdgeInsets(50, 40, 100, 40), true);
            }
        }
Beispiel #3
0
        private void AddPointToZone()
        {
            //if (_recognizer.State == UIGestureRecognizerState.Began)
            //{
            //	_dragStarted = false;
            //             Console.WriteLine("Began !");
            //             return;
            //}
            //else if (_recognizer.State == UIGestureRecognizerState.Changed)
            //{
            //	_dragStarted = true;
            //             Console.WriteLine("Drag !");
            //	// Do dragging stuff here
            //}
            //else if (_recognizer.State == UIGestureRecognizerState.Ended){
            //	if (_dragStarted)
            //	{
            //                 Console.WriteLine("Ended 1!");
            //                 _dragStarted = false;
            //		return;
            //	}
            //	else {
            //             Console.WriteLine("Ended !");
            //             }
            //         }
            if (_recognizer.State == UIGestureRecognizerState.Began)
            {
                //if (_recognizer.State == UIGestureRecognizerState.Began || !IsOnPointAdding) return;
                if (ZonePolygon != null && ZonePolygon.Points.Count() > App.Locator.ModeZone.MAX_NUMBER_OF_POINTS)
                {
                    return;
                }

                // convert touched position to map coordinate
                var userTouch     = _recognizer.LocationInView(MapViewControl);
                var mapPoint      = MapViewControl.ConvertPoint(userTouch, MapViewControl);
                var newAnnotation = new ModeZoneAnnotation(mapPoint, true);

                // change the previous annotation to green
                var lastAnnotation = PointsOfZone.LastOrDefault();
                if (lastAnnotation != null)
                {
                    MapViewControl.RemoveAnnotation(lastAnnotation);
                    ((ModeZoneAnnotation)lastAnnotation).IsLastAnnotation = false;
                    MapViewControl.AddAnnotation(lastAnnotation);
                }

                // refresh the polygone
                List <LatitudeLongitude> zone = PointsOfZone.Select(el => new LatitudeLongitude(el.Coordinate.Latitude, el.Coordinate.Longitude)).ToList();
                zone.Add(new LatitudeLongitude(mapPoint.Latitude, mapPoint.Longitude));
                if (!App.Locator.ModeZone.CheckCorrectAreaFormat(zone))
                {
                    return;
                }

                var pointsToRestore = PointsOfZone.Select(el => el.Coordinate).ToList();
                PointsOfZone.Add(newAnnotation);

                MapViewControl.AddAnnotation(newAnnotation);

                var isInAlert = MapViewModelBase.Mode != null && MapViewModelBase.Mode.StatusDefinition_idstatusDefinition != 1;

                CreateZone(PointsOfZone.Select(s => new LatitudeLongitude(s.Coordinate.Latitude, s.Coordinate.Longitude)).ToList(), isInAlert, true, 0);
                RefreshZone();

                // reverse the action
                UndoActions.Add(new Action(() =>
                {
                    MapViewControl.RemoveAnnotation(newAnnotation);
                    PointsOfZone.Remove(PointsOfZone.Last());
                    var lastAnnotationUndo = PointsOfZone.LastOrDefault();
                    if (lastAnnotationUndo != null)
                    {
                        MapViewControl.RemoveAnnotation(lastAnnotationUndo);
                        ((ModeZoneAnnotation)lastAnnotationUndo).IsLastAnnotation = true;
                        MapViewControl.AddAnnotation(lastAnnotationUndo);
                    }
                    CreateZone(pointsToRestore.Select(s => new LatitudeLongitude(s.Latitude, s.Longitude)).ToList(), isInAlert, true, 0);
                    RefreshZone();
                    if (ZonePolygon == null || ZonePolygon.Points == null || PointsOfZone.Count() < 3)
                    {
                        _nextButton.Enabled = false;
                    }
                    else
                    {
                        _nextButton.Enabled = true;
                    }
                }));

                // if the zone contain 3 points, enable the next button
                if (PointsOfZone.Count < 3)
                {
                    _nextButton.Enabled = false;
                }
                else
                {
                    _nextButton.Enabled = true;
                }
            }
        }