From e1cd5a64b79d0398e3aa38babd848b950ee69e02 Mon Sep 17 00:00:00 2001 From: ClemensF Date: Wed, 13 Jan 2021 21:46:23 +0100 Subject: [PATCH] Update MapPanel.cs --- MapControl/Shared/MapPanel.cs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index 51dce2d4..7c914a30 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -114,18 +114,16 @@ namespace MapControl return null; } - var pos = parentMap.LocationToView(location); + var position = parentMap.LocationToView(location); - if (parentMap.MapProjection.IsNormalCylindrical && - (pos.X < 0d || pos.X > parentMap.RenderSize.Width || - pos.Y < 0d || pos.Y > parentMap.RenderSize.Height)) + if (parentMap.MapProjection.IsNormalCylindrical && !IsVisible(position)) { location = new Location(location.Latitude, parentMap.ConstrainedLongitude(location.Longitude)); - pos = parentMap.LocationToView(location); + position = parentMap.LocationToView(location); } - return pos; + return position; } /// @@ -142,22 +140,20 @@ namespace MapControl public ViewRect GetViewRect(Rect rect) { var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d); - var pos = parentMap.ViewTransform.MapToView(center); + var position = parentMap.ViewTransform.MapToView(center); - if (parentMap.MapProjection.IsNormalCylindrical && - (pos.X < 0d || pos.X > parentMap.RenderSize.Width || - pos.Y < 0d || pos.Y > parentMap.RenderSize.Height)) + if (parentMap.MapProjection.IsNormalCylindrical && !IsVisible(position)) { var location = parentMap.MapProjection.MapToLocation(center); location.Longitude = parentMap.ConstrainedLongitude(location.Longitude); - pos = parentMap.LocationToView(location); + position = parentMap.LocationToView(location); } var width = rect.Width * parentMap.ViewTransform.Scale; var height = rect.Height * parentMap.ViewTransform.Scale; - var x = pos.X - width / 2d; - var y = pos.Y - height / 2d; + var x = position.X - width / 2d; + var y = position.Y - height / 2d; return new ViewRect(x, y, width, height, parentMap.ViewTransform.Rotation); } @@ -213,9 +209,7 @@ namespace MapControl if (GetAutoCollapse(element)) { - if (position.HasValue && - (position.Value.X < 0d || position.Value.X > parentMap.RenderSize.Width || - position.Value.Y < 0d || position.Value.Y > parentMap.RenderSize.Height)) + if (position.HasValue && !IsVisible(position.Value)) { element.SetValue(VisibilityProperty, Visibility.Collapsed); } @@ -248,6 +242,12 @@ namespace MapControl return finalSize; } + private bool IsVisible(Point point) + { + return point.X >= 0d && point.X <= parentMap.RenderSize.Width + && point.Y >= 0d && point.Y <= parentMap.RenderSize.Height; + } + private static void ArrangeElement(FrameworkElement element, ViewRect rect) { element.Width = rect.Width;