Пример #1
0
 public void RemoveRouteAnnotation()
 {
     if (routeAnnotation != null)
     {
         mapView.RemoveAnnotation(routeAnnotation);
         routeAnnotation = null;
     }
 }
Пример #2
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(5.0f);
                    context.SetAlpha(0.40f);

                    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);
                     */
                }
            }
Пример #3
0
        public MapViewController()
            : base()
        {
            BuildView();

            NavigationItem.Title = "Map";

            segmentControl = new UISegmentedControl(new RectangleF(0,0,200,25));
            segmentControl.InsertSegment("Find bikes", 0, false);
            segmentControl.InsertSegment("Find docks", 1, false);
            segmentControl.SelectedSegment = 0;
            segmentControl.ControlStyle = UISegmentedControlStyle.Bar;
            segmentControl.ValueChanged += delegate(object sender, EventArgs e) {
                if (segmentControl.SelectedSegment == 0)
                {
                    CurrentDisplayMode = DisplayMode.Bikes;
                    Analytics.TrackEvent(Analytics.CATEGORY_ACTION, Analytics.ACTION_MAP_BIKES, "", 1);
                } else
                {
                    CurrentDisplayMode = DisplayMode.Docks;
                    Analytics.TrackEvent(Analytics.CATEGORY_ACTION, Analytics.ACTION_MAP_DOCKS, "", 1);
                }

                RefreshPinColours();

                BikeLocation.UpdateFromWebsite(delegate {
                        InvokeOnMainThread(delegate{
                            RefreshPinColours();
                            //RefreshData();
                        });
                    });
            };

            NavigationItem.TitleView = segmentControl;

            NavigationItem.LeftBarButtonItem = new UIBarButtonItem(Resources.Routing, UIBarButtonItemStyle.Bordered, delegate {

                //nulls, think about the nulls!

                if (!CLLocationManager.LocationServicesEnabled)
                {
                    alert = new UIAlertView("No Location Available", "Sorry, no location services are available. However, you may still be able to use the timer and map.", null, "Ok");
                    alert.Show();
                    return;
                }

                if (mapView.UserLocation == null || mapView.UserLocation.Location == null)
                {
                    alert = new UIAlertView("No Location Available", "Sorry, your location is not yet available.", null, "Ok");
                    alert.Show();
                    return;
                }

                NSObject[] selectedPins = mapView.SelectedAnnotations;

                if (selectedPins == null || selectedPins.Length > 1)
                {
                    alert = new UIAlertView("Select a dock", "Please pick a cycle docking station to route to.", null, "Ok");
                    alert.Show();
                    return;
                }

                if (selectedPins.Length == 1)
                {
                    CycleAnnotation ca = selectedPins[0] as CycleAnnotation;
                    if (ca != null)
                    {
                        HideDistanceView();

                        var location = mapView.UserLocation.Location.Coordinate;
            #if DEBUG
                    location = Locations.BanksideMix;
            #endif

                        double distance = BikeLocation.CalculateDistanceInMeters(location, ca.Coordinate);
                        if (distance > 50000)
                        {
                            alert = new UIAlertView("Sorry, your route is too long", "We can only plot cycle routes up to 50km.", null, "Ok");
                            alert.Show();

                            return;
                        }

                        loadingView = new ActivityIndicatorLoadingView();
                        loadingView.Show("Finding your route");
                        Util.TurnOnNetworkActivity();

                        RemoveRouteAnnotation();

                        ThreadPool.QueueUserWorkItem(delegate {

                            using (NSAutoreleasePool newPool = new NSAutoreleasePool())
                            {
                                location = mapView.UserLocation.Location.Coordinate;
            #if DEBUG
                    location = Locations.BanksideMix;
            #endif

                                MapRouting routing = new MapRouting(location, ca.Coordinate);

                                //routing.FindRoute(delegate {
                                routing.FindRoute(delegate {
                                    InvokeOnMainThread(delegate {
                                        //Console.WriteLine("updating");
                                        loadingView.Hide();
                                        Util.TurnOffNetworkActivity();
                                        if (routing.HasRoute)
                                        {

                                            routeAnnotation = new CSRouteAnnotation(routing.PointsList);
                                            mapView.AddAnnotation(routeAnnotation);

                                            var region = routeAnnotation.Region;

                                            region.Span = new MKCoordinateSpan(region.Span.LatitudeDelta * 1.1f, region.Span.LongitudeDelta * 1.1f);

                                            mapView.SetRegion(region, true);

                                            //need to animate the distance etc here.

                                            ShowDistanceView(routing.DistanceForDisplay, routing.TimeForDisplay);

                                            BikeLocation.LogRoute();

                                        } else {
                                            alert = new UIAlertView("No route found", "Sorry, no route could be found or the route is too long.", null, "Ok");
                                            alert.Show();

                                        }
                                    });
                                });

                            }

                        });

                    }
                }
            });

            //NavigationController.NavigationBar.TintColor = Resources.DarkBlue;
            gpsButton = new UIBarButtonItem(Resources.Gps, UIBarButtonItemStyle.Bordered, delegate {

                if (!CLLocationManager.LocationServicesEnabled)
                {
                    alert = new UIAlertView("No Location Available", "Sorry, no location services are available. However, you may still be able to use the timer and map.", null, "Ok");
                    alert.Show();
                    return;
                }

                if (mapView.UserLocation != null)
                {
                    if (mapView.UserLocation.Location != null)
                    {
                        //NavigationItem.RightBarButtonItem = activityButton;

                        BikeLocation.UpdateFromWebsite(delegate {
                        InvokeOnMainThread(delegate{
                                RefreshPinColours();
                                //NavigationItem.RightBarButtonItem = gpsButton;
                            });
                        });

                        CLLocationCoordinate2D location = mapView.UserLocation.Location.Coordinate;
            #if DEBUG
                    location = Locations.BanksideMix;
            #endif
                        MKCoordinateRegion region = new MKCoordinateRegion(location, new MKCoordinateSpan(0.01, 0.01));

                        region = mapView.RegionThatFits(region);
                        mapView.SetRegion(region, true);

                    }
                }
            });

            NavigationItem.RightBarButtonItem = gpsButton;
        }
Пример #4
0
 public void RemoveRouteAnnotation()
 {
     if (routeAnnotation != null)
     {
         mapView.RemoveAnnotation(routeAnnotation);
         routeAnnotation = null;
     }
 }
Пример #5
0
        public MapViewController() : base()
        {
            BuildView();

            NavigationItem.Title = "Map";



            segmentControl = new UISegmentedControl(new RectangleF(0, 0, 200, 25));
            segmentControl.InsertSegment("Find bikes", 0, false);
            segmentControl.InsertSegment("Find docks", 1, false);
            segmentControl.SelectedSegment = 0;
            segmentControl.ControlStyle    = UISegmentedControlStyle.Bar;
            segmentControl.ValueChanged   += delegate(object sender, EventArgs e) {
                if (segmentControl.SelectedSegment == 0)
                {
                    CurrentDisplayMode = DisplayMode.Bikes;
                    Analytics.TrackEvent(Analytics.CATEGORY_ACTION, Analytics.ACTION_MAP_BIKES, "", 1);
                }
                else
                {
                    CurrentDisplayMode = DisplayMode.Docks;
                    Analytics.TrackEvent(Analytics.CATEGORY_ACTION, Analytics.ACTION_MAP_DOCKS, "", 1);
                }

                RefreshPinColours();

                BikeLocation.UpdateFromWebsite(delegate {
                    InvokeOnMainThread(delegate {
                        RefreshPinColours();
                        //RefreshData();
                    });
                });
            };


            NavigationItem.TitleView = segmentControl;


            NavigationItem.LeftBarButtonItem = new UIBarButtonItem(Resources.Routing, UIBarButtonItemStyle.Bordered, delegate {
                //nulls, think about the nulls!

                if (!CLLocationManager.LocationServicesEnabled)
                {
                    alert = new UIAlertView("No Location Available", "Sorry, no location services are available. However, you may still be able to use the timer and map.", null, "Ok");
                    alert.Show();
                    return;
                }

                if (mapView.UserLocation == null || mapView.UserLocation.Location == null)
                {
                    alert = new UIAlertView("No Location Available", "Sorry, your location is not yet available.", null, "Ok");
                    alert.Show();
                    return;
                }



                NSObject[] selectedPins = mapView.SelectedAnnotations;

                if (selectedPins == null || selectedPins.Length > 1)
                {
                    alert = new UIAlertView("Select a dock", "Please pick a cycle docking station to route to.", null, "Ok");
                    alert.Show();
                    return;
                }



                if (selectedPins.Length == 1)
                {
                    CycleAnnotation ca = selectedPins[0] as CycleAnnotation;
                    if (ca != null)
                    {
                        HideDistanceView();

                        var location = mapView.UserLocation.Location.Coordinate;
#if DEBUG
                        location = Locations.BanksideMix;
#endif

                        double distance = BikeLocation.CalculateDistanceInMeters(location, ca.Coordinate);
                        if (distance > 50000)
                        {
                            alert = new UIAlertView("Sorry, your route is too long", "We can only plot cycle routes up to 50km.", null, "Ok");
                            alert.Show();


                            return;
                        }



                        loadingView = new ActivityIndicatorLoadingView();
                        loadingView.Show("Finding your route");
                        Util.TurnOnNetworkActivity();


                        RemoveRouteAnnotation();



                        ThreadPool.QueueUserWorkItem(delegate {
                            using (NSAutoreleasePool newPool = new NSAutoreleasePool())
                            {
                                location = mapView.UserLocation.Location.Coordinate;
#if DEBUG
                                location = Locations.BanksideMix;
#endif

                                MapRouting routing = new MapRouting(location, ca.Coordinate);



                                //routing.FindRoute(delegate {
                                routing.FindRoute(delegate {
                                    InvokeOnMainThread(delegate {
                                        //Console.WriteLine("updating");
                                        loadingView.Hide();
                                        Util.TurnOffNetworkActivity();
                                        if (routing.HasRoute)
                                        {
                                            routeAnnotation = new CSRouteAnnotation(routing.PointsList);
                                            mapView.AddAnnotation(routeAnnotation);

                                            var region = routeAnnotation.Region;

                                            region.Span = new MKCoordinateSpan(region.Span.LatitudeDelta * 1.1f, region.Span.LongitudeDelta * 1.1f);


                                            mapView.SetRegion(region, true);


                                            //need to animate the distance etc here.


                                            ShowDistanceView(routing.DistanceForDisplay, routing.TimeForDisplay);

                                            BikeLocation.LogRoute();
                                        }
                                        else
                                        {
                                            alert = new UIAlertView("No route found", "Sorry, no route could be found or the route is too long.", null, "Ok");
                                            alert.Show();
                                        }
                                    });
                                });
                            }
                        });
                    }
                }
            });

            //NavigationController.NavigationBar.TintColor = Resources.DarkBlue;
            gpsButton = new UIBarButtonItem(Resources.Gps, UIBarButtonItemStyle.Bordered, delegate {
                if (!CLLocationManager.LocationServicesEnabled)
                {
                    alert = new UIAlertView("No Location Available", "Sorry, no location services are available. However, you may still be able to use the timer and map.", null, "Ok");
                    alert.Show();
                    return;
                }

                if (mapView.UserLocation != null)
                {
                    if (mapView.UserLocation.Location != null)
                    {
                        //NavigationItem.RightBarButtonItem = activityButton;

                        BikeLocation.UpdateFromWebsite(delegate {
                            InvokeOnMainThread(delegate {
                                RefreshPinColours();
                                //NavigationItem.RightBarButtonItem = gpsButton;
                            });
                        });

                        CLLocationCoordinate2D location = mapView.UserLocation.Location.Coordinate;
#if DEBUG
                        location = Locations.BanksideMix;
#endif
                        MKCoordinateRegion region = new MKCoordinateRegion(location, new MKCoordinateSpan(0.01, 0.01));

                        region = mapView.RegionThatFits(region);
                        mapView.SetRegion(region, true);
                    }
                }
            });


            NavigationItem.RightBarButtonItem = gpsButton;
        }