コード例 #1
0
 private void CreateDashedLine(List <CLLocationCoordinate2D> points, MGLMapView mapView)
 {
     for (var i = 0; i < (points.Count - 1); i += 2)
     {
         var nextLine = new CLLocationCoordinate2D[2];
         nextLine[0] = points[i];
         nextLine[1] = points[i + 1];
         var polyline = MGLPolyline.PolylineWithCoordinates(ref nextLine[0], (nuint)nextLine.Length);
         mapView.AddAnnotation(polyline);
     }
 }
コード例 #2
0
    public static unsafe MGLPolyline PolylineWithCoordinates(CLLocationCoordinate2D[] coords)
    {
        MGLPolyline line = null;

        fixed(void *arrPtr = coords)
        {
            IntPtr ptr = new IntPtr(arrPtr);

            line = MGLPolyline.PolylineWithCoordinates(ptr, 2);
        }

        return(line);
    }
コード例 #3
0
        public void MapViewDidFinishLoadingMap(MGLMapView mapView)
        {
            var coordinates = new CLLocationCoordinate2D[] {
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude + 0.03, longitude: mapView.CenterCoordinate.Longitude - 0.02),
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude + 0.02, longitude: mapView.CenterCoordinate.Longitude - 0.03),
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude, longitude: mapView.CenterCoordinate.Longitude - 0.02),
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude - 0.01, longitude: mapView.CenterCoordinate.Longitude),
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude - 0.04, longitude: mapView.CenterCoordinate.Longitude + 0.01),
                new CLLocationCoordinate2D(latitude: mapView.CenterCoordinate.Latitude - 0.04, longitude: mapView.CenterCoordinate.Longitude + 0.04)
            };
            var polyline = MGLPolyline.PolylineWithCoordinates(ref coordinates[0], (nuint)coordinates.Length);

            mapView.AddAnnotation(polyline);
        }
コード例 #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            // Create a MapView
            mapView           = new MGLMapView(View.Bounds);
            mapView.StyleURL  = MGLStyle.LightStyleURLWithVersion(9);
            mapView.TintColor = UIColor.DarkGray;
            mapView.SetZoomLevel(1, false);
            mapView.WeakDelegate = this;

            View.AddSubview(mapView);

            // Polyline
            // Create a coordinates array with all of the coordinates for our polyline.
            List <CLLocationCoordinate2D> coordinates = new List <CLLocationCoordinate2D>()
            {
                new CLLocationCoordinate2D(35, -25),
                new CLLocationCoordinate2D(20, -30),
                new CLLocationCoordinate2D(0, -25),
                new CLLocationCoordinate2D(-15, 0),
                new CLLocationCoordinate2D(-45, 10),
                new CLLocationCoordinate2D(-45, 40)
            };

            var coords = coordinates.ToArray();

            //TODO Use CustomPolyline
            MGLPolyline polyline = CustomPolyline.PolylineWithCoordinates(ref coords[0], (uint)coords.Count());

            // Set the custom `color` property, later used in the `mapView:strokeColorForShapeAnnotation:` delegate method.
            //((CustomPolyline)polyline).Color = UIColor.DarkGray;

            // Add the polyline to the map. Note that this method name is singular.
            mapView.AddAnnotation(polyline);


            // Point Annotations
            // Add a custom point annotation for every coordinate (vertex) in the polyline.
            List <CustomPointAnnotation> pointAnnotations = new List <CustomPointAnnotation>();

            foreach (var coordinate in coordinates)
            {
                CustomPointAnnotation point = new CustomPointAnnotation(coordinate, "Custom Point Annotation " + pointAnnotations.Count + 1, "");
                pointAnnotations.Add(point);
            }
            mapView.AddAnnotations(pointAnnotations.ToArray());
        }
コード例 #5
0
 MGLPolyline PolyLineWithCoordinates(LatLng[] positions)
 {
     if (positions == null || positions.Length == 0)
     {
         return null;
     }
     var first = positions[0].ToCLCoordinate();
     var output = MGLPolyline.PolylineWithCoordinates(ref first, 1);
     var i = 1;
     while (i < positions.Length)
     {
         var coord = positions[i].ToCLCoordinate();
         output.AppendCoordinates(ref coord, 1);
         i++;
     }
     return output;
 }
コード例 #6
0
        MGLPolyline PolyLineWithCoordinates(Position[] positions)
        {
            if (positions == null || positions.Length == 0)
            {
                return(null);
            }
            var first  = new CLLocationCoordinate2D(positions [0].Lat, positions [0].Long);
            var output = MGLPolyline.PolylineWithCoordinates(ref first, 1);
            var i      = 1;

            while (i < positions.Length)
            {
                var coord = new CLLocationCoordinate2D(positions [i].Lat, positions [i].Long);
                output.AppendCoordinates(ref coord, 1);
                i++;
            }
            return(output);
        }
コード例 #7
0
        MGLPolyline PolyLineWithCoordinates(Position[] positions)
        {
            if (positions == null || positions.Length == 0)
            {
                return(null);
            }
            var first  = positions[0].ToCLCoordinate();
            var output = MGLPolyline.PolylineWithCoordinates(ref first, 1);
            var i      = 1;

            while (i < positions.Length)
            {
                var     coord   = positions[i].ToCLCoordinate();
                NSArray nsarray = NSArray.FromObjects(coord);
                output.AppendCoordinates(nsarray, 1);
                i++;
            }
            return(output);
        }
コード例 #8
0
 public nfloat MapView_LineWidthForPolylineAnnotation(MGLMapView mapView, MGLPolyline annotation)
 {
     return(2.0f);
 }
コード例 #9
0
        MGLShape ShapeFromAnnotation(FormsMB.Annotation annotation)
        {
            MGLShape shape = null;

            if (annotation is PointAnnotation)
            {
                shape = new MGLPointAnnotation()
                {
                    Coordinate = new CLLocationCoordinate2D(((PointAnnotation)annotation).Coordinate.Lat,
                                                            ((PointAnnotation)annotation).Coordinate.Long),
                };
            }
            else if (annotation is PolylineAnnotation)
            {
                var polyline = annotation as PolylineAnnotation;
                shape = PolyLineWithCoordinates(polyline.Coordinates.ToArray());
                var notifiyCollection = polyline.Coordinates as INotifyCollectionChanged;
                if (notifiyCollection != null)
                {
                    notifiyCollection.CollectionChanged += (sender, e) => {
                        //TODO Move to a separated method
                        if (e.Action == NotifyCollectionChangedAction.Add)
                        {
                            foreach (Position pos in e.NewItems)
                            {
                                var coord = TypeConverter.FromPositionToCoordinate(pos);
                                (shape as MGLPolyline).AppendCoordinates(ref coord, 1);
                            }
                        }
                        else if (e.Action == NotifyCollectionChangedAction.Remove)
                        {
                            (shape as MGLPolyline).RemoveCoordinatesInRange(new NSRange(e.OldStartingIndex, e.OldItems.Count));
                        }
                    };
                }
            }
            else if (annotation is MultiPolylineAnnotation)
            {
                var polyline = annotation as MultiPolylineAnnotation;
                if (polyline.Coordinates == null || polyline.Coordinates.Length == 0)
                {
                    return(null);
                }
                var lines = new MGLPolyline [polyline.Coordinates.Length];
                for (var i = 0; i < polyline.Coordinates.Length; i++)
                {
                    if (polyline.Coordinates [i].Length == 0)
                    {
                        continue;
                    }
                    lines [i] = PolyLineWithCoordinates(polyline.Coordinates[i]);
                }
                shape = MGLMultiPolyline.MultiPolylineWithPolylines(lines);
            }
            if (shape != null)
            {
                if (annotation.Title != null)
                {
                    shape.Title = annotation.Title;
                }
                if (annotation.SubTitle != null)
                {
                    shape.Subtitle = annotation.SubTitle;
                }
                if (!string.IsNullOrEmpty(annotation.Id))
                {
                    shape.SetId(annotation.Id);
                }
            }

            return(shape);
        }
コード例 #10
0
 public virtual nfloat LineWidthForPolylineAnnotation(MGLMapView mapView, MGLPolyline annotation)
 {
     return(2);
 }