Update MapGraticule.cs

This commit is contained in:
ClemensFischer 2026-02-06 11:59:57 +01:00
parent 4905e16df9
commit c8449be6ff

View file

@ -101,11 +101,10 @@ namespace MapControl
{ {
var southWest = ParentMap.ViewToLocation(new Point(0d, ParentMap.ActualHeight)); var southWest = ParentMap.ViewToLocation(new Point(0d, ParentMap.ActualHeight));
var northEast = ParentMap.ViewToLocation(new Point(ParentMap.ActualWidth, 0d)); var northEast = ParentMap.ViewToLocation(new Point(ParentMap.ActualWidth, 0d));
var lineDistance = GetLineDistance(MinLineDistance / var lineDistance = GetLineDistance(false);
(ParentMap.ViewTransform.Scale * MapProjection.Wgs84MeterPerDegree));
var latLabelStart = Math.Ceiling(southWest.Latitude / lineDistance) * lineDistance; var latLabelStart = Math.Ceiling(southWest.Latitude / lineDistance) * lineDistance;
var lonLabelStart = Math.Ceiling(southWest.Longitude / lineDistance) * lineDistance; var lonLabelStart = Math.Ceiling(southWest.Longitude / lineDistance) * lineDistance;
var labelFormat = GetLabelFormat(Math.Min(lineDistance, lineDistance)); var labelFormat = GetLabelFormat(lineDistance);
for (var lat = latLabelStart; lat <= northEast.Latitude; lat += lineDistance) for (var lat = latLabelStart; lat <= northEast.Latitude; lat += lineDistance)
{ {
@ -129,9 +128,8 @@ namespace MapControl
private void DrawGraticule(PathFigureCollection figures, List<Label> labels) private void DrawGraticule(PathFigureCollection figures, List<Label> labels)
{ {
var lineDistance = GetLineDistance(MinLineDistance / var lineDistance = GetLineDistance(true);
(ParentMap.ViewTransform.Scale * MapProjection.Wgs84MeterPerDegree * Math.Cos(ParentMap.Center.Latitude * Math.PI / 180d))); var labelFormat = GetLabelFormat(lineDistance);
var labelFormat = GetLabelFormat(Math.Min(lineDistance, lineDistance));
GetLatitudeRange(lineDistance, out double minLat, out double maxLat); GetLatitudeRange(lineDistance, out double minLat, out double maxLat);
@ -278,8 +276,15 @@ namespace MapControl
} }
} }
private static double GetLineDistance(double minDistance) private double GetLineDistance(bool scaleByLatitude)
{ {
var minDistance = MinLineDistance / (ParentMap.ViewTransform.Scale * MapProjection.Wgs84MeterPerDegree);
if (scaleByLatitude)
{
minDistance /= Math.Cos(ParentMap.Center.Latitude * Math.PI / 180d);
}
minDistance = Math.Max(minDistance, lineDistances.First()); minDistance = Math.Max(minDistance, lineDistances.First());
minDistance = Math.Min(minDistance, lineDistances.Last()); minDistance = Math.Min(minDistance, lineDistances.Last());