mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
FrameworkElementExtensions
This commit is contained in:
parent
24dabf046d
commit
d513ea249e
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
42
MapControl/Shared/FrameworkElementExtensions.cs
Normal file
42
MapControl/Shared/FrameworkElementExtensions.cs
Normal file
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace MapControl
|
|||
|
||||
public MapTileLayer()
|
||||
{
|
||||
MapPanel.SetRenderTransform(this, new MatrixTransform());
|
||||
this.SetRenderTransform(new MatrixTransform());
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<string> SupportedCrsIds { get; } = [WebMercatorProjection.DefaultCrsId];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue