private static T GetProperty <T>( this MGLShape controller, NSString propertyKey) where T : NSObject { var pointer = objc_getAssociatedObject( controller.Handle, propertyKey.Handle ); return(ObjCRuntime.Runtime.GetNSObject <T>(pointer)); }
public virtual UIColor StrokeColorForShapeAnnotation(MGLMapView mapView, MGLShape annotation) { if (annotation.Title == "Crema to Council Crest" && annotation is MGLPolyline) { // Mapbox cyan return(new UIColor(red: 59 / 255, green: 178 / 255, blue: 208 / 255, alpha: 1)); } else { return(UIColor.Red); } }
private static void SetProperty <T>( this MGLShape controller, NSString propertyKey, T value, AssociationPolicy policy) where T : NSObject { objc_setAssociatedObject( controller.Handle, propertyKey.Handle, value.Handle, policy ); }
public virtual UIColor StrokeColorForShapeAnnotation(MGLMapView mapView, MGLShape annotation) { if (annotation is CustomPolyline) { if (((CustomPolyline)annotation).Color == null) { return(UIColor.Orange); } else { return(((CustomPolyline)annotation).Color); } } return(UIColor.Orange); }
public static MGLShape ToShape(this GeoJSON.Net.IGeoJSONObject geoJSONObject) { if (geoJSONObject == null) { return(null); } var json = JsonConvert.SerializeObject(geoJSONObject); var data = NSData.FromString(json); var shape = MGLShape.ShapeWithData(data, (int)NSStringEncoding.UTF8, out var error); // TODO Handle error if (error != null) { return(null); } return(shape); }
public UIColor MapView_StrokeColorForShapeAnnotation(MGLMapView mapView, MGLShape annotation) { return(UIColor.Blue); }
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); }
public static void SetId(this MGLShape shape, string id) { shape.SetProperty(kId, (NSString)id, AssociationPolicy.RetainNonAtomic); }
public static string Id(this MGLShape shape) { var prop = shape.GetProperty <NSString>(kId); return(prop); }
public virtual nfloat AlphaForShapeAnnotation(MGLMapView mapView, MGLShape annotation) { return(0.5f); }
public virtual UIColor StrokeColorForShapeAnnotation(MGLMapView mapView, MGLShape annotation) { return(UIColor.White); }
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); }
MGLShape ShapeFromAnnotation(Annotation annotation) { MGLShape shape = null; if (annotation is SymbolAnnotation symbol) { shape = new MGLPointAnnotation { Coordinate = symbol.Coordinates.ToCLCoordinate(), }; } else if (annotation is LineAnnotation line) { shape = PolyLineWithCoordinates(line.Coordinates.ToArray()); //if (polyline.Coordinates is INotifyCollectionChanged notifiyCollection) //{ // notifiyCollection.CollectionChanged += (sender, e) => // { // //TODO Move to a separated method // if (e.Action == NotifyCollectionChangedAction.Add) // { // foreach (FormsMB.Point 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 FillAnnotation polyline) { //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); } annotation.NativeHandle = shape.Handle; } return shape; }