Private static MKAnnotationView GetViewForAnnotations(MKMapView mapView, IMKAnnotation annotation) Var pin = GetPinForAnnotation(annotation) Private static void OnCalloutClicked(IMKAnnotation annotation) PlatformView.GetViewForAnnotation += GetViewForAnnotations Protected override void ConnectHandler(MauiMKMapView platformView) Then create the CustomMapHandler: public class CustomMapHandler : MapHandler public class CustomAnnotation : MKPointAnnotation IOS/MacCatalyst requires a bit more customization.įirst, we need to create a new class CustomAnnotation. MapHandler.UpdateValue(nameof(IMap.Pins)) Public void OnMapReady(GoogleMap googleMap) Public MapCallbackHandler(IMapHandler mapHandler) We should do it when the map is ready: class MapCallbackHandler :, IOnMapRead圜allback The next step is notifying the handler that our pins are updated. Var marker = map.AddMarker(markerOption) Private static void AddMarker(GoogleMap map, IMapPin pin, List markers, MarkerOptions markerOption) MarkerOption.SetIcon(BitmapDescriptorFactory.FromBitmap(bitmapDrawable.Bitmap)) ĪddMarker(Map, pin, Markers, markerOption) If (result?.Value is BitmapDrawable bitmapDrawable) Var markerOption = mapPinHandler.PlatformView Ĭp.ImageSource.LoadImage(MauiContext, result => If (pinHandler is IMapPinHandler mapPinHandler) Var pinHandler = pin.ToHandler(MauiContext) Private void AddPins(IEnumerable mapPins) If (handler is CustomMapHandler mapHandler)įoreach (var marker in mapHandler.Markers) Private static new void MapPins(IMapHandler handler, IMap map) Var mapReady = new MapCallbackHandler(this) Protected override void ConnectHandler(MapView platformView) Mapper ? CustomMapper, commandMapper ? CommandMapper) Public CustomMapHandler(IPropertyMapper? mapper = null, CommandMapper? commandMapper = null) : base( Public CustomMapHandler() : base(CustomMapper, CommandMapper) Public static readonly IPropertyMapper CustomMapper = To do that, let's create a CustomMapHandler: public class CustomMapHandler : MapHandler To be able to add, update, and remove map elements we need to store them in memory. This control has a bindable property ImageSource that allows us to choose any image source to store our pin icon. Set => SetValue(ImageSourceProperty, value) Get => (ImageSource?)GetValue(ImageSourceProperty) Public static readonly BindableProperty ImageSourceProperty = BindableProperty.Create(nameof(ImageSource), typeof(ImageSource), typeof(CustomPin) We want to display a custom image instead of a standard pin icon.įirst of all, we need to create a new control: public class CustomPin : Pin This article is devoted to the customization of standard map pins. It brings a lot of bug fixes and new features. NET MAUI's next major release is closer and closer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |