From 1588171fb4273d64d77bcdf2e812a03eb3b06dcb Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Fri, 26 Dec 2025 06:40:55 +0100 Subject: [PATCH] Added IsHttp(Uri) extension method --- MapControl/Shared/ImageLoader.cs | 7 ++++++- MapControl/Shared/TileImageLoader.cs | 2 +- MapControl/Shared/WmtsCapabilities.cs | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/MapControl/Shared/ImageLoader.cs b/MapControl/Shared/ImageLoader.cs index f2f5408e..26867ce5 100644 --- a/MapControl/Shared/ImageLoader.cs +++ b/MapControl/Shared/ImageLoader.cs @@ -33,6 +33,11 @@ namespace MapControl HttpClient.DefaultRequestHeaders.Add("User-Agent", $"XAML-Map-Control/{typeof(ImageLoader).Assembly.GetName().Version}"); } + public static bool IsHttp(this Uri uri) + { + return uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps; + } + public static async Task LoadImageAsync(byte[] buffer) { using var stream = new MemoryStream(buffer); @@ -52,7 +57,7 @@ namespace MapControl { image = await LoadImageAsync(uri.OriginalString); } - else if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) + else if (uri.IsHttp()) { var buffer = await GetHttpContent(uri, progress); diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index cbdd9acf..5acb1519 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -163,7 +163,7 @@ namespace MapControl { await tile.LoadImageAsync(() => tileSource.LoadImageAsync(tile.ZoomLevel, tile.Column, tile.Row)).ConfigureAwait(false); } - else if (uri.Scheme != Uri.UriSchemeHttps && uri.Scheme != Uri.UriSchemeHttp || string.IsNullOrEmpty(cacheName)) + else if (!uri.IsHttp() || string.IsNullOrEmpty(cacheName)) { await tile.LoadImageAsync(() => tileSource.LoadImageAsync(uri)).ConfigureAwait(false); } diff --git a/MapControl/Shared/WmtsCapabilities.cs b/MapControl/Shared/WmtsCapabilities.cs index 206d764a..af6b46f2 100644 --- a/MapControl/Shared/WmtsCapabilities.cs +++ b/MapControl/Shared/WmtsCapabilities.cs @@ -38,7 +38,7 @@ namespace MapControl { xmlStream = File.OpenRead(uri.LocalPath); } - else if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) + else if (uri.IsHttp()) { defaultUri = uri.OriginalString.Split('?')[0];