Version 4.8.0: Improved WPF MapPolyline and MapPolygon accuracy.

This commit is contained in:
ClemensF 2018-04-10 22:34:34 +02:00
parent de4ba0765a
commit 5bc42d1f07
19 changed files with 77 additions and 172 deletions

View file

@ -97,6 +97,12 @@
<Compile Include="..\Shared\MapPanel.cs">
<Link>MapPanel.cs</Link>
</Compile>
<Compile Include="..\Shared\MapPolygon.cs">
<Link>MapPolygon.cs</Link>
</Compile>
<Compile Include="..\Shared\MapPolyline.cs">
<Link>MapPolyline.cs</Link>
</Compile>
<Compile Include="..\Shared\MapProjection.cs">
<Link>MapProjection.cs</Link>
</Compile>
@ -150,8 +156,6 @@
<Compile Include="MapGraticule.UWP.cs" />
<Compile Include="MapOverlay.UWP.cs" />
<Compile Include="MapPanel.UWP.cs" />
<Compile Include="MapPolygon.UWP.cs" />
<Compile Include="MapPolyline.UWP.cs" />
<Compile Include="MapShape.UWP.cs" />
<Compile Include="Matrix.UWP.cs" />
<Compile Include="Point.UWP.cs" />

View file

@ -1,40 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2018 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
namespace MapControl
{
/// <summary>
/// A polygon defined by a collection of Locations.
/// </summary>
public class MapPolygon : MapShape
{
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolygon),
new PropertyMetadata(null, (o, e) => ((MapPolygon)o).LocationsPropertyChanged(e)));
/// <summary>
/// Gets or sets the Locations that define the polyline points.
/// </summary>
public IEnumerable<Location> Locations
{
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
set { SetValue(LocationsProperty, value); }
}
protected override void UpdateData()
{
var figures = ((PathGeometry)Data).Figures;
figures.Clear();
if (ParentMap != null)
{
AddPolylineFigures(figures, Locations, true);
}
}
}
}

View file

@ -1,40 +0,0 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2018 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
namespace MapControl
{
/// <summary>
/// A polyline defined by a collection of Locations.
/// </summary>
public class MapPolyline : MapShape
{
public static readonly DependencyProperty LocationsProperty = DependencyProperty.Register(
nameof(Locations), typeof(IEnumerable<Location>), typeof(MapPolyline),
new PropertyMetadata(null, (o, e) => ((MapPolyline)o).LocationsPropertyChanged(e)));
/// <summary>
/// Gets or sets the Locations that define the polyline points.
/// </summary>
public IEnumerable<Location> Locations
{
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
set { SetValue(LocationsProperty, value); }
}
protected override void UpdateData()
{
var figures = ((PathGeometry)Data).Figures;
figures.Clear();
if (ParentMap != null)
{
AddPolylineFigures(figures, Locations, false);
}
}
}
}

View file

@ -14,40 +14,33 @@ namespace MapControl
{
public abstract partial class MapShape : Path
{
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
protected void DataCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
UpdateData();
}
protected void LocationsPropertyChanged(DependencyPropertyChangedEventArgs e)
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
{
INotifyCollectionChanged collection;
if ((collection = e.OldValue as INotifyCollectionChanged) != null)
{
collection.CollectionChanged -= LocationCollectionChanged;
collection.CollectionChanged -= DataCollectionChanged;
}
if ((collection = e.NewValue as INotifyCollectionChanged) != null)
{
collection.CollectionChanged += LocationCollectionChanged;
collection.CollectionChanged += DataCollectionChanged;
}
UpdateData();
}
protected void LocationCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
UpdateData();
}
protected void AddPolylineFigures(PathFigureCollection figures, IEnumerable<Location> locations, bool closed)
{
if (locations != null && locations.Count() >= 2)
{
var viewport = new Rect(0, 0, ParentMap.RenderSize.Width, ParentMap.RenderSize.Height);
var offset = GetLongitudeOffset();
if (offset != 0d)
{
locations = locations.Select(loc => new Location(loc.Latitude, loc.Longitude + offset));
@ -59,6 +52,7 @@ namespace MapControl
points.Add(points[0]);
}
var viewport = new Rect(0, 0, ParentMap.RenderSize.Width, ParentMap.RenderSize.Height);
PathFigure figure = null;
PolyLineSegment segment = null;

View file

@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCompany("Clemens Fischer")]
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("4.7.1")]
[assembly: AssemblyFileVersion("4.7.1")]
[assembly: AssemblyVersion("4.8.0")]
[assembly: AssemblyFileVersion("4.8.0")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]