mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-01-09 18:21:47 +01:00
Update MapProjection and ViewTransform
This commit is contained in:
parent
2a9e112a20
commit
eee71e9190
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// </summary>
|
||||
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
|
|||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -204,7 +204,12 @@ namespace MapControl
|
|||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// Gets the relative map scale at the specified geographic coordinates.
|
||||
/// </summary>
|
||||
public virtual Point GetRelativeScale(double latitude, double longitude) => new Point(1d, 1d);
|
||||
public virtual Point RelativeScale(double latitude, double longitude) => new Point(1d, 1d);
|
||||
|
||||
/// <summary>
|
||||
/// Transforms geographic coordinates to a Point in projected map coordinates.
|
||||
|
|
@ -72,7 +72,7 @@ namespace MapControl
|
|||
/// <summary>
|
||||
/// Gets the relative map scale at the specified geographic Location.
|
||||
/// </summary>
|
||||
public Point GetRelativeScale(Location location) => GetRelativeScale(location.Latitude, location.Longitude);
|
||||
public Point RelativeScale(Location location) => RelativeScale(location.Latitude, location.Longitude);
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a Location in geographic coordinates to a Point in projected map coordinates.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,20 +58,14 @@ namespace MapControl
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a transform Matrix from meters to view coordinates for a relative map scale.
|
||||
/// </summary>
|
||||
public Matrix GetMapTransform(Point relativeScale)
|
||||
{
|
||||
var transform = new Matrix(Scale * relativeScale.X, 0d, 0d, Scale * relativeScale.Y, 0d, 0d);
|
||||
transform.Rotate(Rotation);
|
||||
return transform;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the transform Matrix for the RenderTranform of a MapTileLayer.
|
||||
/// Gets the transform Matrix for the RenderTranform of a MapTileLayer or WmtsTileMatrixLayer.
|
||||
/// </summary>
|
||||
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
|
|||
/// </summary>
|
||||
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.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue