-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
044f902
commit e7be2f9
Showing
3 changed files
with
119 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Android.Gms.Maps; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Maui.Maps.Handlers; | ||
|
||
namespace Microsoft.Maui.Maps.Platform | ||
{ | ||
public static class MapExtensions | ||
{ | ||
public static void UpdateMapType(this GoogleMap googleMap, IMap map) | ||
{ | ||
if (googleMap == null) | ||
return; | ||
|
||
googleMap.MapType = map.MapType switch | ||
{ | ||
MapType.Street => GoogleMap.MapTypeNormal, | ||
MapType.Satellite => GoogleMap.MapTypeSatellite, | ||
MapType.Hybrid => GoogleMap.MapTypeHybrid, | ||
_ => throw new ArgumentOutOfRangeException(), | ||
}; | ||
} | ||
|
||
public static void UpdateIsShowingUser(this GoogleMap googleMap, IMap map, IMauiContext? mauiContext) | ||
{ | ||
if (googleMap == null) | ||
return; | ||
|
||
if (mauiContext?.Context == null) | ||
return; | ||
|
||
googleMap.SetIsShowingUser(map, mauiContext).FireAndForget(); | ||
} | ||
|
||
public static void UpdateIsScrollEnabled(this GoogleMap googleMap, IMap map) | ||
{ | ||
if (googleMap == null) | ||
return; | ||
|
||
googleMap.UiSettings.ScrollGesturesEnabled = map.IsScrollEnabled; | ||
} | ||
|
||
public static void UpdateIsTrafficEnabled(this GoogleMap googleMap, IMap map) | ||
{ | ||
if (googleMap == null) | ||
return; | ||
|
||
googleMap.TrafficEnabled = map.IsTrafficEnabled; | ||
} | ||
|
||
public static void UpdateIsZoomEnabled(this GoogleMap googleMap, IMap map) | ||
{ | ||
if (googleMap == null) | ||
return; | ||
|
||
googleMap.UiSettings.ZoomControlsEnabled = map.IsZoomEnabled; | ||
googleMap.UiSettings.ZoomGesturesEnabled = map.IsZoomEnabled; | ||
} | ||
|
||
internal static async Task SetIsShowingUser(this GoogleMap googleMap, IMap map, IMauiContext? mauiContext) | ||
{ | ||
if (map.IsShowingUser) | ||
{ | ||
var locationStatus = await ApplicationModel.Permissions.CheckStatusAsync<ApplicationModel.Permissions.LocationWhenInUse>(); | ||
|
||
if (locationStatus == ApplicationModel.PermissionStatus.Granted) | ||
{ | ||
googleMap.MyLocationEnabled = googleMap.UiSettings.MyLocationButtonEnabled = true; | ||
} | ||
else | ||
{ | ||
var locationResult = await ApplicationModel.Permissions.RequestAsync<ApplicationModel.Permissions.LocationWhenInUse>(); | ||
if (locationResult == ApplicationModel.PermissionStatus.Granted) | ||
{ | ||
googleMap.MyLocationEnabled = googleMap.UiSettings.MyLocationButtonEnabled = true; | ||
return; | ||
} | ||
else | ||
{ | ||
mauiContext?.Services.GetService<ILogger<MapHandler>>()?.LogWarning("Missing location permissions for IsShowingUser"); | ||
googleMap.MyLocationEnabled = googleMap.UiSettings.MyLocationButtonEnabled = false; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
googleMap.MyLocationEnabled = googleMap.UiSettings.MyLocationButtonEnabled = false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters