Created
March 30, 2021 21:22
-
-
Save rdelrosario/2c1616ce8182ab72546e779e7f9e4a10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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