diff --git a/MapControl/Extensions.WinRT.cs b/MapControl/Extensions.WinRT.cs index 4359f74c..72bc95c7 100644 --- a/MapControl/Extensions.WinRT.cs +++ b/MapControl/Extensions.WinRT.cs @@ -3,6 +3,7 @@ // Licensed under the Microsoft Public License (Ms-PL) using System; +using System.Collections.Generic; using Windows.Foundation; using Windows.UI.Core; using Windows.UI.Xaml; @@ -26,38 +27,34 @@ namespace MapControl public static void BeginAnimation(this DependencyObject obj, DependencyProperty property, DoubleAnimation animation) { animation.EnableDependentAnimation = true; - - if (property == UIElement.OpacityProperty) - { - BeginAnimation(obj, "Opacity", animation); - } - else if (property == MapBase.ZoomLevelProperty) - { - BeginAnimation(obj, "ZoomLevel", animation); - } - else if (property == MapBase.HeadingProperty) - { - BeginAnimation(obj, "Heading", animation); - } + BeginAnimation(obj, property, (Timeline)animation); } public static void BeginAnimation(this DependencyObject obj, DependencyProperty property, PointAnimation animation) { animation.EnableDependentAnimation = true; - - if (property == MapBase.CenterPointProperty) - { - BeginAnimation(obj, "CenterPoint", animation); - } + BeginAnimation(obj, property, (Timeline)animation); } - private static void BeginAnimation(DependencyObject obj, string property, Timeline animation) + private static Dictionary properties = new Dictionary() { - Storyboard.SetTargetProperty(animation, property); - Storyboard.SetTarget(animation, obj); - var storyboard = new Storyboard(); - storyboard.Children.Add(animation); - storyboard.Begin(); + { UIElement.OpacityProperty, "Opacity" }, + { MapBase.ZoomLevelProperty, "ZoomLevel" }, + { MapBase.HeadingProperty, "Heading" }, + { MapBase.CenterPointProperty, "CenterPoint" } + }; + + private static void BeginAnimation(DependencyObject obj, DependencyProperty property, Timeline animation) + { + string propertyName; + if (properties.TryGetValue(property, out propertyName)) + { + Storyboard.SetTargetProperty(animation, propertyName); + Storyboard.SetTarget(animation, obj); + var storyboard = new Storyboard(); + storyboard.Children.Add(animation); + storyboard.Begin(); + } } } } diff --git a/MapControl/MapBase.cs b/MapControl/MapBase.cs index 87448560..bb353ec9 100644 --- a/MapControl/MapBase.cs +++ b/MapControl/MapBase.cs @@ -425,8 +425,8 @@ namespace MapControl { var p1 = mapTransform.Transform(southWest); var p2 = mapTransform.Transform(northEast); - var lonScale = RenderSize.Width / (p2.X - p1.X) * 360d / (double)TileSource.TileSize; - var latScale = RenderSize.Height / (p2.Y - p1.Y) * 360d / (double)TileSource.TileSize; + var lonScale = RenderSize.Width / (p2.X - p1.X) * 360d / TileSource.TileSize; + var latScale = RenderSize.Height / (p2.Y - p1.Y) * 360d / TileSource.TileSize; var lonZoom = Math.Log(lonScale, 2d); var latZoom = Math.Log(latScale, 2d);