From 1c14a29f30fc1354fa1771f369934ae82279897e Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Wed, 25 Jul 2018 09:30:48 -0700 Subject: [PATCH] GH-287 OpenMaps Implementation (#361) (#404) * GH-287 Maps Implementation (#361) * Implemented maps as mentioned in branch name issue. also fixed a spelling mistake * Added samples * Added doc stubs * Added comments for map types * Refactored code * Formatting of docs * Added tests * Changed coordinates to display something recognisable * Added uri escaping, thus removing duplicate code. also had to turn off a warning due to inconsistent style cop and vs warning behaviour. * Removed ref until in is added in c# 7.2 * Adressed issues in pr * Updated launch code * Adressed method to onliner * Updated docs * Removed ClearTop intent, added sample with adress * Rename to align names. Added extensions and additional paramaters. * Update tests * Throw if options are null. * Add overload for lat/long without options --- .../DeviceTests.Shared.projitems | 1 + DeviceTests/DeviceTests.Shared/Maps_Tests.cs | 69 +++++++++ Samples/Samples/View/MapsPage.xaml | 44 ++++++ Samples/Samples/View/MapsPage.xaml.cs | 13 ++ Samples/Samples/ViewModel/HomeViewModel.cs | 6 + Samples/Samples/ViewModel/MapsViewModel.cs | 110 ++++++++++++++ Tests/Maps_Tests.cs | 70 +++++++++ .../Maps/MapDirectionsMode.shared.cs | 10 ++ .../Maps/MapLaunchOptions.shared.cs | 9 ++ Xamarin.Essentials/Maps/Maps.android.cs | 38 +++++ Xamarin.Essentials/Maps/Maps.ios.cs | 85 +++++++++++ Xamarin.Essentials/Maps/Maps.netstandard.cs | 13 ++ Xamarin.Essentials/Maps/Maps.shared.cs | 47 ++++++ Xamarin.Essentials/Maps/Maps.uwp.cs | 37 +++++ .../SecureStorage/SecureStorage.android.cs | 2 + .../Types/LocationExtensions.shared.cs | 10 +- .../Types/PlacemarkExtensions.android.cs | 2 +- .../Types/PlacemarkExtensions.ios.cs | 2 +- .../Types/PlacemarkExtensions.shared.cs | 36 ++++- Xamarin.Essentials/Xamarin.Essentials.csproj | 2 +- Xamarin.Essentials/mdoc.targets | 2 +- .../xamarin-essentials-android.xml | 24 +++ .../xamarin-essentials-ios.xml | 24 +++ .../xamarin-essentials-uwp.xml | 24 +++ .../en/FrameworksIndex/xamarin-essentials.xml | 24 +++ .../Xamarin.Essentials/LocationExtensions.xml | 46 ++++++ .../Xamarin.Essentials/MapDirectionsMode.xml | 86 +++++++++++ docs/en/Xamarin.Essentials/Maps.xml | 139 ++++++++++++++++++ .../Xamarin.Essentials/MapsLaunchOptions.xml | 70 +++++++++ docs/en/Xamarin.Essentials/Placemark.xml | 2 +- .../PlacemarkExtensions.xml | 65 ++++++++ docs/en/Xamarin.Essentials/TextToSpeech.xml | 8 + docs/en/index.xml | 33 +---- 33 files changed, 1116 insertions(+), 37 deletions(-) create mode 100644 DeviceTests/DeviceTests.Shared/Maps_Tests.cs create mode 100644 Samples/Samples/View/MapsPage.xaml create mode 100644 Samples/Samples/View/MapsPage.xaml.cs create mode 100644 Samples/Samples/ViewModel/MapsViewModel.cs create mode 100644 Tests/Maps_Tests.cs create mode 100644 Xamarin.Essentials/Maps/MapDirectionsMode.shared.cs create mode 100644 Xamarin.Essentials/Maps/MapLaunchOptions.shared.cs create mode 100644 Xamarin.Essentials/Maps/Maps.android.cs create mode 100644 Xamarin.Essentials/Maps/Maps.ios.cs create mode 100644 Xamarin.Essentials/Maps/Maps.netstandard.cs create mode 100644 Xamarin.Essentials/Maps/Maps.shared.cs create mode 100644 Xamarin.Essentials/Maps/Maps.uwp.cs create mode 100644 docs/en/Xamarin.Essentials/MapDirectionsMode.xml create mode 100644 docs/en/Xamarin.Essentials/Maps.xml create mode 100644 docs/en/Xamarin.Essentials/MapsLaunchOptions.xml create mode 100644 docs/en/Xamarin.Essentials/PlacemarkExtensions.xml diff --git a/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.projitems b/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.projitems index 48dc3409f..0da11cb8d 100644 --- a/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.projitems +++ b/DeviceTests/DeviceTests.Shared/DeviceTests.Shared.projitems @@ -24,6 +24,7 @@ + diff --git a/DeviceTests/DeviceTests.Shared/Maps_Tests.cs b/DeviceTests/DeviceTests.Shared/Maps_Tests.cs new file mode 100644 index 000000000..cf1e0a9c8 --- /dev/null +++ b/DeviceTests/DeviceTests.Shared/Maps_Tests.cs @@ -0,0 +1,69 @@ +using System; +using System.Threading.Tasks; +using Xamarin.Essentials; +using Xunit; + +namespace DeviceTests +{ + public class Maps_Tests + { + const double testLatitude = 47.645160; + const double testLongitude = -122.1306032; + const string mapName = "Microsoft Building 25"; + + [Fact] + [Trait(Traits.InteractionType, Traits.InteractionTypes.Human)] + public async Task LaunchMap_CoordinatesDisplayCorrectPlace() + { + await Maps.OpenAsync(testLatitude, testLongitude, new MapsLaunchOptions { Name = mapName }); + } + + [Fact] + [Trait(Traits.InteractionType, Traits.InteractionTypes.Human)] + public async Task LaunchMap_PlacemarkDisplayCorrectPlace() + { + var placemark = new Placemark + { + CountryName = "United States", + AdminArea = "WA", + Thoroughfare = "Microsoft Building 25", + Locality = "Redmond" + }; + await Maps.OpenAsync(placemark, new MapsLaunchOptions { Name = mapName }); + } + + [Fact] + public async Task LaunchMap_NullLocation() + { + Location location = null; + await Assert.ThrowsAsync(() => Maps.OpenAsync(location)); + } + + [Fact] + public async Task LaunchMap_NullOptionsLocation() + { + var location = new Location(testLatitude, testLongitude); + await Assert.ThrowsAsync(() => Maps.OpenAsync(location, null)); + } + + [Fact] + public async Task LaunchMap_NullPlacemark() + { + Placemark location = null; + await Assert.ThrowsAsync(() => Maps.OpenAsync(location)); + } + + [Fact] + public async Task LaunchMap_NullOptionsPlacemark() + { + var placemark = new Placemark + { + CountryName = "United States", + AdminArea = "WA", + Thoroughfare = "Microsoft Building 25", + Locality = "Redmond" + }; + await Assert.ThrowsAsync(() => Maps.OpenAsync(placemark, null)); + } + } +} diff --git a/Samples/Samples/View/MapsPage.xaml b/Samples/Samples/View/MapsPage.xaml new file mode 100644 index 000000000..9c7aae675 --- /dev/null +++ b/Samples/Samples/View/MapsPage.xaml @@ -0,0 +1,44 @@ + + + + + + + +