amay077 / Xamarin.Forms.GoogleMaps

Map library for Xamarin.Forms using Google maps API
https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/
MIT License
546 stars 346 forks source link

How to Enable Dark Mode? #703

Closed ianvink closed 4 years ago

ianvink commented 4 years ago

Thank you for a wonderful tool.

Using version 3.3, how do you enable Dark Mode?

iOS and Android devices are in Darkmode, but the map control isn't in Dark mode.

I'm assuming I need to enable it?

                                <googleMaps:Map x:Name="Map" MapClicked="Map_OnMapClicked" 
                                                MapType="Street"
                                                HorizontalOptions="FillAndExpand"
                                                VerticalOptions="FillAndExpand"
                                                Margin="0,0,0,60"
                                                HeightRequest="{OnIdiom Phone=200, Tablet=400}"
                                                AutomationProperties.Name="Map" />
mrehman29 commented 4 years ago

you can create your own theme/style https://mapstyle.withgoogle.com/ export that and use those json files to change Map design

in your xaml you can use MapStyle to bind the design

<map:Map x:Name="MainMap" MapStyle="{Binding MyMapStyle}" HasZoomEnabled="True" CameraIdled="ProcessCamera" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" MyLocationEnabled="False" />

and in your viewmodel you can do something like

    private MapStyle _myMapStyle;
    public MapStyle MyMapStyle
    {
        get
        {
            if (_myMapStyle == null)
            {
                var assembly = typeof(TranslateExtension).GetTypeInfo().Assembly;
                var stream = assembly.GetManifestResourceStream($"MapProject.MapStyle.json");
                string styleFile;
                using (var reader = new System.IO.StreamReader(stream))
                {
                    styleFile = reader.ReadToEnd();
                }
                _myMapStyle = MapStyle.FromJson(styleFile);
            }
            return _myMapStyle;
        }
    }

here i have place json fine in shared project root var stream = assembly.GetManifestResourceStream($"MapProject.MapStyle.json");

ianvink commented 4 years ago

WOW! Perfect, thanks you