Skip to content

Commit

Permalink
- add Update annotation method
Browse files Browse the repository at this point in the history
  • Loading branch information
tuyen-vuduc committed Aug 12, 2024
1 parent 17d8caf commit d713c4a
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 93 deletions.
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 @@ -39,6 +39,18 @@ public void AddAnnotations(params TAnnotation[] annotations)
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

0 comments on commit d713c4a

Please sign in to comment.