mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Version 4.7.0: Added UWP Vector class
This commit is contained in:
parent
32db0f22c1
commit
9c148e13c4
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("4.6.1")]
|
||||
[assembly: AssemblyFileVersion("4.6.1")]
|
||||
[assembly: AssemblyVersion("4.7.0")]
|
||||
[assembly: AssemblyFileVersion("4.7.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.6.1")]
|
||||
[assembly: AssemblyFileVersion("4.6.1")]
|
||||
[assembly: AssemblyVersion("4.7.0")]
|
||||
[assembly: AssemblyFileVersion("4.7.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.6.1")]
|
||||
[assembly: AssemblyFileVersion("4.6.1")]
|
||||
[assembly: AssemblyVersion("4.7.0")]
|
||||
[assembly: AssemblyFileVersion("4.7.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.6.1")]
|
||||
[assembly: AssemblyFileVersion("4.6.1")]
|
||||
[assembly: AssemblyVersion("4.7.0")]
|
||||
[assembly: AssemblyFileVersion("4.7.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ namespace MapControl
|
|||
IsAzimuthal = true;
|
||||
}
|
||||
|
||||
public override Point GetMapScale(Location location)
|
||||
public override Vector GetMapScale(Location location)
|
||||
{
|
||||
return new Point(ViewportScale, ViewportScale);
|
||||
return new Vector(ViewportScale, ViewportScale);
|
||||
}
|
||||
|
||||
public override Rect BoundingBoxToRect(BoundingBox boundingBox)
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ namespace MapControl
|
|||
CrsId = crsId;
|
||||
}
|
||||
|
||||
public override Point GetMapScale(Location location)
|
||||
public override Vector GetMapScale(Location location)
|
||||
{
|
||||
return new Point(
|
||||
return new Vector(
|
||||
ViewportScale / (MetersPerDegree * Math.Cos(location.Latitude * Math.PI / 180d)),
|
||||
ViewportScale / MetersPerDegree);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -276,9 +276,9 @@ namespace MapControl
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the Center property according to the specified map translation in viewport coordinates.
|
||||
/// Changes the Center property according to the specified translation in viewport coordinates.
|
||||
/// </summary>
|
||||
public void TranslateMap(Point translation)
|
||||
public void TranslateMap(Vector translation)
|
||||
{
|
||||
if (transformCenter != null)
|
||||
{
|
||||
|
|
@ -288,8 +288,7 @@ namespace MapControl
|
|||
|
||||
if (translation.X != 0d || translation.Y != 0d)
|
||||
{
|
||||
Center = MapProjection.ViewportPointToLocation(
|
||||
new Point(viewportCenter.X - translation.X, viewportCenter.Y - translation.Y));
|
||||
Center = MapProjection.ViewportPointToLocation(viewportCenter - translation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -298,12 +297,12 @@ namespace MapControl
|
|||
/// viewport coordinate translation, rotation and scale delta values. Rotation and scaling
|
||||
/// is performed relative to the specified center point in viewport coordinates.
|
||||
/// </summary>
|
||||
public void TransformMap(Point center, Point translation, double rotation, double scale)
|
||||
public void TransformMap(Point center, Vector translation, double rotation, double scale)
|
||||
{
|
||||
if (rotation != 0d || scale != 1d)
|
||||
{
|
||||
transformCenter = MapProjection.ViewportPointToLocation(center);
|
||||
viewportCenter = new Point(center.X + translation.X, center.Y + translation.Y);
|
||||
viewportCenter = center + translation;
|
||||
|
||||
if (rotation != 0d)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// Gets the map scale at the specified Location as viewport coordinate units per meter (px/m).
|
||||
/// </summary>
|
||||
public abstract Point GetMapScale(Location location);
|
||||
public abstract Vector GetMapScale(Location location);
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a Location in geographic coordinates to a Point in cartesian map coordinates.
|
||||
|
|
@ -143,14 +143,13 @@ namespace MapControl
|
|||
ViewportScale = Math.Pow(2d, zoomLevel) * PixelPerDegree / TrueScale;
|
||||
|
||||
var center = LocationToPoint(mapCenter);
|
||||
var transformMatrix = CreateTransformMatrix(
|
||||
-center.X, -center.Y, ViewportScale, -ViewportScale, heading, viewportCenter.X, viewportCenter.Y);
|
||||
var matrix = CreateTransformMatrix(center, ViewportScale, -ViewportScale, heading, viewportCenter);
|
||||
|
||||
ViewportTransformMatrix = transformMatrix;
|
||||
ViewportTransform.Matrix = transformMatrix;
|
||||
ViewportTransformMatrix = matrix;
|
||||
ViewportTransform.Matrix = matrix;
|
||||
|
||||
transformMatrix.Invert();
|
||||
inverseViewportTransformMatrix = transformMatrix;
|
||||
matrix.Invert();
|
||||
inverseViewportTransformMatrix = matrix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -183,15 +182,12 @@ namespace MapControl
|
|||
rect.X, rect.Y, (rect.X + rect.Width), (rect.Y + rect.Height), width, height);
|
||||
}
|
||||
|
||||
public static Matrix CreateTransformMatrix(
|
||||
double translation1X, double translation1Y,
|
||||
double scaleX, double scaleY, double rotationAngle,
|
||||
double translation2X, double translation2Y)
|
||||
internal static Matrix CreateTransformMatrix(
|
||||
Point translation1, double scaleX, double scaleY, double rotation, Point translation2)
|
||||
{
|
||||
var matrix = new Matrix(1d, 0d, 0d, 1d, translation1X, translation1Y);
|
||||
matrix.Scale(scaleX, scaleY);
|
||||
matrix.Rotate(rotationAngle);
|
||||
matrix.Translate(translation2X, translation2Y);
|
||||
var matrix = new Matrix(scaleX, 0d, 0d, scaleY, -translation1.X * scaleX, -translation1.Y * scaleY);
|
||||
matrix.Rotate(rotation);
|
||||
matrix.Translate(translation2.X, translation2.Y);
|
||||
return matrix;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -305,14 +305,13 @@ namespace MapControl
|
|||
var tileZoomLevel = Math.Max(0, (int)Math.Round(parentMap.ZoomLevel + ZoomLevelOffset));
|
||||
var tileScale = (double)(1 << tileZoomLevel);
|
||||
var scale = tileScale / (Math.Pow(2d, parentMap.ZoomLevel) * MapProjection.TileSize);
|
||||
var tileCenterX = tileScale * (0.5 + parentMap.Center.Longitude / 360d);
|
||||
var tileCenterY = tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d);
|
||||
var viewCenterX = parentMap.RenderSize.Width / 2d;
|
||||
var viewCenterY = parentMap.RenderSize.Height / 2d;
|
||||
var tileCenter = new Point(tileScale * (0.5 + parentMap.Center.Longitude / 360d),
|
||||
tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d));
|
||||
var viewCenter = new Point(parentMap.RenderSize.Width / 2d, parentMap.RenderSize.Height / 2d);
|
||||
|
||||
var transform = new MatrixTransform
|
||||
{
|
||||
Matrix = MapProjection.CreateTransformMatrix(-viewCenterX, -viewCenterY, scale, scale, -parentMap.Heading, tileCenterX, tileCenterY)
|
||||
Matrix = MapProjection.CreateTransformMatrix(viewCenter, scale, scale, -parentMap.Heading, tileCenter)
|
||||
};
|
||||
|
||||
var bounds = transform.TransformBounds(new Rect(0d, 0d, parentMap.RenderSize.Width, parentMap.RenderSize.Height));
|
||||
|
|
@ -326,15 +325,14 @@ namespace MapControl
|
|||
{
|
||||
var tileScale = (double)(1 << TileGrid.ZoomLevel);
|
||||
var scale = Math.Pow(2d, parentMap.ZoomLevel) / tileScale;
|
||||
var tileCenterX = tileScale * (0.5 + parentMap.Center.Longitude / 360d);
|
||||
var tileCenterY = tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d);
|
||||
var tileOriginX = MapProjection.TileSize * (tileCenterX - TileGrid.XMin);
|
||||
var tileOriginY = MapProjection.TileSize * (tileCenterY - TileGrid.YMin);
|
||||
var viewCenterX = parentMap.RenderSize.Width / 2d;
|
||||
var viewCenterY = parentMap.RenderSize.Height / 2d;
|
||||
var tileCenter = new Point(tileScale * (0.5 + parentMap.Center.Longitude / 360d),
|
||||
tileScale * (0.5 - WebMercatorProjection.LatitudeToY(parentMap.Center.Latitude) / 360d));
|
||||
var tileOrigin = new Point(MapProjection.TileSize * (tileCenter.X - TileGrid.XMin),
|
||||
MapProjection.TileSize * (tileCenter.Y - TileGrid.YMin));
|
||||
var viewCenter = new Point(parentMap.RenderSize.Width / 2d, parentMap.RenderSize.Height / 2d);
|
||||
|
||||
((MatrixTransform)RenderTransform).Matrix = MapProjection.CreateTransformMatrix(
|
||||
-tileOriginX, -tileOriginY, scale, scale, parentMap.Heading, viewCenterX, viewCenterY);
|
||||
((MatrixTransform)RenderTransform).Matrix =
|
||||
MapProjection.CreateTransformMatrix(tileOrigin, scale, scale, parentMap.Heading, viewCenter);
|
||||
}
|
||||
|
||||
private void UpdateTiles()
|
||||
|
|
|
|||
|
|
@ -29,11 +29,11 @@ namespace MapControl
|
|||
MaxLatitude = YToLatitude(180d);
|
||||
}
|
||||
|
||||
public override Point GetMapScale(Location location)
|
||||
public override Vector GetMapScale(Location location)
|
||||
{
|
||||
var scale = ViewportScale / Math.Cos(location.Latitude * Math.PI / 180d);
|
||||
|
||||
return new Point(scale, scale);
|
||||
return new Vector(scale, scale);
|
||||
}
|
||||
|
||||
public override Point LocationToPoint(Location location)
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@ namespace MapControl
|
|||
MaxLatitude = YToLatitude(180d);
|
||||
}
|
||||
|
||||
public override Point GetMapScale(Location location)
|
||||
public override Vector GetMapScale(Location location)
|
||||
{
|
||||
var lat = location.Latitude * Math.PI / 180d;
|
||||
var eSinLat = Wgs84Eccentricity * Math.Sin(lat);
|
||||
var scale = ViewportScale * Math.Sqrt(1d - eSinLat * eSinLat) / Math.Cos(lat);
|
||||
|
||||
return new Point(scale, scale);
|
||||
return new Vector(scale, scale);
|
||||
}
|
||||
|
||||
public override Point LocationToPoint(Location location)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace MapControl
|
|||
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(1d));
|
||||
|
||||
private bool transformPending;
|
||||
private Point transformTranslation;
|
||||
private Vector transformTranslation;
|
||||
private double transformRotation;
|
||||
private double transformScale = 1d;
|
||||
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@
|
|||
<Compile Include="Tile.UWP.cs" />
|
||||
<Compile Include="TileImageLoader.UWP.cs" />
|
||||
<Compile Include="ImageLoader.UWP.cs" />
|
||||
<Compile Include="Vector.UWP.cs" />
|
||||
<EmbeddedResource Include="Properties\MapControl.UWP.rd.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -41,16 +41,6 @@ namespace MapControl
|
|||
OffsetY += y;
|
||||
}
|
||||
|
||||
public void Scale(double scaleX, double scaleY)
|
||||
{
|
||||
if (M12 != 0d || M21 != 0d)
|
||||
{
|
||||
throw new NotSupportedException("Scale not supported for rotated Matrix");
|
||||
}
|
||||
|
||||
SetMatrix(scaleX * M11, 0d, 0d, scaleY * M22, scaleX * OffsetX, scaleY * OffsetY);
|
||||
}
|
||||
|
||||
public void Rotate(double angle)
|
||||
{
|
||||
angle = (angle % 360d) / 180d * Math.PI;
|
||||
|
|
@ -80,10 +70,7 @@ namespace MapControl
|
|||
}
|
||||
|
||||
SetMatrix(
|
||||
invDet * M22,
|
||||
invDet * -M12,
|
||||
invDet * -M21,
|
||||
invDet * M11,
|
||||
invDet * M22, invDet * -M12, invDet * -M21, invDet * M11,
|
||||
invDet * (M21 * OffsetY - M22 * OffsetX),
|
||||
invDet * (M12 * OffsetX - M11 * OffsetY));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,14 +15,39 @@ namespace MapControl
|
|||
Y = y;
|
||||
}
|
||||
|
||||
public static implicit operator Windows.Foundation.Point(Point p)
|
||||
{
|
||||
return new Windows.Foundation.Point(p.X, p.Y);
|
||||
}
|
||||
|
||||
public static implicit operator Point(Windows.Foundation.Point p)
|
||||
{
|
||||
return new Point(p.X, p.Y);
|
||||
}
|
||||
|
||||
public static implicit operator Windows.Foundation.Point(Point p)
|
||||
public static explicit operator Point(Vector v)
|
||||
{
|
||||
return new Windows.Foundation.Point(p.X, p.Y);
|
||||
return new Point(v.X, v.Y);
|
||||
}
|
||||
|
||||
public static Point operator -(Point p)
|
||||
{
|
||||
return new Point(-p.X, -p.Y);
|
||||
}
|
||||
|
||||
public static Point operator +(Point p, Vector v)
|
||||
{
|
||||
return new Point(p.X + v.X, p.Y + v.Y);
|
||||
}
|
||||
|
||||
public static Point operator -(Point p, Vector v)
|
||||
{
|
||||
return new Point(p.X - v.X, p.Y - v.Y);
|
||||
}
|
||||
|
||||
public static Vector operator -(Point p1, Point p2)
|
||||
{
|
||||
return new Vector(p1.X - p2.X, p1.Y - p2.Y);
|
||||
}
|
||||
|
||||
public static bool operator ==(Point p1, Point p2)
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("4.6.1")]
|
||||
[assembly: AssemblyFileVersion("4.6.1")]
|
||||
[assembly: AssemblyVersion("4.7.0")]
|
||||
[assembly: AssemblyFileVersion("4.7.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
73
MapControl/UWP/Vector.UWP.cs
Normal file
73
MapControl/UWP/Vector.UWP.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public struct Vector
|
||||
{
|
||||
public double X { get; set; }
|
||||
public double Y { get; set; }
|
||||
|
||||
public Vector(double x, double y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public static implicit operator Windows.Foundation.Point(Vector v)
|
||||
{
|
||||
return new Windows.Foundation.Point(v.X, v.Y);
|
||||
}
|
||||
|
||||
public static implicit operator Vector(Windows.Foundation.Point v)
|
||||
{
|
||||
return new Vector(v.X, v.Y);
|
||||
}
|
||||
|
||||
public static explicit operator Vector(Point p)
|
||||
{
|
||||
return new Vector(p.X, p.Y);
|
||||
}
|
||||
|
||||
public static Vector operator -(Vector v)
|
||||
{
|
||||
return new Vector(-v.X, -v.Y);
|
||||
}
|
||||
|
||||
public static Point operator +(Vector v, Point p)
|
||||
{
|
||||
return new Point(v.X + p.X, v.Y + p.Y);
|
||||
}
|
||||
|
||||
public static Vector operator +(Vector v1, Vector v2)
|
||||
{
|
||||
return new Vector(v1.X + v2.X, v1.Y + v2.Y);
|
||||
}
|
||||
|
||||
public static Vector operator -(Vector v1, Vector v2)
|
||||
{
|
||||
return new Vector(v1.X - v2.X, v1.Y - v2.Y);
|
||||
}
|
||||
|
||||
public static bool operator ==(Vector v1, Vector v2)
|
||||
{
|
||||
return v1.X == v2.X && v1.Y == v2.Y;
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector v1, Vector v2)
|
||||
{
|
||||
return !(v1 == v2);
|
||||
}
|
||||
|
||||
public override bool Equals(object o)
|
||||
{
|
||||
return o is Vector && this == (Vector)o;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return X.GetHashCode() ^ Y.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -56,24 +56,6 @@ namespace MapControl
|
|||
ScaleRotateTransform.Children.Add(RotateTransform);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the Center property according to the specified translation in viewport coordinates.
|
||||
/// </summary>
|
||||
public void TranslateMap(Vector translation)
|
||||
{
|
||||
TranslateMap((Point)translation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the Center, Heading and ZoomLevel properties according to the specified
|
||||
/// viewport coordinate translation, rotation and scale delta values. Rotation and scaling
|
||||
/// is performed relative to the specified center point in viewport coordinates.
|
||||
/// </summary>
|
||||
public void TransformMap(Point center, Vector translation, double rotation, double scale)
|
||||
{
|
||||
TransformMap(center, (Point)translation, rotation, scale);
|
||||
}
|
||||
|
||||
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
|
||||
{
|
||||
base.OnRenderSizeChanged(sizeInfo);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ using System.Windows;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("4.6.1")]
|
||||
[assembly: AssemblyFileVersion("4.6.1")]
|
||||
[assembly: AssemblyVersion("4.7.0")]
|
||||
[assembly: AssemblyFileVersion("4.7.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCopyright("© 2018 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("4.6.1")]
|
||||
[assembly: AssemblyFileVersion("4.6.1")]
|
||||
[assembly: AssemblyVersion("4.7.0")]
|
||||
[assembly: AssemblyFileVersion("4.7.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[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.6.1")]
|
||||
[assembly: AssemblyFileVersion("4.6.1")]
|
||||
[assembly: AssemblyVersion("4.7.0")]
|
||||
[assembly: AssemblyFileVersion("4.7.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue