Skip to content

Instantly share code, notes, and snippets.

@rdelrosario
Created March 30, 2021 21:22
Show Gist options
  • Save rdelrosario/2c1616ce8182ab72546e779e7f9e4a10 to your computer and use it in GitHub Desktop.
Save rdelrosario/2c1616ce8182ab72546e779e7f9e4a10 to your computer and use it in GitHub Desktop.
namespace App
{
public partial class ExtendedMap : Map
{
public static readonly BindableProperty TappedCommandProperty =
BindableProperty.Create(nameof(TappedCommand), typeof(DelegateCommand<object>), typeof(ExtendedMap), default(DelegateCommand<object>));
public DelegateCommand<object> TappedCommand
{
get { return (DelegateCommand<object>)GetValue(TappedCommandProperty); }
set { SetValue(TappedCommandProperty, value); }
}
public ExtendedMap()
{
InitializeComponent();
}
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == Map.ItemsSourceProperty.PropertyName)
{
var pin = ItemsSource.FirstOrNull();
if (pin is MapPin mapPin)
{
MapSpan mapSpan = MapSpan.FromCenterAndRadius(mapPin.Position, Distance.FromKilometers(0.444));
MoveToRegion(mapSpan);
}
}
}
void Map_MapClicked(System.Object sender, Xamarin.Forms.Maps.MapClickedEventArgs e)
{
if (TappedCommand != null)
{
TappedCommand?.Execute(e.Position);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment