Skip to content

Commit 1fd7843

Browse files
committed
- Add new events WIP - CameraChanged
1 parent 1826695 commit 1fd7843

File tree

6 files changed

+315
-90
lines changed

6 files changed

+315
-90
lines changed

src/libs/Mapbox.Maui/IMapboxView.cs

+36
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,40 @@ public MapTappedEventArgs(MapTappedPosition position)
8080
{
8181
Position = position;
8282
}
83+
}
84+
public class CameraChangedEventArgs : EventArgs
85+
{
86+
public CameraChangedEventArgs(CameraOptions options)
87+
{
88+
Options = options;
89+
}
90+
91+
public CameraOptions Options { get; }
92+
}
93+
public class IndicatorAccuracyRadiusChangedEventArgs : EventArgs
94+
{
95+
public IndicatorAccuracyRadiusChangedEventArgs(double radius)
96+
{
97+
Radius = radius;
98+
}
99+
100+
public double Radius { get; }
101+
}
102+
public class IndicatorBearingChangedEventArgs : EventArgs
103+
{
104+
public IndicatorBearingChangedEventArgs(double bearing)
105+
{
106+
Bearing = bearing;
107+
}
108+
109+
public double Bearing { get; }
110+
}
111+
public class IndicatorPositionChangedEventArgs : EventArgs
112+
{
113+
public IndicatorPositionChangedEventArgs(IPosition position)
114+
{
115+
Position = position;
116+
}
117+
118+
public IPosition Position { get; }
83119
}

src/libs/Mapbox.Maui/MapboxView.Events.cs

+114-33
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,91 @@
44

55
partial class MapboxView
66
{
7-
public event EventHandler<MapTappedEventArgs> MapTapped;
8-
public event EventHandler<MapTappedEventArgs> MapLongTapped;
9-
internal void InvokeMapTapped(MapTappedPosition point)
7+
public event EventHandler<CameraChangedEventArgs> CameraChanged;
8+
public static readonly BindableProperty CameraChangedCommandProperty = BindableProperty.Create(
9+
nameof(CameraChangedCommand),
10+
typeof(ICommand),
11+
typeof(MapboxView)
12+
);
13+
public ICommand CameraChangedCommand
1014
{
11-
MapTapped?.Invoke(this, new MapTappedEventArgs(point));
15+
get => (ICommand)GetValue(CameraChangedCommandProperty);
16+
set => SetValue(CameraChangedCommandProperty, value);
17+
}
18+
internal void InvokeCameraChanged(CameraOptions options)
19+
{
20+
CameraChanged?.Invoke(this, new CameraChangedEventArgs(options));
1221

13-
if (Command?.CanExecute(point) == true)
22+
if (CameraChangedCommand?.CanExecute(options) == true)
1423
{
15-
Command.Execute(point);
24+
CameraChangedCommand.Execute(options);
1625
}
1726
}
18-
19-
internal void InvokeMapLongTapped(MapTappedPosition position)
27+
28+
public event EventHandler<IndicatorAccuracyRadiusChangedEventArgs> IndicatorAccuracyRadiusChanged;
29+
public static readonly BindableProperty IndicatorAccuracyRadiusChangedCommandProperty = BindableProperty.Create(
30+
nameof(IndicatorAccuracyRadiusChangedCommand),
31+
typeof(ICommand),
32+
typeof(MapboxView)
33+
);
34+
public ICommand IndicatorAccuracyRadiusChangedCommand
2035
{
21-
MapLongTapped?.Invoke(this, new MapTappedEventArgs(position));
36+
get => (ICommand)GetValue(IndicatorAccuracyRadiusChangedCommandProperty);
37+
set => SetValue(IndicatorAccuracyRadiusChangedCommandProperty, value);
38+
}
39+
internal void InvokeIndicatorAccuracyRadiusChanged(double radius)
40+
{
41+
IndicatorAccuracyRadiusChanged?.Invoke(this, new IndicatorAccuracyRadiusChangedEventArgs(radius));
2242

23-
if (LongTapCommand?.CanExecute(position) == true)
43+
if (IndicatorAccuracyRadiusChangedCommand?.CanExecute(radius) == true)
2444
{
25-
LongTapCommand.Execute(position);
45+
IndicatorAccuracyRadiusChangedCommand.Execute(radius);
2646
}
2747
}
28-
29-
public static readonly BindableProperty LongTapCommandProperty = BindableProperty.Create(
30-
nameof(LongTapCommand),
48+
49+
public event EventHandler<IndicatorBearingChangedEventArgs> IndicatorBearingChanged;
50+
public static readonly BindableProperty IndicatorBearingChangedCommandProperty = BindableProperty.Create(
51+
nameof(IndicatorBearingChangedCommand),
3152
typeof(ICommand),
3253
typeof(MapboxView)
3354
);
34-
public ICommand LongTapCommand
55+
public ICommand IndicatorBearingChangedCommand
3556
{
36-
get => (ICommand)GetValue(CommandProperty);
37-
set => SetValue(CommandProperty, value);
57+
get => (ICommand)GetValue(IndicatorBearingChangedCommandProperty);
58+
set => SetValue(IndicatorBearingChangedCommandProperty, value);
3859
}
60+
internal void InvokeIndicatorBearingChanged(double bearing)
61+
{
62+
IndicatorBearingChanged?.Invoke(this, new IndicatorBearingChangedEventArgs(bearing));
63+
64+
if (IndicatorBearingChangedCommand?.CanExecute(bearing) == true)
65+
{
66+
IndicatorBearingChangedCommand.Execute(bearing);
67+
}
68+
}
69+
70+
public event EventHandler<IndicatorPositionChangedEventArgs> IndicatorPositionChanged;
71+
public static readonly BindableProperty IndicatorPositionChangedCommandProperty = BindableProperty.Create(
72+
nameof(IndicatorPositionChangedCommand),
73+
typeof(ICommand),
74+
typeof(MapboxView)
75+
);
76+
public ICommand IndicatorPositionChangedCommand
77+
{
78+
get => (ICommand)GetValue(IndicatorPositionChangedCommandProperty);
79+
set => SetValue(IndicatorPositionChangedCommandProperty, value);
80+
}
81+
internal void InvokeIndicatorPositionChanged(IPosition position)
82+
{
83+
IndicatorPositionChanged?.Invoke(this, new IndicatorPositionChangedEventArgs(position));
3984

85+
if (IndicatorPositionChangedCommand?.CanExecute(position) == true)
86+
{
87+
IndicatorPositionChangedCommand.Execute(position);
88+
}
89+
}
90+
91+
public event EventHandler<MapTappedEventArgs> MapTapped;
4092
public static readonly BindableProperty CommandProperty = BindableProperty.Create(
4193
nameof(Command),
4294
typeof(ICommand),
@@ -47,6 +99,36 @@ public ICommand Command
4799
get => (ICommand)GetValue(CommandProperty);
48100
set => SetValue(CommandProperty, value);
49101
}
102+
internal void InvokeMapTapped(MapTappedPosition point)
103+
{
104+
MapTapped?.Invoke(this, new MapTappedEventArgs(point));
105+
106+
if (Command?.CanExecute(point) == true)
107+
{
108+
Command.Execute(point);
109+
}
110+
}
111+
112+
public event EventHandler<MapTappedEventArgs> MapLongTapped;
113+
internal void InvokeMapLongTapped(MapTappedPosition position)
114+
{
115+
MapLongTapped?.Invoke(this, new MapTappedEventArgs(position));
116+
117+
if (LongTapCommand?.CanExecute(position) == true)
118+
{
119+
LongTapCommand.Execute(position);
120+
}
121+
}
122+
public static readonly BindableProperty LongTapCommandProperty = BindableProperty.Create(
123+
nameof(LongTapCommand),
124+
typeof(ICommand),
125+
typeof(MapboxView)
126+
);
127+
public ICommand LongTapCommand
128+
{
129+
get => (ICommand)GetValue(LongTapCommandProperty);
130+
set => SetValue(LongTapCommandProperty, value);
131+
}
50132

51133
public event EventHandler MapReady;
52134
internal void InvokeMapReady()
@@ -58,7 +140,6 @@ internal void InvokeMapReady()
58140
MapReadyCommand.Execute(null);
59141
}
60142
}
61-
62143
public static readonly BindableProperty MapReadyCommandProperty = BindableProperty.Create(
63144
nameof(MapReadyCommand),
64145
typeof(ICommand),
@@ -95,15 +176,6 @@ public ICommand StyleLoadedCommand
95176
}
96177

97178
public event EventHandler MapLoaded;
98-
internal void InvokeMapLoaded()
99-
{
100-
MapLoaded?.Invoke(this, EventArgs.Empty);
101-
102-
if (MapLoadedCommand?.CanExecute(null) == true)
103-
{
104-
MapLoadedCommand.Execute(null);
105-
}
106-
}
107179
public static readonly BindableProperty MapLoadedCommandProperty = BindableProperty.Create(
108180
nameof(MapLoadedCommand),
109181
typeof(ICommand),
@@ -115,17 +187,17 @@ public ICommand MapLoadedCommand
115187
get => (ICommand)GetValue(MapLoadedCommandProperty);
116188
set => SetValue(MapLoadedCommandProperty, value);
117189
}
118-
119-
public event EventHandler MapLoadingError;
120-
internal void InvokeMapLoadingError()
190+
internal void InvokeMapLoaded()
121191
{
122-
MapLoadingError?.Invoke(this, EventArgs.Empty);
192+
MapLoaded?.Invoke(this, EventArgs.Empty);
123193

124-
if (MapLoadingErrorCommand?.CanExecute(null) == true)
194+
if (MapLoadedCommand?.CanExecute(null) == true)
125195
{
126-
MapLoadingErrorCommand.Execute(null);
196+
MapLoadedCommand.Execute(null);
127197
}
128198
}
199+
200+
public event EventHandler MapLoadingError;
129201
public static readonly BindableProperty MapLoadingErrorCommandProperty = BindableProperty.Create(
130202
nameof(MapLoadingErrorCommand),
131203
typeof(ICommand),
@@ -137,4 +209,13 @@ public ICommand MapLoadingErrorCommand
137209
get => (ICommand)GetValue(MapLoadingErrorCommandProperty);
138210
set => SetValue(MapLoadingErrorCommandProperty, value);
139211
}
212+
internal void InvokeMapLoadingError()
213+
{
214+
MapLoadingError?.Invoke(this, EventArgs.Empty);
215+
216+
if (MapLoadingErrorCommand?.CanExecute(null) == true)
217+
{
218+
MapLoadingErrorCommand.Execute(null);
219+
}
220+
}
140221
}

0 commit comments

Comments
 (0)