diff --git a/MapControl/Shared/MapImageLayer.cs b/MapControl/Shared/MapImageLayer.cs index 690217a4..e9137df7 100644 --- a/MapControl/Shared/MapImageLayer.cs +++ b/MapControl/Shared/MapImageLayer.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Linq; using System.Threading.Tasks; #if WPF @@ -181,14 +180,7 @@ namespace MapControl if (boundingBox != null) { - try - { - image = await GetImageAsync(boundingBox, loadingProgress); - } - catch (Exception ex) - { - Debug.WriteLine($"MapImageLayer.GetImageAsync: {ex.Message}"); - } + image = await GetImageAsync(boundingBox, loadingProgress); } SwapImages(image, boundingBox); diff --git a/MapControl/Shared/MapPanel.cs b/MapControl/Shared/MapPanel.cs index f0b4279e..c23eaadb 100644 --- a/MapControl/Shared/MapPanel.cs +++ b/MapControl/Shared/MapPanel.cs @@ -169,14 +169,7 @@ namespace MapControl { foreach (var element in ChildElements) { - try - { - ArrangeChildElement(element, finalSize); - } - catch (Exception ex) - { - Debug.WriteLine($"MapPanel.ArrangeOverride: {element}: {ex.Message}"); - } + ArrangeChildElement(element, finalSize); } } diff --git a/MapControl/Shared/WmsImageLayer.cs b/MapControl/Shared/WmsImageLayer.cs index 0d206ad3..43be953c 100644 --- a/MapControl/Shared/WmsImageLayer.cs +++ b/MapControl/Shared/WmsImageLayer.cs @@ -164,50 +164,57 @@ namespace MapControl { ImageSource image = null; - if (ServiceUri != null && ParentMap?.MapProjection != null) + try { - if (WmsLayers == null && - ServiceUri.ToString().IndexOf("LAYERS=", StringComparison.OrdinalIgnoreCase) < 0) + if (ServiceUri != null && ParentMap?.MapProjection != null) { - // Get first Layer from a GetCapabilities response. - // - WmsLayers = (await GetLayerNamesAsync())?.FirstOrDefault() ?? ""; - } - - if (boundingBox.West >= -180d && boundingBox.East <= 180d || - ParentMap.MapProjection.Type > MapProjectionType.NormalCylindrical) - { - var uri = CreateUri(GetMapRequestUri(boundingBox)); - - if (uri != null) + if (WmsLayers == null && + ServiceUri.ToString().IndexOf("LAYERS=", StringComparison.OrdinalIgnoreCase) < 0) { - image = await ImageLoader.LoadImageAsync(uri, progress); + // Get first Layer from a GetCapabilities response. + // + WmsLayers = (await GetLayerNamesAsync())?.FirstOrDefault() ?? ""; } - } - else - { - BoundingBox bbox1, bbox2; - if (boundingBox.West < -180d) + if (boundingBox.West >= -180d && boundingBox.East <= 180d || + ParentMap.MapProjection.Type > MapProjectionType.NormalCylindrical) { - bbox1 = new BoundingBox(boundingBox.South, boundingBox.West + 360, boundingBox.North, 180d); - bbox2 = new BoundingBox(boundingBox.South, -180d, boundingBox.North, boundingBox.East); + var uri = GetMapRequestUri(boundingBox); + + if (uri != null) + { + image = await ImageLoader.LoadImageAsync(new Uri(uri), progress); + } } else { - bbox1 = new BoundingBox(boundingBox.South, boundingBox.West, boundingBox.North, 180d); - bbox2 = new BoundingBox(boundingBox.South, -180d, boundingBox.North, boundingBox.East - 360d); - } + BoundingBox bbox1, bbox2; - var uri1 = CreateUri(GetMapRequestUri(bbox1)); - var uri2 = CreateUri(GetMapRequestUri(bbox2)); + if (boundingBox.West < -180d) + { + bbox1 = new BoundingBox(boundingBox.South, boundingBox.West + 360, boundingBox.North, 180d); + bbox2 = new BoundingBox(boundingBox.South, -180d, boundingBox.North, boundingBox.East); + } + else + { + bbox1 = new BoundingBox(boundingBox.South, boundingBox.West, boundingBox.North, 180d); + bbox2 = new BoundingBox(boundingBox.South, -180d, boundingBox.North, boundingBox.East - 360d); + } - if (uri1 != null && uri2 != null) - { - image = await ImageLoader.LoadMergedImageAsync(uri1, uri2, progress); + var uri1 = GetMapRequestUri(bbox1); + var uri2 = GetMapRequestUri(bbox2); + + if (uri1 != null && uri2 != null) + { + image = await ImageLoader.LoadMergedImageAsync(new Uri(uri1), new Uri(uri2), progress); + } } } } + catch (Exception ex) + { + Logger?.LogError(ex, "GetImageAsync"); + } return image; } @@ -358,22 +365,5 @@ namespace MapControl return uri.Replace(" ", "%20"); } - - private static Uri CreateUri(string uri) - { - if (!string.IsNullOrEmpty(uri)) - { - try - { - return new Uri(uri, UriKind.RelativeOrAbsolute); - } - catch (Exception ex) - { - Logger?.LogError(ex, "{uri}", uri); - } - } - - return null; - } } }