Exemple #1
0
        /// <summary>
        /// Load the map data from the properties retreived
        /// </summary>
        private void LoadMapData()
        {
            // value to determin where to zoom in
            var topLeft     = new CLLocationCoordinate2D(-90, 180);
            var bottomRight = new CLLocationCoordinate2D(90, -180);

            // loop through all the properties and add them to the list
            foreach (var item in Properties)
            {
                // create the pin and add the annoation
                var pin = new HeritagePropertyAnnotation(item);
                _mapView.AddAnnotation(pin);

                // determin the topleft and right
                topLeft.Longitude     = Math.Min(topLeft.Longitude, pin.Coordinate.Longitude);
                topLeft.Latitude      = Math.Max(topLeft.Latitude, pin.Coordinate.Latitude);
                bottomRight.Longitude = Math.Max(bottomRight.Longitude, pin.Coordinate.Longitude);
                bottomRight.Latitude  = Math.Min(bottomRight.Latitude, pin.Coordinate.Latitude);
            }

            // zoom in on the annotations
            var region = new MKCoordinateRegion();

            region.Center = new CLLocationCoordinate2D(
                topLeft.Latitude - (topLeft.Latitude - bottomRight.Latitude) * 0.5,
                topLeft.Longitude + (bottomRight.Longitude - topLeft.Longitude) * 0.5);
            region.Span.LatitudeDelta  = Math.Abs(topLeft.Latitude - bottomRight.Latitude) * 1.1;
            region.Span.LongitudeDelta = Math.Abs(bottomRight.Longitude - topLeft.Longitude) * 1.1;

            // set the region
            region = _mapView.RegionThatFits(region);
            _mapView.SetRegion(region, true);
        }
Exemple #2
0
            public void ShowUserAndDestinationOnMap()
            {
                var maxLat = Math.Max(_userLocation.Latitude, _destination.Latitude);
                var maxLon = Math.Max(_userLocation.Longitude, _destination.Longitude);
                var minLat = Math.Min(_userLocation.Latitude, _destination.Latitude);
                var minLon = Math.Min(_userLocation.Longitude, _destination.Longitude);

                var mapMargin      = 1.5;
                var leastCoordspan = 0.005;
                var span_x         = Math.Max(leastCoordspan, Math.Abs(maxLat - minLat) * mapMargin);
                var span_y         = Math.Max(leastCoordspan, Math.Abs(maxLon - minLon) * mapMargin);

                var span = new MKCoordinateSpan(span_x, span_y);

                var center = new CLLocationCoordinate2D((maxLat + minLat) / 2, (maxLon + minLon) / 2);
                var region = new MKCoordinateRegion(center, span);

                _mapView.SetRegion(_mapView.RegionThatFits(region), true);
            }
        //zoom
        public void ZoomIn()
        {
            //Zoom in

            // user location
            var userCoord = new CLLocationCoordinate2D {
                Latitude = _userLocation.Latitude, Longitude = _userLocation.Longitude
            };
            // tracking location
            var trackCoord = new CLLocationCoordinate2D {
                Latitude = _trackCoordinate.Latitude, Longitude = _trackCoordinate.Longitude
            };

            List <CLLocationCoordinate2D> annotations = new List <CLLocationCoordinate2D> ();

            annotations.Add(userCoord);
            annotations.Add(trackCoord);

            var tl = new CLLocationCoordinate2D(-90, 180);
            //top left
            var br = new CLLocationCoordinate2D(90, -180);

            //bottom right
            foreach (var anno in annotations)
            {
                tl.Longitude = Math.Min(tl.Longitude, anno.Longitude);
                tl.Latitude  = Math.Max(tl.Latitude, anno.Latitude);
                br.Longitude = Math.Max(br.Longitude, anno.Longitude);
                br.Latitude  = Math.Min(br.Latitude, anno.Latitude);
            }
            var center = new CLLocationCoordinate2D {
                Latitude = tl.Latitude - (tl.Latitude - br.Latitude) * 0.5, Longitude = tl.Longitude + (br.Longitude - tl.Longitude) * 0.5
            };
            var span = new MKCoordinateSpan {
                LatitudeDelta = Math.Abs(tl.Latitude - br.Latitude) * 1.6, LongitudeDelta = Math.Abs(br.Longitude - tl.Longitude) * 1.6
            };
            var region = new MKCoordinateRegion {
                Center = center, Span = span
            };

            region = _mapView.RegionThatFits(region);
            _mapView.SetRegion(region, true);
        }
        public void BuildView()
        {
            if (mapView == null)
            {

                mapView = new MKMapView();
                RectangleF frame = new RectangleF(0,0,320,367);

                mapView.Frame = frame;

                DV = new DistanceView();

                frame = DV.View.Frame;
                //frame.Y = mapView.Frame.Bottom;
                frame.Y = -DV.View.Frame.Height;

                DV.View.Frame = frame;

                DV.TouchUpInside += delegate(object sender, EventArgs e) {

                    RemoveRouteAnnotation();

                    HideDistanceView();
                };

                mapView.RegionWillChange += delegate(object sender, MKMapViewChangeEventArgs e) {
                    if (routeView != null)
                    {
                        routeView.Hidden = true;
                    }
                };

                mapView.RegionChanged += delegate(object sender, MKMapViewChangeEventArgs e) {
                    if (routeView != null)
                    {
                        routeView.Hidden = false;
                        routeView.RegionChanged();
                    }
                };

                mapView.GetViewForAnnotation = delegate(MKMapView mapViewForAnnotation, NSObject annotation) {
                    if (annotation is MKUserLocation) return null;

                    if (annotation is CycleAnnotation)
                    {
                        var mapAnnotation = annotation as CycleAnnotation;
                        if (mapAnnotation == null) return null;

                        MKPinAnnotationView pinView = (MKPinAnnotationView)mapViewForAnnotation.DequeueReusableAnnotation(MapPin);
                        if (pinView == null)
                        {
                            pinView = new MKPinAnnotationView(mapAnnotation, MapPin);
                        } else {
                            pinView.Annotation = annotation;
                        }

                        int valueToCheck = 0;
                        if (CurrentDisplayMode == DisplayMode.Bikes)
                        {
                            valueToCheck = mapAnnotation.Bike.BikesAvailable;
                        } else {
                            valueToCheck = mapAnnotation.Bike.DocksAvailable;
                        }

                        if ((valueToCheck < 5 && valueToCheck != -1)) {
                            if (valueToCheck == 0)
                            {
                                pinView.PinColor = MKPinAnnotationColor.Red;
                            } else {
                                pinView.PinColor = MKPinAnnotationColor.Purple;
                            }
                        } else {
                            pinView.PinColor = MKPinAnnotationColor.Green;
                        }

                        mapAnnotation.PinView = pinView;

                        pinView.CanShowCallout = true;
                        return pinView;
                    }

                    if (annotation is CSRouteAnnotation)
                    {
                        var routeAnnotation = annotation as CSRouteAnnotation;
                        MKAnnotationView annotationView = null;

                        if (annotationView == null)
                        {
                            routeView = new CSRouteView(new RectangleF (0,0, mapView.Frame.Size.Width, mapView.Frame.Size.Height));
                            routeView.Annotation = routeAnnotation;
                            routeView.MapView = mapViewForAnnotation;
                            annotationView = routeView;
                        }

                        return annotationView;
                    }

                    return null;

                };

                List<MKAnnotation> locations = new List<MKAnnotation>();

                double minLon = 200, minLat = 200, maxLon = -200, maxLat = -200;

                foreach(var bike in BikeLocation.AllBikes)
                {
                    if (bike.Location.Longitude < minLon) minLon = bike.Location.Longitude;
                    if (bike.Location.Latitude < minLat) minLat = bike.Location.Latitude;

                    if (bike.Location.Longitude < maxLon) maxLon = bike.Location.Longitude;
                    if (bike.Location.Latitude > maxLat) maxLat = bike.Location.Latitude;

                    locations.Add(new CycleAnnotation(bike));
                }

                if (locations.Count > 0)
                {
                    mapView.AddAnnotation(locations.ToArray());

                    var tl = new CLLocationCoordinate2D(-90, 180);
                    var br = new CLLocationCoordinate2D(90, -180);

                    foreach(MKAnnotation an in mapView.Annotations)
                    {
                        tl.Longitude = Math.Min(tl.Longitude, an.Coordinate.Longitude);
                        tl.Latitude = Math.Max(tl.Latitude, an.Coordinate.Latitude);

                        br.Longitude = Math.Max(br.Longitude, an.Coordinate.Longitude);
                        br.Latitude = Math.Min(br.Latitude, an.Coordinate.Latitude);

                    }

                    var center = new CLLocationCoordinate2D {
                        Latitude = tl.Latitude - (tl.Latitude - br.Latitude) *0.5,
                        Longitude = tl.Longitude - (tl.Longitude - br.Longitude) *0.5
                    };

                    var span = new MKCoordinateSpan
                    {
                        LatitudeDelta = Math.Abs(tl.Latitude - br.Latitude) *0.5,
                        LongitudeDelta = Math.Abs(tl.Longitude - br.Longitude) *0.5

                    };

                    MKCoordinateRegion region = new MKCoordinateRegion (center, span );

                    region = mapView.RegionThatFits(region);

                    mapView.SetRegion(region, true);
                }

                mapView.ShowsUserLocation = true;

                View.AddSubview(mapView);
            }
        }
Exemple #5
0
        public void BuildView()
        {
            if (mapView == null)
            {
                mapView = new MKMapView();
                RectangleF frame = new RectangleF(0, 0, 320, 367);

                mapView.Frame = frame;



                DV = new DistanceView();

                frame = DV.View.Frame;
                //frame.Y = mapView.Frame.Bottom;
                frame.Y = -DV.View.Frame.Height;


                DV.View.Frame = frame;

                DV.TouchUpInside += delegate(object sender, EventArgs e) {
                    RemoveRouteAnnotation();

                    HideDistanceView();
                };

                mapView.RegionWillChange += delegate(object sender, MKMapViewChangeEventArgs e) {
                    if (routeView != null)
                    {
                        routeView.Hidden = true;
                    }
                };

                mapView.RegionChanged += delegate(object sender, MKMapViewChangeEventArgs e) {
                    if (routeView != null)
                    {
                        routeView.Hidden = false;
                        routeView.RegionChanged();
                    }
                };

                mapView.GetViewForAnnotation = delegate(MKMapView mapViewForAnnotation, NSObject annotation) {
                    if (annotation is MKUserLocation)
                    {
                        return(null);
                    }

                    if (annotation is CycleAnnotation)
                    {
                        var mapAnnotation = annotation as CycleAnnotation;
                        if (mapAnnotation == null)
                        {
                            return(null);
                        }


                        MKPinAnnotationView pinView = (MKPinAnnotationView)mapViewForAnnotation.DequeueReusableAnnotation(MapPin);
                        if (pinView == null)
                        {
                            pinView = new MKPinAnnotationView(mapAnnotation, MapPin);
                        }
                        else
                        {
                            pinView.Annotation = annotation;
                        }



                        int valueToCheck = 0;
                        if (CurrentDisplayMode == DisplayMode.Bikes)
                        {
                            valueToCheck = mapAnnotation.Bike.BikesAvailable;
                        }
                        else
                        {
                            valueToCheck = mapAnnotation.Bike.DocksAvailable;
                        }

                        if ((valueToCheck < 5 && valueToCheck != -1))
                        {
                            if (valueToCheck == 0)
                            {
                                pinView.PinColor = MKPinAnnotationColor.Red;
                            }
                            else
                            {
                                pinView.PinColor = MKPinAnnotationColor.Purple;
                            }
                        }
                        else
                        {
                            pinView.PinColor = MKPinAnnotationColor.Green;
                        }

                        mapAnnotation.PinView = pinView;


                        pinView.CanShowCallout = true;
                        return(pinView);
                    }

                    if (annotation is CSRouteAnnotation)
                    {
                        var routeAnnotation             = annotation as CSRouteAnnotation;
                        MKAnnotationView annotationView = null;


                        if (annotationView == null)
                        {
                            routeView            = new CSRouteView(new RectangleF(0, 0, mapView.Frame.Size.Width, mapView.Frame.Size.Height));
                            routeView.Annotation = routeAnnotation;
                            routeView.MapView    = mapViewForAnnotation;
                            annotationView       = routeView;
                        }

                        return(annotationView);
                    }

                    return(null);
                };



                List <MKAnnotation> locations = new List <MKAnnotation>();

                double minLon = 200, minLat = 200, maxLon = -200, maxLat = -200;


                foreach (var bike in BikeLocation.AllBikes)
                {
                    if (bike.Location.Longitude < minLon)
                    {
                        minLon = bike.Location.Longitude;
                    }
                    if (bike.Location.Latitude < minLat)
                    {
                        minLat = bike.Location.Latitude;
                    }

                    if (bike.Location.Longitude < maxLon)
                    {
                        maxLon = bike.Location.Longitude;
                    }
                    if (bike.Location.Latitude > maxLat)
                    {
                        maxLat = bike.Location.Latitude;
                    }

                    locations.Add(new CycleAnnotation(bike));
                }



                if (locations.Count > 0)
                {
                    mapView.AddAnnotation(locations.ToArray());



                    var tl = new CLLocationCoordinate2D(-90, 180);
                    var br = new CLLocationCoordinate2D(90, -180);

                    foreach (MKAnnotation an in mapView.Annotations)
                    {
                        tl.Longitude = Math.Min(tl.Longitude, an.Coordinate.Longitude);
                        tl.Latitude  = Math.Max(tl.Latitude, an.Coordinate.Latitude);

                        br.Longitude = Math.Max(br.Longitude, an.Coordinate.Longitude);
                        br.Latitude  = Math.Min(br.Latitude, an.Coordinate.Latitude);
                    }

                    var center = new CLLocationCoordinate2D {
                        Latitude  = tl.Latitude - (tl.Latitude - br.Latitude) * 0.5,
                        Longitude = tl.Longitude - (tl.Longitude - br.Longitude) * 0.5
                    };

                    var span = new MKCoordinateSpan
                    {
                        LatitudeDelta  = Math.Abs(tl.Latitude - br.Latitude) * 0.5,
                        LongitudeDelta = Math.Abs(tl.Longitude - br.Longitude) * 0.5
                    };



                    MKCoordinateRegion region = new MKCoordinateRegion(center, span);


                    region = mapView.RegionThatFits(region);

                    mapView.SetRegion(region, true);
                }

                mapView.ShowsUserLocation = true;


                View.AddSubview(mapView);
            }
        }