XAML-Map-Control/MapControl/Shared/AzimuthalProjection.cs

50 lines
1.4 KiB
C#
Raw Normal View History

2025-03-10 15:47:33 +01:00
#if WPF
using System.Windows;
#endif
namespace MapControl
{
/// <summary>
/// Base class for azimuthal map projections.
/// </summary>
public abstract class AzimuthalProjection : MapProjection
{
2022-03-05 18:40:57 +01:00
protected AzimuthalProjection()
{
Type = MapProjectionType.Azimuthal;
}
2024-09-08 14:03:55 +02:00
public override Rect? BoundingBoxToMap(BoundingBox boundingBox)
{
2024-09-09 16:44:45 +02:00
Rect? rect = null;
2024-09-08 14:03:55 +02:00
var center = LocationToMap(boundingBox.Center);
if (center.HasValue)
{
var width = boundingBox.Width * Wgs84MeterPerDegree;
var height = boundingBox.Height * Wgs84MeterPerDegree;
var x = center.Value.X - width / 2d;
var y = center.Value.Y - height / 2d;
2024-09-09 16:44:45 +02:00
rect = new Rect(x, y, width, height);
2024-09-08 14:03:55 +02:00
}
2024-09-09 16:44:45 +02:00
return rect;
2024-09-08 14:03:55 +02:00
}
2024-09-09 16:44:45 +02:00
public override BoundingBox MapToBoundingBox(Rect rect)
2024-09-08 14:03:55 +02:00
{
BoundingBox boundingBox = null;
2024-09-09 16:44:45 +02:00
var rectCenter = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
var center = MapToLocation(rectCenter);
2024-09-08 14:03:55 +02:00
if (center != null)
{
2024-09-09 16:44:45 +02:00
boundingBox = new CenteredBoundingBox(center, rect.Width / Wgs84MeterPerDegree, rect.Height / Wgs84MeterPerDegree);
2024-09-08 14:03:55 +02:00
}
return boundingBox;
}
}
}