Version 5.0: Reworked MapBase and MapPath

This commit is contained in:
ClemensF 2020-03-28 21:53:38 +01:00
parent 06fd31c17b
commit 49e15ce424
41 changed files with 466 additions and 1068 deletions

View file

@ -43,6 +43,11 @@ namespace MapControl
0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
(o, e) => ((MapBase)o).TargetHeadingPropertyChanged((double)e.NewValue)));
private static readonly DependencyPropertyKey ViewScalePropertyKey = DependencyProperty.RegisterReadOnly(
nameof(ViewScale), typeof(double), typeof(MapBase), new PropertyMetadata(0d));
public static readonly DependencyProperty ViewScaleProperty = ViewScalePropertyKey.DependencyProperty;
private static readonly DependencyProperty CenterPointProperty = DependencyProperty.Register(
"CenterPoint", typeof(Point), typeof(MapBase),
new PropertyMetadata(new Point(), (o, e) => ((MapBase)o).CenterPointPropertyChanged((Point)e.NewValue)));
@ -61,6 +66,11 @@ namespace MapControl
UpdateTransform();
}
private void SetViewScale(double scale)
{
SetValue(ViewScalePropertyKey, scale);
}
private void CenterPointPropertyChanged(Point center)
{
CenterPointPropertyChanged(new Location(center.Y, center.X));

View file

@ -56,7 +56,7 @@ namespace MapControl
private void DrawCylindricalGraticule(DrawingContext drawingContext, double lineDistance, string labelFormat)
{
var boundingBox = ParentMap.ViewportRectToBoundingBox(new Rect(ParentMap.RenderSize));
var boundingBox = ParentMap.ViewRectToBoundingBox(new Rect(ParentMap.RenderSize));
var latLabelStart = Math.Ceiling(boundingBox.South / lineDistance) * lineDistance;
var lonLabelStart = Math.Ceiling(boundingBox.West / lineDistance) * lineDistance;
var latLabels = new List<Label>((int)((boundingBox.North - latLabelStart) / lineDistance) + 1);
@ -72,8 +72,8 @@ namespace MapControl
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground, pixelsPerDip)));
drawingContext.DrawLine(pen,
ParentMap.LocationToViewportPoint(new Location(lat, boundingBox.West)),
ParentMap.LocationToViewportPoint(new Location(lat, boundingBox.East)));
ParentMap.LocationToView(new Location(lat, boundingBox.West)),
ParentMap.LocationToView(new Location(lat, boundingBox.East)));
}
for (var lon = lonLabelStart; lon <= boundingBox.East; lon += lineDistance)
@ -83,17 +83,17 @@ namespace MapControl
CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, FontSize, Foreground, pixelsPerDip)));
drawingContext.DrawLine(pen,
ParentMap.LocationToViewportPoint(new Location(boundingBox.South, lon)),
ParentMap.LocationToViewportPoint(new Location(boundingBox.North, lon)));
ParentMap.LocationToView(new Location(boundingBox.South, lon)),
ParentMap.LocationToView(new Location(boundingBox.North, lon)));
}
foreach (var latLabel in latLabels)
{
foreach (var lonLabel in lonLabels)
{
var position = ParentMap.LocationToViewportPoint(new Location(latLabel.Position, lonLabel.Position));
var position = ParentMap.LocationToView(new Location(latLabel.Position, lonLabel.Position));
drawingContext.PushTransform(new RotateTransform(ParentMap.Heading, position.X, position.Y));
drawingContext.PushTransform(new RotateTransform(ParentMap.ViewTransform.Rotation, position.X, position.Y));
drawingContext.DrawText(latLabel.Text,
new Point(position.X + StrokeThickness / 2d + 2d, position.Y - StrokeThickness / 2d - latLabel.Text.Height));
drawingContext.DrawText(lonLabel.Text,

View file

@ -16,7 +16,7 @@ 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
public class MapMultiPolygon : MapPath
{
public static readonly DependencyProperty PolygonsProperty = DependencyProperty.Register(
nameof(Polygons), typeof(IEnumerable<IEnumerable<Location>>), typeof(MapMultiPolygon),
@ -31,6 +31,11 @@ namespace MapControl
set { SetValue(PolygonsProperty, value); }
}
public MapMultiPolygon()
{
Data = new PathGeometry();
}
protected override void UpdateData()
{
var figures = ((PathGeometry)Data).Figures;

View file

@ -20,11 +20,11 @@ namespace MapControl
"ParentMap", typeof(MapBase), typeof(MapPanel),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits, ParentMapPropertyChanged));
private static readonly DependencyPropertyKey ViewportPositionPropertyKey = DependencyProperty.RegisterAttachedReadOnly(
"ViewportPosition", typeof(Point?), typeof(MapPanel), new PropertyMetadata());
private static readonly DependencyPropertyKey ViewPositionPropertyKey = DependencyProperty.RegisterAttachedReadOnly(
"ViewPosition", typeof(Point?), typeof(MapPanel), new PropertyMetadata());
public static readonly DependencyProperty ParentMapProperty = ParentMapPropertyKey.DependencyProperty;
public static readonly DependencyProperty ViewportPositionProperty = ViewportPositionPropertyKey.DependencyProperty;
public static readonly DependencyProperty ViewPositionProperty = ViewPositionPropertyKey.DependencyProperty;
public static MapBase GetParentMap(FrameworkElement element)
{
@ -39,9 +39,9 @@ namespace MapControl
}
}
private static void SetViewportPosition(FrameworkElement element, Point? viewportPosition)
private static void SetViewPosition(FrameworkElement element, Point? viewPosition)
{
element.SetValue(ViewportPositionPropertyKey, viewportPosition);
element.SetValue(ViewPositionPropertyKey, viewPosition);
}
}
}

View file

@ -12,9 +12,15 @@ using System.Windows.Shapes;
namespace MapControl
{
public abstract partial class MapShape : Shape, IWeakEventListener
public partial class MapPath : Shape, IWeakEventListener
{
public Geometry Data { get; }
public static readonly DependencyProperty DataProperty = Path.DataProperty.AddOwner(typeof(MapPath));
public Geometry Data
{
get { return (Geometry)GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}
protected override Geometry DefiningGeometry
{
@ -48,13 +54,7 @@ namespace MapControl
{
if (locations != null && locations.Count() >= 2)
{
var offset = GetLongitudeOffset();
if (offset != 0d)
{
locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset));
}
var points = locations.Select(loc => LocationToViewportPoint(loc));
var points = locations.Select(loc => LocationToView(loc));
var figure = new PathFigure
{
StartPoint = points.First(),