Rework Map/WmsImageLayer

This commit is contained in:
ClemensFischer 2022-11-30 17:59:38 +01:00
parent c3e1ffd685
commit 9db1987ee5
7 changed files with 265 additions and 103 deletions

View file

@ -134,11 +134,6 @@ namespace MapControl
private set => SetValue(LoadingProgressProperty, value);
}
/// <summary>
/// The current BoundingBox
/// </summary>
public BoundingBox BoundingBox { get; private set; }
protected override void SetParentMap(MapBase map)
{
if (map != null)
@ -179,6 +174,8 @@ namespace MapControl
}
}
protected abstract Task<ImageSource> GetImageAsync(BoundingBox boundingBox, IProgress<double> progress);
protected async Task UpdateImageAsync()
{
if (updateInProgress)
@ -190,45 +187,44 @@ namespace MapControl
else
{
updateTimer.Stop();
updateInProgress = true;
if (ParentMap != null && ParentMap.RenderSize.Width > 0 && ParentMap.RenderSize.Height > 0)
ImageSource image = null;
var boundingBox = GetImageBoundingBox();
if (boundingBox != null)
{
updateInProgress = true;
UpdateBoundingBox();
ImageSource image = null;
if (BoundingBox != null)
try
{
try
{
image = await GetImageAsync(imageProgress);
}
catch (Exception ex)
{
Debug.WriteLine($"MapImageLayer: {ex.Message}");
}
image = await GetImageAsync(boundingBox, imageProgress);
}
catch (Exception ex)
{
Debug.WriteLine($"MapImageLayer: {ex.Message}");
}
SwapImages(image);
updateInProgress = false;
}
SwapImages(image, boundingBox);
updateInProgress = false;
}
}
protected abstract Task<ImageSource> GetImageAsync(IProgress<double> progress);
private void UpdateBoundingBox()
protected BoundingBox GetImageBoundingBox()
{
var width = ParentMap.RenderSize.Width * RelativeImageSize;
var height = ParentMap.RenderSize.Height * RelativeImageSize;
var x = (ParentMap.RenderSize.Width - width) / 2d;
var y = (ParentMap.RenderSize.Height - height) / 2d;
var rect = new Rect(x, y, width, height);
BoundingBox boundingBox = null;
BoundingBox = ParentMap.ViewRectToBoundingBox(rect);
if (ParentMap != null && ParentMap.RenderSize.Width > 0d && ParentMap.RenderSize.Height > 0d)
{
var width = ParentMap.RenderSize.Width * RelativeImageSize;
var height = ParentMap.RenderSize.Height * RelativeImageSize;
var x = (ParentMap.RenderSize.Width - width) / 2d;
var y = (ParentMap.RenderSize.Height - height) / 2d;
boundingBox = ParentMap.ViewRectToBoundingBox(new Rect(x, y, width, height));
}
return boundingBox;
}
private void ClearImages()
@ -240,7 +236,7 @@ namespace MapControl
}
}
private void SwapImages(ImageSource image)
private void SwapImages(ImageSource image, BoundingBox boundingBox)
{
if (Children.Count >= 2)
{
@ -251,7 +247,7 @@ namespace MapControl
Children.Insert(1, topImage);
topImage.Source = image;
SetBoundingBox(topImage, BoundingBox);
SetBoundingBox(topImage, boundingBox);
topImage.BeginAnimation(OpacityProperty, new DoubleAnimation
{