From 17fdde66d94155fc62a034fa6658995bef6fd6e5 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Tue, 22 Mar 2016 13:02:25 -0700 Subject: Initial import --- Xamarin.Forms.Maps/Pin.cs | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Xamarin.Forms.Maps/Pin.cs (limited to 'Xamarin.Forms.Maps/Pin.cs') diff --git a/Xamarin.Forms.Maps/Pin.cs b/Xamarin.Forms.Maps/Pin.cs new file mode 100644 index 00000000..6c0fb556 --- /dev/null +++ b/Xamarin.Forms.Maps/Pin.cs @@ -0,0 +1,99 @@ +using System; + +namespace Xamarin.Forms.Maps +{ + public sealed class Pin : BindableObject + { + public static readonly BindableProperty TypeProperty = BindableProperty.Create("Type", typeof(PinType), typeof(Pin), default(PinType)); + + public static readonly BindableProperty PositionProperty = BindableProperty.Create("Position", typeof(Position), typeof(Pin), default(Position)); + + public static readonly BindableProperty AddressProperty = BindableProperty.Create("Address", typeof(string), typeof(Pin), default(string)); + + // introduced to store the unique id for Android markers + + string _label; + + public string Address + { + get { return (string)GetValue(AddressProperty); } + set { SetValue(AddressProperty, value); } + } + + public string Label + { + get { return _label; } + set + { + if (_label == value) + return; + _label = value; + OnPropertyChanged(); + } + } + + public Position Position + { + get { return (Position)GetValue(PositionProperty); } + set { SetValue(PositionProperty, value); } + } + + public PinType Type + { + get { return (PinType)GetValue(TypeProperty); } + set { SetValue(TypeProperty, value); } + } + + internal object Id { get; set; } + + public event EventHandler Clicked; + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) + return false; + if (ReferenceEquals(this, obj)) + return true; + if (obj.GetType() != GetType()) + return false; + return Equals((Pin)obj); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = Label?.GetHashCode() ?? 0; + hashCode = (hashCode * 397) ^ Position.GetHashCode(); + hashCode = (hashCode * 397) ^ (int)Type; + hashCode = (hashCode * 397) ^ (Address?.GetHashCode() ?? 0); + return hashCode; + } + } + + public static bool operator ==(Pin left, Pin right) + { + return Equals(left, right); + } + + public static bool operator !=(Pin left, Pin right) + { + return !Equals(left, right); + } + + internal bool SendTap() + { + EventHandler handler = Clicked; + if (handler == null) + return false; + + handler(this, EventArgs.Empty); + return true; + } + + bool Equals(Pin other) + { + return string.Equals(Label, other.Label) && Equals(Position, other.Position) && Type == other.Type && string.Equals(Address, other.Address); + } + } +} \ No newline at end of file -- cgit v1.2.3