From 14c26b34e8d17c243e628c28fcd3910162b7a13d Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Wed, 2 Nov 2022 19:49:18 +0100 Subject: [PATCH] Restore MapBase.ViewScale property --- MapControl/Shared/MapBase.cs | 8 ++++++++ MapControl/WPF/MapBase.WPF.cs | 10 ++++++++++ MapControl/WinUI/MapBase.WinUI.cs | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index f7a3b078..a2183bb2 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -215,6 +215,12 @@ namespace MapControl set => SetValue(AnimationEasingFunctionProperty, value); } + /// + /// Gets the scaling factor from cartesian map coordinates to view coordinates, + /// i.e. pixels per meter, as a read-only dependency property. + /// + public double ViewScale => (double)GetValue(ViewScaleProperty); + /// /// Gets the ViewTransform instance that is used to transform between cartesian map coordinates /// and view coordinates. @@ -770,6 +776,8 @@ namespace MapControl } } + SetViewScale(ViewTransform.Scale); + OnViewportChanged(new ViewportChangedEventArgs(projectionChanged, Center.Longitude - centerLongitude)); centerLongitude = Center.Longitude; diff --git a/MapControl/WPF/MapBase.WPF.cs b/MapControl/WPF/MapBase.WPF.cs index 1b8dfe7c..89a2d691 100644 --- a/MapControl/WPF/MapBase.WPF.cs +++ b/MapControl/WPF/MapBase.WPF.cs @@ -42,6 +42,11 @@ namespace MapControl 0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (o, e) => ((MapBase)o).TargetHeadingPropertyChanged((double)e.NewValue))); + private static readonly DependencyPropertyKey ViewScalePropertyKey = DependencyProperty.RegisterReadOnly( + nameof(ViewScale), typeof(double), typeof(MapBase), new PropertyMetadata(0d)); + + public static readonly DependencyProperty ViewScaleProperty = ViewScalePropertyKey.DependencyProperty; + private static readonly DependencyProperty CenterPointProperty = DependencyProperty.Register( "CenterPoint", typeof(Point), typeof(MapBase), new PropertyMetadata(new Point(), (o, e) => @@ -63,5 +68,10 @@ namespace MapControl ResetTransformCenter(); UpdateTransform(); } + + private void SetViewScale(double scale) + { + SetValue(ViewScalePropertyKey, scale); + } } } diff --git a/MapControl/WinUI/MapBase.WinUI.cs b/MapControl/WinUI/MapBase.WinUI.cs index 6abe835c..1e2348da 100644 --- a/MapControl/WinUI/MapBase.WinUI.cs +++ b/MapControl/WinUI/MapBase.WinUI.cs @@ -43,6 +43,9 @@ namespace MapControl nameof(TargetHeading), typeof(double), typeof(MapBase), new PropertyMetadata(0d, (o, e) => ((MapBase)o).TargetHeadingPropertyChanged((double)e.NewValue))); + public static readonly DependencyProperty ViewScaleProperty = DependencyProperty.Register( + nameof(ViewScale), typeof(double), typeof(MapBase), new PropertyMetadata(0d)); + internal static readonly DependencyProperty CenterPointProperty = DependencyProperty.Register( "CenterPoint", typeof(Windows.Foundation.Point), typeof(MapBase), new PropertyMetadata(new Windows.Foundation.Point(), (o, e) => @@ -71,5 +74,10 @@ namespace MapControl ResetTransformCenter(); UpdateTransform(); } + + private void SetViewScale(double scale) + { + SetValue(ViewScaleProperty, scale); + } } }