Xamarin.Forms.GoogleMaps icon indicating copy to clipboard operation
Xamarin.Forms.GoogleMaps copied to clipboard

Device theme mode compatibility

Open rubenc57 opened this issue 5 years ago • 1 comments

SUMMARY

To present the map according with the device theme mode

DETAILS

IMG_0367

IMG_0368

// How to use of your requested feature

No need for a setting, just check the current theme mode

PLATFORMS

  • [x] Android
  • [x ] iOS
  • [ ] UWP

rubenc57 avatar Nov 08 '19 16:11 rubenc57

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");

mrehman29 avatar Apr 01 '20 00:04 mrehman29