-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAnnotationManager.cs
75 lines (61 loc) · 2.07 KB
/
AnnotationManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
namespace MapboxMaui.Annotations;
using Foundation;
using MapboxMapsObjC;
public abstract partial class AnnotationManager<TAnnotationManager, TAnnotation>
: NSObject
, IAnnotationManager<TAnnotation>
, ITMBAnnotationInteractionDelegate
where TAnnotationManager : ITMBAnnotationManager
where TAnnotation : IAnnotation
{
private readonly string id;
protected AnnotationManager(string id, ITMBAnnotationManager nativeManager)
{
this.id = id;
NativeManager = nativeManager;
}
public ITMBAnnotationManager NativeManager { get; init; }
public string Id => id;
public string SourceId => id;
public string LayerId => id;
public event EventHandler<AnnotationsSelectedEventArgs> AnnotationsSelected;
public void DidDetectTappedAnnotations(ITMBAnnotationManager manager, NSObject[] annotations)
{
if (AnnotationsSelected == null) return;
AnnotationsSelected?.Invoke(
this,
new AnnotationsSelectedEventArgs(
annotations
.Cast<ITMBAnnotation>()
.Select(x => x.Id)
.ToArray()
)
);
}
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);
}