This commit is contained in:
ClemensF 2018-12-02 17:13:55 +01:00
parent b0b4e0ea89
commit d916278845
4 changed files with 22 additions and 29 deletions

View file

@ -16,9 +16,7 @@ namespace MapControl
public class BoundingBox
{
private double south;
private double west;
private double north;
private double east;
public BoundingBox()
{
@ -32,48 +30,40 @@ namespace MapControl
East = east;
}
public double West { get; set; }
public double East { get; set; }
public double South
{
get { return south; }
set { south = Math.Min(Math.Max(value, -90d), 90d); }
}
public double West
{
get { return west; }
set { west = value; }
}
public double North
{
get { return north; }
set { north = Math.Min(Math.Max(value, -90d), 90d); }
}
public double East
{
get { return east; }
set { east = value; }
}
public virtual double Width
{
get { return east - west; }
get { return East - West; }
}
public virtual double Height
{
get { return north - south; }
get { return North - South; }
}
public bool HasValidBounds
{
get { return south < north && west < east; }
get { return South < North && West < East; }
}
public virtual BoundingBox Clone()
{
return new BoundingBox(south, west, north, east);
return new BoundingBox(South, West, North, East);
}
public static BoundingBox Parse(string s)

View file

@ -244,13 +244,14 @@ namespace MapControl
if (parentMap != null)
{
pos = parentMap.MapProjection.LocationToViewportPoint(location);
var projection = parentMap.MapProjection;
pos = projection.LocationToViewportPoint(location);
if (parentMap.MapProjection.IsCylindrical &&
if (projection.IsCylindrical &&
(pos.X < 0d || pos.X > parentMap.RenderSize.Width ||
pos.Y < 0d || pos.Y > parentMap.RenderSize.Height))
{
pos = parentMap.MapProjection.LocationToViewportPoint(new Location(
pos = projection.LocationToViewportPoint(new Location(
location.Latitude,
Location.NearestLongitude(location.Longitude, parentMap.Center.Longitude)));
}
@ -310,7 +311,7 @@ namespace MapControl
var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
var pos = projection.ViewportTransform.Transform(center);
if (parentMap.MapProjection.IsCylindrical &&
if (projection.IsCylindrical &&
(pos.X < 0d || pos.X > parentMap.RenderSize.Width ||
pos.Y < 0d || pos.Y > parentMap.RenderSize.Height))
{

View file

@ -25,8 +25,6 @@ namespace MapControl
public const double Wgs84EquatorialRadius = 6378137d;
public const double MetersPerDegree = Wgs84EquatorialRadius * Math.PI / 180d;
private Matrix inverseViewportTransformMatrix;
/// <summary>
/// Gets or sets the WMS 1.3.0 CRS Identifier.
/// </summary>
@ -58,6 +56,11 @@ namespace MapControl
/// </summary>
public Matrix ViewportTransform { get; private set; }
/// <summary>
/// Gets the transform matrix from viewport coordinates to cartesian map coordinates (pixels).
/// </summary>
public Matrix InverseViewportTransform { get; private set; }
/// <summary>
/// Gets the scaling factor from cartesian map coordinates to viewport coordinates.
/// </summary>
@ -115,7 +118,7 @@ namespace MapControl
/// </summary>
public Location ViewportPointToLocation(Point point)
{
return PointToLocation(inverseViewportTransformMatrix.Transform(point));
return PointToLocation(InverseViewportTransform.Transform(point));
}
/// <summary>
@ -123,7 +126,7 @@ namespace MapControl
/// </summary>
public BoundingBox ViewportRectToBoundingBox(Rect rect)
{
var transform = new MatrixTransform { Matrix = inverseViewportTransformMatrix };
var transform = new MatrixTransform { Matrix = InverseViewportTransform };
return RectToBoundingBox(transform.TransformBounds(rect));
}
@ -139,9 +142,8 @@ namespace MapControl
var matrix = CreateTransformMatrix(center, ViewportScale, -ViewportScale, heading, viewportCenter);
ViewportTransform = matrix;
matrix.Invert();
inverseViewportTransformMatrix = matrix;
InverseViewportTransform = matrix;
}
/// <summary>

View file

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace MapControl
{
public class XmlDocument : System.Xml.XmlDocument
internal class XmlDocument : System.Xml.XmlDocument
{
public static XmlDocument LoadFromUri(Uri uri)
{