forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PushPin.cs
67 lines (57 loc) · 1.55 KB
/
PushPin.cs
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
using System;
using System.ComponentModel;
using Windows.Devices.Geolocation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Maps;
using Windows.UI.Xaml.Input;
namespace Xamarin.Forms.Maps.UWP
{
internal class PushPin : ContentControl
{
readonly Pin _pin;
internal PushPin(Pin pin)
{
if (pin == null)
throw new ArgumentNullException();
ContentTemplate = Windows.UI.Xaml.Application.Current.Resources["PushPinTemplate"] as Windows.UI.Xaml.DataTemplate;
DataContext = Content = _pin = pin;
UpdateLocation();
Loaded += PushPinLoaded;
Unloaded += PushPinUnloaded;
Tapped += PushPinTapped;
}
void PushPinLoaded(object sender, RoutedEventArgs e)
{
_pin.PropertyChanged += PinPropertyChanged;
}
void PushPinUnloaded(object sender, RoutedEventArgs e)
{
_pin.PropertyChanged -= PinPropertyChanged;
Tapped -= PushPinTapped;
}
void PinPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == Pin.PositionProperty.PropertyName)
UpdateLocation();
}
void PushPinTapped(object sender, TappedRoutedEventArgs e)
{
#pragma warning disable CS0618
_pin.SendTap();
#pragma warning restore CS0618
_pin.SendMarkerClick();
}
void UpdateLocation()
{
var anchor = new Windows.Foundation.Point(0.65, 1);
var location = new Geopoint(new BasicGeoposition
{
Latitude = _pin.Position.Latitude,
Longitude = _pin.Position.Longitude
});
MapControl.SetLocation(this, location);
MapControl.SetNormalizedAnchorPoint(this, anchor);
}
}
}