From 8cdc03e411dd126c4acb66487cc90a382f1ebcd8 Mon Sep 17 00:00:00 2001 From: Clemens Date: Tue, 22 Feb 2022 22:12:15 +0100 Subject: [PATCH] Updated BoundingBox --- MapControl/Shared/AzimuthalProjection.cs | 13 +-- MapControl/Shared/BoundingBox.cs | 7 +- MapControl/Shared/CenteredBoundingBox.cs | 26 ++---- MapControl/Shared/MapImageLayer.cs | 103 ++--------------------- SampleApps/UniversalApp/MainPage.xaml | 1 + SampleApps/UniversalApp/MainPage.xaml.cs | 4 + 6 files changed, 27 insertions(+), 127 deletions(-) diff --git a/MapControl/Shared/AzimuthalProjection.cs b/MapControl/Shared/AzimuthalProjection.cs index 53a8f614..f3157b5b 100644 --- a/MapControl/Shared/AzimuthalProjection.cs +++ b/MapControl/Shared/AzimuthalProjection.cs @@ -18,16 +18,11 @@ namespace MapControl { public override Rect BoundingBoxToRect(BoundingBox boundingBox) { - if (boundingBox is CenteredBoundingBox cbbox) - { - var center = LocationToMap(cbbox.Center); + var center = LocationToMap(boundingBox.Center); - return new Rect( - center.X - cbbox.Width / 2d, center.Y - cbbox.Height / 2d, - cbbox.Width, cbbox.Height); - } - - return base.BoundingBoxToRect(boundingBox); + return new Rect( + center.X - boundingBox.Width / 2d, center.Y - boundingBox.Height / 2d, + boundingBox.Width, boundingBox.Height); } public override BoundingBox RectToBoundingBox(Rect rect) diff --git a/MapControl/Shared/BoundingBox.cs b/MapControl/Shared/BoundingBox.cs index c07e0cc1..a8baabbc 100644 --- a/MapControl/Shared/BoundingBox.cs +++ b/MapControl/Shared/BoundingBox.cs @@ -49,16 +49,19 @@ namespace MapControl public virtual double Width { get { return East - West; } + protected set { } } public virtual double Height { get { return North - South; } + protected set { } } - public virtual BoundingBox Clone() + public virtual Location Center { - return new BoundingBox(South, West, North, East); + get { return new Location((South + North) / 2d, (West + East) / 2d); } + protected set { } } public static BoundingBox Parse(string s) diff --git a/MapControl/Shared/CenteredBoundingBox.cs b/MapControl/Shared/CenteredBoundingBox.cs index 751c2874..35704f4e 100644 --- a/MapControl/Shared/CenteredBoundingBox.cs +++ b/MapControl/Shared/CenteredBoundingBox.cs @@ -8,31 +8,15 @@ namespace MapControl { public class CenteredBoundingBox : BoundingBox { - private readonly double width; - private readonly double height; - public CenteredBoundingBox(Location center, double width, double height) { Center = center; - this.width = Math.Max(width, 0d); - this.height = Math.Max(height, 0d); + Width = Math.Max(width, 0d); + Height = Math.Max(height, 0d); } - public Location Center { get; private set; } - - public override double Width - { - get { return width; } - } - - public override double Height - { - get { return height; } - } - - public override BoundingBox Clone() - { - return new CenteredBoundingBox(Center, Width, Height); - } + public override double Width { get; protected set; } + public override double Height { get; protected set; } + public override Location Center { get; protected set; } } } diff --git a/MapControl/Shared/MapImageLayer.cs b/MapControl/Shared/MapImageLayer.cs index 36b5f8eb..8f03249c 100644 --- a/MapControl/Shared/MapImageLayer.cs +++ b/MapControl/Shared/MapImageLayer.cs @@ -25,7 +25,6 @@ using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Threading; -using System.Xml.Linq; #endif namespace MapControl @@ -39,21 +38,6 @@ namespace MapControl public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register( nameof(Description), typeof(string), typeof(MapImageLayer), new PropertyMetadata(null)); - public static readonly DependencyProperty MinLatitudeProperty = DependencyProperty.Register( - nameof(MinLatitude), typeof(double), typeof(MapImageLayer), new PropertyMetadata(double.NaN)); - - public static readonly DependencyProperty MaxLatitudeProperty = DependencyProperty.Register( - nameof(MaxLatitude), typeof(double), typeof(MapImageLayer), new PropertyMetadata(double.NaN)); - - public static readonly DependencyProperty MinLongitudeProperty = DependencyProperty.Register( - nameof(MinLongitude), typeof(double), typeof(MapImageLayer), new PropertyMetadata(double.NaN)); - - public static readonly DependencyProperty MaxLongitudeProperty = DependencyProperty.Register( - nameof(MaxLongitude), typeof(double), typeof(MapImageLayer), new PropertyMetadata(double.NaN)); - - public static readonly DependencyProperty MaxBoundingBoxWidthProperty = DependencyProperty.Register( - nameof(MaxBoundingBoxWidth), typeof(double), typeof(MapImageLayer), new PropertyMetadata(double.NaN)); - public static readonly DependencyProperty RelativeImageSizeProperty = DependencyProperty.Register( nameof(RelativeImageSize), typeof(double), typeof(MapImageLayer), new PropertyMetadata(1d)); @@ -92,51 +76,6 @@ namespace MapControl set { SetValue(DescriptionProperty, value); } } - /// - /// Optional minimum latitude value. Default is NaN. - /// - public double MinLatitude - { - get { return (double)GetValue(MinLatitudeProperty); } - set { SetValue(MinLatitudeProperty, value); } - } - - /// - /// Optional maximum latitude value. Default is NaN. - /// - public double MaxLatitude - { - get { return (double)GetValue(MaxLatitudeProperty); } - set { SetValue(MaxLatitudeProperty, value); } - } - - /// - /// Optional minimum longitude value. Default is NaN. - /// - public double MinLongitude - { - get { return (double)GetValue(MinLongitudeProperty); } - set { SetValue(MinLongitudeProperty, value); } - } - - /// - /// Optional maximum longitude value. Default is NaN. - /// - public double MaxLongitude - { - get { return (double)GetValue(MaxLongitudeProperty); } - set { SetValue(MaxLongitudeProperty, value); } - } - - /// - /// Optional maximum width of the map image's bounding box. Default is NaN. - /// - public double MaxBoundingBoxWidth - { - get { return (double)GetValue(MaxBoundingBoxWidthProperty); } - set { SetValue(MaxBoundingBoxWidthProperty, value); } - } - /// /// Relative size of the map image in relation to the current view size. /// Setting a value greater than one will let MapImageLayer request images that @@ -271,46 +210,20 @@ namespace MapControl var rect = new Rect(x, y, width, height); BoundingBox = ParentMap.ViewRectToBoundingBox(rect); - - if (BoundingBox != null) - { - if (!double.IsNaN(MinLatitude) && BoundingBox.South < MinLatitude) - { - BoundingBox.South = MinLatitude; - } - - if (!double.IsNaN(MinLongitude) && BoundingBox.West < MinLongitude) - { - BoundingBox.West = MinLongitude; - } - - if (!double.IsNaN(MaxLatitude) && BoundingBox.North > MaxLatitude) - { - BoundingBox.North = MaxLatitude; - } - - if (!double.IsNaN(MaxLongitude) && BoundingBox.East > MaxLongitude) - { - BoundingBox.East = MaxLongitude; - } - - if (!double.IsNaN(MaxBoundingBoxWidth) && BoundingBox.Width > MaxBoundingBoxWidth) - { - var margin = (BoundingBox.Width - MaxBoundingBoxWidth) / 2d; - BoundingBox.West += margin; - BoundingBox.East -= margin; - } - } } private void AdjustBoundingBox(double longitudeOffset) { - if (Math.Abs(longitudeOffset) > 180d && BoundingBox != null) + if (Math.Abs(longitudeOffset) > 180d && + BoundingBox != null && + BoundingBox.West < BoundingBox.East && // not an azimuthal projection + BoundingBox.South < BoundingBox.North) { var offset = 360d * Math.Sign(longitudeOffset); - BoundingBox.West += offset; - BoundingBox.East += offset; + BoundingBox = new BoundingBox( + BoundingBox.South, BoundingBox.West + offset, + BoundingBox.North, BoundingBox.East + offset); foreach (var image in Children.OfType()) { @@ -344,7 +257,7 @@ namespace MapControl Children.Insert(1, topImage); topImage.Source = image; - SetBoundingBox(topImage, BoundingBox?.Clone()); + SetBoundingBox(topImage, BoundingBox); topImage.BeginAnimation(OpacityProperty, new DoubleAnimation { diff --git a/SampleApps/UniversalApp/MainPage.xaml b/SampleApps/UniversalApp/MainPage.xaml index 1bb0bbaf..101e7cd2 100644 --- a/SampleApps/UniversalApp/MainPage.xaml +++ b/SampleApps/UniversalApp/MainPage.xaml @@ -197,6 +197,7 @@ diff --git a/SampleApps/UniversalApp/MainPage.xaml.cs b/SampleApps/UniversalApp/MainPage.xaml.cs index 2b1d8290..544b2790 100644 --- a/SampleApps/UniversalApp/MainPage.xaml.cs +++ b/SampleApps/UniversalApp/MainPage.xaml.cs @@ -72,8 +72,12 @@ namespace SampleApplication } }); } + + AddChartServerLayer(); } + partial void AddChartServerLayer(); + private void ResetHeadingButtonClick(object sender, RoutedEventArgs e) { map.TargetHeading = 0d;