diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs index 69b7bd59..e0729b1f 100644 --- a/MapControl/Shared/MapBase.cs +++ b/MapControl/Shared/MapBase.cs @@ -734,7 +734,10 @@ namespace MapControl var viewScale = ViewTransform.ZoomLevelToScale(ZoomLevel); var projection = MapProjection; - projection.Center = ProjectionCenter ?? Center; + if (projection.Type == MapProjectionType.Azimuthal) + { + projection.Center = ProjectionCenter ?? Center; + } var mapCenter = projection.LocationToMap(transformCenter ?? Center); @@ -767,7 +770,11 @@ namespace MapControl { ResetTransformCenter(); - projection.Center = ProjectionCenter ?? center; + if (projection.Type == MapProjectionType.Azimuthal) + { + projection.Center = ProjectionCenter ?? Center; + } + mapCenter = projection.LocationToMap(center); if (MapProjection.IsValid(mapCenter)) diff --git a/MapControl/Shared/MapProjection.cs b/MapControl/Shared/MapProjection.cs index 60ec4730..200cfed2 100644 --- a/MapControl/Shared/MapProjection.cs +++ b/MapControl/Shared/MapProjection.cs @@ -44,7 +44,7 @@ namespace MapControl public string CrsId { get; protected set; } = string.Empty; /// - /// Gets or sets the projection center. + /// Gets or sets an optional projection center. /// public Location Center { get; set; } = new Location(); diff --git a/MapControl/WPF/MapGraticule.WPF.cs b/MapControl/WPF/MapGraticule.WPF.cs index 253d7ea0..99faf9fe 100644 --- a/MapControl/WPF/MapGraticule.WPF.cs +++ b/MapControl/WPF/MapGraticule.WPF.cs @@ -137,20 +137,30 @@ namespace MapControl var latPoints = latSegments * interpolationCount; var centerLon = Math.Round(ParentMap.Center.Longitude / lineDistance) * lineDistance; + var westLimit = centerLon - 180d; + var eastLimit = centerLon + 180d; + + if (ParentMap.MapProjection.Type == MapProjectionType.TransverseCylindrical) + { + westLimit = ParentMap.MapProjection.Center.Longitude - 15d; + eastLimit = ParentMap.MapProjection.Center.Longitude + 15d; + westLimit = Math.Floor(westLimit / lineDistance) * lineDistance; + eastLimit = Math.Ceiling(eastLimit / lineDistance) * lineDistance; + } + var minLon = centerLon - lineDistance; var maxLon = centerLon + lineDistance; - var lonRange = ParentMap.MapProjection.Type == MapProjectionType.TransverseCylindrical ? 15d : 180d; if (DrawMeridian(path.Figures, centerLon, minLat, interpolationDistance, latPoints)) { while (DrawMeridian(path.Figures, minLon, minLat, interpolationDistance, latPoints) && - minLon > centerLon - lonRange) + minLon > westLimit) { minLon -= lineDistance; } while (DrawMeridian(path.Figures, maxLon, minLat, interpolationDistance, latPoints) && - maxLon <= centerLon + lonRange) + maxLon < eastLimit) { maxLon += lineDistance; } diff --git a/MapProjections/Shared/GeoApiProjection.cs b/MapProjections/Shared/GeoApiProjection.cs index 580f7208..b40b6506 100644 --- a/MapProjections/Shared/GeoApiProjection.cs +++ b/MapProjections/Shared/GeoApiProjection.cs @@ -25,6 +25,7 @@ namespace MapControl.Projections public class GeoApiProjection : MapProjection { private ICoordinateSystem coordinateSystem; + private Location center; private double scaleFactor; private string bboxFormat; @@ -100,6 +101,10 @@ namespace MapControl.Projections Type = MapProjectionType.TransverseCylindrical; } + Center = new Location( + centralParallel != null ? centralParallel.Value : 0d, + centralMeridian != null ? centralMeridian.Value : 0d); + scaleFactor = 1d; bboxFormat = "{0},{1},{2},{3}"; } diff --git a/MapProjections/Shared/PolarStereographicProjection.cs b/MapProjections/Shared/PolarStereographicProjection.cs index 33dead12..a4dcdf75 100644 --- a/MapProjections/Shared/PolarStereographicProjection.cs +++ b/MapProjections/Shared/PolarStereographicProjection.cs @@ -19,7 +19,6 @@ namespace MapControl.Projections public static double ConvergenceTolerance { get; set; } = 1e-6; public static int MaxIterations { get; set; } = 10; - public bool IsNorth { get; } public double ScaleFactor { get; } public double FalseEasting { get; } public double FalseNorthing { get; } @@ -27,7 +26,7 @@ namespace MapControl.Projections public PolarStereographicProjection(string crsId, bool isNorth, double scaleFactor, double falseEasting, double falseNorthing) { CrsId = crsId; - IsNorth = isNorth; + Center = new Location(isNorth ? 90d : -90d, 0d); ScaleFactor = scaleFactor; FalseEasting = falseEasting; FalseNorthing = falseNorthing; @@ -35,7 +34,7 @@ namespace MapControl.Projections public override Vector GetRelativeScale(Location location) { - var lat = (IsNorth ? location.Latitude : -location.Latitude) * Math.PI / 180d; + var lat = Math.Sign(Center.Latitude) * location.Latitude * Math.PI / 180d; var a = Wgs84EquatorialRadius; var e = Wgs84Eccentricity; var s = Math.Sqrt(Math.Pow(1 + e, 1 + e) * Math.Pow(1 - e, 1 - e)); @@ -53,7 +52,7 @@ namespace MapControl.Projections var lat = location.Latitude * Math.PI / 180d; var lon = location.Longitude * Math.PI / 180d; - if (IsNorth) + if (Center.Latitude > 0d) { lon = Math.PI - lon; } @@ -92,7 +91,7 @@ namespace MapControl.Projections lat = newLat; } - if (IsNorth) + if (Center.Latitude > 0d) { lon = Math.PI - lon; }