Reworked MapProjection

Return nullable Point from LocationToMap. Use MapRect instead of WinUI/UWP Rect replacement. Drop Vector. Add Scale struct.
This commit is contained in:
ClemensFischer 2022-12-02 16:50:10 +01:00
parent bab1788334
commit 218a85316c
28 changed files with 249 additions and 324 deletions

View file

@ -203,12 +203,13 @@ namespace MapControl
return finalSize;
}
protected Point GetViewPosition(Location location)
protected Point? GetViewPosition(Location location)
{
var position = parentMap.LocationToView(location);
if (parentMap.MapProjection.Type <= MapProjectionType.NormalCylindrical &&
IsOutsideViewport(position))
position.HasValue &&
IsOutsideViewport(position.Value))
{
location = new Location(location.Latitude, parentMap.ConstrainedLongitude(location.Longitude));
position = parentMap.LocationToView(location);
@ -219,10 +220,10 @@ namespace MapControl
protected ViewRect GetViewRect(BoundingBox boundingBox)
{
return GetViewRect(parentMap.MapProjection.BoundingBoxToRect(boundingBox));
return GetViewRect(parentMap.MapProjection.BoundingBoxToMapRect(boundingBox));
}
protected ViewRect GetViewRect(Rect rect)
protected ViewRect GetViewRect(MapRect rect)
{
var center = new Point(rect.X + rect.Width / 2d, rect.Y + rect.Height / 2d);
var position = parentMap.ViewTransform.MapToView(center);
@ -235,7 +236,12 @@ namespace MapControl
if (location != null)
{
location.Longitude = parentMap.ConstrainedLongitude(location.Longitude);
position = parentMap.LocationToView(location);
var pos = parentMap.LocationToView(location);
if (pos.HasValue)
{
position = pos.Value;
}
}
}