Ejemplo n.º 1
0
 public void DrawPolyline(MKPolyline polygon,MKMapRect mapRect, float zoomScale, CGContext context)
 {
     CGPath path = this.polyPath (polygon,mapRect,zoomScale,context);
     if (path != null)
     {
         this.ApplyFillProperties (context, zoomScale);
         context.BeginPath ();
         context.AddPath (path);
         context.DrawPath (CGPathDrawingMode.Stroke);
         this.ApplyStrokeProperties (context, zoomScale);
         context.BeginPath ();
         context.AddPath (path);
         context.StrokePath ();
     }
 }
Ejemplo n.º 2
0
        public void SelectedAnnotations_BackingFields()
        {
            if (MapViewPoker.NewRefcountEnabled())
            {
                Assert.Inconclusive("backing fields are removed when newrefcount is enabled");
            }

#if !MONOMAC
            if (TestRuntime.CheckSystemVersion(ApplePlatform.iOS, 7, 0))
            {
                // This test selects annotations on a map view, but according to apple's docs
                // and a lot of googling this will not necessarily work until the map view is
                // show. Since we can't relinquish control of the UI thread, we have no option
                // but ignoring this test. For now I've only seen it fail on iOS 7 DP4.
                Assert.Inconclusive("This test is not deterministic on iOS7 DP4.");
            }
#endif

            using (var a = new MKCircle())                      // MKAnnotation is abstract
                using (var o1 = new MKPolygon())                // it must export 'coordinate' or this will fail
                    using (var o2 = new MKPolyline())
                        using (var mv = new MapViewPoker()) {
                            Assert.Null(mv.SelectedAnnotationsBackingField, "1a");
                            Assert.Null(mv.SelectedAnnotations, "1b");      // not an empty array

                            mv.SelectAnnotation(a, false);
                            Assert.AreSame(a, mv.SelectedAnnotationsBackingField [0], "2a");
                            Assert.AreSame(a, mv.SelectedAnnotations [0], "2b");

                            // sanity
                            Assert.Null(mv.AnnotationsBackingField, "3a");
                            Assert.That(mv.Annotations, Is.Empty, "3b");

                            mv.SelectedAnnotations = new IMKAnnotation[] { o1, o2 };
                            // note: when assigning the property only the first item is selected (by design)
                            // so we're not exactly backing up correctly (we still hold 'o2')
                            // OTOH we do not want to recursively [PostGet] the same property (unless handled by the generator)
                            Assert.That(mv.SelectedAnnotationsBackingField.Length, Is.EqualTo(2), "4a");
                            Assert.That(mv.SelectedAnnotations.Length, Is.EqualTo(1), "4b");

                            mv.DeselectAnnotation(o1, false);
                            // since only 'o1' was really selected, unselecting it will return null
                            Assert.Null(mv.SelectedAnnotationsBackingField, "5a");
                            Assert.Null(mv.SelectedAnnotations, "5b");      // not an empty array
                        }
        }
Ejemplo n.º 3
0
        private async void OverlayNewRoute(Rider rider)
        {
            this.MapView.RemoveOverlay(this.firstRoute);

            //rider.Position
            var pickupPoint = new Position();

            pickupPoint.Latitude  = rider.Lat;
            pickupPoint.Longitude = rider.Lon;

            var routeResult = await Ride2GoService.GetRoute(this.driverPosition, this.destinationPosition, pickupPoint);

            this.MapView.AddOverlay(MKPolyline.FromCoordinates(routeResult.Locations));
            var annotation = new BasicMapAnnotation(new CLLocationCoordinate2D(rider.Lat, rider.Lon), rider.Name);

            this.MapView.AddAnnotation(annotation);
        }
Ejemplo n.º 4
0
        async void ShowPath()
        {
            var inputController = new InputDataController();
            var data            = await inputController.GetListAsync(_jsonResult);

            var locations = new List <CLLocationCoordinate2D>();


            foreach (var item in data)
            {
                locations.Add(new CLLocationCoordinate2D()
                {
                    Latitude = item.Latitude, Longitude = item.Longitude
                });
            }
            MapView.RemoveAnnotations(MapView.Annotations);
            if (locations.Count > 0)
            {
                var polyline = MKPolyline.FromCoordinates(locations.ToArray());
                MapView.AddOverlay(polyline);

                var startLocation = new CLLocation(locations[0].Latitude,
                                                   locations[0].Longitude);
                var endLocation = new CLLocation(locations.Last().Latitude,
                                                 locations.Last().Longitude);
                var distance = startLocation.DistanceFrom(endLocation);


                var region = MKCoordinateRegion.FromDistance(locations[(locations.Count / 2)],
                                                             distance + 10000, distance + 10000);
                MapView.SetRegion(region, animated: false);

                var annoStart = new FlightAnnotation(title: "Starting point",
                                                     subtitle: "",
                                                     coordinate: locations[0]);
                MapView.AddAnnotation(annoStart);


                var annoEnd = new FlightAnnotation(title: "End point",
                                                   subtitle: "",
                                                   coordinate: locations.Last());
                annoEnd.TintColor = UIColor.Purple;

                MapView.AddAnnotation(annoEnd);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// React to changes in the route.
        /// </summary>
        /// <param name="route">The route that changed</param>
        private void OnDetailsRouteChanged(Route route)
        {
            if (route != null && osmMap.ShowDetailsRoute)
            {
                IList <CLLocationCoordinate2D> waypoints = new List <CLLocationCoordinate2D> ();

                // add user location and route locations
                if (osmMap.GpsLocation != null)
                {
                    waypoints.Add(new CLLocationCoordinate2D(osmMap.GpsLocation.Latitude, osmMap.GpsLocation.Longitude));
                }
                waypoints = waypoints.Concat(route.Waypoints.Select(waypoint => new CLLocationCoordinate2D(waypoint.Location.Latitude, waypoint.Location.Longitude))).ToList();

                var polyline = MKPolyline.FromCoordinates(waypoints.ToArray());
                Control.AddOverlay(polyline);
            }
        }
Ejemplo n.º 6
0
        public void setCoordinate_Selector()
        {
            MKPolyline pl = MKPolyline.FromPoints(new MKMapPoint [] { });

            try {
                pl.Coordinate = new CLLocationCoordinate2D(10, 20);
            }
#if NET
            catch (ObjCException mte) {
#else
            catch (MonoTouchException mte) {
#endif
                Assert.True(mte.Message.Contains("unrecognized selector sent to instance"));
            }
            catch {
                Assert.Fail("API could be working/implemented");
            }
        }
Ejemplo n.º 7
0
        public override void TouchesEnded(NSSet touches, UIEvent evt)
        {
            base.TouchesEnded(touches, evt);

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

            pointlist.ForEach(Point =>
            {
                CoordinateList.Add(MapView.ConvertPoint(Point, MapView));
            });

            if (CoordinateList.Count > 0)
            {
                MapView.AddOverlay(MKPolyline.FromCoordinates(CoordinateList.ToArray()));
            }

            pointlist = new List <CGPoint>();
        }
Ejemplo n.º 8
0
        MKPolyline CreatePolyline(List <Plugin.Geolocator.Abstractions.Position> useList)
        {
            CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[useList.Count];
            MKPolyline routeOverlay         = new MKPolyline();

            if (useList.Count > 1)
            {
                int index = 0;
                foreach (var position in useList)
                {
                    coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                    index++;
                }
                routeOverlay = MKPolyline.FromCoordinates(coords);
            }

            return(routeOverlay);
        }
        private void AddtoPolylineCoordinates(List <Position> TempNewLatLong)
        {
            newRouteCoordinates = new CLLocationCoordinate2D[TempNewLatLong.Count];

            int index = 0;

            foreach (var Item in TempNewLatLong)
            {
                newRouteCoordinates[index] = new CLLocationCoordinate2D(Item.Latitude, Item.Longitude);
                index++;
            }

            nativeMap.OverlayRenderer = GetOverlayRenderer;

            var NewOverlay = MKPolyline.FromCoordinates(newRouteCoordinates);

            nativeMap.AddOverlay(NewOverlay);
        }
Ejemplo n.º 10
0
        void GetPath()
        {
            var locations   = new List <CLLocationCoordinate2D>();
            var appDelegate = UIApplication.SharedApplication.Delegate as AppDelegate;
            var data        = appDelegate.ProfileData;

            foreach (var item in data)
            {
                locations.Add(new CLLocationCoordinate2D()
                {
                    Latitude = item.Latitude, Longitude = item.Longitude
                });
            }

            if (locations.Count > 0)
            {
                var polyline = MKPolyline.FromCoordinates(locations.ToArray());
                mapView.AddOverlay(polyline);

                var startLocation = new CLLocation(locations[0].Latitude,
                                                   locations[0].Longitude);
                var endLocation = new CLLocation(locations.Last().Latitude,
                                                 locations.Last().Longitude);
                var distance = startLocation.DistanceFrom(endLocation);


                var region = MKCoordinateRegion.FromDistance(locations[(locations.Count / 2)],
                                                             distance + 10000, distance + 10000);
                mapView.SetRegion(region, animated: false);

                var annoStart = new FlightAnnotation(title: "Starting Point".GetLocalString(),
                                                     subtitle: "",
                                                     coordinate: locations[0]);
                mapView.AddAnnotation(annoStart);


                var annoEnd = new FlightAnnotation(title: "End Point".GetLocalString(),
                                                   subtitle: "",
                                                   coordinate: locations.Last());
                annoEnd.TintColor = UIColor.Purple;

                mapView.AddAnnotation(annoEnd);
            }
        }
Ejemplo n.º 11
0
        private async void OnDidSelectAnnotationViewAsync(object sender, MKAnnotationViewEventArgs e)
        {
            var nativeMap = Control as MKMapView;

            // Get user's location
            var userLocation = nativeMap.UserLocation.Location.Coordinate;

            //System.Diagnostics.Debug.WriteLine("Pin clicked");
            var start = new Position(userLocation.Latitude, userLocation.Longitude);
            var end   = e.View.Annotation.Coordinate;

            var emptyDict = new NSDictionary();
            var request   = new MKDirectionsRequest()
            {
                Source = new MKMapItem(new MKPlacemark(
                                           new CLLocationCoordinate2D(start.Latitude, start.Longitude), emptyDict)),
                Destination = new MKMapItem(new MKPlacemark(
                                                new CLLocationCoordinate2D(end.Latitude, end.Longitude), emptyDict)),
                TransportType = MKDirectionsTransportType.Walking
            };

            var directions = new MKDirections(request);
            var response   = await directions.CalculateDirectionsAsync();

            var r      = response.Routes[0];
            var coords = r.Polyline.GetCoordinates(0, (int)r.Polyline.PointCount);

            foreach (var point in coords)
            {
                System.Diagnostics.Debug.WriteLine("" + point.Latitude + "/" + point.Longitude);
            }


            nativeMap.DeselectAnnotation(e.View.Annotation, false);

            if (nativeMap.Overlays != null)
            {
                nativeMap.RemoveOverlays(nativeMap.Overlays);
            }

            MKPolyline polyline = response.Routes[0].Polyline;

            nativeMap.AddOverlay(polyline);
        }
Ejemplo n.º 12
0
        public MKPolylineEx(MKMapView map, List <MKPolylineEx> polylines, CLLocationCoordinate2D[] coordinates)
        {
            _map        = map;
            _collection = polylines;
            var idxStart = 0;

            while (idxStart < coordinates.Length)
            {
                var coordsToAdd = new List <CLLocationCoordinate2D>();
                for (var i = idxStart; i < Math.Min(idxStart + PolylineSegmentLength + 1, coordinates.Length); i++)
                {
                    coordsToAdd.Add(coordinates[i]);
                }
                var polylineToAdd = MKPolyline.FromCoordinates(coordsToAdd.ToArray());
                _polylines.Add(polylineToAdd);

                idxStart += PolylineSegmentLength;
            }
        }
Ejemplo n.º 13
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);
            }
        }
Ejemplo n.º 14
0
        public void Ctor_Annotation()
        {
            using (var a = new MKPolyline())
                using (MKPinAnnotationView av = new MKPinAnnotationView(a, "reuse")) {
                    Assert.AreSame(a, av.Annotation, "Annotation");

                    if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))              // Crashes with EXC_BAD_ACCESS (SIGABRT) if < iOS 7.0
                    {
                        Assert.False(av.AnimatesDrop, "AnimatesDrop");
                    }

                    if (!UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
                    {
                        return;
                    }
                    Assert.That(av.PinColor, Is.EqualTo(MKPinAnnotationColor.Red), "PinColor");
                    Assert.NotNull(av.PinTintColor, "PinTintColor");
                }
        }
Ejemplo n.º 15
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);
            if (isLoaded)
            {
                nativeMap.RemoveOverlays(nativeMap.Overlays);
            }
            if (e.OldElement != null)
            {
                nativeMap = Control as MKMapView;
                nativeMap.OverlayRenderer = null;
            }

            if (e.NewElement != null)
            {
                var formsMap = (CustomMap)e.NewElement;
                nativeMap = Control as MKMapView;
                isCircle  = formsMap.DrawCircle;
                if (!isCircle)
                {
                    nativeMap.OverlayRenderer = GetOverlayRenderer;

                    CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count];

                    int index = 0;
                    foreach (var position in formsMap.RouteCoordinates)
                    {
                        coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                        index++;
                    }

                    var routeOverlay = MKPolyline.FromCoordinates(coords);
                    nativeMap.AddOverlay(routeOverlay);
                }
                if (isCircle)
                {
                    var circle = formsMap.Circle;
                    nativeMap.OverlayRenderer = GetOverlayRenderer;
                    var circleOverlay = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius);
                    nativeMap.AddOverlay(circleOverlay);
                }
            }
        }
Ejemplo n.º 16
0
        public void Overlays()
        {
            using (var polygon = new MKPolygon())
                using (var polyline = new MKPolyline())
                    using (var circle = new MKCircle())
                        using (MKMapView mv = new MKMapView()) {
                            // old API accepted NSObject (limited protocol support)
                            mv.AddOverlay(polygon);
                            Assert.That(mv.Overlays.Length, Is.EqualTo(1), "1");
                            mv.RemoveOverlay(polygon);
                            Assert.That(mv.Overlays, Is.Empty, "2");

                            IMKOverlay[] list = { polygon, polyline, circle };
                            mv.AddOverlays(list);
                            Assert.That(mv.Overlays.Length, Is.EqualTo(3), "3");
                            mv.RemoveOverlays(list);
                            Assert.That(mv.Overlays, Is.Empty, "4");
                        }
        }
Ejemplo n.º 17
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var nativeMap = Control as MKMapView;
                if (nativeMap != null)
                {
                    //rendering for route
                    nativeMap.RemoveOverlays(nativeMap.Overlays);
                    nativeMap.OverlayRenderer = null;
                    polylineRenderer          = null;

                    //rendering for annotations (pins)
                    nativeMap.RemoveAnnotations(nativeMap.Annotations);
                    nativeMap.GetViewForAnnotation = null;
                }
            }

            if (e.NewElement != null)
            {
                BindableMap formsMap  = (BindableMap)e.NewElement;
                var         nativeMap = Control as MKMapView;
                nativeMap.OverlayRenderer = GetOverlayRenderer;

                CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count];
                int index = 0;
                foreach (var position in formsMap.RouteCoordinates)
                {
                    coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                    index++;
                }

                var routeOverlay = MKPolyline.FromCoordinates(coords);
                nativeMap.AddOverlay(routeOverlay);

                //var mypins = formsMap.Pins;

                nativeMap.GetViewForAnnotation = GetViewForAnnotation;
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                nativeMap = Control as MKMapView;
                nativeMap.OverlayRenderer = null;
                #region For different pin images
                nativeMap.GetViewForAnnotation           = null;
                nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped;
                nativeMap.DidSelectAnnotationView       -= OnDidSelectAnnotationView;
                nativeMap.DidDeselectAnnotationView     -= OnDidDeselectAnnotationView;
                #endregion
            }

            if (e.NewElement != null)
            {
                var formsMap = (CustomMap)e.NewElement;
                nativeMap  = Control as MKMapView;
                customPins = new List <Pin>(formsMap.Pins);

                nativeMap.OverlayRenderer = GetOverlayRenderer;
                int index = 0;
                foreach (var position in CustomMap.RouteCoordinates)
                {
                    coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                    index++;
                }

                routeOverlay = MKPolyline.FromCoordinates(coords);

                nativeMap.AddOverlay(routeOverlay);
                nativeMap.ScrollEnabled = true;
                #region For different pin images
                nativeMap.GetViewForAnnotation           = GetViewForAnnotation;
                nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;
                nativeMap.DidSelectAnnotationView       += OnDidSelectAnnotationView;
                nativeMap.DidDeselectAnnotationView     += OnDidDeselectAnnotationView;
                #endregion
            }
        }
Ejemplo n.º 19
0
        private void UpdatePolyline()
        {
            var MapaIoS = Control as MKMapView;

            MapaIoS.OverlayRenderer = GetOverlayRenderer;

            CLLocationCoordinate2D[] coordenada = new CLLocationCoordinate2D[_map.CoordenadasRota.Count];

            int index = 0;

            foreach (var posicao in _map.CoordenadasRota)
            {
                coordenada[index] = new CLLocationCoordinate2D(posicao.Latitude, posicao.Longitude);
                index++;
            }

            var polilyne = MKPolyline.FromCoordinates(coordenada);

            MapaIoS.AddOverlay(polilyne);
        }
Ejemplo n.º 20
0
        void Update()
        {
            CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[_formsMap.PolylineCoordinates.Count];

            int index = 0;

            foreach (var position in _formsMap.PolylineCoordinates)
            {
                coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                index++;
            }

            if (_nativeMap.Overlays?.Length > 0 && _routeOverlay != null)
            {
                _nativeMap.RemoveOverlay(_routeOverlay);
            }

            _routeOverlay = MKPolyline.FromCoordinates(coords);
            _nativeMap.AddOverlay(_routeOverlay);
        }
Ejemplo n.º 21
0
        public void Draw()
        {
            var nativeMap = Control as MKMapView;

            nativeMap.OverlayRenderer = GetOverlayRenderer;

            List <MKPolyline> polylines = new List <MKPolyline>();

            foreach (Line line in formsMap.Lines)
            {
                currentFillColor   = line.FillColor.ToUIColor();
                currentStrokeColor = line.StrokeColor.ToUIColor();

                CLLocationCoordinate2D[] cds = new CLLocationCoordinate2D[line.Positions.Count];

                int index = 0;
                foreach (var position in line.Positions)
                {
                    cds[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                    index++;
                }

                MKPolyline overlay = MKPolyline.FromCoordinates(cds);
                polylines.Add(overlay);
            }

            List <MKCircle> circles = new List <MKCircle>();

            foreach (Circle circle in formsMap.Circles)
            {
                currentFillColor   = circle.FillColor.ToUIColor();
                currentStrokeColor = circle.StrokeColor.ToUIColor();
                currentLineWidth   = (nfloat)circle.LineWidth;

                MKCircle overlay = MKCircle.Circle(new CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius);
                circles.Add(overlay);
            }

            nativeMap.AddOverlays(polylines.ToArray());
            nativeMap.AddOverlays(circles.ToArray());
        }
Ejemplo n.º 22
0
        public CGPath polyPath(MKPolyline polyline,MKMapRect mapRect, float zoomScale, CGContext context)
        {
            MKMapPoint[] points = polyline.Points;
            Int32 pointCount = polyline.PointCount;
            Int32 i;

            if (pointCount < 3)
                return null;

            CGPath path = new CGPath ();

            PointF relativePoint = this.PointForMapPoint (points[0]);
            path.MoveToPoint (relativePoint.X, relativePoint.Y);
            for (i = 1; i < pointCount; i++)
            {
                relativePoint = this.PointForMapPoint (points[i]);
                path.AddLineToPoint(relativePoint);
            }

            return path;
        }
Ejemplo n.º 23
0
        private void DrawPolyline()
        {
            var nativeMap = Control as MKMapView;

            nativeMap.OverlayRenderer = GetPolylineRenderer;
            CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[_routeCoordinates.Count];
            int index = 0;

            foreach (var position in _routeCoordinates)
            {
                coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                index++;
            }
            if (nativeMap.Overlays != null)
            {
                nativeMap.RemoveOverlays(nativeMap.Overlays);
            }
            var polylineOverlay = MKPolyline.FromCoordinates(coords);

            nativeMap.AddOverlay(polylineOverlay);
        }
Ejemplo n.º 24
0
        private void UpdateAnnotation()
        {
            //Removes all current overlays

            while (true)
            {
                CLLocationCoordinate2D[] dataArray = LocationFinderManager.data.GetAndRemoveData();
                if (dataArray.Length > 1)
                {
                    InvokeOnMainThread(delegate
                    {
                        UIApplicationState state = UIApplication.SharedApplication.ApplicationState;
                        if (state == UIApplicationState.Active)
                        {
                            MapView.AddOverlay(MKPolyline.FromCoordinates(dataArray));
                        }
                    });
                }
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 25
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var nativeMap = Control as MKMapView;
                nativeMap.GetViewForAnnotation           = null;
                nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped;
                nativeMap.DidSelectAnnotationView       -= OnDidSelectAnnotationView;
                nativeMap.DidDeselectAnnotationView     -= OnDidDeselectAnnotationView;
                if (nativeMap != null)
                {
                    nativeMap.RemoveOverlays(nativeMap.Overlays);
                    nativeMap.OverlayRenderer = null;
                    polylineRenderer          = null;
                }
            }

            if (e.NewElement != null)
            {
                var formsMap  = (CustomMap)e.NewElement;
                var nativeMap = Control as MKMapView;
                customPins = formsMap.CustomPins;
                nativeMap.GetViewForAnnotation           = GetViewForAnnotation;
                nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;
                nativeMap.DidSelectAnnotationView       += OnDidSelectAnnotationView;
                nativeMap.DidDeselectAnnotationView     += OnDidDeselectAnnotationView;
                nativeMap.OverlayRenderer = GetOverlayRenderer;
                CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count];
                int index = 0;
                foreach (var position in formsMap.RouteCoordinates)
                {
                    coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                    index++;
                }
                var routeOverlay = MKPolyline.FromCoordinates(coords);
                nativeMap.AddOverlay(routeOverlay);
            }
        }
Ejemplo n.º 26
0
        public void Annotations_BackingFields()
        {
            if (MapViewPoker.NewRefcountEnabled())
            {
                Assert.Inconclusive("backing fields are removed when newrefcount is enabled");
            }

            using (var a = new MKCircle())                      // MKAnnotation is abstract
                using (var o1 = new MKPolygon())                // it must export 'coordinate' or this will fail
                    using (var o2 = new MKPolyline())
                        using (var mv = new MapViewPoker()) {
                            Assert.Null(mv.AnnotationsBackingField, "1a");
                            Assert.That(mv.Annotations, Is.Empty, "1b");

                            mv.AddAnnotation(a);
                            Assert.AreSame(a, mv.AnnotationsBackingField [0], "2a");
                            Assert.AreSame(a, mv.Annotations [0], "2b");

                            mv.RemoveAnnotation(a);
                            Assert.That(mv.AnnotationsBackingField, Is.Empty, "3a");
                            Assert.That(mv.Annotations, Is.Empty, "3b");

                            mv.AddAnnotation(o1);
                            Assert.AreSame(o1, mv.AnnotationsBackingField [0], "4a");
                            Assert.AreSame(o1, mv.Annotations [0], "4b");

                            mv.RemoveAnnotation(o1);
                            Assert.That(mv.AnnotationsBackingField, Is.Empty, "5a");
                            Assert.That(mv.Annotations, Is.Empty, "5b");

                            mv.AddAnnotations(new IMKAnnotation[] { o1, o2 });
                            // don't assume ordering
                            Assert.That(mv.AnnotationsBackingField.Length, Is.EqualTo(2), "6a");
                            Assert.That(mv.Annotations.Length, Is.EqualTo(2), "6b");

                            mv.RemoveAnnotations(new IMKAnnotation[] { o2, o1 });
                            Assert.That(mv.AnnotationsBackingField, Is.Empty, "7a");
                            Assert.That(mv.Annotations, Is.Empty, "7b");
                        }
        }
Ejemplo n.º 27
0
Archivo: vcMap.cs Proyecto: pauZc/8_iOS
        private void Do_Rute(MKDirectionsRequest req, UIColor color, CLLocationCoordinate2D[] coord, MKMapView mapView)
        {
            var dir = new MKDirections(req);

            dir.CalculateDirections((response, error) =>
            {
                if (error == null)
                {
                    var rute = response.Routes[0];
                    var rteL = new MKPolylineRenderer(rute.Polyline)
                    {
                        LineWidth   = 5.0f,
                        StrokeColor = color
                    };
                    mapView.OverlayRenderer = (mv, ol) => rteL;
                    var circleoverlay       = MKCircle.Circle(mapView.CenterCoordinate, 1000);
                    mapView.AddOverlay(circleoverlay);

                    int index = 0;

                    foreach (var position in coord)
                    {
                        coord[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                        index++;
                    }
                    var routeOverlay = MKPolyline.FromCoordinates(coord);


                    mapView.AddOverlay(routeOverlay);
                    mapView.SetCenterCoordinate(coord[1], true);

                    //mapView.AddOverlay(rute.Polyline, MKOverlayLevel.AboveRoads);
                }
                else
                {
                    Console.WriteLine("Error");
                }
            });
        }
Ejemplo n.º 28
0
        private void UpdateRouteCoordinates()
        {
            if (_mapView == null)
            {
                return;
            }

            RemoveRouteCoordinates();
            _mapView.OverlayRenderer = GetOverlayRenderer;

            foreach (var routeCoordinates in _customMap.RouteCoordinates)
            {
                foreach (var positionEstimate in routeCoordinates.PositionEstimates)
                {
                    int index       = 0;
                    var coordinates = new CLLocationCoordinate2D[positionEstimate.ActualPositions.Count];

                    foreach (var actualPosition in positionEstimate.ActualPositions)
                    {
                        coordinates[index] = new CLLocationCoordinate2D(actualPosition.Latitude, actualPosition.Longitude);
                        index++;
                    }

                    _routeOverlay = MKPolyline.FromCoordinates(coordinates);

                    var trackColor = GetColor(routeCoordinates.Color);
                    var o          = ObjCRuntime.Runtime.GetNSObject(_routeOverlay.Handle) as MKPolyline;

                    _polylineRenderer = new MKPolylineRenderer(o)
                    {
                        StrokeColor = trackColor,
                        LineWidth   = 1
                    };

                    _mapView.AddOverlay(_routeOverlay);
                    _polylines.Add(_routeOverlay);
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Draw the polyline from the PolylineCoordinates.
        /// </summary>
        private void UpdatePolyLine()
        {
            if (nativeMap != null)
            {
                var formsMap = ((CustomMap)this.Element);
                nativeMap = Control as MKMapView;

                nativeMap.OverlayRenderer = GetOverlayRenderer;

                CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.PolylineCoordinates.Count];

                int index = 0;
                foreach (var position in formsMap.PolylineCoordinates)
                {
                    coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                    index++;
                }

                var routeOverlay = MKPolyline.FromCoordinates(coords);
                nativeMap.AddOverlay(routeOverlay);
            }
        }
Ejemplo n.º 30
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName.Equals("VisibleRegion"))
            {
                var formsMap  = (CustomMap)sender;
                var nativeMap = Control as MKMapView;
                nativeMap.OverlayRenderer = GetOverlayRenderer;

                CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count];
                int index = 0;
                foreach (var position in formsMap.RouteCoordinates)
                {
                    coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                    index++;
                }

                var routeOverlay = MKPolyline.FromCoordinates(coords);
                nativeMap.AddOverlay(routeOverlay);
            }
        }
        protected override void DataSourceUpdated(WebDataSource oldDataSource, WebDataSource newDataSource)
        {
            if (mapView.Overlays != null)
            {
                mapView.RemoveOverlays(mapView.Overlays);
            }

            var representation = (XIMapViewWebDocumentRepresentation)newDataSource?.Representation;

            if (representation == null || !representation.LocationIsValid)
            {
                return;
            }

            if (representation.Polyline == null)
            {
                var coordinate = representation.Location.ToCoordinate();
                AddLocationAnnotation(coordinate);
                mapView.Region = MKCoordinateRegion.FromDistance(coordinate, 15000, 15000);
            }
            else
            {
                var coords = representation.Polyline.Value.ToCoordinates();
                for (var i = 0; i < coords.Length; i++)
                {
                    AddLocationAnnotation(
                        coords [i],
                        representation.Polyline,
                        i);
                }

                var mkpolyline = MKPolyline.FromCoordinates(coords);
                mapView.AddOverlay(mkpolyline);
                mapView.SetVisibleMapRect(
                    mkpolyline.BoundingMapRect,
                    new NSEdgeInsets(45, 35, 35, 35),
                    false);
            }
        }
Ejemplo n.º 32
0
        private void updateMapFromDictionary(int index)
        {
            if (mapView.Overlays != null)
            {
                mapView.RemoveOverlays(mapView.Overlays);
            }

            if (mapView.Annotations != null)
            {
                mapView.RemoveAnnotations(mapView.Annotations);
            }

            From fromPlace = fromNameDictionary [index];

            mapView.AddAnnotation(new MKStartPointAnnotation()
            {
                Title      = fromPlace.name,
                Coordinate = new CLLocationCoordinate2D(fromPlace.lat, fromPlace.lon),
                Mode       = modeDictionary[index]
            });


            To toPlace = toNameDictionary [index];

            mapView.AddAnnotation(new MKEndPointAnnotation()
            {
                Title      = toPlace.name,
                Coordinate = new CLLocationCoordinate2D(toPlace.lat, toPlace.lon)
            });

            MKPolyline polyline = polylineDictionary [index];

            mapView.AddOverlay(polyline);

            MKPolygon polygon = MKPolygon.FromPoints(polyline.Points);

            mapView.SetVisibleMapRect(polygon.BoundingMapRect, new UIEdgeInsets(20, 10, 10, 10), true);
        }
Ejemplo n.º 33
0
 public PolylineOverlay(MKPolyline polyline)
 {
     _polyline = polyline;
 }
Ejemplo n.º 34
0
        void LoadRoute()
        {
            var filePath = NSBundle.MainBundle.PathForResource("route", "csv", "os4Maps","");
            var fileContents = System.IO.File.ReadAllText(filePath);
            var pointStrings = fileContents.Split('\n');

            MKMapPoint northEastPoint = new MKMapPoint(), southWestPoint = new MKMapPoint();
            var pointArr = new List<MKMapPoint>();
            var coordArr = new List<CLLocationCoordinate2D>();

            // start with the widest possible viewport
            var tl = new CLLocationCoordinate2D (-90, 180);
            // top left
            var br = new CLLocationCoordinate2D (90, -180);
            foreach (var s in pointStrings)
            {
                string[] latlonArr = s.Split(',');
                double latitude = Convert.ToDouble(latlonArr[0]);
                double longitude = Convert.ToDouble(latlonArr[1]);

                CLLocationCoordinate2D coordinate = new CLLocationCoordinate2D (latitude, longitude);

                // narrow the viewport bit-by-bit
                tl.Longitude = Math.Min (tl.Longitude, coordinate.Longitude);
                tl.Latitude = Math.Max (tl.Latitude, coordinate.Latitude);
                br.Longitude = Math.Max (br.Longitude, coordinate.Longitude);
                br.Latitude = Math.Min (br.Latitude, coordinate.Latitude);

                coordArr.Add(coordinate);

                // Can't find MonoTouch **MKMapPointForCoordinate**
            //				MKMapPoint point = ???????? (coordinate);
            //				if (northEastPoint.X == 0 & northEastPoint.Y == 0)
            //				{
            //					Debug.WriteLine("First Point: {0},{1}",point.X, point.Y);
            //					northEastPoint = point;
            //					southWestPoint = point;
            //				}
            //				else
            //				{
            //					if (point.X > northEastPoint.X)
            //						northEastPoint.X = point.X;
            //					if(point.Y > northEastPoint.Y)
            //						northEastPoint.Y = point.Y;
            //					if (point.X < southWestPoint.X)
            //						southWestPoint.X = point.X;
            //					if (point.Y < southWestPoint.Y)
            //						southWestPoint.Y = point.Y;
            //				}
            //				pointArr.Add(point);
            }
            // Can't use MKMapRect without the **MKMapPointForCoordinate**
            //_routeRect = new MKMapRect (southWestPoint.X, southWestPoint.Y, northEastPoint.X - southWestPoint.X, northEastPoint.Y - southWestPoint.Y);
            //Debug.WriteLine("RouteRect: {0},{1};{2},{3}", _routeRect.Origin.X, _routeRect.Origin.Y, _routeRect.Size.Width, _routeRect.Size.Height);

            CLLocationCoordinate2D[] clar = coordArr.ToArray();
            RouteLine = MKPolyline.FromCoordinates (clar);
            // divide the range by two to get the center
            var center = new CLLocationCoordinate2D { Latitude = tl.Latitude - (tl.Latitude - br.Latitude) * 0.5, Longitude = tl.Longitude + (br.Longitude - tl.Longitude) * 0.5 };
            // calculate the span, with 20% margin so pins aren't on the edge
            var span = new MKCoordinateSpan { LatitudeDelta = Math.Abs (tl.Latitude - br.Latitude) * 1.2, LongitudeDelta = Math.Abs (br.Longitude - tl.Longitude) * 1.2 };
            RouteRegion = new MKCoordinateRegion { Center = center, Span = span };
        }
 public UnifiedPolylineOverlay(MKPolyline line)
     : base(line.Handle)
 {
 }
Ejemplo n.º 36
0
        internal MKPolylineView OnCreateView(MKPolyline polyline)
        {
            foreach (var p in _polylines)
            {
                if (p == polyline)
                {
                    var polylineView = new MKPolylineView(polyline);
                    polylineView.StrokeColor = _color;
                    return polylineView;
                }
            }

            return null;
        }