diff --git a/MapControl/Shared/AutoEquirectangularProjection.cs b/MapControl/Shared/AutoEquirectangularProjection.cs index c9c441e9..c8898505 100644 --- a/MapControl/Shared/AutoEquirectangularProjection.cs +++ b/MapControl/Shared/AutoEquirectangularProjection.cs @@ -28,7 +28,7 @@ namespace MapControl CrsId = crsId; } - public override Point GetRelativeScale(double latitude, double longitude) + public override Point RelativeScale(double latitude, double longitude) { return new Point( Math.Cos(Center.Latitude * Math.PI / 180d) / Math.Cos(latitude * Math.PI / 180d), diff --git a/MapControl/Shared/EquirectangularProjection.cs b/MapControl/Shared/EquirectangularProjection.cs index b5c8c746..01cc075b 100644 --- a/MapControl/Shared/EquirectangularProjection.cs +++ b/MapControl/Shared/EquirectangularProjection.cs @@ -28,7 +28,7 @@ namespace MapControl CrsId = crsId; } - public override Point GetRelativeScale(double latitude, double longitude) + public override Point RelativeScale(double latitude, double longitude) { return new Point(1d / Math.Cos(latitude * Math.PI / 180d), 1d); } diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index 0a66bac2..97cac30d 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -2,6 +2,8 @@ #if WPF using System.Windows; using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; #elif UWP using Windows.UI.Xaml; using Windows.UI.Xaml.Media; @@ -182,7 +184,7 @@ namespace MapControl /// public Point GetMapScale(double latitude, double longitude) { - var relativeScale = MapProjection.GetRelativeScale(latitude, longitude); + var relativeScale = MapProjection.RelativeScale(latitude, longitude); return new Point(ViewTransform.Scale * relativeScale.X, ViewTransform.Scale * relativeScale.Y); } @@ -193,9 +195,7 @@ namespace MapControl /// public Point GetMapScale(Location location) { - var relativeScale = MapProjection.GetRelativeScale(location); - - return new Point(ViewTransform.Scale * relativeScale.X, ViewTransform.Scale * relativeScale.Y); + return GetMapScale(location.Latitude, location.Longitude); } /// @@ -204,7 +204,12 @@ namespace MapControl /// public Matrix GetMapTransform(Location location) { - return ViewTransform.GetMapTransform(MapProjection.GetRelativeScale(location)); + var mapScale = GetMapScale(location); + var transform = new Matrix(mapScale.X, 0d, 0d, mapScale.Y, 0d, 0d); + + transform.Rotate(ViewTransform.Rotation); + + return transform; } /// diff --git a/MapControl/Shared/MapProjection.cs b/MapControl/Shared/MapProjection.cs index db2d31f5..8cb106bb 100644 --- a/MapControl/Shared/MapProjection.cs +++ b/MapControl/Shared/MapProjection.cs @@ -55,7 +55,7 @@ namespace MapControl /// /// Gets the relative map scale at the specified geographic coordinates. /// - public virtual Point GetRelativeScale(double latitude, double longitude) => new Point(1d, 1d); + public virtual Point RelativeScale(double latitude, double longitude) => new Point(1d, 1d); /// /// Transforms geographic coordinates to a Point in projected map coordinates. @@ -72,7 +72,7 @@ namespace MapControl /// /// Gets the relative map scale at the specified geographic Location. /// - public Point GetRelativeScale(Location location) => GetRelativeScale(location.Latitude, location.Longitude); + public Point RelativeScale(Location location) => RelativeScale(location.Latitude, location.Longitude); /// /// Transforms a Location in geographic coordinates to a Point in projected map coordinates. diff --git a/MapControl/Shared/PolarStereographicProjection.cs b/MapControl/Shared/PolarStereographicProjection.cs index 69244dc4..ae8a2c58 100644 --- a/MapControl/Shared/PolarStereographicProjection.cs +++ b/MapControl/Shared/PolarStereographicProjection.cs @@ -26,7 +26,7 @@ namespace MapControl public double FalseNorthing { get; set; } = 2e6; public bool IsNorth { get; set; } - public override Point GetRelativeScale(double latitude, double longitude) + public override Point RelativeScale(double latitude, double longitude) { latitude *= Math.PI / 180d; diff --git a/MapControl/Shared/TransverseMercatorProjection.cs b/MapControl/Shared/TransverseMercatorProjection.cs index 644636e2..38a54285 100644 --- a/MapControl/Shared/TransverseMercatorProjection.cs +++ b/MapControl/Shared/TransverseMercatorProjection.cs @@ -25,7 +25,7 @@ namespace MapControl Type = MapProjectionType.TransverseCylindrical; } - public override Point GetRelativeScale(double latitude, double longitude) + public override Point RelativeScale(double latitude, double longitude) { return new Point(ScaleFactor, ScaleFactor); } diff --git a/MapControl/Shared/ViewTransform.cs b/MapControl/Shared/ViewTransform.cs index f282b8ee..8bafdffb 100644 --- a/MapControl/Shared/ViewTransform.cs +++ b/MapControl/Shared/ViewTransform.cs @@ -58,20 +58,14 @@ namespace MapControl } /// - /// Gets a transform Matrix from meters to view coordinates for a relative map scale. - /// - public Matrix GetMapTransform(Point relativeScale) - { - var transform = new Matrix(Scale * relativeScale.X, 0d, 0d, Scale * relativeScale.Y, 0d, 0d); - transform.Rotate(Rotation); - return transform; - } - - /// - /// Gets the transform Matrix for the RenderTranform of a MapTileLayer. + /// Gets the transform Matrix for the RenderTranform of a MapTileLayer or WmtsTileMatrixLayer. /// public Matrix GetTileLayerTransform(double tileMatrixScale, Point tileMatrixTopLeft, Point tileMatrixOrigin) { + var scale = Scale / tileMatrixScale; + var transform = new Matrix(scale, 0d, 0d, scale, 0d, 0d); + transform.Rotate(Rotation); + // Tile matrix origin in map coordinates. // var mapOrigin = new Point( @@ -81,11 +75,8 @@ namespace MapControl // Tile matrix origin in view coordinates. // var viewOrigin = MapToViewMatrix.Transform(mapOrigin); - - var scale = Scale / tileMatrixScale; - var transform = new Matrix(scale, 0d, 0d, scale, 0d, 0d); - transform.Rotate(Rotation); transform.Translate(viewOrigin.X, viewOrigin.Y); + return transform; } @@ -94,19 +85,19 @@ namespace MapControl /// public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, double viewWidth, double viewHeight) { + var scale = tileMatrixScale / Scale; + var transform = new Matrix(scale, 0d, 0d, scale, 0d, 0d); + transform.Rotate(-Rotation); + // View origin in map coordinates. // var origin = ViewToMapMatrix.Transform(new Point()); // Translation from origin to tile matrix origin in pixels. // - var originOffsetX = tileMatrixScale * (origin.X - tileMatrixTopLeft.X); - var originOffsetY = tileMatrixScale * (tileMatrixTopLeft.Y - origin.Y); - - var scale = tileMatrixScale / Scale; - var transform = new Matrix(scale, 0d, 0d, scale, 0d, 0d); - transform.Rotate(-Rotation); - transform.Translate(originOffsetX, originOffsetY); + transform.Translate( + tileMatrixScale * (origin.X - tileMatrixTopLeft.X), + tileMatrixScale * (tileMatrixTopLeft.Y - origin.Y)); // Transform view bounds to tile pixel bounds. // diff --git a/MapControl/Shared/WebMercatorProjection.cs b/MapControl/Shared/WebMercatorProjection.cs index 632d84ea..fe36ba89 100644 --- a/MapControl/Shared/WebMercatorProjection.cs +++ b/MapControl/Shared/WebMercatorProjection.cs @@ -27,7 +27,7 @@ namespace MapControl CrsId = crsId; } - public override Point GetRelativeScale(double latitude, double longitude) + public override Point RelativeScale(double latitude, double longitude) { var k = 1d / Math.Cos(latitude * Math.PI / 180d); // p.44 (7-3) diff --git a/MapControl/Shared/WorldMercatorProjection.cs b/MapControl/Shared/WorldMercatorProjection.cs index e607c1e2..0b934c58 100644 --- a/MapControl/Shared/WorldMercatorProjection.cs +++ b/MapControl/Shared/WorldMercatorProjection.cs @@ -27,7 +27,7 @@ namespace MapControl CrsId = crsId; } - public override Point GetRelativeScale(double latitude, double longitude) + public override Point RelativeScale(double latitude, double longitude) { var lat = latitude * Math.PI / 180d; var eSinLat = Wgs84Eccentricity * Math.Sin(lat); diff --git a/MapProjections/Shared/GeoApiProjection.cs b/MapProjections/Shared/GeoApiProjection.cs index 060830b8..eed792f8 100644 --- a/MapProjections/Shared/GeoApiProjection.cs +++ b/MapProjections/Shared/GeoApiProjection.cs @@ -94,7 +94,7 @@ namespace MapControl.Projections public IMathTransform MapToLocationTransform { get; private set; } - public override Point GetRelativeScale(double latitude, double longitude) + public override Point RelativeScale(double latitude, double longitude) { var k = CoordinateSystem?.Projection?.GetParameter("scale_factor")?.Value ?? 1d; diff --git a/MapProjections/Shared/WebMercatorProjection.cs b/MapProjections/Shared/WebMercatorProjection.cs index c8cbb219..38d83a56 100644 --- a/MapProjections/Shared/WebMercatorProjection.cs +++ b/MapProjections/Shared/WebMercatorProjection.cs @@ -19,7 +19,7 @@ namespace MapControl.Projections CoordinateSystem = ProjectedCoordinateSystem.WebMercator; } - public override Point GetRelativeScale(double latitude, double longitude) + public override Point RelativeScale(double latitude, double longitude) { var k = 1d / Math.Cos(latitude * Math.PI / 180d); // p.44 (7-3) diff --git a/MapProjections/Shared/WorldMercatorProjection.cs b/MapProjections/Shared/WorldMercatorProjection.cs index 8dc5b74f..3019e4d9 100644 --- a/MapProjections/Shared/WorldMercatorProjection.cs +++ b/MapProjections/Shared/WorldMercatorProjection.cs @@ -40,7 +40,7 @@ namespace MapControl.Projections + "AUTHORITY[\"EPSG\",\"3395\"]]"; } - public override Point GetRelativeScale(double latitude, double longitude) + public override Point RelativeScale(double latitude, double longitude) { var lat = latitude * Math.PI / 180d; var eSinLat = Wgs84Eccentricity * Math.Sin(lat);