Beispiel #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            RouteViews = new Dictionary <string, CSRouteView>();

            // load the points from local resource (file)
            var filePath     = NSBundle.MainBundle.PathForResource("route", "csv", "MapLineSharp", "");
            var fileContents = System.IO.File.ReadAllText(filePath);
            var pointStrings = fileContents.Split('\n');

            var points = new List <CLLocation>();

            foreach (var ps in pointStrings)
            {
                // break the string down into latitude and longitude fields
                var        latLonArr       = ps.Split(',');
                double     latitude        = Convert.ToDouble(latLonArr[0]);
                double     longitude       = Convert.ToDouble(latLonArr[1]);
                CLLocation currentLocation = new CLLocation(latitude, longitude);
                points.Add(currentLocation);
            }
            //
            // Create our map view and add it as as subview.
            //
            _mapView       = new MKMapView();
            _mapView.Frame = new RectangleF(0, 0, this.View.Frame.Width, this.View.Frame.Height);
            View.AddSubview(_mapView);
            _mapView.Delegate = new MapViewDelegate(this);


            // CREATE THE ANNOTATIONS AND ADD THEM TO THE MAP

            // first create the route annotation
            CSRouteAnnotation routeAnnotation = new CSRouteAnnotation(points);

            _mapView.AddAnnotation(routeAnnotation);

            CSMapAnnotation annotation = null;

            annotation = new CSMapAnnotation(points[0].Coordinate, CSMapAnnotationType.Start, "Start Point");
            _mapView.AddAnnotation(annotation);

            annotation = new CSMapAnnotation(points[points.Count - 1].Coordinate, CSMapAnnotationType.End, "End Point");
            _mapView.AddAnnotation(annotation);

            //TODO:create the image annotation

            _mapView.SetRegion(routeAnnotation.Region, false);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            RouteViews = new Dictionary<string,CSRouteView>();

            // load the points from local resource (file)
            var filePath = NSBundle.MainBundle.PathForResource("route", "csv", "MapLineSharp","");
            var fileContents = System.IO.File.ReadAllText(filePath);
            var pointStrings = fileContents.Split('\n');

            var points = new List<CLLocation>();

            foreach (var ps in pointStrings)
            {
                // break the string down into latitude and longitude fields
                var latLonArr = ps.Split(',');
                double latitude = Convert.ToDouble(latLonArr[0]);
                double longitude = Convert.ToDouble(latLonArr[1]);
                CLLocation currentLocation = new CLLocation(latitude, longitude);
                points.Add(currentLocation);
            }
            //
            // Create our map view and add it as as subview.
            //
            _mapView = new MKMapView();
            _mapView.Frame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height);
            View.AddSubview(_mapView);
            _mapView.Delegate = new MapViewDelegate(this);

            // CREATE THE ANNOTATIONS AND ADD THEM TO THE MAP

            // first create the route annotation
            CSRouteAnnotation routeAnnotation = new CSRouteAnnotation(points);
            _mapView.AddAnnotation(routeAnnotation);

            CSMapAnnotation annotation = null;

            annotation = new CSMapAnnotation (points[0].Coordinate, CSMapAnnotationType.Start, "Start Point");
            _mapView.AddAnnotation (annotation);

            annotation = new CSMapAnnotation (points[points.Count - 1].Coordinate, CSMapAnnotationType.End, "End Point");
            _mapView.AddAnnotation (annotation);

            //TODO:create the image annotation

            _mapView.SetRegion (routeAnnotation.Region, false);
        }
Beispiel #3
0
            public override void Draw(RectangleF rect)
            {
                CSRouteAnnotation routeAnnotation = RouteView.Annotation as CSRouteAnnotation;

                if (!this.Hidden && routeAnnotation.Points != null && routeAnnotation.Points.Count > 0)
                {
                    CGContext context = UIGraphics.GetCurrentContext();
                    if (routeAnnotation.LineColor != null)
                    {
                        routeAnnotation.LineColor = UIColor.Blue;
                    }

                    context.SetStrokeColorWithColor(routeAnnotation.LineColor.CGColor);
                    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 < routeAnnotation.Points.Count; idx++)
                    {
                        CLLocation location = routeAnnotation.Points[idx];
                        PointF     point    = RouteView.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);
                        }
                    }
                    context.StrokePath();

                    // 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);
                     */
                }
            }