mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Revised animations.
This commit is contained in:
parent
1861e9ca5d
commit
b3665b92c0
|
|
@ -321,15 +321,15 @@ namespace MapControl
|
||||||
if (rotation != 0d)
|
if (rotation != 0d)
|
||||||
{
|
{
|
||||||
var heading = (((Heading + rotation) % 360d) + 360d) % 360d;
|
var heading = (((Heading + rotation) % 360d) + 360d) % 360d;
|
||||||
InternalSetValue(HeadingProperty, heading);
|
SetValueInternal(HeadingProperty, heading);
|
||||||
InternalSetValue(TargetHeadingProperty, heading);
|
SetValueInternal(TargetHeadingProperty, heading);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scale != 1d)
|
if (scale != 1d)
|
||||||
{
|
{
|
||||||
var zoomLevel = Math.Min(Math.Max(ZoomLevel + Math.Log(scale, 2d), MinZoomLevel), MaxZoomLevel);
|
var zoomLevel = Math.Min(Math.Max(ZoomLevel + Math.Log(scale, 2d), MinZoomLevel), MaxZoomLevel);
|
||||||
InternalSetValue(ZoomLevelProperty, zoomLevel);
|
SetValueInternal(ZoomLevelProperty, zoomLevel);
|
||||||
InternalSetValue(TargetZoomLevelProperty, zoomLevel);
|
SetValueInternal(TargetZoomLevelProperty, zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateTransform(true);
|
UpdateTransform(true);
|
||||||
|
|
@ -355,6 +355,7 @@ namespace MapControl
|
||||||
if (double.IsNaN(MapProjection.LongitudeScale))
|
if (double.IsNaN(MapProjection.LongitudeScale))
|
||||||
{
|
{
|
||||||
ZoomLevel = zoomLevel;
|
ZoomLevel = zoomLevel;
|
||||||
|
ResetTransformCenter();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -444,7 +445,7 @@ namespace MapControl
|
||||||
if (center == null)
|
if (center == null)
|
||||||
{
|
{
|
||||||
center = new Location();
|
center = new Location();
|
||||||
InternalSetValue(property, center);
|
SetValueInternal(property, center);
|
||||||
}
|
}
|
||||||
else if (center.Longitude < -180d || center.Longitude > 180d ||
|
else if (center.Longitude < -180d || center.Longitude > 180d ||
|
||||||
center.Latitude < -MapProjection.MaxLatitude || center.Latitude > MapProjection.MaxLatitude)
|
center.Latitude < -MapProjection.MaxLatitude || center.Latitude > MapProjection.MaxLatitude)
|
||||||
|
|
@ -452,7 +453,7 @@ namespace MapControl
|
||||||
center = new Location(
|
center = new Location(
|
||||||
Math.Min(Math.Max(center.Latitude, -MapProjection.MaxLatitude), MapProjection.MaxLatitude),
|
Math.Min(Math.Max(center.Latitude, -MapProjection.MaxLatitude), MapProjection.MaxLatitude),
|
||||||
Location.NormalizeLongitude(center.Longitude));
|
Location.NormalizeLongitude(center.Longitude));
|
||||||
InternalSetValue(property, center);
|
SetValueInternal(property, center);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -465,8 +466,7 @@ namespace MapControl
|
||||||
|
|
||||||
if (centerAnimation == null)
|
if (centerAnimation == null)
|
||||||
{
|
{
|
||||||
InternalSetValue(TargetCenterProperty, center);
|
SetValueInternal(TargetCenterProperty, center);
|
||||||
InternalSetValue(CenterPointProperty, MapProjection.LocationToPoint(center));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -484,19 +484,16 @@ namespace MapControl
|
||||||
centerAnimation.Completed -= CenterAnimationCompleted;
|
centerAnimation.Completed -= CenterAnimationCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
// animate private CenterPoint property by PointAnimation
|
|
||||||
centerAnimation = new PointAnimation
|
centerAnimation = new PointAnimation
|
||||||
{
|
{
|
||||||
From = MapProjection.LocationToPoint(Center),
|
From = new Point(Center.Longitude, Center.Latitude),
|
||||||
To = MapProjection.LocationToPoint(new Location(
|
To = new Point(Location.NearestLongitude(targetCenter.Longitude, Center.Longitude), targetCenter.Latitude),
|
||||||
targetCenter.Latitude,
|
|
||||||
Location.NearestLongitude(targetCenter.Longitude, Center.Longitude))),
|
|
||||||
Duration = AnimationDuration,
|
Duration = AnimationDuration,
|
||||||
EasingFunction = AnimationEasingFunction,
|
EasingFunction = AnimationEasingFunction
|
||||||
FillBehavior = AnimationFillBehavior
|
|
||||||
};
|
};
|
||||||
|
|
||||||
centerAnimation.Completed += CenterAnimationCompleted;
|
centerAnimation.Completed += CenterAnimationCompleted;
|
||||||
|
|
||||||
this.BeginAnimation(CenterPointProperty, centerAnimation);
|
this.BeginAnimation(CenterPointProperty, centerAnimation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -509,20 +506,15 @@ namespace MapControl
|
||||||
centerAnimation.Completed -= CenterAnimationCompleted;
|
centerAnimation.Completed -= CenterAnimationCompleted;
|
||||||
centerAnimation = null;
|
centerAnimation = null;
|
||||||
|
|
||||||
InternalSetValue(CenterProperty, TargetCenter);
|
this.BeginAnimation(CenterPointProperty, null);
|
||||||
InternalSetValue(CenterPointProperty, MapProjection.LocationToPoint(TargetCenter));
|
|
||||||
UpdateTransform();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CenterPointPropertyChanged(Point centerPoint)
|
private void CenterPointPropertyChanged(Point centerPoint)
|
||||||
{
|
{
|
||||||
if (!internalPropertyChange)
|
if (centerAnimation != null)
|
||||||
{
|
{
|
||||||
var center = MapProjection.PointToLocation(centerPoint);
|
SetValueInternal(CenterProperty, new Location(centerPoint.Y, centerPoint.X));
|
||||||
center.Longitude = Location.NormalizeLongitude(center.Longitude);
|
|
||||||
|
|
||||||
InternalSetValue(CenterProperty, center);
|
|
||||||
UpdateTransform();
|
UpdateTransform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -532,7 +524,7 @@ namespace MapControl
|
||||||
if (minZoomLevel < 0d || minZoomLevel > MaxZoomLevel)
|
if (minZoomLevel < 0d || minZoomLevel > MaxZoomLevel)
|
||||||
{
|
{
|
||||||
minZoomLevel = Math.Min(Math.Max(minZoomLevel, 0d), MaxZoomLevel);
|
minZoomLevel = Math.Min(Math.Max(minZoomLevel, 0d), MaxZoomLevel);
|
||||||
InternalSetValue(MinZoomLevelProperty, minZoomLevel);
|
SetValueInternal(MinZoomLevelProperty, minZoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZoomLevel < minZoomLevel)
|
if (ZoomLevel < minZoomLevel)
|
||||||
|
|
@ -546,7 +538,7 @@ namespace MapControl
|
||||||
if (maxZoomLevel < MinZoomLevel || maxZoomLevel > MaximumZoomLevel)
|
if (maxZoomLevel < MinZoomLevel || maxZoomLevel > MaximumZoomLevel)
|
||||||
{
|
{
|
||||||
maxZoomLevel = Math.Min(Math.Max(maxZoomLevel, MinZoomLevel), MaximumZoomLevel);
|
maxZoomLevel = Math.Min(Math.Max(maxZoomLevel, MinZoomLevel), MaximumZoomLevel);
|
||||||
InternalSetValue(MaxZoomLevelProperty, maxZoomLevel);
|
SetValueInternal(MaxZoomLevelProperty, maxZoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZoomLevel > maxZoomLevel)
|
if (ZoomLevel > maxZoomLevel)
|
||||||
|
|
@ -560,7 +552,7 @@ namespace MapControl
|
||||||
if (zoomLevel < MinZoomLevel || zoomLevel > MaxZoomLevel)
|
if (zoomLevel < MinZoomLevel || zoomLevel > MaxZoomLevel)
|
||||||
{
|
{
|
||||||
zoomLevel = Math.Min(Math.Max(zoomLevel, MinZoomLevel), MaxZoomLevel);
|
zoomLevel = Math.Min(Math.Max(zoomLevel, MinZoomLevel), MaxZoomLevel);
|
||||||
InternalSetValue(property, zoomLevel);
|
SetValueInternal(property, zoomLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -573,7 +565,7 @@ namespace MapControl
|
||||||
|
|
||||||
if (zoomLevelAnimation == null)
|
if (zoomLevelAnimation == null)
|
||||||
{
|
{
|
||||||
InternalSetValue(TargetZoomLevelProperty, zoomLevel);
|
SetValueInternal(TargetZoomLevelProperty, zoomLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -595,11 +587,11 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
To = targetZoomLevel,
|
To = targetZoomLevel,
|
||||||
Duration = AnimationDuration,
|
Duration = AnimationDuration,
|
||||||
EasingFunction = AnimationEasingFunction,
|
EasingFunction = AnimationEasingFunction
|
||||||
FillBehavior = AnimationFillBehavior
|
|
||||||
};
|
};
|
||||||
|
|
||||||
zoomLevelAnimation.Completed += ZoomLevelAnimationCompleted;
|
zoomLevelAnimation.Completed += ZoomLevelAnimationCompleted;
|
||||||
|
|
||||||
this.BeginAnimation(ZoomLevelProperty, zoomLevelAnimation);
|
this.BeginAnimation(ZoomLevelProperty, zoomLevelAnimation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -609,11 +601,13 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
if (zoomLevelAnimation != null)
|
if (zoomLevelAnimation != null)
|
||||||
{
|
{
|
||||||
|
SetValueInternal(ZoomLevelProperty, TargetZoomLevel);
|
||||||
|
UpdateTransform(true);
|
||||||
|
|
||||||
zoomLevelAnimation.Completed -= ZoomLevelAnimationCompleted;
|
zoomLevelAnimation.Completed -= ZoomLevelAnimationCompleted;
|
||||||
zoomLevelAnimation = null;
|
zoomLevelAnimation = null;
|
||||||
|
|
||||||
InternalSetValue(ZoomLevelProperty, TargetZoomLevel);
|
this.BeginAnimation(ZoomLevelProperty, null);
|
||||||
UpdateTransform(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -622,7 +616,7 @@ namespace MapControl
|
||||||
if (heading < 0d || heading > 360d)
|
if (heading < 0d || heading > 360d)
|
||||||
{
|
{
|
||||||
heading = ((heading % 360d) + 360d) % 360d;
|
heading = ((heading % 360d) + 360d) % 360d;
|
||||||
InternalSetValue(property, heading);
|
SetValueInternal(property, heading);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -635,7 +629,7 @@ namespace MapControl
|
||||||
|
|
||||||
if (headingAnimation == null)
|
if (headingAnimation == null)
|
||||||
{
|
{
|
||||||
InternalSetValue(TargetHeadingProperty, heading);
|
SetValueInternal(TargetHeadingProperty, heading);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -668,11 +662,11 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
By = delta,
|
By = delta,
|
||||||
Duration = AnimationDuration,
|
Duration = AnimationDuration,
|
||||||
EasingFunction = AnimationEasingFunction,
|
EasingFunction = AnimationEasingFunction
|
||||||
FillBehavior = AnimationFillBehavior
|
|
||||||
};
|
};
|
||||||
|
|
||||||
headingAnimation.Completed += HeadingAnimationCompleted;
|
headingAnimation.Completed += HeadingAnimationCompleted;
|
||||||
|
|
||||||
this.BeginAnimation(HeadingProperty, headingAnimation);
|
this.BeginAnimation(HeadingProperty, headingAnimation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -682,15 +676,17 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
if (headingAnimation != null)
|
if (headingAnimation != null)
|
||||||
{
|
{
|
||||||
|
SetValueInternal(HeadingProperty, TargetHeading);
|
||||||
|
UpdateTransform();
|
||||||
|
|
||||||
headingAnimation.Completed -= HeadingAnimationCompleted;
|
headingAnimation.Completed -= HeadingAnimationCompleted;
|
||||||
headingAnimation = null;
|
headingAnimation = null;
|
||||||
|
|
||||||
InternalSetValue(HeadingProperty, TargetHeading);
|
this.BeginAnimation(HeadingProperty, null);
|
||||||
UpdateTransform();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InternalSetValue(DependencyProperty property, object value)
|
private void SetValueInternal(DependencyProperty property, object value)
|
||||||
{
|
{
|
||||||
internalPropertyChange = true;
|
internalPropertyChange = true;
|
||||||
SetValue(property, value);
|
SetValue(property, value);
|
||||||
|
|
@ -715,12 +711,11 @@ namespace MapControl
|
||||||
resetTransformCenter = true;
|
resetTransformCenter = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
InternalSetValue(CenterProperty, center);
|
SetValueInternal(CenterProperty, center);
|
||||||
|
|
||||||
if (centerAnimation == null)
|
if (centerAnimation == null)
|
||||||
{
|
{
|
||||||
InternalSetValue(TargetCenterProperty, center);
|
SetValueInternal(TargetCenterProperty, center);
|
||||||
InternalSetValue(CenterPointProperty, projection.LocationToPoint(center));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resetTransformCenter)
|
if (resetTransformCenter)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
// © 2017 Clemens Fischer
|
// © 2017 Clemens Fischer
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Windows.Foundation;
|
using Windows.Foundation;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
|
|
@ -17,38 +16,42 @@ namespace MapControl
|
||||||
return transform.TransformPoint(point);
|
return transform.TransformPoint(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void BeginAnimation(this DependencyObject obj, DependencyProperty property, DoubleAnimation animation)
|
public static void BeginAnimation(this DependencyObject obj, DependencyProperty property, Timeline animation)
|
||||||
{
|
{
|
||||||
animation.EnableDependentAnimation = true;
|
if (animation != null)
|
||||||
BeginAnimation(obj, property, (Timeline)animation);
|
{
|
||||||
|
string propertyName = null;
|
||||||
|
|
||||||
|
if (property == MapBase.CenterPointProperty)
|
||||||
|
{
|
||||||
|
propertyName = "CenterPoint";
|
||||||
|
((PointAnimation)animation).EnableDependentAnimation = true;
|
||||||
|
}
|
||||||
|
else if (property == MapBase.ZoomLevelProperty)
|
||||||
|
{
|
||||||
|
propertyName = "ZoomLevel";
|
||||||
|
((DoubleAnimation)animation).EnableDependentAnimation = true;
|
||||||
|
}
|
||||||
|
else if (property == MapBase.HeadingProperty)
|
||||||
|
{
|
||||||
|
propertyName = "Heading";
|
||||||
|
((DoubleAnimation)animation).EnableDependentAnimation = true;
|
||||||
|
}
|
||||||
|
else if (property == UIElement.OpacityProperty)
|
||||||
|
{
|
||||||
|
propertyName = "Opacity";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void BeginAnimation(this DependencyObject obj, DependencyProperty property, PointAnimation animation)
|
if (propertyName != null)
|
||||||
{
|
|
||||||
animation.EnableDependentAnimation = true;
|
|
||||||
BeginAnimation(obj, property, (Timeline)animation);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Dictionary<DependencyProperty, string> properties = new Dictionary<DependencyProperty, string>()
|
|
||||||
{
|
|
||||||
{ 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.SetTargetProperty(animation, propertyName);
|
||||||
Storyboard.SetTarget(animation, obj);
|
Storyboard.SetTarget(animation, obj);
|
||||||
|
|
||||||
var storyboard = new Storyboard();
|
var storyboard = new Storyboard();
|
||||||
storyboard.Children.Add(animation);
|
storyboard.Children.Add(animation);
|
||||||
storyboard.Begin();
|
storyboard.Begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,11 @@ using Windows.Foundation;
|
||||||
using Windows.UI;
|
using Windows.UI;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
using Windows.UI.Xaml.Media.Animation;
|
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
public partial class MapBase
|
public partial class MapBase
|
||||||
{
|
{
|
||||||
private const FillBehavior AnimationFillBehavior = FillBehavior.HoldEnd;
|
|
||||||
|
|
||||||
public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register(
|
||||||
nameof(Foreground), typeof(Brush), typeof(MapBase),
|
nameof(Foreground), typeof(Brush), typeof(MapBase),
|
||||||
new PropertyMetadata(new SolidColorBrush(Colors.Black)));
|
new PropertyMetadata(new SolidColorBrush(Colors.Black)));
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,11 @@
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Animation;
|
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
public partial class MapBase
|
public partial class MapBase
|
||||||
{
|
{
|
||||||
private const FillBehavior AnimationFillBehavior = FillBehavior.Stop;
|
|
||||||
|
|
||||||
public static readonly DependencyProperty ForegroundProperty =
|
public static readonly DependencyProperty ForegroundProperty =
|
||||||
Control.ForegroundProperty.AddOwner(typeof(MapBase));
|
Control.ForegroundProperty.AddOwner(typeof(MapBase));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue