Skip to content

Commit d713c4a

Browse files
committed
- add Update annotation method
1 parent 17d8caf commit d713c4a

File tree

10 files changed

+59
-93
lines changed

10 files changed

+59
-93
lines changed

src/libs/Mapbox.Maui/Mapbox.Maui.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<RepositoryUrl>https://github.com/tuyen-vuduc/mapbox-maui</RepositoryUrl>
6262
<PackageProjectUrl>https://mapbox.tuyen-vuduc.tech</PackageProjectUrl>
6363
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
64-
<PackageVersion>11.5.1-alpha01</PackageVersion>
64+
<PackageVersion>11.5.1-alpha02</PackageVersion>
6565
<PackageReadmeFile>README.md</PackageReadmeFile>
6666
<PackageLicenseFile>LICENSE</PackageLicenseFile>
6767
<PackageIcon>tv-mapbox.png</PackageIcon>
@@ -94,7 +94,7 @@
9494
<PackageReference Include="Xamarin.AndroidX.Annotation" Version="1.8.0.1" />
9595
</ItemGroup>
9696
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
97-
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.2" />
97+
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.3" />
9898
<PackageReference Include="MapboxMaps.iOS" Version="11.5.2" />
9999
</ItemGroup>
100100
<ItemGroup>

src/libs/Mapbox.Maui/Models/Annotations/IAnnotationManager.cs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public interface IAnnotationManager<TAnnotation> where TAnnotation : IAnnotation
1414

1515
void AddAnnotations(params TAnnotation[] annotations);
1616

17+
void UpdateAnnotations(params TAnnotation[] annotations);
18+
1719
void RemoveAnnotations(params string[] annotationIDs);
1820

1921
void RemoveAllAnnotations();

src/libs/Mapbox.Maui/Platforms/Android/Annotations/AnnotationManager.cs

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ public void AddAnnotations(params TAnnotation[] annotations)
3939
annotations[i].Id = item.Id.ToString();
4040
}
4141
}
42+
43+
public void UpdateAnnotations(params TAnnotation[] annotations)
44+
{
45+
if (annotations.Length == 0) return;
46+
47+
var xannotations = annotations
48+
.Select(ToPlatformAnnotationOption)
49+
.ToList();
50+
51+
NativeManager.Update(xannotations);
52+
}
53+
4254
public void RemoveAllAnnotations()
4355
=> NativeManager.DeleteAll();
4456
public void RemoveAnnotations(params string[] annotationIDs)

src/libs/Mapbox.Maui/Platforms/iOS/Annotations/AnnotationManager.cs

+31-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,35 @@ public void DidDetectTappedAnnotations(ITMBAnnotationManager manager, NSObject[]
4141
);
4242
}
4343

44-
public abstract void AddAnnotations(params TAnnotation[] annotations);
45-
public abstract void RemoveAllAnnotations();
46-
public abstract void RemoveAnnotations(params string[] annotationIDs);
44+
public void AddAnnotations(params TAnnotation[] xitems)
45+
{
46+
if (xitems.Length == 0) return;
47+
48+
var items = xitems
49+
.Select(ToPlatformAnnotationOption)
50+
.ToArray();
51+
52+
NativeManager.AddAnnotations(items);
53+
}
54+
public void UpdateAnnotations(params TAnnotation[] xitems)
55+
{
56+
if (xitems.Length == 0) return;
57+
58+
var items = xitems
59+
.Select(ToPlatformAnnotationOption)
60+
.ToArray();
61+
62+
NativeManager.UpdateAnnotations(items);
63+
}
64+
public void RemoveAllAnnotations()
65+
=> NativeManager.RemoveAllAnnotations();
66+
public void RemoveAnnotations(params string[] annotationIDs)
67+
{
68+
for (int i = 0; i < annotationIDs.Length; i++)
69+
{
70+
NativeManager.RemoveAnnotationById(annotationIDs[i]);
71+
}
72+
}
73+
74+
protected abstract ITMBAnnotation ToPlatformAnnotationOption(TAnnotation annotation);
4775
}

src/libs/Mapbox.Maui/Platforms/iOS/Annotations/CircleAnnotationManager.cs

+2-21
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,7 @@ public CircleTranslateAnchor? CircleTranslateAnchor
4545
set => nativeManager.CircleTranslateAnchor = value?.ToPlatform();
4646
}
4747

48-
public override void AddAnnotations(params CircleAnnotation[] xitems)
49-
{
50-
var items = xitems
51-
.Select(x => x.ToPlatformValue())
52-
.ToArray();
53-
54-
nativeManager.AddAnnotations(items);
55-
}
56-
57-
public override void RemoveAllAnnotations()
58-
{
59-
nativeManager.RemoveAllAnnotations();
60-
}
61-
62-
public override void RemoveAnnotations(params string[] annotationIDs)
63-
{
64-
for (int i = 0; i < annotationIDs.Length; i++)
65-
{
66-
nativeManager.RemoveAnnotationById(annotationIDs[i]);
67-
}
68-
}
48+
protected override ITMBAnnotation ToPlatformAnnotationOption(CircleAnnotation annotation)
49+
=> annotation.ToPlatformValue();
6950
}
7051

src/libs/Mapbox.Maui/Platforms/iOS/Annotations/PointAnnotationManager.cs

+2-21
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,7 @@ public TextTranslateAnchor? TextTranslateAnchor
166166
set => nativeManager.TextTranslateAnchor = value?.ToPlatform();
167167
}
168168

169-
public override void AddAnnotations(params PointAnnotation[] xitems)
170-
{
171-
var items = xitems
172-
.Select(x => x.ToPlatformValue())
173-
.ToArray();
174-
175-
nativeManager.AddAnnotations(items);
176-
}
177-
178-
public override void RemoveAllAnnotations()
179-
{
180-
nativeManager.RemoveAllAnnotations();
181-
}
182-
183-
public override void RemoveAnnotations(params string[] annotationIDs)
184-
{
185-
for (int i = 0; i < annotationIDs.Length; i++)
186-
{
187-
nativeManager.RemoveAnnotationById(annotationIDs[i]);
188-
}
189-
}
169+
protected override ITMBAnnotation ToPlatformAnnotationOption(PointAnnotation annotation)
170+
=> annotation.ToPlatformValue();
190171
}
191172

src/libs/Mapbox.Maui/Platforms/iOS/Annotations/PolygonAnnotationManager.cs

+2-21
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,6 @@ public FillTranslateAnchor? FillTranslateAnchor
3535
set => nativeManager.FillTranslateAnchor = value?.ToPlatform();
3636
}
3737

38-
public override void AddAnnotations(params PolygonAnnotation[] xitems)
39-
{
40-
var items = xitems
41-
.Select(x => x.ToPlatformValue())
42-
.ToArray();
43-
44-
nativeManager.AddAnnotations(items);
45-
}
46-
47-
public override void RemoveAllAnnotations()
48-
{
49-
nativeManager.RemoveAllAnnotations();
50-
}
51-
52-
public override void RemoveAnnotations(params string[] annotationIDs)
53-
{
54-
for (int i = 0; i < annotationIDs.Length; i++)
55-
{
56-
nativeManager.RemoveAnnotationById(annotationIDs[i]);
57-
}
58-
}
38+
protected override ITMBAnnotation ToPlatformAnnotationOption(PolygonAnnotation annotation)
39+
=> annotation.ToPlatformValue();
5940
}

src/libs/Mapbox.Maui/Platforms/iOS/Annotations/PolylineAnnotationManager.cs

+2-21
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,6 @@ public double[] LineTrimOffset
5555
set => nativeManager.LineTrimOffset = value?.ToPlatform();
5656
}
5757

58-
public override void AddAnnotations(params PolylineAnnotation[] xitems)
59-
{
60-
var items = xitems
61-
.Select(x => x.ToPlatformValue())
62-
.ToArray();
63-
64-
nativeManager.AddAnnotations(items);
65-
}
66-
67-
public override void RemoveAllAnnotations()
68-
{
69-
nativeManager.RemoveAllAnnotations();
70-
}
71-
72-
public override void RemoveAnnotations(params string[] annotationIDs)
73-
{
74-
for (int i = 0; i < annotationIDs.Length; i++)
75-
{
76-
nativeManager.RemoveAnnotationById(annotationIDs[i]);
77-
}
78-
}
58+
protected override ITMBAnnotation ToPlatformAnnotationOption(PolylineAnnotation annotation)
59+
=> annotation.ToPlatformValue();
7960
}

src/qs/MapboxMauiQs/Examples/Lab/67.AddRemoveAnnotations/AddRemoveAnnotationsExample.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ private async void RemoveAnnotation()
145145
}
146146
private async void RemoveAllAnnotations()
147147
{
148-
pointAnnotationManager.RemoveAllAnnotations();
149-
circleAnnotationManager.RemoveAllAnnotations();
148+
pointAnnotationManager?.RemoveAllAnnotations();
149+
circleAnnotationManager?.RemoveAllAnnotations();
150150
await DisplayAlert("Info", $"All annotations were removed", "OK");
151-
annotations.Clear();
151+
annotations?.Clear();
152152
map.CameraController.EaseTo(new CameraOptions
153153
{
154154
Center = defaultCenterPosition,

src/qs/MapboxMauiQs/MapboxMauiQs.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
</Compile>
107107
</ItemGroup>
108108
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
109-
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.2" />
109+
<PackageReference Include="MapboxMapsObjC.iOS" Version="11.5.2.3" />
110110
<PackageReference Include="MapboxMaps.iOS" Version="11.5.2" />
111111

112112
<Compile Include="..\..\libs\Mapbox.Maui\Platforms\iOS\**\**\*.cs">

0 commit comments

Comments
 (0)