mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Improve Data handling in WPF MapPath
This commit is contained in:
parent
2652e5eb0f
commit
65c93d1a3e
|
|
@ -68,23 +68,22 @@ namespace MapControl
|
||||||
|
|
||||||
protected virtual void UpdateData()
|
protected virtual void UpdateData()
|
||||||
{
|
{
|
||||||
#if !WINUI && !UWP
|
|
||||||
if (Data != null && Data.IsFrozen)
|
|
||||||
{
|
|
||||||
Data = Data.Clone();
|
|
||||||
return; // UpdateData called again from DataPropertyChanged callback
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
MapPanel.SetLocation(this, Location);
|
MapPanel.SetLocation(this, Location);
|
||||||
|
|
||||||
if (parentMap != null && Location != null && Data != null)
|
if (parentMap != null && Location != null && Data != null)
|
||||||
{
|
{
|
||||||
var scale = parentMap.GetScale(Location);
|
var scale = parentMap.GetScale(Location);
|
||||||
var transform = new Matrix(scale.X, 0d, 0d, scale.Y, 0d, 0d);
|
var matrix = new Matrix(scale.X, 0d, 0d, scale.Y, 0d, 0d);
|
||||||
|
matrix.Rotate(parentMap.ViewTransform.Rotation);
|
||||||
|
|
||||||
transform.Rotate(parentMap.ViewTransform.Rotation);
|
if (Data.Transform is MatrixTransform transform)
|
||||||
|
{
|
||||||
Data.Transform = new MatrixTransform { Matrix = transform };
|
transform.Matrix = matrix;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Data.Transform = new MatrixTransform { Matrix = matrix };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,7 @@ namespace MapControl
|
||||||
public partial class MapPath : Shape, IWeakEventListener
|
public partial class MapPath : Shape, IWeakEventListener
|
||||||
{
|
{
|
||||||
public static readonly DependencyProperty DataProperty = Path.DataProperty.AddOwner(
|
public static readonly DependencyProperty DataProperty = Path.DataProperty.AddOwner(
|
||||||
typeof(MapPath), new PropertyMetadata(null,
|
typeof(MapPath), new PropertyMetadata(null, DataPropertyChanged));
|
||||||
(o, e) =>
|
|
||||||
{
|
|
||||||
if (e.NewValue != e.OldValue) // Data is actually a new Geometry
|
|
||||||
{
|
|
||||||
((MapPath)o).UpdateData();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
public Geometry Data
|
public Geometry Data
|
||||||
{
|
{
|
||||||
|
|
@ -32,6 +25,25 @@ namespace MapControl
|
||||||
|
|
||||||
protected override Geometry DefiningGeometry => Data;
|
protected override Geometry DefiningGeometry => Data;
|
||||||
|
|
||||||
|
private static void DataPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.NewValue != null && !ReferenceEquals(e.NewValue, e.OldValue)) // Data is actually a new Geometry
|
||||||
|
{
|
||||||
|
var path = (MapPath)obj;
|
||||||
|
var data = (Geometry)e.NewValue;
|
||||||
|
|
||||||
|
if (data.IsFrozen)
|
||||||
|
{
|
||||||
|
path.Data = data.Clone(); // DataPropertyChanged called again
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data.Transform = new MatrixTransform();
|
||||||
|
path.UpdateData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region Methods used only by derived classes MapPolyline, MapPolygon and MapMultiPolygon
|
#region Methods used only by derived classes MapPolyline, MapPolygon and MapMultiPolygon
|
||||||
|
|
||||||
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue