diff --git a/MapControl/Avalonia/MapPanel.Avalonia.cs b/MapControl/Avalonia/MapPanel.Avalonia.cs index 5f4fcb08..f126f16c 100644 --- a/MapControl/Avalonia/MapPanel.Avalonia.cs +++ b/MapControl/Avalonia/MapPanel.Avalonia.cs @@ -17,6 +17,8 @@ namespace MapControl public static readonly AttachedProperty BoundingBoxProperty = DependencyPropertyHelper.RegisterAttached("BoundingBox"); + protected IEnumerable ChildElements => Children; + static MapPanel() { AffectsParentArrange(LocationProperty, BoundingBoxProperty); @@ -41,8 +43,6 @@ namespace MapControl element.RenderTransformOrigin = new RelativePoint(originX, originY, RelativeUnit.Relative); } - protected IEnumerable ChildElements => Children; - private static void SetVisible(Control element, bool visible) { element.IsVisible = visible; diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index 0992ea48..9b64ff8c 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -192,8 +192,7 @@ namespace MapControl var position = parentMap.LocationToView(location); if (parentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical && - position.HasValue && - IsOutsideViewport(position.Value)) + IsOutsideViewport(position)) { position = parentMap.LocationToView( new Location(location.Latitude, parentMap.CoerceLongitude(location.Longitude))); @@ -220,7 +219,8 @@ namespace MapControl var position = parentMap.ViewTransform.MapToView(rectCenter); var projection = parentMap.MapProjection; - if (projection.Type <= MapProjectionType.NormalCylindrical && IsOutsideViewport(position)) + if (projection.Type <= MapProjectionType.NormalCylindrical && + IsOutsideViewport(position)) { var location = projection.MapToLocation(rectCenter); @@ -250,6 +250,11 @@ namespace MapControl || point.Y < 0d || point.Y > parentMap.ActualHeight; } + private bool IsOutsideViewport(Point? point) + { + return point.HasValue && IsOutsideViewport(point.Value); + } + private void ArrangeChildElement(FrameworkElement element, Size panelSize) { var location = GetLocation(element); @@ -259,7 +264,7 @@ namespace MapControl if (GetAutoCollapse(element)) { - SetVisible(element, !(position.HasValue && IsOutsideViewport(position.Value))); + SetVisible(element, !IsOutsideViewport(position)); } if (position.HasValue) diff --git a/MapControl/WPF/MapPanel.WPF.cs b/MapControl/WPF/MapPanel.WPF.cs index bc2fd1e6..636bcd62 100644 --- a/MapControl/WPF/MapPanel.WPF.cs +++ b/MapControl/WPF/MapPanel.WPF.cs @@ -22,6 +22,8 @@ namespace MapControl DependencyPropertyHelper.RegisterAttached("BoundingBox", null, FrameworkPropertyMetadataOptions.AffectsParentArrange); + protected IEnumerable ChildElements => InternalChildren.OfType(); + public MapPanel() { if (this is MapBase) @@ -41,8 +43,6 @@ namespace MapControl element.RenderTransformOrigin = new Point(originX, originY); } - protected IEnumerable ChildElements => InternalChildren.OfType(); - private static void SetVisible(FrameworkElement element, bool visible) { element.Visibility = visible ? Visibility.Visible : Visibility.Collapsed; diff --git a/MapControl/WinUI/MapPanel.WinUI.cs b/MapControl/WinUI/MapPanel.WinUI.cs index 8695317c..31bdecd1 100644 --- a/MapControl/WinUI/MapPanel.WinUI.cs +++ b/MapControl/WinUI/MapPanel.WinUI.cs @@ -27,6 +27,8 @@ namespace MapControl DependencyPropertyHelper.RegisterAttached("BoundingBox", null, (element, oldValue, newValue) => (element.Parent as MapPanel)?.InvalidateArrange()); + protected IEnumerable ChildElements => Children.OfType(); + public MapPanel() { InitMapElement(this); @@ -74,8 +76,6 @@ namespace MapControl element.RenderTransformOrigin = new Point(originX, originY); } - protected IEnumerable ChildElements => Children.OfType(); - private static void SetVisible(FrameworkElement element, bool visible) { element.Visibility = visible ? Visibility.Visible : Visibility.Collapsed;