-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAnimatedMarkerExample.cs
88 lines (72 loc) · 2.46 KB
/
AnimatedMarkerExample.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
namespace MapboxMauiQs;
public class AnimatedMarkerExample : ContentPage, IExamplePage, IQueryAttributable
{
static class Constants
{
public const string markerIconId = "marker_icon";
public const string sourceId = "source-id";
public const double animationDuration = 2;
}
MapboxView map;
IExampleInfo info;
private IPosition currentPosition = new MapPosition(64.900932, -18.167040);
public AnimatedMarkerExample()
{
iOSPage.SetUseSafeArea(this, false);
Content = map = new MapboxView();
map.MapReady += Map_MapReady;
map.MapLoaded += Map_MapLoaded;
map.Command = new Command<MapTappedPosition>(HandleMapTapped);
}
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
info = query["example"] as IExampleInfo;
Title = info?.Title;
}
private void HandleMapTapped(MapTappedPosition point)
{
// Create a GeoJSON data source.
var feature = new Feature(
new GPoint(point.MapPosition)
);
var source = new GeoJSONSource(Constants.sourceId)
{
Data = new RawGeoJSONObject(
JsonSerializer.Serialize(feature)
)
};
map.Sources = new[] { source };
}
private void Map_MapReady(object sender, EventArgs e)
{
var cameraOptions = new CameraOptions
{
Center = currentPosition,
Zoom = 5,
};
map.CameraOptions = cameraOptions;
map.MapboxStyle = MapboxStyle.SATELLITE_STREETS;
}
private void Map_MapLoaded(object sender, EventArgs e)
{
var image = new ResolvedImage(Constants.markerIconId, "red_marker");
map.Images = new[] { image };
// Create a GeoJSON data source.
var feature = new Feature(
new GPoint(currentPosition)
);
var source = new GeoJSONSource(Constants.sourceId)
{
Data = new RawGeoJSONObject(
JsonSerializer.Serialize(feature)
)
};
map.Sources = new[] { source };
// Create a symbol layer
var symbolLayer = new SymbolLayer(id: "layer-id", Constants.sourceId);
symbolLayer.IconImage = image;
symbolLayer.IconIgnorePlacement = true;
symbolLayer.IconAllowOverlap = true;
map.Layers = new[] { symbolLayer };
}
}