Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Update annotation method #34

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libs/Mapbox.Maui/Mapbox.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<RepositoryUrl>https://github.com/tuyen-vuduc/mapbox-maui</RepositoryUrl>
<PackageProjectUrl>https://mapbox.tuyen-vuduc.tech</PackageProjectUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageVersion>11.5.1-alpha01</PackageVersion>
<PackageVersion>11.5.1-alpha02</PackageVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>tv-mapbox.png</PackageIcon>
Expand Down Expand Up @@ -94,7 +94,7 @@
<PackageReference Include="Xamarin.AndroidX.Annotation" Version="1.8.0.1" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.2" />
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.3" />
<PackageReference Include="MapboxMaps.iOS" Version="11.5.2" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Mapbox.Maui/Models/Annotations/IAnnotationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface IAnnotationManager<TAnnotation> where TAnnotation : IAnnotation

void AddAnnotations(params TAnnotation[] annotations);

void UpdateAnnotations(params TAnnotation[] annotations);

void RemoveAnnotations(params string[] annotationIDs);

void RemoveAllAnnotations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public string SourceId => id;
public string LayerId => id;

public event EventHandler<AnnotationsSelectedEventArgs> AnnotationsSelected;

Check warning on line 28 in src/libs/Mapbox.Maui/Platforms/Android/Annotations/AnnotationManager.cs

View workflow job for this annotation

GitHub Actions / build-then-publish

The event 'AnnotationManager<TAnnotationManager, TAnnotation>.AnnotationsSelected' is never used

public void AddAnnotations(params TAnnotation[] annotations)
{
Expand All @@ -39,6 +39,18 @@
annotations[i].Id = item.Id.ToString();
}
}

public void UpdateAnnotations(params TAnnotation[] annotations)
{
if (annotations.Length == 0) return;

var xannotations = annotations
.Select(ToPlatformAnnotationOption)
.ToList();

NativeManager.Update(xannotations);
}

public void RemoveAllAnnotations()
=> NativeManager.DeleteAll();
public void RemoveAnnotations(params string[] annotationIDs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,35 @@ public void DidDetectTappedAnnotations(ITMBAnnotationManager manager, NSObject[]
);
}

public abstract void AddAnnotations(params TAnnotation[] annotations);
public abstract void RemoveAllAnnotations();
public abstract void RemoveAnnotations(params string[] annotationIDs);
public void AddAnnotations(params TAnnotation[] xitems)
{
if (xitems.Length == 0) return;

var items = xitems
.Select(ToPlatformAnnotationOption)
.ToArray();

NativeManager.AddAnnotations(items);
}
public void UpdateAnnotations(params TAnnotation[] xitems)
{
if (xitems.Length == 0) return;

var items = xitems
.Select(ToPlatformAnnotationOption)
.ToArray();

NativeManager.UpdateAnnotations(items);
}
public void RemoveAllAnnotations()
=> NativeManager.RemoveAllAnnotations();
public void RemoveAnnotations(params string[] annotationIDs)
{
for (int i = 0; i < annotationIDs.Length; i++)
{
NativeManager.RemoveAnnotationById(annotationIDs[i]);
}
}

protected abstract ITMBAnnotation ToPlatformAnnotationOption(TAnnotation annotation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,7 @@ public CircleTranslateAnchor? CircleTranslateAnchor
set => nativeManager.CircleTranslateAnchor = value?.ToPlatform();
}

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

nativeManager.AddAnnotations(items);
}

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

public override void RemoveAnnotations(params string[] annotationIDs)
{
for (int i = 0; i < annotationIDs.Length; i++)
{
nativeManager.RemoveAnnotationById(annotationIDs[i]);
}
}
protected override ITMBAnnotation ToPlatformAnnotationOption(CircleAnnotation annotation)
=> annotation.ToPlatformValue();
}

Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,7 @@ public TextTranslateAnchor? TextTranslateAnchor
set => nativeManager.TextTranslateAnchor = value?.ToPlatform();
}

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

nativeManager.AddAnnotations(items);
}

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

public override void RemoveAnnotations(params string[] annotationIDs)
{
for (int i = 0; i < annotationIDs.Length; i++)
{
nativeManager.RemoveAnnotationById(annotationIDs[i]);
}
}
protected override ITMBAnnotation ToPlatformAnnotationOption(PointAnnotation annotation)
=> annotation.ToPlatformValue();
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,6 @@ public FillTranslateAnchor? FillTranslateAnchor
set => nativeManager.FillTranslateAnchor = value?.ToPlatform();
}

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

nativeManager.AddAnnotations(items);
}

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

public override void RemoveAnnotations(params string[] annotationIDs)
{
for (int i = 0; i < annotationIDs.Length; i++)
{
nativeManager.RemoveAnnotationById(annotationIDs[i]);
}
}
protected override ITMBAnnotation ToPlatformAnnotationOption(PolygonAnnotation annotation)
=> annotation.ToPlatformValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,6 @@ public double[] LineTrimOffset
set => nativeManager.LineTrimOffset = value?.ToPlatform();
}

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

nativeManager.AddAnnotations(items);
}

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

public override void RemoveAnnotations(params string[] annotationIDs)
{
for (int i = 0; i < annotationIDs.Length; i++)
{
nativeManager.RemoveAnnotationById(annotationIDs[i]);
}
}
protected override ITMBAnnotation ToPlatformAnnotationOption(PolylineAnnotation annotation)
=> annotation.ToPlatformValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ private async void RemoveAnnotation()
}
private async void RemoveAllAnnotations()
{
pointAnnotationManager.RemoveAllAnnotations();
circleAnnotationManager.RemoveAllAnnotations();
pointAnnotationManager?.RemoveAllAnnotations();
circleAnnotationManager?.RemoveAllAnnotations();
await DisplayAlert("Info", $"All annotations were removed", "OK");
annotations.Clear();
annotations?.Clear();
map.CameraController.EaseTo(new CameraOptions
{
Center = defaultCenterPosition,
Expand Down
2 changes: 1 addition & 1 deletion src/qs/MapboxMauiQs/MapboxMauiQs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</Compile>
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.2" />
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.3" />
<PackageReference Include="MapboxMaps.iOS" Version="11.5.2" />

<Compile Include="..\..\libs\Mapbox.Maui\Platforms\iOS\**\**\*.cs">
Expand Down
Loading