Update GeoApiProjection.cs

This commit is contained in:
ClemensF 2020-04-19 21:31:31 +02:00
parent b6f33b5c1a
commit 802a5255d7

View file

@ -25,6 +25,7 @@ namespace MapControl.Projections
private ICoordinateSystem coordinateSystem; private ICoordinateSystem coordinateSystem;
private bool isNormalCylindrical; private bool isNormalCylindrical;
private bool isWebMercator; private bool isWebMercator;
private double scaleFactor;
private string bboxFormat; private string bboxFormat;
public IMathTransform LocationToMapTransform { get; private set; } public IMathTransform LocationToMapTransform { get; private set; }
@ -64,17 +65,19 @@ namespace MapControl.Projections
var falseNorthing = projection.GetParameter("false_northing"); var falseNorthing = projection.GetParameter("false_northing");
isNormalCylindrical = isNormalCylindrical =
centralMeridian != null && centralMeridian.Value == 0d && (centralMeridian == null || centralMeridian.Value == 0d) &&
centralParallel != null && centralParallel.Value == 0d && (centralParallel == null || centralParallel.Value == 0d) &&
(falseEasting == null || falseEasting.Value == 0d) && (falseEasting == null || falseEasting.Value == 0d) &&
(falseNorthing == null || falseNorthing.Value == 0d); (falseNorthing == null || falseNorthing.Value == 0d);
isWebMercator = CrsId == "EPSG:3857" || CrsId == "EPSG:900913"; isWebMercator = CrsId == "EPSG:3857" || CrsId == "EPSG:900913";
scaleFactor = 1d;
bboxFormat = "{0},{1},{2},{3}"; bboxFormat = "{0},{1},{2},{3}";
} }
else else
{ {
isNormalCylindrical = true; isNormalCylindrical = true;
isWebMercator = false; isWebMercator = false;
scaleFactor = Wgs84MetersPerDegree;
bboxFormat = "{1},{0},{3},{2}"; bboxFormat = "{1},{0},{3},{2}";
} }
} }
@ -108,9 +111,10 @@ namespace MapControl.Projections
throw new InvalidOperationException("The CoordinateSystem property is not set."); throw new InvalidOperationException("The CoordinateSystem property is not set.");
} }
var coordinate = LocationToMapTransform.Transform(new Coordinate(location.Longitude, location.Latitude)); var coordinate = LocationToMapTransform.Transform(
new Coordinate(location.Longitude, location.Latitude));
return new Point(coordinate.X, coordinate.Y); return new Point(coordinate.X * scaleFactor, coordinate.Y * scaleFactor);
} }
public override Location MapToLocation(Point point) public override Location MapToLocation(Point point)
@ -120,15 +124,17 @@ namespace MapControl.Projections
throw new InvalidOperationException("The CoordinateSystem property is not set."); throw new InvalidOperationException("The CoordinateSystem property is not set.");
} }
var coordinate = MapToLocationTransform.Transform(new Coordinate(point.X, point.Y)); var coordinate = MapToLocationTransform.Transform(
new Coordinate(point.X / scaleFactor, point.Y / scaleFactor));
return new Location(coordinate.Y, coordinate.X); return new Location(coordinate.Y, coordinate.X);
} }
public override string GetBboxValue(Rect rect) public override string GetBboxValue(Rect rect)
{ {
return string.Format(CultureInfo.InvariantCulture, return string.Format(CultureInfo.InvariantCulture, bboxFormat,
bboxFormat, rect.X, rect.Y, (rect.X + rect.Width), (rect.Y + rect.Height)); rect.X / scaleFactor, rect.Y / scaleFactor,
(rect.X + rect.Width) / scaleFactor, (rect.Y + rect.Height) / scaleFactor);
} }
} }
} }