Version 2.4.6: Implemented MapPath.UpdateData()

This commit is contained in:
ClemensF 2015-02-10 17:25:00 +01:00
parent 78e7e67614
commit 40fecef3e8
5 changed files with 32 additions and 25 deletions

View file

@ -11,8 +11,8 @@ namespace MapControl
public partial class MapPath : Shape
{
public static readonly DependencyProperty DataProperty = DependencyProperty.Register(
"Data", typeof(Geometry), typeof(MapPath),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
"Data", typeof(Geometry), typeof(MapPath), new FrameworkPropertyMetadata(
null, FrameworkPropertyMetadataOptions.AffectsRender, (o, e) => ((MapPath)o).UpdateData()));
public Geometry Data
{

View file

@ -4,14 +4,17 @@
#if WINDOWS_RUNTIME
using Windows.Foundation;
using Windows.UI.Xaml.Media;
#else
using System.Windows;
using System.Windows.Media;
#endif
namespace MapControl
{
/// <summary>
/// Base class for map shapes.
/// Base class for map shapes. The shape geometry is given by the Data property,
/// which must contain a Geometry defined in cartesian (projected) map coordinates.
/// </summary>
public partial class MapPath : IMapElement
{
@ -29,6 +32,17 @@ namespace MapControl
protected virtual void UpdateData()
{
if (Data != null)
{
if (parentMap != null)
{
Data.Transform = ParentMap.ViewportTransform;
}
else
{
Data.ClearValue(Geometry.TransformProperty);
}
}
}
protected override Size MeasureOverride(Size constraint)

View file

@ -21,37 +21,32 @@ namespace MapControl
protected override void UpdateData()
{
var geometry = (PathGeometry)Data;
var locations = Locations;
Location first;
geometry.Figures.Clear();
if (ParentMap != null && locations != null && (first = locations.FirstOrDefault()) != null)
if (ParentMap != null && Locations != null && Locations.Any())
{
var points = Locations.Select(l => ParentMap.MapTransform.Transform(l));
var figure = new PathFigure
{
StartPoint = ParentMap.MapTransform.Transform(first),
StartPoint = points.First(),
IsClosed = IsClosed,
IsFilled = IsClosed
};
var segment = new PolyLineSegment();
foreach (var location in locations.Skip(1))
foreach (var point in points.Skip(1))
{
segment.Points.Add(ParentMap.MapTransform.Transform(location));
segment.Points.Add(point);
}
if (segment.Points.Count > 0)
{
figure.Segments.Add(segment);
}
geometry.Figures.Clear();
figure.Segments.Add(segment);
geometry.Figures.Add(figure);
geometry.Transform = ParentMap.ViewportTransform;
}
else
{
geometry.Figures.Clear();
geometry.ClearValue(Geometry.TransformProperty);
}
}

View file

@ -17,18 +17,15 @@ namespace MapControl
protected override void UpdateData()
{
var geometry = (StreamGeometry)Data;
var locations = Locations;
Location first;
if (ParentMap != null && locations != null && (first = locations.FirstOrDefault()) != null)
if (ParentMap != null && Locations != null && Locations.Any())
{
using (var context = geometry.Open())
{
var startPoint = ParentMap.MapTransform.Transform(first);
var points = locations.Skip(1).Select(l => ParentMap.MapTransform.Transform(l)).ToList();
var points = Locations.Select(l => ParentMap.MapTransform.Transform(l));
context.BeginFigure(startPoint, IsClosed, IsClosed);
context.PolyLineTo(points, true, false);
context.BeginFigure(points.First(), IsClosed, IsClosed);
context.PolyLineTo(points.Skip(1).ToList(), true, false);
}
geometry.Transform = ParentMap.ViewportTransform;

View file

@ -34,12 +34,13 @@ namespace MapControl
"North", typeof(double), typeof(MapRectangle),
new PropertyMetadata(double.NaN, (o, e) => ((MapRectangle)o).UpdateData()));
private bool boundingBoxValid = true;
private bool boundingBoxValid;
public MapRectangle()
{
Data = new RectangleGeometry();
StrokeThickness = 0d;
Data = new RectangleGeometry();
boundingBoxValid = true;
}
public double West