Skip to content

Commit

Permalink
feat: v11.5.0-alpha01 (#30)
Browse files Browse the repository at this point in the history
* - fix for Android

* - change btns style

* - add MapLoadingError (iOS only)

* - use latest Mapbox Android SDK

* - use latest iOS SDK v11.5.1
- use new functions to add/remove annotations for iOS

* - correct build script

* - correct build script
  • Loading branch information
tuyen-vuduc authored Jul 12, 2024
1 parent 0f38649 commit a75786b
Show file tree
Hide file tree
Showing 21 changed files with 373 additions and 172 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,27 @@ NOTE: A handy command to generate a new example
dotnet cake -- --name SymbolClustering --index 58 --group Annotations --title "Add Cluster Symbol Annotations" --subtitle "Show fire hydrants in Washington DC area in a cluster using a symbol layer."
````
# Known issues
- The library is not yet able to build to run on iOS real device. [Issue](https://github.com/xamarin/xamarin-macios/issues/8917)
# NOTES
1) Failed to delete `.gradle` folder
Due to Java process not killed gratefully.
```
taskkill -F -im java.exe
```
2) Xamarin.Build.Download
Xamarin.Build.Download is a tool to help download artifacts from remote URL to avoid embedding the native artifacts within the NuGet package with advantages
- Very thin and lightweight NuGet package
- Avoid any license viloation if the owner of the native lib doesn't want us to redistribute their lib
The downloaded artifact will be located at
- MacOS: `~/Library/Caches/XamarinBuildDownload`
- Windows: `%USERPROFILE%/AppData/Local/XamarinBuildDownloadCache`
3) Kill all .NET processes
```
taskkill -F -im dotnet.exe
```
# Maintainer
This project is maintained by [tuyen-vuduc](https://github.com/tuyen-vuduc) in his spare time and/or when requested.<br>
Expand Down
11 changes: 4 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
dotnet nuget locals -c all
# dotnet nuget locals -c all

# Build to trigger gradle process
dotnet build -t:Clean,Rebuild src/qs/MapboxMauiQs/MapboxMauiQs.csproj \
-property:MAPBOX_DOWNLOADS_TOKEN=$MAPBOX_DOWNLOADS_TOKEN

dotnet pack -c Release -t:Clean,Rebuild src/libs/Mapbox.Maui/Mapbox.Maui.csproj \
--output $PWD/nugets
# Add this option to view detail output
# -v d
dotnet pack -c Release -t:Clean,Rebuild src/libs/Mapbox.Maui/Mapbox.Maui.csproj --output $PWD/nugets
23 changes: 19 additions & 4 deletions src/libs/Mapbox.Maui/Mapbox.Maui.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Condition="EXISTS('Mapbox.Maui.props')" Project="Mapbox.Maui.props" />
<Import Condition="EXISTS('Mapbox.Maui.targets')" Project="Mapbox.Maui.targets" />
<Target Name="_CleanAarOutputPath" AfterTargets="_CreateAar" BeforeTargets="_IncludeAarInNuGetPackage">
<Delete Files="$(_AarOutputPath)" />
</Target>
Expand Down Expand Up @@ -42,6 +44,12 @@
<Compile Remove="**\**\*.iOS.cs" />
</ItemGroup>

<PropertyGroup>
<AndroidTargetSdkVersion>34</AndroidTargetSdkVersion>
<AndroidSdkDirectory Condition=" '$(OS)' == 'Unix' ">$(Home)/Library/Android/sdk</AndroidSdkDirectory>
<AndroidSdkDirectory Condition=" '$(OS)' != 'Unix' ">$(UserProfile)/AppData/Local/Android/sdk</AndroidSdkDirectory>
</PropertyGroup>

<PropertyGroup>
<PackageId>Mapbox.Maui</PackageId>
<Title>Mapbox SDK for .NET MAUI</Title>
Expand All @@ -53,7 +61,7 @@
<RepositoryUrl>https://github.com/tuyen-vuduc/mapbox-maui</RepositoryUrl>
<PackageProjectUrl>https://mapbox.tuyen-vuduc.tech</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageVersion>11.4.0-alpha02</PackageVersion>
<PackageVersion>11.5.0-alpha01</PackageVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>tv-mapbox.png</PackageIcon>
Expand All @@ -72,16 +80,17 @@
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.40" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
<PackageReference Include="Com.Mapbox.Maps.Android" Version="11.4.1" />
<PackageReference Include="Com.Mapbox.Maps.Android" Version="11.5.0" />
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.6.1.10" />
<PackageReference Include="Xamarin.AndroidX.Fragment " Version="1.7.0.2" />
<PackageReference Include="Xamarin.AndroidX.Fragment.Ktx" Version="1.7.0.2" />
<PackageReference Include="Xamarin.Kotlin.StdLib" Version="1.9.23.3" PrivateAssets="none" />
<PackageReference Include="Xamarin.Kotlin.StdLib.Common" Version="1.9.23.3" PrivateAssets="none" />
<PackageReference Include="Dependencies.Gradle" Version="8.6.0.1" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.4.0.2" />
<PackageReference Include="MapboxMaps.iOS" Version="11.4.0.1" />
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.1" />
<PackageReference Include="MapboxMaps.iOS" Version="11.5.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\Styles\" />
Expand Down Expand Up @@ -113,4 +122,10 @@
<ItemGroup>
<PackageReference Update="Microsoft.Maui.Controls.Compatibility" Version="8.0.40" />
</ItemGroup>

<Target
Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'"
Name="_GradleDependencyResolverTrigger"
DependsOnTargets="_GradleSync"
BeforeTargets="_BuildLibraryImportsCache" />
</Project>
22 changes: 22 additions & 0 deletions src/libs/Mapbox.Maui/Mapbox.Maui.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ItemGroup>
<GradleRepository Include="https://api.mapbox.com/downloads/v2/releases/maven">
<Repository>
maven {
url = uri("https://api.mapbox.com/downloads/v2/releases/maven")
authentication {
create&lt;BasicAuthentication&gt;("basic")
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = "mapbox"
// Use the secret token you stored in gradle.properties as the password
password = providers.gradleProperty("MAPBOX_DOWNLOADS_TOKEN").get()
}
}
</Repository>
</GradleRepository>
</ItemGroup>
</Project>
23 changes: 22 additions & 1 deletion src/libs/Mapbox.Maui/MapboxView.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ internal void InvokeMapLoaded()
MapLoadedCommand.Execute(null);
}
}

public static readonly BindableProperty MapLoadedCommandProperty = BindableProperty.Create(
nameof(MapLoadedCommand),
typeof(ICommand),
Expand All @@ -116,4 +115,26 @@ public ICommand MapLoadedCommand
get => (ICommand)GetValue(MapLoadedCommandProperty);
set => SetValue(MapLoadedCommandProperty, value);
}

public event EventHandler MapLoadingError;
internal void InvokeMapLoadingError()
{
MapLoadingError?.Invoke(this, EventArgs.Empty);

if (MapLoadingErrorCommand?.CanExecute(null) == true)
{
MapLoadingErrorCommand.Execute(null);
}
}
public static readonly BindableProperty MapLoadingErrorCommandProperty = BindableProperty.Create(
nameof(MapLoadingErrorCommand),
typeof(ICommand),
typeof(MapboxView),
default(ICommand)
);
public ICommand MapLoadingErrorCommand
{
get => (ICommand)GetValue(MapLoadingErrorCommandProperty);
set => SetValue(MapLoadingErrorCommandProperty, value);
}
}
7 changes: 5 additions & 2 deletions src/libs/Mapbox.Maui/Models/Annotations/ClusterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ public class ClusterOptions

/// Radius of each cluster if clustering is enabled. A value of 512 indicates a radius equal
/// to the width of a tile, 50 by default. Value must be greater than or equal to 0.
public double ClusterRadius { get; set; }
public double ClusterRadius { get; set; } = 50;

/// Max zoom on which to cluster points if clustering is enabled. Defaults to one zoom less
/// than maxzoom (so that last zoom features are not clustered). Clusters are re-evaluated at integer zoom
/// levels so setting clusterMaxZoom to 14 means the clusters will be displayed until z15.
public double ClusterMaxZoom { get; set; }
public double ClusterMaxZoom { get; set; } = 14;

/// Minimum number of points necessary to form a cluster if clustering is enabled. Defaults to `2`.
public double ClusterMinPoints { get; set; } = 2;

/// An object defining custom properties on the generated clusters if clustering is enabled, aggregating values from
/// clustered points. Has the form `{"property_name": [operator, map_expression]}`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
namespace MapboxMaui.Annotations;

using Com.Mapbox.Maps.Plugins.Annotations;
using System.Collections;
using IPlatformAnnotationManager = Com.Mapbox.Maps.Plugins.Annotations.IAnnotationManager;

public abstract partial class AnnotationManager<TAnnotationManager, TAnnotation>
: IAnnotationManager<TAnnotation>
where TAnnotationManager: IPlatformAnnotationManager
where TAnnotation: IAnnotation
where TAnnotationManager : IPlatformAnnotationManager
where TAnnotation : IAnnotation
{
private readonly string id;

Expand All @@ -25,7 +27,26 @@ protected AnnotationManager(

public event EventHandler<AnnotationsSelectedEventArgs> AnnotationsSelected;

public abstract void AddAnnotations(params TAnnotation[] annotations);
public abstract void RemoveAllAnnotations();
public abstract void RemoveAnnotations(params string[] annotationIDs);
public void AddAnnotations(params TAnnotation[] annotations)
{
var xannotations = annotations
.Select(ToPlatformAnnotationOption)
.ToList();
var platformAnnotations = NativeManager.Create(xannotations);
for (int i = 0; i < platformAnnotations.Count; i++)
{
var item = platformAnnotations[i] as Com.Mapbox.Maps.Plugins.Annotations.Annotation;
annotations[i].Id = item.Id.ToString();
}
}
public void RemoveAllAnnotations()
=> NativeManager.DeleteAll();
public void RemoveAnnotations(params string[] annotationIDs)
{
var annotations = GetNativeAnnotations(annotationIDs);
NativeManager.Delete(annotations);
}

protected abstract IAnnotationOptions ToPlatformAnnotationOption(TAnnotation annotation);
protected abstract IList GetNativeAnnotations(params string[] annotationIDs);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace MapboxMaui.Annotations;

using Com.Mapbox.Maps.Plugins.Annotations;
using System.Collections;
using PlatformCircleAnnotationManager = Com.Mapbox.Maps.Plugins.Annotations.Generated.CircleAnnotationManager;

public partial class CircleAnnotationManager
: AnnotationManager<PlatformCircleAnnotationManager, CircleAnnotation>
, ICircleAnnotationManager
: AnnotationManager<PlatformCircleAnnotationManager, CircleAnnotation>
, ICircleAnnotationManager
{
private readonly PlatformCircleAnnotationManager nativeManager;

Expand Down Expand Up @@ -41,28 +43,11 @@ public CircleTranslateAnchor? CircleTranslateAnchor
set => nativeManager.CircleTranslateAnchor = value?.ToPlatform();
}

public override void AddAnnotations(params CircleAnnotation[] xitems)
{
var items = xitems
.Select(x => x.ToPlatformValue())
.ToList();

var platformAnnotations = nativeManager.Create(items);

for (int i = 0; i < platformAnnotations.Count; i++)
{
var item = platformAnnotations[i] as Com.Mapbox.Maps.Plugins.Annotations.Generated.CircleAnnotation;
xitems[i].Id = item.Id.ToString();
}
}

public override void RemoveAllAnnotations()
{
nativeManager.Annotations.Clear();
}

public override void RemoveAnnotations(params string[] annotationIDs)
protected override IAnnotationOptions ToPlatformAnnotationOption(CircleAnnotation annotation)
=> annotation.ToPlatformValue();
protected override IList GetNativeAnnotations(params string[] annotationIDs)
{
var itemsToDelete = new List<Com.Mapbox.Maps.Plugins.Annotations.Generated.CircleAnnotation>();
foreach (var xid in annotationIDs)
{
var item = nativeManager
Expand All @@ -72,8 +57,9 @@ public override void RemoveAnnotations(params string[] annotationIDs)

if (item == null) continue;

nativeManager.Annotations.Remove(item);
itemsToDelete.Add(item);
}
return itemsToDelete;
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace MapboxMaui.Annotations;

using Com.Mapbox.Maps.Plugins.Annotations;
using System.Collections;
using PlatformPointAnnotationManager = Com.Mapbox.Maps.Plugins.Annotations.Generated.PointAnnotationManager;

public partial class PointAnnotationManager
Expand Down Expand Up @@ -153,28 +155,13 @@ public TextTranslateAnchor? TextTranslateAnchor
get => nativeManager.TextTranslateAnchor?.GetValue();
set => nativeManager.TextTranslateAnchor = value?.ToPlatform();
}
public override void AddAnnotations(params PointAnnotation[] xitems)
{
var items = xitems
.Select(x => x.ToPlatformValue())
.ToList();

var platformAnnotations = nativeManager.Create(items);

for (int i = 0; i < platformAnnotations.Count; i++)
{
var item = platformAnnotations[i] as Com.Mapbox.Maps.Plugins.Annotations.Generated.PointAnnotation;
xitems[i].Id = item.Id.ToString();
}
}

public override void RemoveAllAnnotations()
{
nativeManager.Annotations.Clear();
}
protected override IAnnotationOptions ToPlatformAnnotationOption(PointAnnotation annotation)
=> annotation.ToPlatformValue();

public override void RemoveAnnotations(params string[] annotationIDs)
protected override IList GetNativeAnnotations(params string[] annotationIDs)
{
var itemsToDelete = new List<Com.Mapbox.Maps.Plugins.Annotations.Generated.PointAnnotation>();
foreach (var xid in annotationIDs)
{
var item = nativeManager
Expand All @@ -184,8 +171,9 @@ public override void RemoveAnnotations(params string[] annotationIDs)

if (item == null) continue;

nativeManager.Annotations.Remove(item);
itemsToDelete.Add(item);
}
return itemsToDelete;
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace MapboxMaui.Annotations;

using Com.Mapbox.Maps.Plugins.Annotations;
using System.Collections;
using PlatformPolygonAnnotationManager = Com.Mapbox.Maps.Plugins.Annotations.Generated.PolygonAnnotationManager;

partial class PolygonAnnotationManager
Expand Down Expand Up @@ -36,28 +38,11 @@ public FillTranslateAnchor? FillTranslateAnchor
: null;
}

public override void AddAnnotations(params PolygonAnnotation[] xitems)
{
var items = xitems
.Select(x => x.ToPlatformValue())
.ToList();

var platformAnnotations = nativeManager.Create(items);

for (int i = 0; i < platformAnnotations.Count; i++)
{
var item = platformAnnotations[i] as Com.Mapbox.Maps.Plugins.Annotations.Generated.PolygonAnnotation;
xitems[i].Id = item.Id.ToString();
}
}

public override void RemoveAllAnnotations()
{
nativeManager.Annotations.Clear();
}

public override void RemoveAnnotations(params string[] annotationIDs)
protected override IAnnotationOptions ToPlatformAnnotationOption(PolygonAnnotation annotation)
=> annotation.ToPlatformValue();
protected override IList GetNativeAnnotations(params string[] annotationIDs)
{
var itemsToDelete = new List<Com.Mapbox.Maps.Plugins.Annotations.Generated.PolygonAnnotation>();
foreach (var id in annotationIDs)
{
var item = nativeManager
Expand All @@ -67,7 +52,8 @@ public override void RemoveAnnotations(params string[] annotationIDs)

if (item == null) continue;

nativeManager.Annotations.Remove(item);
itemsToDelete.Add(item);
}
return itemsToDelete;
}
}
Loading

0 comments on commit a75786b

Please sign in to comment.