Minor changes to MapPath

This commit is contained in:
ClemensFischer 2023-01-23 18:42:10 +01:00
parent ee985aa777
commit f5d5e1d620
3 changed files with 27 additions and 16 deletions

View file

@ -4,13 +4,10 @@
#if WINUI #if WINUI
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
#elif UWP #elif UWP
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#else #else
using System.Windows; using System.Windows;
using System.Windows.Media;
#endif #endif
namespace MapControl namespace MapControl
@ -30,7 +27,7 @@ namespace MapControl
/// <summary> /// <summary>
/// Gets or sets a Location that is used as /// Gets or sets a Location that is used as
/// - either the origin point of a geometry specified in projected map coordinates (meters) /// - either the origin point of a geometry specified in projected map coordinates (meters)
/// - or as an optional value to constrain the view position of MapPaths with multiple /// - or as an optional anchor point to constrain the view position of MapPaths with multiple
/// Locations (like MapPolyline or MapPolygon) to the visible map viewport, as done /// Locations (like MapPolyline or MapPolygon) to the visible map viewport, as done
/// for elements where the MapPanel.Location property is set. /// for elements where the MapPanel.Location property is set.
/// </summary> /// </summary>
@ -73,16 +70,7 @@ namespace MapControl
{ {
if (parentMap != null && Location != null && Data != null) if (parentMap != null && Location != null && Data != null)
{ {
var matrix = parentMap.GetMapTransform(Location); SetMapTransform(parentMap.GetMapTransform(Location));
if (Data.Transform is MatrixTransform transform)
{
transform.Matrix = matrix;
}
else
{
Data.Transform = new MatrixTransform { Matrix = matrix };
}
} }
MapPanel.SetLocation(this, Location); MapPanel.SetLocation(this, Location);

View file

@ -40,12 +40,23 @@ namespace MapControl
} }
else else
{ {
data.Transform = new MatrixTransform();
path.UpdateData(); path.UpdateData();
} }
} }
} }
private void SetMapTransform(Matrix matrix)
{
if (Data.Transform is MatrixTransform transform && !transform.IsFrozen)
{
transform.Matrix = matrix;
}
else
{
Data.Transform = new MatrixTransform(matrix);
}
}
#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)

View file

@ -25,7 +25,19 @@ namespace MapControl
MapPanel.InitMapElement(this); MapPanel.InitMapElement(this);
} }
#region Methods used only by derived classes MapPolyline and MapPolygon private void SetMapTransform(Matrix matrix)
{
if (Data.Transform is MatrixTransform transform)
{
transform.Matrix = matrix;
}
else
{
Data.Transform = new MatrixTransform { Matrix = matrix };
}
}
#region Methods used only by derived classes MapPolyline and MapPolygon
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e) protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
{ {