-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathViewAnnotationWithPointAnnotationExample.cs
103 lines (82 loc) · 2.88 KB
/
ViewAnnotationWithPointAnnotationExample.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
namespace MapboxMauiQs;
public class ViewAnnotationWithPointAnnotationExample : ContentPage, IExamplePage, IQueryAttributable
{
MapboxView map;
IExampleInfo info;
IPointAnnotationManager pointAnnotationManager;
float markerHeight = 24;
private class Constants
{
public const string blueIconId = "blue";
public const float selectedAddCoefPX = 50;
public static readonly string markerId = Guid.NewGuid().ToString();
}
public ViewAnnotationWithPointAnnotationExample()
{
iOSPage.SetUseSafeArea(this, false);
Content = map = new MapboxView();
map.MapReady += Map_MapReady;
map.MapLoaded += Map_MapLoaded;
map.MapTapped += Map_MapTapped;
}
private void Map_MapTapped(object sender, MapTappedEventArgs e)
{
}
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
info = query["example"] as IExampleInfo;
Title = info?.Title;
}
private void Map_MapReady(object sender, EventArgs e)
{
var centerLocation = new MapPosition(39.7128, -75.0060);
var cameraOptions = new CameraOptions
{
Center = centerLocation,
Zoom = 7,
};
map.CameraOptions = cameraOptions;
map.MapboxStyle = MapboxStyle.MAPBOX_STREETS;
pointAnnotationManager = map.AnnotationController.CreatePointAnnotationManager(
nameof(pointAnnotationManager),
LayerPosition.Unknown());
}
private void Map_MapLoaded(object sender, EventArgs e)
{
var image = new ResolvedImage(Constants.blueIconId, "blue_marker_view");
map.Images = new[] { image };
AddPointAndViewAnnotationAt(map.CameraOptions.Center);
}
private void AddPointAndViewAnnotationAt(IPosition coordinate)
{
if (coordinate is null) return;
AddPointAnnotationAt(coordinate);
AddViewAnnotationAt(coordinate);
}
private void AddViewAnnotationAt(IPosition value)
{
var options = new ViewAnnotationOptions
{
Geometry = new GeoJSON.Text.Geometry.Point(value),
Width = 128,
Height = 64,
AssociatedFeatureId = Constants.markerId,
AllowOverlap = false,
Anchor = ViewAnnotationAnchor.Bottom,
OffsetY = markerHeight,
Title = $"Lat={value.Latitude}, Lng={value.Longitude}",
};
map.ViewAnnotations = new[] { options };
}
private void AddPointAnnotationAt(IPosition value)
{
var pointAnnotation = new PointAnnotation(
new GeoJSON.Text.Geometry.Point(value),
id: Constants.markerId)
{
IconImage = Constants.blueIconId,
IconAnchor = IconAnchor.Bottom,
};
pointAnnotationManager.AddAnnotations(pointAnnotation);
}
}