mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 06:26:41 +00:00
Version 4.8.0: Improved WPF MapPolyline and MapPolygon accuracy.
This commit is contained in:
parent
de4ba0765a
commit
5bc42d1f07
19 changed files with 77 additions and 172 deletions
|
|
@ -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 ||
|
||||
|
|
|
|||
49
MapControl/Shared/MapPolygon.cs
Normal file
49
MapControl/Shared/MapPolygon.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// 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;
|
||||
#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
|
||||
{
|
||||
/// <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).DataCollectionPropertyChanged(e)));
|
||||
|
||||
/// <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); }
|
||||
set { SetValue(LocationsProperty, value); }
|
||||
}
|
||||
|
||||
protected override void UpdateData()
|
||||
{
|
||||
var figures = ((PathGeometry)Data).Figures;
|
||||
figures.Clear();
|
||||
|
||||
if (ParentMap != null)
|
||||
{
|
||||
AddPolylineFigures(figures, Locations, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
49
MapControl/Shared/MapPolyline.cs
Normal file
49
MapControl/Shared/MapPolyline.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// 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;
|
||||
#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
|
||||
{
|
||||
/// <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).DataCollectionPropertyChanged(e)));
|
||||
|
||||
/// <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); }
|
||||
set { SetValue(LocationsProperty, value); }
|
||||
}
|
||||
|
||||
protected override void UpdateData()
|
||||
{
|
||||
var figures = ((PathGeometry)Data).Figures;
|
||||
figures.Clear();
|
||||
|
||||
if (ParentMap != null)
|
||||
{
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue