diff --git a/MapControl/Avalonia/MapPanel.Avalonia.cs b/MapControl/Avalonia/MapPanel.Avalonia.cs index 0f38ad2c..a2f10119 100644 --- a/MapControl/Avalonia/MapPanel.Avalonia.cs +++ b/MapControl/Avalonia/MapPanel.Avalonia.cs @@ -1,6 +1,4 @@ -global using FrameworkElement = Avalonia.Controls.Control; -using Avalonia; -using Avalonia.Media; +using Avalonia; namespace MapControl { @@ -24,16 +22,5 @@ namespace MapControl { return (MapBase)element.GetValue(ParentMapProperty); } - - public static void SetRenderTransform(FrameworkElement element, Transform transform, double originX = 0d, double originY = 0d) - { - element.RenderTransform = transform; - element.RenderTransformOrigin = new RelativePoint(originX, originY, RelativeUnit.Relative); - } - - private static void SetVisible(FrameworkElement element, bool visible) - { - element.IsVisible = visible; - } } } diff --git a/MapControl/Shared/FrameworkElementExtensions.cs b/MapControl/Shared/FrameworkElementExtensions.cs new file mode 100644 index 00000000..7af31e04 --- /dev/null +++ b/MapControl/Shared/FrameworkElementExtensions.cs @@ -0,0 +1,42 @@ +#if AVALONIA +global using FrameworkElement = Avalonia.Controls.Control; +using Avalonia; +using Avalonia.Media; +#elif WPF +using System.Windows; +using System.Windows.Media; +#elif UWP +using Windows.UI.Xaml; +using Windows.UI.Xaml.Media; +#elif WINUI +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Media; +#endif + +namespace MapControl +{ + public static class FrameworkElementExtensions + { + public static void SetRenderTransform(this FrameworkElement element, Transform transform, bool center = false) + { + element.RenderTransform = transform; +#if AVALONIA + element.RenderTransformOrigin = center ? RelativePoint.Center : RelativePoint.TopLeft; +#else + if (center) + { + element.RenderTransformOrigin = new Point(0.5, 0.5); + } +#endif + } + + public static void SetVisible(this FrameworkElement element, bool visible) + { +#if AVALONIA + element.IsVisible = visible; +#else + element.Visibility = visible ? Visibility.Visible : Visibility.Collapsed; +#endif + } + } +} diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index ca7348ba..e8b1c3de 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -259,7 +259,7 @@ namespace MapControl if (GetAutoCollapse(element)) { - SetVisible(element, position.HasValue && parentMap.InsideViewBounds(position.Value)); + element.SetVisible(position.HasValue && parentMap.InsideViewBounds(position.Value)); } if (position.HasValue) @@ -320,7 +320,7 @@ namespace MapControl } else if (rotation != 0d) { - SetRenderTransform(element, new RotateTransform { Angle = rotation }, 0.5, 0.5); + element.SetRenderTransform(new RotateTransform { Angle = rotation }, true); } } } diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index f3961ac5..00be27ec 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -50,7 +50,7 @@ namespace MapControl public MapTileLayer() { - MapPanel.SetRenderTransform(this, new MatrixTransform()); + this.SetRenderTransform(new MatrixTransform()); } public override IReadOnlyCollection SupportedCrsIds { get; } = [WebMercatorProjection.DefaultCrsId]; diff --git a/MapControl/Shared/WmtsTileMatrixLayer.cs b/MapControl/Shared/WmtsTileMatrixLayer.cs index 9b750f8b..f3e23355 100644 --- a/MapControl/Shared/WmtsTileMatrixLayer.cs +++ b/MapControl/Shared/WmtsTileMatrixLayer.cs @@ -25,8 +25,7 @@ namespace MapControl // public WmtsTileMatrixLayer(WmtsTileMatrix wmtsTileMatrix, int zoomLevel) { - MapPanel.SetRenderTransform(this, new MatrixTransform()); - + this.SetRenderTransform(new MatrixTransform()); WmtsTileMatrix = wmtsTileMatrix; TileMatrix = new TileMatrix(zoomLevel, 1, 1, 0, 0); } diff --git a/MapControl/WPF/MapPanel.WPF.cs b/MapControl/WPF/MapPanel.WPF.cs index 63a65a03..4e0e923e 100644 --- a/MapControl/WPF/MapPanel.WPF.cs +++ b/MapControl/WPF/MapPanel.WPF.cs @@ -1,5 +1,4 @@ using System.Windows; -using System.Windows.Media; namespace MapControl { @@ -20,16 +19,5 @@ namespace MapControl { return (MapBase)element.GetValue(ParentMapProperty); } - - public static void SetRenderTransform(FrameworkElement element, Transform transform, double originX = 0d, double originY = 0d) - { - element.RenderTransform = transform; - element.RenderTransformOrigin = new Point(originX, originY); - } - - 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 b15196b4..7a85a8e5 100644 --- a/MapControl/WinUI/MapPanel.WinUI.cs +++ b/MapControl/WinUI/MapPanel.WinUI.cs @@ -49,16 +49,5 @@ namespace MapControl return parentMap; } - - public static void SetRenderTransform(FrameworkElement element, Transform transform, double originX = 0d, double originY = 0d) - { - element.RenderTransform = transform; - element.RenderTransformOrigin = new Point(originX, originY); - } - - private static void SetVisible(FrameworkElement element, bool visible) - { - element.Visibility = visible ? Visibility.Visible : Visibility.Collapsed; - } } }