diff --git a/FileDbCache/UWP/Properties/AssemblyInfo.cs b/FileDbCache/UWP/Properties/AssemblyInfo.cs index 143c6db6..65b78324 100644 --- a/FileDbCache/UWP/Properties/AssemblyInfo.cs +++ b/FileDbCache/UWP/Properties/AssemblyInfo.cs @@ -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)] diff --git a/FileDbCache/WPF/Properties/AssemblyInfo.cs b/FileDbCache/WPF/Properties/AssemblyInfo.cs index cbe9711a..589f6001 100644 --- a/FileDbCache/WPF/Properties/AssemblyInfo.cs +++ b/FileDbCache/WPF/Properties/AssemblyInfo.cs @@ -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)] diff --git a/MBTiles/UWP/Properties/AssemblyInfo.cs b/MBTiles/UWP/Properties/AssemblyInfo.cs index 9be431b6..0139d9ec 100644 --- a/MBTiles/UWP/Properties/AssemblyInfo.cs +++ b/MBTiles/UWP/Properties/AssemblyInfo.cs @@ -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)] diff --git a/MBTiles/WPF/Properties/AssemblyInfo.cs b/MBTiles/WPF/Properties/AssemblyInfo.cs index 27f1064b..d557551c 100644 --- a/MBTiles/WPF/Properties/AssemblyInfo.cs +++ b/MBTiles/WPF/Properties/AssemblyInfo.cs @@ -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)] diff --git a/MapControl/Shared/AzimuthalProjection.cs b/MapControl/Shared/AzimuthalProjection.cs index cfb41438..49f9ba80 100644 --- a/MapControl/Shared/AzimuthalProjection.cs +++ b/MapControl/Shared/AzimuthalProjection.cs @@ -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) diff --git a/MapControl/Shared/EquirectangularProjection.cs b/MapControl/Shared/EquirectangularProjection.cs index 0b4d2fe9..58ee38a4 100644 --- a/MapControl/Shared/EquirectangularProjection.cs +++ b/MapControl/Shared/EquirectangularProjection.cs @@ -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); } diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index 98109256..609a7a05 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -276,9 +276,9 @@ namespace MapControl } /// - /// 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. /// - 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. /// - 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) { diff --git a/MapControl/Shared/MapProjection.cs b/MapControl/Shared/MapProjection.cs index 4df53a90..bdef163d 100644 --- a/MapControl/Shared/MapProjection.cs +++ b/MapControl/Shared/MapProjection.cs @@ -76,7 +76,7 @@ namespace MapControl /// /// Gets the map scale at the specified Location as viewport coordinate units per meter (px/m). /// - public abstract Point GetMapScale(Location location); + public abstract Vector GetMapScale(Location location); /// /// 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; } /// @@ -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; } } diff --git a/MapControl/Shared/MapTileLayer.cs b/MapControl/Shared/MapTileLayer.cs index 2e585075..732a3955 100644 --- a/MapControl/Shared/MapTileLayer.cs +++ b/MapControl/Shared/MapTileLayer.cs @@ -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() diff --git a/MapControl/Shared/WebMercatorProjection.cs b/MapControl/Shared/WebMercatorProjection.cs index 24938817..cf021a8e 100644 --- a/MapControl/Shared/WebMercatorProjection.cs +++ b/MapControl/Shared/WebMercatorProjection.cs @@ -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) diff --git a/MapControl/Shared/WorldMercatorProjection.cs b/MapControl/Shared/WorldMercatorProjection.cs index 475d71ee..12d3b836 100644 --- a/MapControl/Shared/WorldMercatorProjection.cs +++ b/MapControl/Shared/WorldMercatorProjection.cs @@ -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) diff --git a/MapControl/UWP/Map.UWP.cs b/MapControl/UWP/Map.UWP.cs index e9a11915..daa1ee5a 100644 --- a/MapControl/UWP/Map.UWP.cs +++ b/MapControl/UWP/Map.UWP.cs @@ -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; diff --git a/MapControl/UWP/MapControl.UWP.csproj b/MapControl/UWP/MapControl.UWP.csproj index ed9760bf..591ec074 100644 --- a/MapControl/UWP/MapControl.UWP.csproj +++ b/MapControl/UWP/MapControl.UWP.csproj @@ -159,6 +159,7 @@ + diff --git a/MapControl/UWP/Matrix.UWP.cs b/MapControl/UWP/Matrix.UWP.cs index 27484b15..b95b45f3 100644 --- a/MapControl/UWP/Matrix.UWP.cs +++ b/MapControl/UWP/Matrix.UWP.cs @@ -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)); } diff --git a/MapControl/UWP/Point.UWP.cs b/MapControl/UWP/Point.UWP.cs index 833c592f..ba22b84f 100644 --- a/MapControl/UWP/Point.UWP.cs +++ b/MapControl/UWP/Point.UWP.cs @@ -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) diff --git a/MapControl/UWP/Properties/AssemblyInfo.cs b/MapControl/UWP/Properties/AssemblyInfo.cs index 19928c47..49515f25 100644 --- a/MapControl/UWP/Properties/AssemblyInfo.cs +++ b/MapControl/UWP/Properties/AssemblyInfo.cs @@ -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)] diff --git a/MapControl/UWP/Vector.UWP.cs b/MapControl/UWP/Vector.UWP.cs new file mode 100644 index 00000000..325ed939 --- /dev/null +++ b/MapControl/UWP/Vector.UWP.cs @@ -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(); + } + } +} diff --git a/MapControl/WPF/MapBase.WPF.cs b/MapControl/WPF/MapBase.WPF.cs index 6ba52a65..d85178f2 100644 --- a/MapControl/WPF/MapBase.WPF.cs +++ b/MapControl/WPF/MapBase.WPF.cs @@ -56,24 +56,6 @@ namespace MapControl ScaleRotateTransform.Children.Add(RotateTransform); } - /// - /// Changes the Center property according to the specified translation in viewport coordinates. - /// - public void TranslateMap(Vector translation) - { - TranslateMap((Point)translation); - } - - /// - /// 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. - /// - 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); diff --git a/MapControl/WPF/Properties/AssemblyInfo.cs b/MapControl/WPF/Properties/AssemblyInfo.cs index 5195fc33..259e762b 100644 --- a/MapControl/WPF/Properties/AssemblyInfo.cs +++ b/MapControl/WPF/Properties/AssemblyInfo.cs @@ -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)] diff --git a/SampleApps/UniversalApp/Properties/AssemblyInfo.cs b/SampleApps/UniversalApp/Properties/AssemblyInfo.cs index 6822cfd2..8d6a54ea 100644 --- a/SampleApps/UniversalApp/Properties/AssemblyInfo.cs +++ b/SampleApps/UniversalApp/Properties/AssemblyInfo.cs @@ -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)] diff --git a/SampleApps/WpfApplication/Properties/AssemblyInfo.cs b/SampleApps/WpfApplication/Properties/AssemblyInfo.cs index d7d32aca..65a61e30 100644 --- a/SampleApps/WpfApplication/Properties/AssemblyInfo.cs +++ b/SampleApps/WpfApplication/Properties/AssemblyInfo.cs @@ -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)]