forked from tuyen-vuduc/mapbox-maui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomPointAnnotationExample.cs
71 lines (59 loc) · 2.45 KB
/
CustomPointAnnotationExample.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
namespace MapboxMauiQs;
public class CustomPointAnnotationExample : ContentPage, IExamplePage, IQueryAttributable
{
MapboxView map;
IExampleInfo info;
public CustomPointAnnotationExample()
{
iOSPage.SetUseSafeArea(this, false);
Content = map = new MapboxView();
map.MapReady += Map_MapReady;
map.MapLoaded += Map_MapLoaded;
}
private void Map_MapLoaded(object sender, EventArgs e)
{
var image = new ResolvedImage("my-custom-image-name", "star");
map.Images = new[] { image };
// We want to display the annotation at the center of the map's current viewport
var centerCoordinate = map.CameraOptions.Center;
// Make a `PointAnnotationManager` which will be responsible for managing
// a collection of `PointAnnotion`s.
// Annotation managers are kept alive by `AnnotationOrchestrator`
// (`mapView.annotations`) until you explicitly destroy them
// by calling `mapView.annotations.removeAnnotationManager(withId:)`
var pointAnnotationManager = map.AnnotationController.CreatePointAnnotationManager(
"pointAnnotationManager",
LayerPosition.Unknown()
);
// Initialize a point annotation with a geometry ("coordinate" in this case)
// and configure it with a custom image (sourced from the asset catalogue)
var customPointAnnotation = new PointAnnotation(
new GeoJSON.Text.Geometry.Point(
new Position(centerCoordinate.Value.X, centerCoordinate.Value.Y)
)
)
{
IsDraggable = true,
IconImage = "my-custom-image-name"
};
//customPointAnnotation.Image = .init(image: customImage, name: "my-custom-image-name")
// Add the annotation to the manager in order to render it on the map.
pointAnnotationManager.AddAnnotations(customPointAnnotation);
}
private void Map_MapReady(object sender, EventArgs e)
{
var centerLocation = new Point(40.7128, -74.0060);
var cameraOptions = new CameraOptions
{
Center = centerLocation,
Zoom = 9,
};
map.CameraOptions = cameraOptions;
map.MapboxStyle = MapboxStyle.MAPBOX_STREETS;
}
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
info = query["example"] as IExampleInfo;
Title = info?.Title;
}
}