Version 4.4.1: MapPolygon for UWP in progress

This commit is contained in:
ClemensF 2018-02-13 20:11:16 +01:00
parent 946713b8eb
commit 2f828fbe2d
7 changed files with 64 additions and 30 deletions

View file

@ -17,12 +17,17 @@ namespace MapControl
/// for the Polygons property if collection changes of the property itself and its
/// elements are both supposed to trigger a UI update.
/// </summary>
public class MapMultiPolygon : MapShape, IWeakEventListener
public class MapMultiPolygon : MapShape
{
public static readonly DependencyProperty PolygonsProperty = DependencyProperty.Register(
nameof(Polygons), typeof(IEnumerable<IEnumerable<Location>>), typeof(MapMultiPolygon),
new PropertyMetadata(null, (o, e) => ((MapMultiPolygon)o).DataCollectionPropertyChanged(e)));
public MapMultiPolygon()
: base(new PathGeometry())
{
}
/// <summary>
/// Gets or sets the Locations that define the multi-polygon points.
/// </summary>
@ -34,7 +39,8 @@ namespace MapControl
protected override void UpdateData()
{
Data.Figures.Clear();
var figures = ((PathGeometry)Data).Figures;
figures.Clear();
if (ParentMap != null && Polygons != null)
{
@ -43,7 +49,7 @@ namespace MapControl
var points = polygon.Select(loc => LocationToPoint(loc));
var polyline = new PolyLineSegment(points.Skip(1), true);
Data.Figures.Add(new PathFigure(points.First(), new PathSegment[] { polyline }, true));
figures.Add(new PathFigure(points.First(), new PathSegment[] { polyline }, true));
}
}
}

View file

@ -19,6 +19,16 @@ namespace MapControl
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolygon),
new PropertyMetadata(null, (o, e) => ((MapPolygon)o).DataCollectionPropertyChanged(e)));
public static readonly DependencyProperty FillRuleProperty = DependencyProperty.Register(
nameof(FillRule), typeof(FillRule), typeof(MapPolygon),
new FrameworkPropertyMetadata(FillRule.EvenOdd, FrameworkPropertyMetadataOptions.AffectsRender,
(o, e) => ((PathGeometry)((MapPolygon)o).Data).FillRule = (FillRule)e.NewValue));
public MapPolygon()
: base(new PathGeometry())
{
}
/// <summary>
/// Gets or sets the Locations that define the polygon points.
/// </summary>
@ -29,16 +39,26 @@ namespace MapControl
set { SetValue(LocationsProperty, value); }
}
/// <summary>
/// Gets or sets the FillRule of the PathGeometry that represents the polyline.
/// </summary>
public FillRule FillRule
{
get { return (FillRule)GetValue(FillRuleProperty); }
set { SetValue(FillRuleProperty, value); }
}
protected override void UpdateData()
{
Data.Figures.Clear();
var figures = ((PathGeometry)Data).Figures;
figures.Clear();
if (ParentMap != null && Locations != null && Locations.Count() >= 2)
{
var points = Locations.Select(loc => LocationToPoint(loc));
var polyline = new PolyLineSegment(points.Skip(1), true);
Data.Figures.Add(new PathFigure(points.First(), new PathSegment[] { polyline }, true));
figures.Add(new PathFigure(points.First(), new PathSegment[] { polyline }, true));
}
}
}

View file

@ -19,6 +19,11 @@ namespace MapControl
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolyline),
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).DataCollectionPropertyChanged(e)));
public MapPolyline()
: base(new PathGeometry())
{
}
/// <summary>
/// Gets or sets the Locations that define the polyline points.
/// </summary>
@ -31,14 +36,15 @@ namespace MapControl
protected override void UpdateData()
{
Data.Figures.Clear();
var figures = ((PathGeometry)Data).Figures;
figures.Clear();
if (ParentMap != null && Locations != null && Locations.Count() >= 2)
{
var points = Locations.Select(loc => LocationToPoint(loc));
var polyline = new PolyLineSegment(points.Skip(1), true);
Data.Figures.Add(new PathFigure(points.First(), new PathSegment[] { polyline }, false));
figures.Add(new PathFigure(points.First(), new PathSegment[] { polyline }, false));
}
}
}

View file

@ -12,21 +12,7 @@ namespace MapControl
{
public abstract partial class MapShape : Shape, IWeakEventListener
{
public static readonly DependencyProperty FillRuleProperty = DependencyProperty.Register(
nameof(FillRule), typeof(FillRule), typeof(MapShape),
new FrameworkPropertyMetadata(FillRule.EvenOdd, FrameworkPropertyMetadataOptions.AffectsRender,
(o, e) => ((MapShape)o).Data.FillRule = (FillRule)e.NewValue));
/// <summary>
/// Gets or sets the FillRule of the StreamGeometry that represents the polyline.
/// </summary>
public FillRule FillRule
{
get { return (FillRule)GetValue(FillRuleProperty); }
set { SetValue(FillRuleProperty, value); }
}
protected PathGeometry Data { get; }
protected Geometry Data { get; }
protected override Geometry DefiningGeometry
{
@ -38,7 +24,9 @@ namespace MapControl
if (parentMap != null)
{
var transform = new TransformGroup();
transform.Children.Add(new TranslateTransform(GetLongitudeOffset() * parentMap.MapProjection.TrueScale, 0d));
var offsetX = GetLongitudeOffset() * parentMap.MapProjection.TrueScale;
transform.Children.Add(new TranslateTransform(offsetX, 0d));
transform.Children.Add(parentMap.MapProjection.ViewportTransform);
Data.Transform = transform;