Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sample): advanced viewport gestures #32

Merged
merged 19 commits into from
Aug 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
- Add new events WIP - CameraChanged
  • Loading branch information
tuyen-vuduc committed Jul 17, 2024
commit 1fd78438c2e36475df38d6f067cf097bef2e1ad0
36 changes: 36 additions & 0 deletions src/libs/Mapbox.Maui/IMapboxView.cs
Original file line number Diff line number Diff line change
@@ -80,4 +80,40 @@ public MapTappedEventArgs(MapTappedPosition position)
{
Position = position;
}
}
public class CameraChangedEventArgs : EventArgs
{
public CameraChangedEventArgs(CameraOptions options)
{
Options = options;
}

public CameraOptions Options { get; }
}
public class IndicatorAccuracyRadiusChangedEventArgs : EventArgs
{
public IndicatorAccuracyRadiusChangedEventArgs(double radius)
{
Radius = radius;
}

public double Radius { get; }
}
public class IndicatorBearingChangedEventArgs : EventArgs
{
public IndicatorBearingChangedEventArgs(double bearing)
{
Bearing = bearing;
}

public double Bearing { get; }
}
public class IndicatorPositionChangedEventArgs : EventArgs
{
public IndicatorPositionChangedEventArgs(IPosition position)
{
Position = position;
}

public IPosition Position { get; }
}
147 changes: 114 additions & 33 deletions src/libs/Mapbox.Maui/MapboxView.Events.cs
Original file line number Diff line number Diff line change
@@ -4,39 +4,91 @@

partial class MapboxView
{
public event EventHandler<MapTappedEventArgs> MapTapped;
public event EventHandler<MapTappedEventArgs> MapLongTapped;
internal void InvokeMapTapped(MapTappedPosition point)
public event EventHandler<CameraChangedEventArgs> CameraChanged;
public static readonly BindableProperty CameraChangedCommandProperty = BindableProperty.Create(
nameof(CameraChangedCommand),
typeof(ICommand),
typeof(MapboxView)
);
public ICommand CameraChangedCommand
{
MapTapped?.Invoke(this, new MapTappedEventArgs(point));
get => (ICommand)GetValue(CameraChangedCommandProperty);
set => SetValue(CameraChangedCommandProperty, value);
}
internal void InvokeCameraChanged(CameraOptions options)
{
CameraChanged?.Invoke(this, new CameraChangedEventArgs(options));

if (Command?.CanExecute(point) == true)
if (CameraChangedCommand?.CanExecute(options) == true)
{
Command.Execute(point);
CameraChangedCommand.Execute(options);
}
}

internal void InvokeMapLongTapped(MapTappedPosition position)

public event EventHandler<IndicatorAccuracyRadiusChangedEventArgs> IndicatorAccuracyRadiusChanged;
public static readonly BindableProperty IndicatorAccuracyRadiusChangedCommandProperty = BindableProperty.Create(
nameof(IndicatorAccuracyRadiusChangedCommand),
typeof(ICommand),
typeof(MapboxView)
);
public ICommand IndicatorAccuracyRadiusChangedCommand
{
MapLongTapped?.Invoke(this, new MapTappedEventArgs(position));
get => (ICommand)GetValue(IndicatorAccuracyRadiusChangedCommandProperty);
set => SetValue(IndicatorAccuracyRadiusChangedCommandProperty, value);
}
internal void InvokeIndicatorAccuracyRadiusChanged(double radius)
{
IndicatorAccuracyRadiusChanged?.Invoke(this, new IndicatorAccuracyRadiusChangedEventArgs(radius));

if (LongTapCommand?.CanExecute(position) == true)
if (IndicatorAccuracyRadiusChangedCommand?.CanExecute(radius) == true)
{
LongTapCommand.Execute(position);
IndicatorAccuracyRadiusChangedCommand.Execute(radius);
}
}

public static readonly BindableProperty LongTapCommandProperty = BindableProperty.Create(
nameof(LongTapCommand),

public event EventHandler<IndicatorBearingChangedEventArgs> IndicatorBearingChanged;
public static readonly BindableProperty IndicatorBearingChangedCommandProperty = BindableProperty.Create(
nameof(IndicatorBearingChangedCommand),
typeof(ICommand),
typeof(MapboxView)
);
public ICommand LongTapCommand
public ICommand IndicatorBearingChangedCommand
{
get => (ICommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
get => (ICommand)GetValue(IndicatorBearingChangedCommandProperty);
set => SetValue(IndicatorBearingChangedCommandProperty, value);
}
internal void InvokeIndicatorBearingChanged(double bearing)
{
IndicatorBearingChanged?.Invoke(this, new IndicatorBearingChangedEventArgs(bearing));

if (IndicatorBearingChangedCommand?.CanExecute(bearing) == true)
{
IndicatorBearingChangedCommand.Execute(bearing);
}
}

public event EventHandler<IndicatorPositionChangedEventArgs> IndicatorPositionChanged;
public static readonly BindableProperty IndicatorPositionChangedCommandProperty = BindableProperty.Create(
nameof(IndicatorPositionChangedCommand),
typeof(ICommand),
typeof(MapboxView)
);
public ICommand IndicatorPositionChangedCommand
{
get => (ICommand)GetValue(IndicatorPositionChangedCommandProperty);
set => SetValue(IndicatorPositionChangedCommandProperty, value);
}
internal void InvokeIndicatorPositionChanged(IPosition position)
{
IndicatorPositionChanged?.Invoke(this, new IndicatorPositionChangedEventArgs(position));

if (IndicatorPositionChangedCommand?.CanExecute(position) == true)
{
IndicatorPositionChangedCommand.Execute(position);
}
}

public event EventHandler<MapTappedEventArgs> MapTapped;
public static readonly BindableProperty CommandProperty = BindableProperty.Create(
nameof(Command),
typeof(ICommand),
@@ -47,6 +99,36 @@ public ICommand Command
get => (ICommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
internal void InvokeMapTapped(MapTappedPosition point)
{
MapTapped?.Invoke(this, new MapTappedEventArgs(point));

if (Command?.CanExecute(point) == true)
{
Command.Execute(point);
}
}

public event EventHandler<MapTappedEventArgs> MapLongTapped;
internal void InvokeMapLongTapped(MapTappedPosition position)
{
MapLongTapped?.Invoke(this, new MapTappedEventArgs(position));

if (LongTapCommand?.CanExecute(position) == true)
{
LongTapCommand.Execute(position);
}
}
public static readonly BindableProperty LongTapCommandProperty = BindableProperty.Create(
nameof(LongTapCommand),
typeof(ICommand),
typeof(MapboxView)
);
public ICommand LongTapCommand
{
get => (ICommand)GetValue(LongTapCommandProperty);
set => SetValue(LongTapCommandProperty, value);
}

public event EventHandler MapReady;
internal void InvokeMapReady()
@@ -58,7 +140,6 @@ internal void InvokeMapReady()
MapReadyCommand.Execute(null);
}
}

public static readonly BindableProperty MapReadyCommandProperty = BindableProperty.Create(
nameof(MapReadyCommand),
typeof(ICommand),
@@ -95,15 +176,6 @@ public ICommand StyleLoadedCommand
}

public event EventHandler MapLoaded;
internal void InvokeMapLoaded()
{
MapLoaded?.Invoke(this, EventArgs.Empty);

if (MapLoadedCommand?.CanExecute(null) == true)
{
MapLoadedCommand.Execute(null);
}
}
public static readonly BindableProperty MapLoadedCommandProperty = BindableProperty.Create(
nameof(MapLoadedCommand),
typeof(ICommand),
@@ -115,17 +187,17 @@ public ICommand MapLoadedCommand
get => (ICommand)GetValue(MapLoadedCommandProperty);
set => SetValue(MapLoadedCommandProperty, value);
}

public event EventHandler MapLoadingError;
internal void InvokeMapLoadingError()
internal void InvokeMapLoaded()
{
MapLoadingError?.Invoke(this, EventArgs.Empty);
MapLoaded?.Invoke(this, EventArgs.Empty);

if (MapLoadingErrorCommand?.CanExecute(null) == true)
if (MapLoadedCommand?.CanExecute(null) == true)
{
MapLoadingErrorCommand.Execute(null);
MapLoadedCommand.Execute(null);
}
}

public event EventHandler MapLoadingError;
public static readonly BindableProperty MapLoadingErrorCommandProperty = BindableProperty.Create(
nameof(MapLoadingErrorCommand),
typeof(ICommand),
@@ -137,4 +209,13 @@ public ICommand MapLoadingErrorCommand
get => (ICommand)GetValue(MapLoadingErrorCommandProperty);
set => SetValue(MapLoadingErrorCommandProperty, value);
}
internal void InvokeMapLoadingError()
{
MapLoadingError?.Invoke(this, EventArgs.Empty);

if (MapLoadingErrorCommand?.CanExecute(null) == true)
{
MapLoadingErrorCommand.Execute(null);
}
}
}
Loading