public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation)
            {
                MKAnnotationView annotationView = null;

                if (annotation is PointAnnotation)
                {
                    Debug.WriteLine("it's a pin class");
                }
                else if (annotation is GeometryAnnotation)
                {
                    Debug.WriteLine("it's a line class");

                    GeometryAnnotation geometryAnnotation = annotation as GeometryAnnotation;

                    LinePolygonAnnotationView _annotationView = new LinePolygonAnnotationView(
                        new RectangleF(0, 0, mapView.Frame.Size.Width, mapView.Frame.Size.Height));
                    _annotationView.Annotation = geometryAnnotation;
                    _annotationView.MapView    = mapView;

                    _viewController.currentAnnotationView = _annotationView;
                    annotationView = _annotationView;
                }
                return(annotationView);
            }
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            UITouch aTouch = (UITouch)touches.AnyObject;
            PointF location = aTouch.LocationInView(this);
            Debug.WriteLine("TouchesBegan {0},{1}", location.X, location.Y);

            var coordinate = MapView.ConvertPoint (location, this);

            switch (geometry.Type)
            {
                case GeometryType.Point:
                    if (geometry.Count == 1)
                    {
                        var point = geometry[0];
                        MapView.RemoveAnnotation(point);
                        geometry.Remove(geometry[0]);

                        var newPoint = new PointAnnotation(coordinate);
                        geometry.Add(newPoint);
                        MapView.AddAnnotation(newPoint);
                    }
                    else
                    {
                        var point = new PointAnnotation(coordinate);
                        geometry.Add(point);
                        MapView.AddAnnotation(point);
                    }
                    break;
                case GeometryType.Line:
                    var _point = new PointAnnotation (coordinate);
                    geometry.Add(_point);

                    foreach (var a in annotationViewsArray)
                        MapView.RemoveAnnotation(a as MKAnnotation);
                    annotationViewsArray.Clear();

                    if (geometry.Count >= 2)
                    {
                        var _lineAnnotation = new GeometryAnnotation(geometry.Points, geometry.Type);
                        MapView.AddAnnotation(_lineAnnotation);
                        annotationViewsArray.Add(_lineAnnotation);
                    }
                    MapView.AddAnnotation(_point);
                    break;
                case GeometryType.Polygon:
                    var __point = new PointAnnotation (coordinate);
                    geometry.Add(__point);

                    foreach (var a in annotationViewsArray)
                        MapView.RemoveAnnotation(a as MKAnnotation);
                    annotationViewsArray.Clear();

                    if (geometry.Count == 2)
                    {
                        var _lineAnnotation = new GeometryAnnotation(geometry.Points, geometry.Type);
                        MapView.AddAnnotation(_lineAnnotation);
                        annotationViewsArray.Add(_lineAnnotation);
                    }
                    else
                    {
                        var _polygonAnnotation = new GeometryAnnotation(geometry.Points, geometry.Type);
                        MapView.AddAnnotation(_polygonAnnotation);
                        annotationViewsArray.Add(_polygonAnnotation);
                    }
                    MapView.AddAnnotation(__point);
                    break;
                default:
                    break;
            }
        }
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            UITouch aTouch   = (UITouch)touches.AnyObject;
            PointF  location = aTouch.LocationInView(this);

            Debug.WriteLine("TouchesBegan {0},{1}", location.X, location.Y);

            var coordinate = MapView.ConvertPoint(location, this);

            switch (geometry.Type)
            {
            case GeometryType.Point:
                if (geometry.Count == 1)
                {
                    var point = geometry[0];
                    MapView.RemoveAnnotation(point);
                    geometry.Remove(geometry[0]);

                    var newPoint = new PointAnnotation(coordinate);
                    geometry.Add(newPoint);
                    MapView.AddAnnotation(newPoint);
                }
                else
                {
                    var point = new PointAnnotation(coordinate);
                    geometry.Add(point);
                    MapView.AddAnnotation(point);
                }
                break;

            case GeometryType.Line:
                var _point = new PointAnnotation(coordinate);
                geometry.Add(_point);

                foreach (var a in annotationViewsArray)
                {
                    MapView.RemoveAnnotation(a as MKAnnotation);
                }
                annotationViewsArray.Clear();

                if (geometry.Count >= 2)
                {
                    var _lineAnnotation = new GeometryAnnotation(geometry.Points, geometry.Type);
                    MapView.AddAnnotation(_lineAnnotation);
                    annotationViewsArray.Add(_lineAnnotation);
                }
                MapView.AddAnnotation(_point);
                break;

            case GeometryType.Polygon:
                var __point = new PointAnnotation(coordinate);
                geometry.Add(__point);

                foreach (var a in annotationViewsArray)
                {
                    MapView.RemoveAnnotation(a as MKAnnotation);
                }
                annotationViewsArray.Clear();

                if (geometry.Count == 2)
                {
                    var _lineAnnotation = new GeometryAnnotation(geometry.Points, geometry.Type);
                    MapView.AddAnnotation(_lineAnnotation);
                    annotationViewsArray.Add(_lineAnnotation);
                }
                else
                {
                    var _polygonAnnotation = new GeometryAnnotation(geometry.Points, geometry.Type);
                    MapView.AddAnnotation(_polygonAnnotation);
                    annotationViewsArray.Add(_polygonAnnotation);
                }
                MapView.AddAnnotation(__point);
                break;

            default:
                break;
            }
        }
Example #4
0
            public override void Draw(RectangleF rect)
            {
                GeometryAnnotation myAnnotation = MainView.Annotation as GeometryAnnotation;

                // only draw our lines if we're not in the middle of a transition and we
                // acutally have some points to draw.
                if (!this.Hidden && myAnnotation.Points != null && myAnnotation.Points.Count > 0)
                {
                    CGContext context = UIGraphics.GetCurrentContext();
                    if (myAnnotation.LineColor != null)
                    {
                        myAnnotation.LineColor = UIColor.White;
                    }

                    context.SetStrokeColorWithColor(myAnnotation.LineColor.CGColor);

                    if (myAnnotation.Type == GeometryType.Polygon)
                    {
                        context.SetRGBFillColor(0.0f, 0.0f, 1.0f, 1.0f);
                    }

                    // Draw them with a 2.0 stroke width so they are a bit more visible
                    context.SetLineWidth(2.0f);

                    for (int idx = 0; idx < myAnnotation.Points.Count; idx++)
                    {
                        CLLocation location = myAnnotation.Points[idx];
                        PointF     point    = MainView.MapView.ConvertCoordinate(location.Coordinate, this);

                        //Debug.WriteLine("Point: {0}, {1}", point.X, point.Y);

                        if (idx == 0)
                        {
                            context.MoveTo(point.X, point.Y);
                        }
                        else
                        {
                            context.AddLineToPoint(point.X, point.Y);
                        }
                    }
                    if (myAnnotation.Type == GeometryType.Line)
                    {
                        context.StrokePath();
                    }
                    else if (myAnnotation.Type == GeometryType.Polygon)
                    {
                        context.ClosePath();
                        context.DrawPath(CGPathDrawingMode.FillStroke);
                    }

                    // debug. Draw the line around our view.

                    /*
                     * CGContextMoveToPoint(context, 0, 0);
                     * CGContextAddLineToPoint(context, 0, self.frame.size.height);
                     * CGContextAddLineToPoint(context, self.frame.size.width, self.frame.size.height);
                     * CGContextAddLineToPoint(context, self.frame.size.width, 0);
                     * CGContextAddLineToPoint(context, 0, 0);
                     * CGContextStrokePath(context);
                     */
                }
            }