diff --git a/MapControl/Avalonia/ViewTransform.Avalonia.cs b/MapControl/Avalonia/ViewTransform.Avalonia.cs deleted file mode 100644 index 9a80600c..00000000 --- a/MapControl/Avalonia/ViewTransform.Avalonia.cs +++ /dev/null @@ -1,81 +0,0 @@ -using Avalonia; - -namespace MapControl -{ - public partial class ViewTransform - { - /// - /// Initializes a ViewTransform from a map center point in projected coordinates, - /// a view conter point, a scaling factor from projected coordinates to view coordinates - /// and a rotation angle in degrees. - /// - public void SetTransform(Point mapCenter, Point viewCenter, double scale, double rotation) - { - Scale = scale; - Rotation = ((rotation % 360d) + 360d) % 360d; - - MapToViewMatrix = Matrix.CreateTranslation(-mapCenter.X, -mapCenter.Y) - * Matrix.CreateScale(scale, -scale) - * Matrix.CreateRotation(Matrix.ToRadians(Rotation)) - * Matrix.CreateTranslation(viewCenter.X, viewCenter.Y); - - ViewToMapMatrix = MapToViewMatrix.Invert(); - } - - /// - /// Gets a transform Matrix from meters to view coordinates for a relative map scale. - /// - public Matrix GetMapTransform(Point relativeScale) - { - return Matrix.CreateScale(Scale * relativeScale.X, Scale * relativeScale.Y) - * Matrix.CreateRotation(Matrix.ToRadians(Rotation)); - } - - /// - /// Gets the transform Matrix for the RenderTranform of a MapTileLayer. - /// - public Matrix GetTileLayerTransform(double tileMatrixScale, Point tileMatrixTopLeft, Point tileMatrixOrigin) - { - // Tile matrix origin in map coordinates. - // - var mapOrigin = new Point( - tileMatrixTopLeft.X + tileMatrixOrigin.X / tileMatrixScale, - tileMatrixTopLeft.Y - tileMatrixOrigin.Y / tileMatrixScale); - - // Tile matrix origin in view coordinates. - // - var viewOrigin = MapToViewMatrix.Transform(mapOrigin); - - var transformScale = Scale / tileMatrixScale; - - return Matrix.CreateScale(transformScale, transformScale) - * Matrix.CreateRotation(Matrix.ToRadians(Rotation)) - * Matrix.CreateTranslation(viewOrigin.X, viewOrigin.Y); - } - - /// - /// Gets the index bounds of a tile matrix. - /// - public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, double viewWidth, double viewHeight) - { - // View origin in map coordinates. - // - var origin = ViewToMapMatrix.Transform(new Point()); - - var transformScale = tileMatrixScale / Scale; - - var transform = Matrix.CreateScale(transformScale, transformScale) - * Matrix.CreateRotation(Matrix.ToRadians(-Rotation)); - - // Translate origin to tile matrix origin in pixels. - // - transform *= Matrix.CreateTranslation( - tileMatrixScale * (origin.X - tileMatrixTopLeft.X), - tileMatrixScale * (tileMatrixTopLeft.Y - origin.Y)); - - // Transform view bounds to tile pixel bounds. - // - return new Rect(0d, 0d, viewWidth, viewHeight).TransformToAABB(transform); - } - } -} diff --git a/MapControl/Shared/TransverseMercatorProjection.cs b/MapControl/Shared/TransverseMercatorProjection.cs index 33acf07c..644636e2 100644 --- a/MapControl/Shared/TransverseMercatorProjection.cs +++ b/MapControl/Shared/TransverseMercatorProjection.cs @@ -32,7 +32,7 @@ namespace MapControl public override Point? LocationToMap(double latitude, double longitude) { -#if NETFRAMEWORK || UWP +#if NETFRAMEWORK static double Atanh(double x) => Math.Log((1d + x) / (1d - x)) / 2d; #else static double Atanh(double x) => Math.Atanh(x); diff --git a/MapControl/Shared/ViewTransform.cs b/MapControl/Shared/ViewTransform.cs index 2214eec7..4502ad85 100644 --- a/MapControl/Shared/ViewTransform.cs +++ b/MapControl/Shared/ViewTransform.cs @@ -15,7 +15,7 @@ namespace MapControl /// Defines the transformation between projected map coordinates in meters /// and view coordinates in pixels. /// - public partial class ViewTransform + public class ViewTransform { /// /// Gets the scaling factor from projected map coordinates to view coordinates, @@ -38,7 +38,6 @@ namespace MapControl /// public Matrix ViewToMapMatrix { get; private set; } -#if !AVALONIA /// /// Initializes a ViewTransform from a map center point in projected coordinates, /// a view conter point, a scaling factor from projected coordinates to view coordinates @@ -48,16 +47,22 @@ namespace MapControl { Scale = scale; Rotation = ((rotation % 360d) + 360d) % 360d; +#if AVALONIA + MapToViewMatrix = Matrix.CreateTranslation(-mapCenter.X, -mapCenter.Y) + * Matrix.CreateScale(scale, -scale) + * Matrix.CreateRotation(Matrix.ToRadians(Rotation)) + * Matrix.CreateTranslation(viewCenter.X, viewCenter.Y); + ViewToMapMatrix = MapToViewMatrix.Invert(); +#else var transform = new Matrix(scale, 0d, 0d, -scale, -scale * mapCenter.X, scale * mapCenter.Y); transform.Rotate(Rotation); transform.Translate(viewCenter.X, viewCenter.Y); - MapToViewMatrix = transform; transform.Invert(); - ViewToMapMatrix = transform; +#endif } /// @@ -65,10 +70,14 @@ namespace MapControl /// public Matrix GetMapTransform(Point relativeScale) { +#if AVALONIA + return Matrix.CreateScale(Scale * relativeScale.X, Scale * relativeScale.Y) + * Matrix.CreateRotation(Matrix.ToRadians(Rotation)); +#else var transform = new Matrix(Scale * relativeScale.X, 0d, 0d, Scale * relativeScale.Y, 0d, 0d); transform.Rotate(Rotation); - return transform; +#endif } /// @@ -87,12 +96,16 @@ namespace MapControl var viewOrigin = MapToViewMatrix.Transform(mapOrigin); var transformScale = Scale / tileMatrixScale; - +#if AVALONIA + return Matrix.CreateScale(transformScale, transformScale) + * Matrix.CreateRotation(Matrix.ToRadians(Rotation)) + * Matrix.CreateTranslation(viewOrigin.X, viewOrigin.Y); +#else var transform = new Matrix(transformScale, 0d, 0d, transformScale, 0d, 0d); transform.Rotate(Rotation); transform.Translate(viewOrigin.X, viewOrigin.Y); - return transform; +#endif } /// @@ -105,7 +118,17 @@ namespace MapControl var origin = ViewToMapMatrix.Transform(new Point()); var transformScale = tileMatrixScale / Scale; +#if AVALONIA + var transform = Matrix.CreateScale(transformScale, transformScale) + * Matrix.CreateRotation(Matrix.ToRadians(-Rotation)) + * Matrix.CreateTranslation( + tileMatrixScale * (origin.X - tileMatrixTopLeft.X), + tileMatrixScale * (tileMatrixTopLeft.Y - origin.Y)); + // Transform view bounds to tile pixel bounds. + // + return new Rect(0d, 0d, viewWidth, viewHeight).TransformToAABB(transform); +#else var transform = new Matrix(transformScale, 0d, 0d, transformScale, 0d, 0d); transform.Rotate(-Rotation); @@ -119,7 +142,7 @@ namespace MapControl // return new MatrixTransform { Matrix = transform } .TransformBounds(new Rect(0d, 0d, viewWidth, viewHeight)); - } #endif + } } } diff --git a/MapControl/Shared/WmsImageLayer.cs b/MapControl/Shared/WmsImageLayer.cs index cff27aaa..53a5a3f7 100644 --- a/MapControl/Shared/WmsImageLayer.cs +++ b/MapControl/Shared/WmsImageLayer.cs @@ -308,6 +308,26 @@ namespace MapControl return uriBuilder.Uri; } + protected virtual Uri GetRequestUri(IDictionary queryParameters) + { + var query = ServiceUri.Query; + + if (!string.IsNullOrEmpty(query)) + { + // Parameters from ServiceUri.Query take higher precedence than queryParameters. + // + foreach (var param in query.Substring(1).Split('&')) + { + var pair = param.Split('='); + queryParameters[pair[0]] = pair.Length > 1 ? pair[1] : ""; + } + } + + query = string.Join("&", queryParameters.Select(kv => kv.Key + "=" + kv.Value)); + + return new Uri(ServiceUri.GetLeftPart(UriPartial.Path) + "?" + query); + } + protected virtual string GetCrsValue() { var projection = ParentMap.MapProjection; @@ -315,7 +335,7 @@ namespace MapControl if (crs.StartsWith("AUTO2:") || crs.StartsWith("AUTO:")) { - crs = string.Format(CultureInfo.InvariantCulture, "{0},1,{1},{2}", crs, projection.Center.Longitude, projection.Center.Latitude); + crs = string.Format(CultureInfo.InvariantCulture, "{0},1,{1:F8},{2:F8}", crs, projection.Center.Longitude, projection.Center.Latitude); } return crs; @@ -341,26 +361,5 @@ namespace MapControl return string.Format(CultureInfo.InvariantCulture, format, x1, y1, x2, y2); } - - protected Uri GetRequestUri(IDictionary queryParameters) - { - var query = ServiceUri.Query; - - if (!string.IsNullOrEmpty(query)) - { - // Parameters from ServiceUri.Query take higher precedence than queryParameters. - // - foreach (var param in query.Substring(1).Split('&')) - { - var pair = param.Split('='); - queryParameters[pair[0].ToUpper()] = pair.Length > 1 ? pair[1] : ""; - } - } - - var uri = ServiceUri.GetLeftPart(UriPartial.Path) + "?" + - string.Join("&", queryParameters.Select(kv => kv.Key + "=" + kv.Value)); - - return new Uri(uri.Replace(" ", "%20")); - } } } diff --git a/MapControl/WinUI/Matrix.WinUI.cs b/MapControl/WinUI/Matrix.WinUI.cs index d0fbd279..5f42ce3a 100644 --- a/MapControl/WinUI/Matrix.WinUI.cs +++ b/MapControl/WinUI/Matrix.WinUI.cs @@ -10,24 +10,14 @@ namespace MapControl /// /// Replaces Windows.UI.Xaml.Media.Matrix for double floating point precision. /// - public struct Matrix + public struct Matrix(double m11, double m12, double m21, double m22, double offsetX, double offsetY) { - public Matrix(double m11, double m12, double m21, double m22, double offsetX, double offsetY) - { - M11 = m11; - M12 = m12; - M21 = m21; - M22 = m22; - OffsetX = offsetX; - OffsetY = offsetY; - } - - public double M11 { get; set; } - public double M12 { get; set; } - public double M21 { get; set; } - public double M22 { get; set; } - public double OffsetX { get; set; } - public double OffsetY { get; set; } + public double M11 { get; private set; } = m11; + public double M12 { get; private set; } = m12; + public double M21 { get; private set; } = m21; + public double M22 { get; private set; } = m22; + public double OffsetX { get; private set; } = offsetX; + public double OffsetY { get; private set; } = offsetY; public static implicit operator WindowsUI.Xaml.Media.Matrix(Matrix m) {