diff --git a/MapControl/Shared/GeoImage.cs b/MapControl/Shared/GeoImage.cs
index 5fda3faf..ccf0fb62 100644
--- a/MapControl/Shared/GeoImage.cs
+++ b/MapControl/Shared/GeoImage.cs
@@ -44,9 +44,17 @@ namespace MapControl
var p2 = transform.Transform(new Point(bitmap.PixelWidth, bitmap.PixelHeight));
#endif
BitmapSource = bitmap;
- BoundingBox = projection != null
- ? projection.MapToBoundingBox(new Rect(p1, p2))
- : new BoundingBox(p1.Y, p1.X, p2.Y, p2.X);
+
+ if (projection != null)
+ {
+ var sw = projection.MapToLocation(p1);
+ var ne = projection.MapToLocation(p2);
+ BoundingBox = new BoundingBox(sw.Latitude, sw.Longitude, ne.Latitude, ne.Longitude);
+ }
+ else
+ {
+ BoundingBox = new BoundingBox(p1.Y, p1.X, p2.Y, p2.X);
+ }
}
public BitmapSource BitmapSource { get; }
diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs
index 8aa67f39..13b16784 100644
--- a/MapControl/Shared/MapBase.cs
+++ b/MapControl/Shared/MapBase.cs
@@ -195,11 +195,6 @@ namespace MapControl
///
public Location ViewToLocation(Point point) => MapProjection.MapToLocation(ViewTransform.ViewToMap(point));
- ///
- /// Gets a BoundingBox in geographic coordinates that covers a rectangle in view coordinates.
- ///
- public BoundingBox ViewToBoundingBox(Rect rect) => MapProjection.MapToBoundingBox(ViewTransform.ViewToMapBounds(rect));
-
///
/// Sets a temporary center point in view coordinates for scaling and rotation transformations.
/// This center point is automatically reset when the Center property is set by application code
diff --git a/MapControl/Shared/MapGraticule.cs b/MapControl/Shared/MapGraticule.cs
index a166b0da..f934660b 100644
--- a/MapControl/Shared/MapGraticule.cs
+++ b/MapControl/Shared/MapGraticule.cs
@@ -34,8 +34,6 @@ namespace MapControl
public double Rotation => rotation;
}
- private const double LineInterpolationResolution = 2d;
-
public static readonly DependencyProperty MinLineDistanceProperty =
DependencyPropertyHelper.Register(nameof(MinLineDistance), 150d);
@@ -75,124 +73,61 @@ namespace MapControl
set => SetValue(FontSizeProperty, value);
}
- private double PixelPerDegree => Math.Max(1d, ParentMap.ViewTransform.Scale * MapProjection.Wgs84MeterPerDegree);
-
- private double lineDistance;
- private string labelFormat;
-
- private void SetLineDistance()
- {
- var minDistance = MinLineDistance / PixelPerDegree;
- var scale = minDistance < 1d / 60d ? 3600d : minDistance < 1d ? 60d : 1d;
- minDistance *= scale;
-
- var lineDistances = new double[] { 1d, 2d, 5d, 10d, 15d, 30d, 60d };
- var i = 0;
-
- while (i < lineDistances.Length - 1 && lineDistances[i] < minDistance)
- {
- i++;
- }
-
- lineDistance = Math.Min(lineDistances[i] / scale, 30d);
-
- labelFormat = lineDistance < 1d / 60d ? "{0} {1}°{2:00}'{3:00}\""
- : lineDistance < 1d ? "{0} {1}°{2:00}'" : "{0} {1}°";
- }
-
- private string GetLabelText(double value, string hemispheres)
- {
- var hemisphere = hemispheres[0];
-
- if (value < -1e-8) // ~1 mm
- {
- value = -value;
- hemisphere = hemispheres[1];
- }
-
- var seconds = (int)Math.Round(value * 3600d);
-
- return string.Format(CultureInfo.InvariantCulture,
- labelFormat, hemisphere, seconds / 3600, seconds / 60 % 60, seconds % 60);
- }
-
- private void AddLabel(List
public abstract Matrix RelativeTransform(double latitude, double longitude);
- ///
- /// Gets the grid convergence angle in degrees at the specified projected map coordinates.
- /// Used for rotating the Rect resulting from BoundingBoxToMap in non-normal-cylindrical
- /// projections, i.e. Transverse Mercator and Polar Stereographic.
- ///
- public virtual double GridConvergence(double x, double y) => 0d;
-
///
/// Transforms geographic coordinates to a Point in projected map coordinates.
///
@@ -76,6 +69,13 @@ namespace MapControl
///
public abstract Location MapToLocation(double x, double y);
+ ///
+ /// Gets the grid convergence angle in degrees at the specified projected map coordinates.
+ /// Used for rotating the Rect resulting from BoundingBoxToMap in non-normal-cylindrical
+ /// projections, i.e. Transverse Mercator and Polar Stereographic.
+ ///
+ public virtual double GridConvergence(double x, double y) => 0d;
+
///
/// Gets the relative transform at the specified geographic Location.
///
@@ -93,7 +93,7 @@ namespace MapControl
///
/// Transforms a BoundingBox in geographic coordinates to a Rect in projected map coordinates
- /// with an optional rotation angle in degrees.
+ /// with an optional rotation angle in degrees for non-normal-cylindrical projections.
///
public (Rect, double) BoundingBoxToMap(BoundingBox boundingBox)
{
@@ -124,24 +124,12 @@ namespace MapControl
var height = Math.Sqrt(dx * dx + dy * dy);
rect = new Rect(centerX - width / 2d, centerY - height / 2d, width, height);
-
rotation = -GridConvergence(centerX, centerY); // invert direction for RotateTransform
}
return (rect, rotation);
}
- ///
- /// Transforms a Rect in projected map coordinates to a BoundingBox in geographic coordinates.
- ///
- public BoundingBox MapToBoundingBox(Rect rect)
- {
- var southWest = MapToLocation(rect.X, rect.Y);
- var northEast = MapToLocation(rect.X + rect.Width, rect.Y + rect.Height);
-
- return new BoundingBox(southWest.Latitude, southWest.Longitude, northEast.Latitude, northEast.Longitude);
- }
-
public override string ToString()
{
return CrsId;