mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Version 2.4.6: Implemented MapPath.UpdateData()
This commit is contained in:
parent
78e7e67614
commit
40fecef3e8
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue