summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Maps/Pin.cs
blob: 6c0fb5569982686564e1ff90f9e43e11f861d58b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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);
		}
	}
}