diff --git a/MapControl/Shared/AutoEquirectangularProjection.cs b/MapControl/Shared/AutoEquirectangularProjection.cs
index 7ba9bf93..13ede2d5 100644
--- a/MapControl/Shared/AutoEquirectangularProjection.cs
+++ b/MapControl/Shared/AutoEquirectangularProjection.cs
@@ -24,7 +24,7 @@ namespace MapControl
CrsId = DefaultCrsId;
}
- public override Point LocationToMap(Location location)
+ public override Point? LocationToMap(Location location)
{
return new Point(
Wgs84MeterPerDegree * (location.Longitude - Center.Longitude) * Math.Cos(Center.Latitude * Math.PI / 180d),
diff --git a/MapControl/Shared/AzimuthalEquidistantProjection.cs b/MapControl/Shared/AzimuthalEquidistantProjection.cs
index 73f8aba2..2a49d7a8 100644
--- a/MapControl/Shared/AzimuthalEquidistantProjection.cs
+++ b/MapControl/Shared/AzimuthalEquidistantProjection.cs
@@ -20,7 +20,7 @@ namespace MapControl
CrsId = crsId;
}
- public override Point LocationToMap(Location location)
+ public override Point? LocationToMap(Location location)
{
if (location.Equals(Center))
{
diff --git a/MapControl/Shared/AzimuthalProjection.cs b/MapControl/Shared/AzimuthalProjection.cs
index a73799a7..986dd1dd 100644
--- a/MapControl/Shared/AzimuthalProjection.cs
+++ b/MapControl/Shared/AzimuthalProjection.cs
@@ -19,22 +19,34 @@ namespace MapControl
Type = MapProjectionType.Azimuthal;
}
- public override Rect BoundingBoxToRect(BoundingBox boundingBox)
+ public override MapRect BoundingBoxToMapRect(BoundingBox boundingBox)
{
var center = LocationToMap(boundingBox.Center);
+
+ if (!center.HasValue)
+ {
+ return null;
+ }
+
var width = boundingBox.Width * Wgs84MeterPerDegree;
var height = boundingBox.Height * Wgs84MeterPerDegree;
- return new Rect(center.X - width / 2d, center.Y - height / 2d, width, height);
+ return new MapRect(center.Value.X - width / 2d, center.Value.Y - height / 2d, width, height);
}
- public override BoundingBox RectToBoundingBox(Rect rect)
+ public override BoundingBox MapRectToBoundingBox(MapRect rect)
{
var center = MapToLocation(new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d));
+
+ if (center == null)
+ {
+ return null;
+ }
+
var width = rect.Width / Wgs84MeterPerDegree;
var height = rect.Height / Wgs84MeterPerDegree;
- return center != null ? new CenteredBoundingBox(center, width, height) : null;
+ return new CenteredBoundingBox(center, width, height);
}
///
diff --git a/MapControl/Shared/EquirectangularProjection.cs b/MapControl/Shared/EquirectangularProjection.cs
index 565019ef..0ad0ac15 100644
--- a/MapControl/Shared/EquirectangularProjection.cs
+++ b/MapControl/Shared/EquirectangularProjection.cs
@@ -25,14 +25,14 @@ namespace MapControl
CrsId = DefaultCrsId;
}
- public override Vector GetRelativeScale(Location location)
+ public override Scale GetRelativeScale(Location location)
{
- return new Vector(
+ return new Scale(
1d / Math.Cos(location.Latitude * Math.PI / 180d),
1d);
}
- public override Point LocationToMap(Location location)
+ public override Point? LocationToMap(Location location)
{
return new Point(
Wgs84MeterPerDegree * location.Longitude,
@@ -46,7 +46,7 @@ namespace MapControl
point.X / Wgs84MeterPerDegree);
}
- public override string GetBboxValue(Rect rect)
+ public override string GetBboxValue(MapRect rect)
{
return string.Format(CultureInfo.InvariantCulture,
CrsId == "CRS:84" ? "{0},{1},{2},{3}" : "{1},{0},{3},{2}",
diff --git a/MapControl/Shared/GeoImage.cs b/MapControl/Shared/GeoImage.cs
index b0272433..58aa1d46 100644
--- a/MapControl/Shared/GeoImage.cs
+++ b/MapControl/Shared/GeoImage.cs
@@ -100,7 +100,7 @@ namespace MapControl
transform.M21 = 0;
}
- var rect = new Rect(
+ var rect = new MapRect(
transform.Transform(new Point()),
transform.Transform(new Point(bitmap.PixelWidth, bitmap.PixelHeight)));
diff --git a/MapControl/Shared/GnomonicProjection.cs b/MapControl/Shared/GnomonicProjection.cs
index 20b5f963..6611c504 100644
--- a/MapControl/Shared/GnomonicProjection.cs
+++ b/MapControl/Shared/GnomonicProjection.cs
@@ -22,7 +22,7 @@ namespace MapControl
CrsId = DefaultCrsId;
}
- public override Point LocationToMap(Location location)
+ public override Point? LocationToMap(Location location)
{
if (location.Equals(Center))
{
diff --git a/MapControl/Shared/Intersections.cs b/MapControl/Shared/Intersections.cs
index 4c36660b..bbe16102 100644
--- a/MapControl/Shared/Intersections.cs
+++ b/MapControl/Shared/Intersections.cs
@@ -3,7 +3,9 @@
// Licensed under the Microsoft Public License (Ms-PL)
using System;
-#if !WINUI && !UWP
+#if WINUI || UWP
+using Windows.Foundation;
+#else
using System.Windows;
#endif
@@ -48,30 +50,30 @@ namespace MapControl
return true;
}
- var topLeft = new Point(rect.X, rect.Y);
- var topRight = new Point(rect.X + rect.Width, rect.Y);
- var bottomLeft = new Point(rect.X, rect.Y + rect.Height);
- var bottomRight = new Point(rect.X + rect.Width, rect.Y + rect.Height);
+ var topLeft = new Point(rect.Left, rect.Top);
+ var topRight = new Point(rect.Right, rect.Top);
+ var bottomLeft = new Point(rect.Left, rect.Bottom);
+ var bottomRight = new Point(rect.Right, rect.Bottom);
var numIntersections = 0;
- if (GetIntersection(ref p1, ref p2, topLeft, bottomLeft, p => p.X <= rect.X)) // left edge
+ if (GetIntersection(ref p1, ref p2, topLeft, bottomLeft, p => p.X <= rect.Left)) // left edge
{
numIntersections++;
}
- if (GetIntersection(ref p1, ref p2, topLeft, topRight, p => p.Y <= rect.Y)) // top edge
+ if (GetIntersection(ref p1, ref p2, topLeft, topRight, p => p.Y <= rect.Top)) // top edge
{
numIntersections++;
}
if (numIntersections < 2 &&
- GetIntersection(ref p1, ref p2, topRight, bottomRight, p => p.X >= rect.X + rect.Width)) // right edge
+ GetIntersection(ref p1, ref p2, topRight, bottomRight, p => p.X >= rect.Right)) // right edge
{
numIntersections++;
}
if (numIntersections < 2 &&
- GetIntersection(ref p1, ref p2, bottomLeft, bottomRight, p => p.Y >= rect.Y + rect.Height)) // bottom edge
+ GetIntersection(ref p1, ref p2, bottomLeft, bottomRight, p => p.Y >= rect.Bottom)) // bottom edge
{
numIntersections++;
}
diff --git a/MapControl/Shared/MapBase.cs b/MapControl/Shared/MapBase.cs
index f4d06e0f..032f9eea 100644
--- a/MapControl/Shared/MapBase.cs
+++ b/MapControl/Shared/MapBase.cs
@@ -4,10 +4,12 @@
using System;
#if WINUI
+using Windows.Foundation;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Animation;
#elif UWP
+using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
@@ -229,7 +231,7 @@ namespace MapControl
/// Gets the map scale as the horizontal and vertical scaling factors from geographic
/// coordinates to view coordinates at the specified location, as pixels per meter.
///
- public Vector GetScale(Location location)
+ public Scale GetScale(Location location)
{
return ViewTransform.Scale * MapProjection.GetRelativeScale(location);
}
@@ -237,9 +239,16 @@ namespace MapControl
///
/// Transforms a Location in geographic coordinates to a Point in view coordinates.
///
- public Point LocationToView(Location location)
+ public Point? LocationToView(Location location)
{
- return ViewTransform.MapToView(MapProjection.LocationToMap(location));
+ var point = MapProjection.LocationToMap(location);
+
+ if (!point.HasValue)
+ {
+ return null;
+ }
+
+ return ViewTransform.MapToView(point.Value);
}
///
@@ -265,7 +274,7 @@ namespace MapControl
var y1 = Math.Min(p1.Y, Math.Min(p2.Y, Math.Min(p3.Y, p4.Y)));
var y2 = Math.Max(p1.Y, Math.Max(p2.Y, Math.Max(p3.Y, p4.Y)));
- return MapProjection.RectToBoundingBox(new Rect(x1, y1, x2 - x1, y2 - y1));
+ return MapProjection.MapRectToBoundingBox(new MapRect(x1, y1, x2 - x1, y2 - y1));
}
///
@@ -291,7 +300,7 @@ namespace MapControl
///
/// Changes the Center property according to the specified translation in view coordinates.
///
- public void TranslateMap(Vector translation)
+ public void TranslateMap(Point translation)
{
if (transformCenter != null)
{
@@ -301,7 +310,8 @@ namespace MapControl
if (translation.X != 0d || translation.Y != 0d)
{
- var center = ViewToLocation(viewCenter - translation);
+ var center = ViewToLocation(new Point(viewCenter.X - translation.X, viewCenter.Y - translation.Y));
+
if (center != null)
{
Center = center;
@@ -314,12 +324,14 @@ namespace MapControl
/// view coordinate translation, rotation and scale delta values. Rotation and scaling
/// is performed relative to the specified center point in view coordinates.
///
- public void TransformMap(Point center, Vector translation, double rotation, double scale)
+ public void TransformMap(Point center, Point translation, double rotation, double scale)
{
if (rotation != 0d || scale != 1d)
{
SetTransformCenter(center);
- viewCenter += translation;
+
+ viewCenter.X += translation.X;
+ viewCenter.Y += translation.Y;
if (rotation != 0d)
{
@@ -368,7 +380,7 @@ namespace MapControl
///
public void ZoomToBounds(BoundingBox boundingBox)
{
- var rect = MapProjection.BoundingBoxToRect(boundingBox);
+ var rect = MapProjection.BoundingBoxToMapRect(boundingBox);
var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
var targetCenter = MapProjection.MapToLocation(center);
@@ -737,9 +749,9 @@ namespace MapControl
var mapCenter = projection.LocationToMap(transformCenter ?? Center);
- if (MapProjection.IsValid(mapCenter))
+ if (mapCenter.HasValue)
{
- ViewTransform.SetTransform(mapCenter, viewCenter, viewScale, -Heading);
+ ViewTransform.SetTransform(mapCenter.Value, viewCenter, viewScale, -Heading);
if (transformCenter != null)
{
@@ -774,9 +786,9 @@ namespace MapControl
mapCenter = projection.LocationToMap(center);
- if (MapProjection.IsValid(mapCenter))
+ if (mapCenter.HasValue)
{
- ViewTransform.SetTransform(mapCenter, viewCenter, viewScale, -Heading);
+ ViewTransform.SetTransform(mapCenter.Value, viewCenter, viewScale, -Heading);
}
}
}
diff --git a/MapControl/Shared/MapGraticule.cs b/MapControl/Shared/MapGraticule.cs
index 135ceed2..c5426492 100644
--- a/MapControl/Shared/MapGraticule.cs
+++ b/MapControl/Shared/MapGraticule.cs
@@ -7,9 +7,11 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
#if WINUI
+using Windows.Foundation;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
#elif UWP
+using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#else
@@ -104,8 +106,7 @@ namespace MapControl
private void AddLabel(ICollection