Update MapImageLayer.cs

This commit is contained in:
ClemensFischer 2025-04-04 14:35:18 +02:00
parent 50c2429b07
commit 75d8d4a70b

View file

@ -176,10 +176,17 @@ namespace MapControl
updateTimer.Stop();
ImageSource image = null;
var boundingBox = GetImageBoundingBox();
BoundingBox boundingBox = null;
if (boundingBox != null)
if (ParentMap != null && ParentMap.ActualWidth > 0d && ParentMap.ActualHeight > 0d)
{
var width = ParentMap.ActualWidth * RelativeImageSize;
var height = ParentMap.ActualHeight * RelativeImageSize;
var x = (ParentMap.ActualWidth - width) / 2d;
var y = (ParentMap.ActualHeight - height) / 2d;
boundingBox = ParentMap.ViewRectToBoundingBox(new Rect(x, y, width, height));
image = await GetImageAsync(boundingBox, loadingProgress);
}
@ -189,23 +196,6 @@ namespace MapControl
}
}
private BoundingBox GetImageBoundingBox()
{
BoundingBox boundingBox = null;
if (ParentMap != null && ParentMap.ActualWidth > 0d && ParentMap.ActualHeight > 0d)
{
var width = ParentMap.ActualWidth * RelativeImageSize;
var height = ParentMap.ActualHeight * RelativeImageSize;
var x = (ParentMap.ActualWidth - width) / 2d;
var y = (ParentMap.ActualHeight - height) / 2d;
boundingBox = ParentMap.ViewRectToBoundingBox(new Rect(x, y, width, height));
}
return boundingBox;
}
private void ClearImages()
{
foreach (var image in Children.OfType<Image>())