diff --git a/MapControl/MapPath.WPF.cs b/MapControl/MapPath.WPF.cs index c02af5ba..4bb4c14a 100644 --- a/MapControl/MapPath.WPF.cs +++ b/MapControl/MapPath.WPF.cs @@ -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 { diff --git a/MapControl/MapPath.cs b/MapControl/MapPath.cs index 665b3016..17fa8c80 100644 --- a/MapControl/MapPath.cs +++ b/MapControl/MapPath.cs @@ -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 { /// - /// 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. /// 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) diff --git a/MapControl/MapPolyline.Silverlight.WinRT.cs b/MapControl/MapPolyline.Silverlight.WinRT.cs index 6a9d8df4..532d1678 100644 --- a/MapControl/MapPolyline.Silverlight.WinRT.cs +++ b/MapControl/MapPolyline.Silverlight.WinRT.cs @@ -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); } } diff --git a/MapControl/MapPolyline.WPF.cs b/MapControl/MapPolyline.WPF.cs index 4cb7970e..2ae660cf 100644 --- a/MapControl/MapPolyline.WPF.cs +++ b/MapControl/MapPolyline.WPF.cs @@ -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; diff --git a/MapControl/MapRectangle.cs b/MapControl/MapRectangle.cs index ed168e0c..2cbd2c37 100644 --- a/MapControl/MapRectangle.cs +++ b/MapControl/MapRectangle.cs @@ -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