mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-08 16:05:50 +00:00
Updated ViewTransform and WmsImageLayer
This commit is contained in:
parent
4628395c37
commit
f8f6fdc973
5 changed files with 60 additions and 129 deletions
|
|
@ -15,7 +15,7 @@ namespace MapControl
|
|||
/// Defines the transformation between projected map coordinates in meters
|
||||
/// and view coordinates in pixels.
|
||||
/// </summary>
|
||||
public partial class ViewTransform
|
||||
public class ViewTransform
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the scaling factor from projected map coordinates to view coordinates,
|
||||
|
|
@ -38,7 +38,6 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public Matrix ViewToMapMatrix { get; private set; }
|
||||
|
||||
#if !AVALONIA
|
||||
/// <summary>
|
||||
/// 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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -65,10 +70,14 @@ namespace MapControl
|
|||
/// </summary>
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue