mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Add MapItem.MapTransform property
This commit is contained in:
parent
b253d0696a
commit
85cc01f086
|
|
@ -8,15 +8,19 @@ using Windows.Foundation;
|
|||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
#elif UWP
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
|
|
@ -43,6 +47,35 @@ namespace MapControl
|
|||
get => (Location)GetValue(LocationProperty);
|
||||
set => SetValue(LocationProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Transform for scaling and rotating geometries
|
||||
/// in map coordinates (meters) to view coordinates (pixels).
|
||||
/// </summary>
|
||||
public Transform MapTransform
|
||||
{
|
||||
get => mapTransform ?? (mapTransform = new MatrixTransform());
|
||||
}
|
||||
|
||||
private MatrixTransform mapTransform;
|
||||
|
||||
protected override Size ArrangeOverride(Size bounds)
|
||||
{
|
||||
if (mapTransform != null) // property in use, e.g. as source of a Binding
|
||||
{
|
||||
var parentMap = (VisualTreeHelper.GetParent(this) as MapPanel)?.ParentMap;
|
||||
|
||||
if (parentMap != null && Location != null)
|
||||
{
|
||||
var scale = parentMap.GetScale(Location);
|
||||
var matrix = new Matrix(scale.X, 0d, 0d, scale.Y, 0d, 0d);
|
||||
matrix.Rotate(parentMap.ViewTransform.Rotation);
|
||||
mapTransform.Matrix = matrix;
|
||||
}
|
||||
}
|
||||
|
||||
return base.ArrangeOverride(bounds);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ namespace MapControl
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the position of an element with Location in view coordinates,
|
||||
/// Gets the view position of an element with Location
|
||||
/// or null when the element has no Location.
|
||||
/// </summary>
|
||||
public static Point? GetViewPosition(FrameworkElement element)
|
||||
|
|
|
|||
|
|
@ -26,26 +26,40 @@
|
|||
<VisualState x:Name="Pressed"/>
|
||||
<VisualState x:Name="Selected">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.75" Duration="0"/>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="0.75" Duration="0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="SelectedUnfocused">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.75" Duration="0"/>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="0.75" Duration="0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="SelectedPointerOver">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.75" Duration="0"/>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="0.75" Duration="0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="SelectedPressed">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.75" Duration="0"/>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="0.75" Duration="0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Path Fill="Red" Opacity="0.4" IsHitTestVisible="False">
|
||||
<Path.Data>
|
||||
<EllipseGeometry RadiusX="20" RadiusY="20"
|
||||
Transform="{Binding MapTransform, RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||
</Path.Data>
|
||||
</Path>
|
||||
<Path x:Name="selectedPath" Fill="White" Opacity="0">
|
||||
<Path.Data>
|
||||
<EllipseGeometry RadiusX="12" RadiusY="12"/>
|
||||
|
|
|
|||
|
|
@ -33,26 +33,40 @@
|
|||
<VisualState x:Name="Pressed"/>
|
||||
<VisualState x:Name="Selected">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.75" Duration="0"/>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="0.75" Duration="0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="SelectedUnfocused">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.75" Duration="0"/>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="0.75" Duration="0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="SelectedPointerOver">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.75" Duration="0"/>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="0.75" Duration="0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="SelectedPressed">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath" Storyboard.TargetProperty="Opacity" To="0.75" Duration="0"/>
|
||||
<DoubleAnimation Storyboard.TargetName="selectedPath"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="0.75" Duration="0"/>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Path Fill="Red" Opacity="0.4" IsHitTestVisible="False">
|
||||
<Path.Data>
|
||||
<EllipseGeometry RadiusX="20" RadiusY="20"
|
||||
Transform="{Binding MapTransform, RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||
</Path.Data>
|
||||
</Path>
|
||||
<Path x:Name="selectedPath" Fill="White" Opacity="0">
|
||||
<Path.Data>
|
||||
<EllipseGeometry RadiusX="12" RadiusY="12"/>
|
||||
|
|
|
|||
|
|
@ -48,6 +48,12 @@
|
|||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Path Fill="Red" Opacity="0.4" IsHitTestVisible="False">
|
||||
<Path.Data>
|
||||
<EllipseGeometry RadiusX="20" RadiusY="20"
|
||||
Transform="{Binding MapTransform, RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||
</Path.Data>
|
||||
</Path>
|
||||
<Path x:Name="selectedPath" Fill="White" Opacity="0">
|
||||
<Path.Data>
|
||||
<EllipseGeometry RadiusX="12" RadiusY="12"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue