-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* MauiMaps * Add Android * net7.0 * iOS/MacCatalyst maps
- Loading branch information
1 parent
7c403a8
commit 94f0838
Showing
70 changed files
with
1,266 additions
and
48 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
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
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
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,14 @@ | ||
<?xml version = "1.0" encoding = "UTF-8" ?> | ||
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:MauiMaps" | ||
x:Class="MauiMaps.App"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="Resources/Styles/Colors.xaml" /> | ||
<ResourceDictionary Source="Resources/Styles/Styles.xaml" /> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</Application.Resources> | ||
</Application> |
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,11 @@ | ||
namespace MauiMaps; | ||
|
||
public partial class App : Application | ||
{ | ||
public App() | ||
{ | ||
InitializeComponent(); | ||
|
||
MainPage = new AppShell(); | ||
} | ||
} |
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<Shell | ||
x:Class="MauiMaps.AppShell" | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:MauiMaps" | ||
Shell.FlyoutBehavior="Disabled"> | ||
|
||
<ShellContent | ||
Title="Home" | ||
ContentTemplate="{DataTemplate local:MainPage}" | ||
Route="MainPage" /> | ||
|
||
</Shell> |
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,9 @@ | ||
namespace MauiMaps; | ||
|
||
public partial class AppShell : Shell | ||
{ | ||
public AppShell() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
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,53 @@ | ||
namespace MauiMaps; | ||
|
||
using Microsoft.Maui.Controls.Maps; | ||
|
||
public class CustomPin : Pin | ||
{ | ||
public static readonly BindableProperty ImageSourceProperty = | ||
BindableProperty.Create(nameof(ImageSource), typeof(ImageSource), typeof(CustomPin), propertyChanged:OnImageSourceChanged); | ||
|
||
public ImageSource? ImageSource | ||
{ | ||
get => (ImageSource?)GetValue(ImageSourceProperty); | ||
set => SetValue(ImageSourceProperty, value); | ||
} | ||
|
||
public Microsoft.Maui.Maps.IMap? Map { get; set; } | ||
|
||
static async void OnImageSourceChanged(BindableObject bindable, object oldValue, object newValue) | ||
{ | ||
var control = (CustomPin)bindable; | ||
var imageSource = control.ImageSource; | ||
|
||
if (control.Handler?.PlatformView is null) | ||
{ | ||
// Workaround for when this executes the Handler and PlatformView is null | ||
control.HandlerChanged += OnHandlerChanged; | ||
return; | ||
} | ||
|
||
if (imageSource is not null) | ||
{ | ||
#if ANDROID || IOS || MACCATALYST | ||
await control.AddAnnotation(); | ||
#else | ||
await Task.CompletedTask; | ||
#endif | ||
} | ||
else | ||
{ | ||
#if ANDROID | ||
|
||
#elif IOS | ||
|
||
#endif | ||
} | ||
|
||
void OnHandlerChanged(object? s, EventArgs e) | ||
{ | ||
OnImageSourceChanged(control, oldValue, newValue); | ||
control.HandlerChanged -= OnHandlerChanged; | ||
} | ||
} | ||
} |
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="MauiMaps.MainPage"> | ||
|
||
<Grid> | ||
<Map x:Name="MyMap"/> | ||
|
||
</Grid> | ||
|
||
</ContentPage> |
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,30 @@ | ||
namespace MauiMaps; | ||
|
||
using Microsoft.Maui.Maps; | ||
|
||
public partial class MainPage : ContentPage | ||
{ | ||
public MainPage() | ||
{ | ||
InitializeComponent(); | ||
var customPin1 = new CustomPin() | ||
{ | ||
Label = "label", | ||
Location = new Location(10, 10), | ||
Address = "Address", | ||
ImageSource = ImageSource.FromUri(new Uri("https://picsum.photos/50")), | ||
Map = MyMap | ||
}; | ||
var customPin2 = new CustomPin() | ||
{ | ||
Label = "label2", | ||
Location = new Location(11, 11), | ||
Address = "Address2", | ||
ImageSource = ImageSource.FromUri(new Uri("https://picsum.photos/60")), | ||
Map = MyMap | ||
}; | ||
MyMap.Pins.Add(customPin1); | ||
MyMap.Pins.Add(customPin2); | ||
MyMap.MoveToRegion(new MapSpan(new Location(10,10), 10, 10)); | ||
} | ||
} |
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,27 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31611.283 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiMaps", "MauiMaps.csproj", "{FDF55EA0-A4E1-4E6E-89D2-70B8F08EB018}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FDF55EA0-A4E1-4E6E-89D2-70B8F08EB018}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FDF55EA0-A4E1-4E6E-89D2-70B8F08EB018}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FDF55EA0-A4E1-4E6E-89D2-70B8F08EB018}.Debug|Any CPU.Deploy.0 = Debug|Any CPU | ||
{FDF55EA0-A4E1-4E6E-89D2-70B8F08EB018}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FDF55EA0-A4E1-4E6E-89D2-70B8F08EB018}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{FDF55EA0-A4E1-4E6E-89D2-70B8F08EB018}.Release|Any CPU.Deploy.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572} | ||
EndGlobalSection | ||
EndGlobal |
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,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>MauiMaps</RootNamespace> | ||
|
||
<!-- Display name --> | ||
<ApplicationTitle>MauiMaps</ApplicationTitle> | ||
|
||
<!-- App Identifier --> | ||
<ApplicationId>com.vladislavantonyuk.mauimaps</ApplicationId> | ||
<ApplicationIdGuid>1761D471-B6ED-41DB-8307-708EEEF95479</ApplicationIdGuid> | ||
|
||
<!-- Versions --> | ||
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> | ||
<ApplicationVersion>1</ApplicationVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<!-- App Icon --> | ||
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" /> | ||
|
||
<!-- Splash Screen --> | ||
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" /> | ||
|
||
<!-- Images --> | ||
<MauiImage Include="Resources\Images\*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Maui.Controls.Maps" Version="7.0.0-rc.1.6683" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,18 @@ | ||
namespace MauiMaps; | ||
|
||
public static class MauiProgram | ||
{ | ||
public static MauiApp CreateMauiApp() | ||
{ | ||
var builder = MauiApp.CreateBuilder(); | ||
builder.UseMauiApp<App>().UseMauiMaps(); | ||
builder.ConfigureMauiHandlers(handlers=> | ||
{ | ||
#if IOS || MACCATALYST | ||
handlers.AddHandler<CustomPin, CustomPinHandler>(); | ||
#endif | ||
}); | ||
|
||
return builder.Build(); | ||
} | ||
} |
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,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"> | ||
<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_KEY_HERE"/> | ||
</application> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<queries> | ||
<intent> | ||
<action android:name="android.intent.action.VIEW" /> | ||
<data android:scheme="geo"/> | ||
</intent> | ||
</queries> | ||
</manifest> |
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,15 @@ | ||
using Android.App; | ||
using Android.Content.PM; | ||
|
||
namespace MauiMaps; | ||
|
||
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, | ||
ConfigurationChanges = ConfigChanges.ScreenSize | | ||
ConfigChanges.Orientation | | ||
ConfigChanges.UiMode | | ||
ConfigChanges.ScreenLayout | | ||
ConfigChanges.SmallestScreenSize | | ||
ConfigChanges.Density)] | ||
public class MainActivity : MauiAppCompatActivity | ||
{ | ||
} |
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,14 @@ | ||
using Android.App; | ||
using Android.Runtime; | ||
|
||
namespace MauiMaps; | ||
|
||
[Application] | ||
public class MainApplication : MauiApplication | ||
{ | ||
public MainApplication(IntPtr handle, JniHandleOwnership ownership) : base(handle, ownership) | ||
{ | ||
} | ||
|
||
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
} |
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,28 @@ | ||
namespace MauiMaps; | ||
|
||
using Android.App; | ||
using Android.Gms.Maps.Model; | ||
using Microsoft.Maui.Controls.Compatibility.Platform.Android; | ||
using Microsoft.Maui.Maps.Handlers; | ||
|
||
public static class MapExtensions | ||
{ | ||
public static async Task AddAnnotation(this CustomPin pin) | ||
{ | ||
var googleMap = ((IMapHandler?)pin.Map?.Handler)?.Map; | ||
if (googleMap is not null) | ||
{ | ||
var markerWithIcon = new MarkerOptions(); | ||
markerWithIcon.SetPosition(new LatLng(pin.Location.Latitude, pin.Location.Longitude)); | ||
markerWithIcon.SetTitle(pin.Label); | ||
markerWithIcon.SetSnippet(pin.Address); | ||
var imageSourceHandler = new ImageLoaderSourceHandler(); | ||
var bitmap = await imageSourceHandler.LoadImageAsync(pin.ImageSource, Application.Context); | ||
markerWithIcon.SetIcon(bitmap is null | ||
? BitmapDescriptorFactory.DefaultMarker() | ||
: BitmapDescriptorFactory.FromBitmap(bitmap)); | ||
|
||
googleMap.AddMarker(markerWithIcon); | ||
} | ||
} | ||
} |
Oops, something went wrong.