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;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Data;
|
using Microsoft.UI.Xaml.Data;
|
||||||
|
using Microsoft.UI.Xaml.Media;
|
||||||
#elif UWP
|
#elif UWP
|
||||||
using Windows.Foundation;
|
using Windows.Foundation;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Data;
|
using Windows.UI.Xaml.Data;
|
||||||
|
using Windows.UI.Xaml.Media;
|
||||||
#else
|
#else
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Markup;
|
||||||
|
using System.Windows.Media;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
|
|
@ -43,6 +47,35 @@ namespace MapControl
|
||||||
get => (Location)GetValue(LocationProperty);
|
get => (Location)GetValue(LocationProperty);
|
||||||
set => SetValue(LocationProperty, value);
|
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>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// or null when the element has no Location.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Point? GetViewPosition(FrameworkElement element)
|
public static Point? GetViewPosition(FrameworkElement element)
|
||||||
|
|
|
||||||
|
|
@ -26,26 +26,40 @@
|
||||||
<VisualState x:Name="Pressed"/>
|
<VisualState x:Name="Pressed"/>
|
||||||
<VisualState x:Name="Selected">
|
<VisualState x:Name="Selected">
|
||||||
<Storyboard>
|
<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>
|
</Storyboard>
|
||||||
</VisualState>
|
</VisualState>
|
||||||
<VisualState x:Name="SelectedUnfocused">
|
<VisualState x:Name="SelectedUnfocused">
|
||||||
<Storyboard>
|
<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>
|
</Storyboard>
|
||||||
</VisualState>
|
</VisualState>
|
||||||
<VisualState x:Name="SelectedPointerOver">
|
<VisualState x:Name="SelectedPointerOver">
|
||||||
<Storyboard>
|
<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>
|
</Storyboard>
|
||||||
</VisualState>
|
</VisualState>
|
||||||
<VisualState x:Name="SelectedPressed">
|
<VisualState x:Name="SelectedPressed">
|
||||||
<Storyboard>
|
<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>
|
</Storyboard>
|
||||||
</VisualState>
|
</VisualState>
|
||||||
</VisualStateGroup>
|
</VisualStateGroup>
|
||||||
</VisualStateManager.VisualStateGroups>
|
</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 x:Name="selectedPath" Fill="White" Opacity="0">
|
||||||
<Path.Data>
|
<Path.Data>
|
||||||
<EllipseGeometry RadiusX="12" RadiusY="12"/>
|
<EllipseGeometry RadiusX="12" RadiusY="12"/>
|
||||||
|
|
|
||||||
|
|
@ -33,26 +33,40 @@
|
||||||
<VisualState x:Name="Pressed"/>
|
<VisualState x:Name="Pressed"/>
|
||||||
<VisualState x:Name="Selected">
|
<VisualState x:Name="Selected">
|
||||||
<Storyboard>
|
<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>
|
</Storyboard>
|
||||||
</VisualState>
|
</VisualState>
|
||||||
<VisualState x:Name="SelectedUnfocused">
|
<VisualState x:Name="SelectedUnfocused">
|
||||||
<Storyboard>
|
<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>
|
</Storyboard>
|
||||||
</VisualState>
|
</VisualState>
|
||||||
<VisualState x:Name="SelectedPointerOver">
|
<VisualState x:Name="SelectedPointerOver">
|
||||||
<Storyboard>
|
<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>
|
</Storyboard>
|
||||||
</VisualState>
|
</VisualState>
|
||||||
<VisualState x:Name="SelectedPressed">
|
<VisualState x:Name="SelectedPressed">
|
||||||
<Storyboard>
|
<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>
|
</Storyboard>
|
||||||
</VisualState>
|
</VisualState>
|
||||||
</VisualStateGroup>
|
</VisualStateGroup>
|
||||||
</VisualStateManager.VisualStateGroups>
|
</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 x:Name="selectedPath" Fill="White" Opacity="0">
|
||||||
<Path.Data>
|
<Path.Data>
|
||||||
<EllipseGeometry RadiusX="12" RadiusY="12"/>
|
<EllipseGeometry RadiusX="12" RadiusY="12"/>
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,12 @@
|
||||||
</VisualState>
|
</VisualState>
|
||||||
</VisualStateGroup>
|
</VisualStateGroup>
|
||||||
</VisualStateManager.VisualStateGroups>
|
</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 x:Name="selectedPath" Fill="White" Opacity="0">
|
||||||
<Path.Data>
|
<Path.Data>
|
||||||
<EllipseGeometry RadiusX="12" RadiusY="12"/>
|
<EllipseGeometry RadiusX="12" RadiusY="12"/>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue