Updated MapImageLayer and WmsImageLayer

This commit is contained in:
ClemensFischer 2025-12-30 12:59:06 +01:00
parent 612a4048c0
commit f059d2174d
2 changed files with 24 additions and 38 deletions

View file

@ -170,7 +170,7 @@ namespace MapControl
} }
} }
protected abstract Task<ImageSource> GetImageAsync(BoundingBox boundingBox, IProgress<double> progress); protected abstract Task<ImageSource> GetImageAsync(Rect mapBoundingBox, IProgress<double> progress);
protected async Task UpdateImageAsync() protected async Task UpdateImageAsync()
{ {
@ -191,12 +191,13 @@ namespace MapControl
var height = ParentMap.ActualHeight * RelativeImageSize; var height = ParentMap.ActualHeight * RelativeImageSize;
var x = (ParentMap.ActualWidth - width) / 2d; var x = (ParentMap.ActualWidth - width) / 2d;
var y = (ParentMap.ActualHeight - height) / 2d; var y = (ParentMap.ActualHeight - height) / 2d;
var mapRect = ParentMap.ViewRectToMap(x, y, width, height);
boundingBox = ParentMap.ViewRectToBoundingBox(x, y, width, height); boundingBox = ParentMap.MapProjection.MapToBoundingBox(mapRect);
if (boundingBox != null) if (boundingBox != null)
{ {
image = await GetImageAsync(boundingBox, loadingProgress); image = await GetImageAsync(mapRect, loadingProgress);
} }
} }

View file

@ -180,51 +180,40 @@ namespace MapControl
/// <summary> /// <summary>
/// Loads an ImageSource from the URL returned by GetMapRequestUri(). /// Loads an ImageSource from the URL returned by GetMapRequestUri().
/// </summary> /// </summary>
protected override async Task<ImageSource> GetImageAsync(BoundingBox boundingBox, IProgress<double> progress) protected override async Task<ImageSource> GetImageAsync(Rect bbox, IProgress<double> progress)
{ {
ImageSource image = null; ImageSource image = null;
if (ServiceUri != null && HasLayer) if (ServiceUri != null && HasLayer)
{ {
if (boundingBox.West >= -180d && boundingBox.East <= 180d || var xMin = -180d * MapProjection.Wgs84MeterPerDegree;
ParentMap.MapProjection.Type > MapProjectionType.NormalCylindrical) var xMax = 180d * MapProjection.Wgs84MeterPerDegree;
if (ParentMap.MapProjection.Type > MapProjectionType.NormalCylindrical ||
bbox.X >= xMin && bbox.X + bbox.Width <= xMax)
{ {
var bbox = ParentMap.MapProjection.BoundingBoxToMap(boundingBox); var uri = GetMapRequestUri(bbox);
if (bbox.HasValue) image = await ImageLoader.LoadImageAsync(uri, progress);
{
var uri = GetMapRequestUri(bbox.Value);
image = await ImageLoader.LoadImageAsync(uri, progress);
}
} }
else else
{ {
var west = boundingBox.West; var x = bbox.X;
var east = boundingBox.East;
if (west < -180d) if (x < xMin)
{ {
west += 360d; x += xMax - xMin;
}
else
{
east -= 360d;
} }
var boundingBox1 = new BoundingBox(boundingBox.South, west, boundingBox.North, 180d); var width1 = Math.Floor(xMax * 1e3) / 1e3 - x; // round down xMax to avoid gap between images
var boundingBox2 = new BoundingBox(boundingBox.South, -180d, boundingBox.North, east); var width2 = bbox.Width - width1;
var bbox1 = new Rect(x, bbox.Y, width1, bbox.Height);
var bbox2 = new Rect(xMin, bbox.Y, width2, bbox.Height);
var bbox1 = ParentMap.MapProjection.BoundingBoxToMap(boundingBox1); var uri1 = GetMapRequestUri(bbox1);
var bbox2 = ParentMap.MapProjection.BoundingBoxToMap(boundingBox2); var uri2 = GetMapRequestUri(bbox2);
if (bbox1.HasValue && bbox2.HasValue) image = await ImageLoader.LoadMergedImageAsync(uri1, uri2, progress);
{
var uri1 = GetMapRequestUri(bbox1.Value);
var uri2 = GetMapRequestUri(bbox2.Value);
image = await ImageLoader.LoadMergedImageAsync(uri1, uri2, progress);
}
} }
} }
@ -327,7 +316,7 @@ namespace MapControl
protected virtual string GetBboxValue(Rect bbox) protected virtual string GetBboxValue(Rect bbox)
{ {
var crs = ParentMap.MapProjection.CrsId; var crs = ParentMap.MapProjection.CrsId;
var format = "{0},{1},{2},{3}"; var format = "{0:F3},{1:F3},{2:F3},{3:F3}";
var x1 = bbox.X; var x1 = bbox.X;
var y1 = bbox.Y; var y1 = bbox.Y;
var x2 = bbox.X + bbox.Width; var x2 = bbox.X + bbox.Width;
@ -335,11 +324,7 @@ namespace MapControl
if (crs == "CRS:84" || crs == "EPSG:4326") if (crs == "CRS:84" || crs == "EPSG:4326")
{ {
if (crs == "EPSG:4326") format = crs == "CRS:84" ? "{0:F8},{1:F8},{2:F8},{3:F8}" : "{1:F8},{0:F8},{3:F8},{2:F8}";
{
format = "{1},{0},{3},{2}";
}
x1 /= MapProjection.Wgs84MeterPerDegree; x1 /= MapProjection.Wgs84MeterPerDegree;
y1 /= MapProjection.Wgs84MeterPerDegree; y1 /= MapProjection.Wgs84MeterPerDegree;
x2 /= MapProjection.Wgs84MeterPerDegree; x2 /= MapProjection.Wgs84MeterPerDegree;