mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-01-14 04:30:11 +01:00
Version 4.8.0: Improved WPF MapPolyline and MapPolygon accuracy.
This commit is contained in:
parent
de4ba0765a
commit
5bc42d1f07
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -222,7 +222,12 @@ namespace MapControl
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scaling transformation from meters to viewport coordinate units at the Center location.
|
||||
/// Gets the transformation from cartesian map coordinates to viewport coordinates (pixels).
|
||||
/// </summary>
|
||||
public MatrixTransform ViewportTransform { get; } = new MatrixTransform();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scaling transformation from meters to viewport coordinates at the Center location.
|
||||
/// </summary>
|
||||
public ScaleTransform ScaleTransform { get; } = new ScaleTransform();
|
||||
|
||||
|
|
@ -708,9 +713,12 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
ViewportTransform.Matrix = projection.ViewportTransform;
|
||||
|
||||
var scale = projection.GetMapScale(center);
|
||||
ScaleTransform.ScaleX = scale.X;
|
||||
ScaleTransform.ScaleY = scale.Y;
|
||||
|
||||
RotateTransform.Angle = Heading;
|
||||
|
||||
OnViewportChanged(new ViewportChangedEventArgs(projectionChanged, Center.Longitude - centerLongitude));
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ namespace MapControl
|
|||
var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
|
||||
|
||||
rotation = parentMap.Heading;
|
||||
viewportPosition = projection.ViewportTransformMatrix.Transform(center);
|
||||
viewportPosition = projection.ViewportTransform.Transform(center);
|
||||
|
||||
if (parentMap.MapProjection.IsContinuous &&
|
||||
(viewportPosition.X < 0d || viewportPosition.X > parentMap.RenderSize.Width ||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,14 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
#if WINDOWS_UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
|
|
@ -21,7 +26,9 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// Gets or sets the Locations that define the polygon points.
|
||||
/// </summary>
|
||||
#if !WINDOWS_UWP
|
||||
[TypeConverter(typeof(LocationCollectionConverter))]
|
||||
#endif
|
||||
public IEnumerable<Location> Locations
|
||||
{
|
||||
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
|
||||
|
|
@ -35,7 +42,7 @@ namespace MapControl
|
|||
|
||||
if (ParentMap != null)
|
||||
{
|
||||
AddPolylineFigure(figures, Locations, true);
|
||||
AddPolylineFigures(figures, Locations, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,14 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
#if WINDOWS_UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
#else
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
|
|
@ -21,7 +26,9 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// Gets or sets the Locations that define the polyline points.
|
||||
/// </summary>
|
||||
#if !WINDOWS_UWP
|
||||
[TypeConverter(typeof(LocationCollectionConverter))]
|
||||
#endif
|
||||
public IEnumerable<Location> Locations
|
||||
{
|
||||
get { return (IEnumerable<Location>)GetValue(LocationsProperty); }
|
||||
|
|
@ -35,7 +42,7 @@ namespace MapControl
|
|||
|
||||
if (ParentMap != null)
|
||||
{
|
||||
AddPolylineFigure(figures, Locations, false);
|
||||
AddPolylineFigures(figures, Locations, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -59,14 +59,9 @@ namespace MapControl
|
|||
public double MaxLatitude { get; protected set; } = 90d;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the transformation matrix from cartesian map coordinates to viewport coordinates (pixels).
|
||||
/// Gets the transform matrix from cartesian map coordinates to viewport coordinates (pixels).
|
||||
/// </summary>
|
||||
public Matrix ViewportTransformMatrix { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the transformation from cartesian map coordinates to viewport coordinates (pixels).
|
||||
/// </summary>
|
||||
public MatrixTransform ViewportTransform { get; } = new MatrixTransform();
|
||||
public Matrix ViewportTransform { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scaling factor from cartesian map coordinates to viewport coordinates.
|
||||
|
|
@ -114,7 +109,7 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public Point LocationToViewportPoint(Location location)
|
||||
{
|
||||
return ViewportTransformMatrix.Transform(LocationToPoint(location));
|
||||
return ViewportTransform.Transform(LocationToPoint(location));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -145,8 +140,7 @@ namespace MapControl
|
|||
var center = LocationToPoint(mapCenter);
|
||||
var matrix = CreateTransformMatrix(center, ViewportScale, -ViewportScale, heading, viewportCenter);
|
||||
|
||||
ViewportTransformMatrix = matrix;
|
||||
ViewportTransform.Matrix = matrix;
|
||||
ViewportTransform = matrix;
|
||||
|
||||
matrix.Invert();
|
||||
inverseViewportTransformMatrix = matrix;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace MapControl
|
|||
{
|
||||
if (parentMap != null)
|
||||
{
|
||||
OnViewportChanged(parentMap, new ViewportChangedEventArgs());
|
||||
UpdateData();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,11 +58,17 @@ namespace MapControl
|
|||
parentMap.ViewportChanged += OnViewportChanged;
|
||||
}
|
||||
|
||||
SetDataTransform();
|
||||
UpdateData();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
|
||||
{
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
protected abstract void UpdateData();
|
||||
|
||||
protected MapShape()
|
||||
: this(new PathGeometry())
|
||||
{
|
||||
|
|
@ -75,10 +81,6 @@ namespace MapControl
|
|||
MapPanel.InitMapElement(this);
|
||||
}
|
||||
|
||||
partial void SetDataTransform(); // WPF only
|
||||
|
||||
protected abstract void UpdateData();
|
||||
|
||||
protected Point LocationToPoint(Location location)
|
||||
{
|
||||
var point = parentMap.MapProjection.LocationToPoint(location);
|
||||
|
|
@ -97,7 +99,7 @@ namespace MapControl
|
|||
|
||||
protected Point LocationToViewportPoint(Location location)
|
||||
{
|
||||
return parentMap.MapProjection.ViewportTransformMatrix.Transform(LocationToPoint(location));
|
||||
return parentMap.MapProjection.ViewportTransform.Transform(LocationToPoint(location));
|
||||
}
|
||||
|
||||
protected double GetLongitudeOffset()
|
||||
|
|
|
|||
|
|
@ -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" />
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -116,6 +116,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>
|
||||
|
|
@ -171,8 +177,6 @@
|
|||
<Compile Include="MapMultiPolygon.WPF.cs" />
|
||||
<Compile Include="MapOverlay.WPF.cs" />
|
||||
<Compile Include="MapPanel.WPF.cs" />
|
||||
<Compile Include="MapPolygon.WPF.cs" />
|
||||
<Compile Include="MapPolyline.WPF.cs" />
|
||||
<Compile Include="MapShape.WPF.cs" />
|
||||
<Compile Include="TileImageLoader.WPF.cs" />
|
||||
<Compile Include="ImageLoader.WPF.cs" />
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace MapControl
|
|||
{
|
||||
foreach (var polygon in Polygons)
|
||||
{
|
||||
AddPolylineFigure(figures, polygon, true);
|
||||
AddPolylineFigures(figures, polygon, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,50 +21,9 @@ namespace MapControl
|
|||
get { return Data; }
|
||||
}
|
||||
|
||||
partial void SetDataTransform()
|
||||
{
|
||||
if (parentMap != null)
|
||||
{
|
||||
var transform = new TransformGroup();
|
||||
var offsetX = GetLongitudeOffset() * parentMap.MapProjection.TrueScale;
|
||||
|
||||
transform.Children.Add(new TranslateTransform(offsetX, 0d));
|
||||
transform.Children.Add(parentMap.MapProjection.ViewportTransform);
|
||||
|
||||
Data.Transform = transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
Data.Transform = Transform.Identity;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
|
||||
{
|
||||
var transform = (TransformGroup)Data.Transform;
|
||||
var offset = (TranslateTransform)transform.Children[0];
|
||||
|
||||
offset.X = GetLongitudeOffset() * parentMap.MapProjection.TrueScale;
|
||||
|
||||
if (e.ProjectionChanged)
|
||||
{
|
||||
transform.Children[1] = parentMap.MapProjection.ViewportTransform;
|
||||
}
|
||||
|
||||
if (e.ProjectionChanged || parentMap.MapProjection.IsAzimuthal)
|
||||
{
|
||||
UpdateData();
|
||||
}
|
||||
else if (Fill != null)
|
||||
{
|
||||
InvalidateVisual(); // Fill brush may be rendered only partially or not at all
|
||||
}
|
||||
}
|
||||
|
||||
bool IWeakEventListener.ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
|
||||
{
|
||||
UpdateData();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -85,11 +44,17 @@ namespace MapControl
|
|||
UpdateData();
|
||||
}
|
||||
|
||||
protected void AddPolylineFigure(PathFigureCollection figures, IEnumerable<Location> locations, bool closed)
|
||||
protected void AddPolylineFigures(PathFigureCollection figures, IEnumerable<Location> locations, bool closed)
|
||||
{
|
||||
if (locations != null && locations.Count() >= 2)
|
||||
{
|
||||
var points = locations.Select(loc => LocationToPoint(loc));
|
||||
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 figure = new PathFigure
|
||||
{
|
||||
StartPoint = points.First(),
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ using System.Windows;
|
|||
[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)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue