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

@ -63,9 +63,9 @@ namespace MapControl
}
}
protected MapShape()
protected MapShape(Geometry data)
{
Data = new PathGeometry();
Data = data;
MapPanel.InitMapElement(this);
}
@ -88,13 +88,18 @@ namespace MapControl
return point;
}
protected Point LocationToViewportPoint(Location location)
{
return parentMap.MapProjection.ViewportTransform.Transform(LocationToPoint(location));
}
protected double GetLongitudeOffset()
{
var longitudeOffset = 0d;
if (parentMap.MapProjection.IsContinuous && Location != null)
{
var viewportPosition = parentMap.MapProjection.LocationToViewportPoint(Location);
var viewportPosition = LocationToViewportPoint(Location);
if (viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
viewportPosition.Y < 0d || viewportPosition.Y > parentMap.RenderSize.Height)

View file

@ -18,6 +18,11 @@ namespace MapControl
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolygon),
new PropertyMetadata(null, (o, e) => ((MapPolygon)o).LocationsPropertyChanged(e)));
public MapPolygon()
: base(new PathGeometry())
{
}
/// <summary>
/// Gets or sets the Locations that define the polyline points.
/// </summary>
@ -29,8 +34,7 @@ namespace MapControl
protected override void UpdateData()
{
var figures = ((PathGeometry)Data).Figures;
figures.Clear();
((PathGeometry)Data).Figures.Clear();
if (ParentMap != null && Locations != null && Locations.Count() >= 2)
{
@ -42,7 +46,7 @@ namespace MapControl
locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset));
}
var points = locations.Select(loc => ParentMap.MapProjection.LocationToViewportPoint(loc)).ToList();
var points = locations.Select(loc => LocationToViewportPoint(loc)).ToList();
points.Add(points[0]);
CreatePolylineFigures(points);

View file

@ -18,6 +18,11 @@ namespace MapControl
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolyline),
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).LocationsPropertyChanged(e)));
public MapPolyline()
: base(new PathGeometry())
{
}
/// <summary>
/// Gets or sets the Locations that define the polyline points.
/// </summary>
@ -41,7 +46,7 @@ namespace MapControl
locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset));
}
var points = locations.Select(loc => ParentMap.MapProjection.LocationToViewportPoint(loc)).ToList();
var points = locations.Select(loc => LocationToViewportPoint(loc)).ToList();
CreatePolylineFigures(points);
}

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;