summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Maps.UWP/PushPin.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Maps.UWP/PushPin.cs')
-rw-r--r--Xamarin.Forms.Maps.UWP/PushPin.cs70
1 files changed, 70 insertions, 0 deletions
diff --git a/Xamarin.Forms.Maps.UWP/PushPin.cs b/Xamarin.Forms.Maps.UWP/PushPin.cs
new file mode 100644
index 0000000..2eaaa65
--- /dev/null
+++ b/Xamarin.Forms.Maps.UWP/PushPin.cs
@@ -0,0 +1,70 @@
+´╗┐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;
+
+#if WINDOWS_UWP
+
+namespace Xamarin.Forms.Maps.UWP
+#else
+
+namespace Xamarin.Forms.Maps.WinRT
+#endif
+{
+ 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)
+ {
+ _pin.SendTap();
+ }
+
+ 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);
+ }
+ }
+} \ No newline at end of file