0

As I wrote in the title, I use the Microsoft Xamarin.Forms.Maps nugget to show map in my app. First I started with Xamarin.Forms.GoogleMaps, but when I saw that I can't customise InfoWindows (when I touch one pin), I must go back and start using Xamarin.Forms.Maps. The only problem is that I have to apply a "gray style" to the map or something similar. And I can't find any link or guide to do this. It seems that CustomRender can't modify style or colors.

Please, can someone help me? Any links, documentation or examples?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

1

If you are referring to Dark Mode you can create custom renderer to achieve that .

iOS

Set OverrideUserInterfaceStyle in OnElementChanged .

[assembly: ExportRenderer(typeof(Map), typeof(MyRenderer))]
namespace FormsApp.iOS
{
    class MyRenderer : MapRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<View> e)
        {
            base.OnElementChanged(e);
            if (e.NewElement != null)
            {
                var nativeMap = Control as MKMapView;
                nativeMap.OverrideUserInterfaceStyle = UIUserInterfaceStyle.Dark;
            }
        }
    }
}

Android

Create a dark mode file in resource and set mapStyle in OnElementChanged .

[assembly: ExportRenderer(typeof(Map), typeof(MyMapRenderer))]
namespace FormsApp.Droid
{
    class MyMapRenderer : MapRenderer
    {
        Context _context;

        public MyMapRenderer(Context context) : base(context)
        {
            _context = context;        
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Map> e)
        {
            base.OnElementChanged(e);

            if(e.NewElement != null)
            {
                NativeMap.SetMapStyle(MapStyleOptions.LoadRawResourceStyle(this.Context, Resource.Raw.map_style_night));
            }
        }
    }
}

Refer to

https://forums.xamarin.com/discussion/comment/429548/#Comment_429548.

How to use Dark Mode Google Maps in Xamarin.Forms.Maps?.

ColeX
  • 14,062
  • 5
  • 43
  • 240
  • I refer for example something like this: https://mapstyle.withgoogle.com/. – Alessandro L Jun 29 '21 at 10:06
  • For example, if I create in this website (mapstyle.withgoogle.com) my style map, am I able to set the mapstyle whit the custom render that you show? – Alessandro L Jun 29 '21 at 10:09
  • I think that your refer links talking about a Xamarin.Forms.GoogleMap, and I use Xamarin.Forms.Maps. Is there any solution to make a personal style using this nugget? – Alessandro L Jun 29 '21 at 21:29
  • No , this is the solution for Xamarin.Forms.Maps , click into that link for details. – ColeX Jun 30 '21 at 01:28