mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 22:18:56 +00:00
Update MapProjection and ViewTransform
This commit is contained in:
parent
2a9e112a20
commit
eee71e9190
12 changed files with 34 additions and 38 deletions
|
|
@ -28,7 +28,7 @@ namespace MapControl
|
||||||
CrsId = crsId;
|
CrsId = crsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Point GetRelativeScale(double latitude, double longitude)
|
public override Point RelativeScale(double latitude, double longitude)
|
||||||
{
|
{
|
||||||
return new Point(
|
return new Point(
|
||||||
Math.Cos(Center.Latitude * Math.PI / 180d) / Math.Cos(latitude * Math.PI / 180d),
|
Math.Cos(Center.Latitude * Math.PI / 180d) / Math.Cos(latitude * Math.PI / 180d),
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace MapControl
|
||||||
CrsId = crsId;
|
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);
|
return new Point(1d / Math.Cos(latitude * Math.PI / 180d), 1d);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
#if WPF
|
#if WPF
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Shapes;
|
||||||
#elif UWP
|
#elif UWP
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
|
|
@ -182,7 +184,7 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Point GetMapScale(double latitude, double longitude)
|
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);
|
return new Point(ViewTransform.Scale * relativeScale.X, ViewTransform.Scale * relativeScale.Y);
|
||||||
}
|
}
|
||||||
|
|
@ -193,9 +195,7 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Point GetMapScale(Location location)
|
public Point GetMapScale(Location location)
|
||||||
{
|
{
|
||||||
var relativeScale = MapProjection.GetRelativeScale(location);
|
return GetMapScale(location.Latitude, location.Longitude);
|
||||||
|
|
||||||
return new Point(ViewTransform.Scale * relativeScale.X, ViewTransform.Scale * relativeScale.Y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -204,7 +204,12 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Matrix GetMapTransform(Location location)
|
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>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace MapControl
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the relative map scale at the specified geographic coordinates.
|
/// Gets the relative map scale at the specified geographic coordinates.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Transforms geographic coordinates to a Point in projected map coordinates.
|
/// Transforms geographic coordinates to a Point in projected map coordinates.
|
||||||
|
|
@ -72,7 +72,7 @@ namespace MapControl
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the relative map scale at the specified geographic Location.
|
/// Gets the relative map scale at the specified geographic Location.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Point GetRelativeScale(Location location) => GetRelativeScale(location.Latitude, location.Longitude);
|
public Point RelativeScale(Location location) => RelativeScale(location.Latitude, location.Longitude);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Transforms a Location in geographic coordinates to a Point in projected map coordinates.
|
/// 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 double FalseNorthing { get; set; } = 2e6;
|
||||||
public bool IsNorth { get; set; }
|
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;
|
latitude *= Math.PI / 180d;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace MapControl
|
||||||
Type = MapProjectionType.TransverseCylindrical;
|
Type = MapProjectionType.TransverseCylindrical;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Point GetRelativeScale(double latitude, double longitude)
|
public override Point RelativeScale(double latitude, double longitude)
|
||||||
{
|
{
|
||||||
return new Point(ScaleFactor, ScaleFactor);
|
return new Point(ScaleFactor, ScaleFactor);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,20 +58,14 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a transform Matrix from meters to view coordinates for a relative map scale.
|
/// Gets the transform Matrix for the RenderTranform of a MapTileLayer or WmtsTileMatrixLayer.
|
||||||
/// </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.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Matrix GetTileLayerTransform(double tileMatrixScale, Point tileMatrixTopLeft, Point tileMatrixOrigin)
|
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.
|
// Tile matrix origin in map coordinates.
|
||||||
//
|
//
|
||||||
var mapOrigin = new Point(
|
var mapOrigin = new Point(
|
||||||
|
|
@ -81,11 +75,8 @@ namespace MapControl
|
||||||
// Tile matrix origin in view coordinates.
|
// Tile matrix origin in view coordinates.
|
||||||
//
|
//
|
||||||
var viewOrigin = MapToViewMatrix.Transform(mapOrigin);
|
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);
|
transform.Translate(viewOrigin.X, viewOrigin.Y);
|
||||||
|
|
||||||
return transform;
|
return transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,19 +85,19 @@ namespace MapControl
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Rect GetTileMatrixBounds(double tileMatrixScale, Point tileMatrixTopLeft, double viewWidth, double viewHeight)
|
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.
|
// View origin in map coordinates.
|
||||||
//
|
//
|
||||||
var origin = ViewToMapMatrix.Transform(new Point());
|
var origin = ViewToMapMatrix.Transform(new Point());
|
||||||
|
|
||||||
// Translation from origin to tile matrix origin in pixels.
|
// Translation from origin to tile matrix origin in pixels.
|
||||||
//
|
//
|
||||||
var originOffsetX = tileMatrixScale * (origin.X - tileMatrixTopLeft.X);
|
transform.Translate(
|
||||||
var originOffsetY = tileMatrixScale * (tileMatrixTopLeft.Y - origin.Y);
|
tileMatrixScale * (origin.X - tileMatrixTopLeft.X),
|
||||||
|
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 view bounds to tile pixel bounds.
|
// Transform view bounds to tile pixel bounds.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace MapControl
|
||||||
CrsId = crsId;
|
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)
|
var k = 1d / Math.Cos(latitude * Math.PI / 180d); // p.44 (7-3)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace MapControl
|
||||||
CrsId = crsId;
|
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 lat = latitude * Math.PI / 180d;
|
||||||
var eSinLat = Wgs84Eccentricity * Math.Sin(lat);
|
var eSinLat = Wgs84Eccentricity * Math.Sin(lat);
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ namespace MapControl.Projections
|
||||||
|
|
||||||
public IMathTransform MapToLocationTransform { get; private set; }
|
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;
|
var k = CoordinateSystem?.Projection?.GetParameter("scale_factor")?.Value ?? 1d;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace MapControl.Projections
|
||||||
CoordinateSystem = ProjectedCoordinateSystem.WebMercator;
|
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)
|
var k = 1d / Math.Cos(latitude * Math.PI / 180d); // p.44 (7-3)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace MapControl.Projections
|
||||||
+ "AUTHORITY[\"EPSG\",\"3395\"]]";
|
+ "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 lat = latitude * Math.PI / 180d;
|
||||||
var eSinLat = Wgs84Eccentricity * Math.Sin(lat);
|
var eSinLat = Wgs84Eccentricity * Math.Sin(lat);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue