public static List <NSObject> toFeatureList(this IEnumerable <Route> routes) { var features = new List <NSObject>(); var nativeScale = DisplayMetricsHelper.instance.nativeScale; foreach (var route in routes) { var coordinates = route.points.Select((MapBox.Models.Position arg) => { return(new CLLocationCoordinate2D(arg.latitude, arg.longitude)); }); var featureInArrayFormat = coordinates.ToArray(); var feature = new MGLPolylineFeature(); feature.SetCoordinates(ref featureInArrayFormat[0], (System.nuint)featureInArrayFormat.Length); feature.Attributes = NSDictionary <NSString, NSObject> .FromObjectsAndKeys( new object[] { route.borderLineColor, route.lineColor, (route.borderLineWidth * 2 + route.lineWidth) * nativeScale, route.lineWidth *nativeScale }, new object[] { MapboxRenderer.border_line_color_key, MapboxRenderer.line_color_key, MapboxRenderer.border_line_width_key, MapboxRenderer.line_width_key }); features.Add(feature); } return(features); }
void DrawPolyline() { var jsonPath = NSBundle.MainBundle.PathForResource("example", "geojson"); NSData data = NSFileManager.DefaultManager.Contents(jsonPath); NSError err; MGLShapeCollectionFeature shapeCollectionFeature = (MGLShapeCollectionFeature)MGLShape.ShapeWithData(data, (uint)NSStringEncoding.UTF8, out err); MGLPolylineFeature polyline = (MGLPolylineFeature)shapeCollectionFeature.Shapes.First(); mapView.AddAnnotation(polyline); }