mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
Version 5.0: Separated map projection and view transform.
This commit is contained in:
parent
53723844a0
commit
c7cb2efcdb
47 changed files with 401 additions and 382 deletions
|
|
@ -25,11 +25,11 @@ namespace MapControl.Projections
|
|||
private ICoordinateSystem coordinateSystem;
|
||||
private bool isNormalCylindrical;
|
||||
private bool isWebMercator;
|
||||
private double trueScale;
|
||||
private double unitsPerDegree;
|
||||
private string bboxFormat;
|
||||
|
||||
public IMathTransform LocationToPointTransform { get; private set; }
|
||||
public IMathTransform PointToLocationTransform { get; private set; }
|
||||
public IMathTransform LocationToMapTransform { get; private set; }
|
||||
public IMathTransform MapToLocationTransform { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ICoordinateSystem of the MapProjection.
|
||||
|
|
@ -48,11 +48,11 @@ namespace MapControl.Projections
|
|||
|
||||
var transformFactory = new CoordinateTransformationFactory();
|
||||
|
||||
LocationToPointTransform = transformFactory
|
||||
LocationToMapTransform = transformFactory
|
||||
.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, coordinateSystem)
|
||||
.MathTransform;
|
||||
|
||||
PointToLocationTransform = transformFactory
|
||||
MapToLocationTransform = transformFactory
|
||||
.CreateFromCoordinateSystems(coordinateSystem, GeographicCoordinateSystem.WGS84)
|
||||
.MathTransform;
|
||||
|
||||
|
|
@ -76,14 +76,14 @@ namespace MapControl.Projections
|
|||
(falseEasting == null || falseEasting.Value == 0d) &&
|
||||
(falseNorthing == null || falseNorthing.Value == 0d);
|
||||
isWebMercator = CrsId == "EPSG:3857" || CrsId == "EPSG:900913";
|
||||
trueScale = (scaleFactor != null ? scaleFactor.Value : 1d) * Wgs84MetersPerDegree;
|
||||
unitsPerDegree = (scaleFactor != null ? scaleFactor.Value : 1d) * Wgs84MetersPerDegree;
|
||||
bboxFormat = "{0},{1},{2},{3}";
|
||||
}
|
||||
else
|
||||
{
|
||||
isNormalCylindrical = true;
|
||||
isWebMercator = false;
|
||||
trueScale = 1d;
|
||||
unitsPerDegree = 1d;
|
||||
bboxFormat = "{1},{0},{3},{2}";
|
||||
}
|
||||
}
|
||||
|
|
@ -110,31 +110,31 @@ namespace MapControl.Projections
|
|||
get { return isWebMercator; }
|
||||
}
|
||||
|
||||
public override double TrueScale
|
||||
public override double UnitsPerDegree
|
||||
{
|
||||
get { return trueScale; }
|
||||
get { return unitsPerDegree; }
|
||||
}
|
||||
|
||||
public override Point LocationToPoint(Location location)
|
||||
public override Point LocationToMap(Location location)
|
||||
{
|
||||
if (LocationToPointTransform == null)
|
||||
if (LocationToMapTransform == null)
|
||||
{
|
||||
throw new InvalidOperationException("The CoordinateSystem property is not set.");
|
||||
}
|
||||
|
||||
var coordinate = LocationToPointTransform.Transform(new Coordinate(location.Longitude, location.Latitude));
|
||||
var coordinate = LocationToMapTransform.Transform(new Coordinate(location.Longitude, location.Latitude));
|
||||
|
||||
return new Point(coordinate.X, coordinate.Y);
|
||||
}
|
||||
|
||||
public override Location PointToLocation(Point point)
|
||||
public override Location MapToLocation(Point point)
|
||||
{
|
||||
if (PointToLocationTransform == null)
|
||||
if (MapToLocationTransform == null)
|
||||
{
|
||||
throw new InvalidOperationException("The CoordinateSystem property is not set.");
|
||||
}
|
||||
|
||||
var coordinate = PointToLocationTransform.Transform(new Coordinate(point.X, point.Y));
|
||||
var coordinate = MapToLocationTransform.Transform(new Coordinate(point.X, point.Y));
|
||||
|
||||
return new Location(coordinate.Y, coordinate.X);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,12 +33,12 @@ namespace MapControl.Projections
|
|||
this.falseNorthing = falseNorthing;
|
||||
}
|
||||
|
||||
public override double TrueScale
|
||||
public override double UnitsPerDegree
|
||||
{
|
||||
get { return scaleFactor * Wgs84MetersPerDegree; }
|
||||
}
|
||||
|
||||
public override Vector GetMapScale(Location location)
|
||||
public override Vector GetRelativeScale(Location location)
|
||||
{
|
||||
var lat = (north ? location.Latitude : -location.Latitude) * Math.PI / 180d;
|
||||
var a = Wgs84EquatorialRadius;
|
||||
|
|
@ -50,10 +50,10 @@ namespace MapControl.Projections
|
|||
var m = Math.Cos(lat) / Math.Sqrt(1d - eSinLat * eSinLat);
|
||||
var k = rho / (a * m);
|
||||
|
||||
return new Vector(ViewportScale * k, ViewportScale * k);
|
||||
return new Vector(k, k);
|
||||
}
|
||||
|
||||
public override Point LocationToPoint(Location location)
|
||||
public override Point LocationToMap(Location location)
|
||||
{
|
||||
var lat = location.Latitude * Math.PI / 180d;
|
||||
var lon = location.Longitude * Math.PI / 180d;
|
||||
|
|
@ -76,7 +76,7 @@ namespace MapControl.Projections
|
|||
return new Point(rho * Math.Sin(lon) + falseEasting, rho * Math.Cos(lon) + falseNorthing);
|
||||
}
|
||||
|
||||
public override Location PointToLocation(Point point)
|
||||
public override Location MapToLocation(Point point)
|
||||
{
|
||||
point.X -= falseEasting;
|
||||
point.Y -= falseNorthing;
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ namespace MapControl.Projections
|
|||
CoordinateSystem = ProjectedCoordinateSystem.WebMercator;
|
||||
}
|
||||
|
||||
public override Vector GetMapScale(Location location)
|
||||
public override Vector GetRelativeScale(Location location)
|
||||
{
|
||||
var k = 1d / Math.Cos(location.Latitude * Math.PI / 180d); // p.44 (7-3)
|
||||
|
||||
return new Vector(ViewportScale * k, ViewportScale * k);
|
||||
return new Vector(k, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,13 +37,13 @@ namespace MapControl.Projections
|
|||
"AUTHORITY[\"EPSG\",\"3395\"]]";
|
||||
}
|
||||
|
||||
public override Vector GetMapScale(Location location)
|
||||
public override Vector GetRelativeScale(Location location)
|
||||
{
|
||||
var lat = location.Latitude * Math.PI / 180d;
|
||||
var eSinLat = Wgs84Eccentricity * Math.Sin(lat);
|
||||
var k = Math.Sqrt(1d - eSinLat * eSinLat) / Math.Cos(lat); // p.44 (7-8)
|
||||
|
||||
return new Vector(ViewportScale * k, ViewportScale * k);
|
||||
return new Vector(k, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue