mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-17 20:35:09 +00:00
Added IsHttp(Uri) extension method
This commit is contained in:
parent
2961836792
commit
1588171fb4
3 changed files with 8 additions and 3 deletions
|
|
@ -33,6 +33,11 @@ namespace MapControl
|
||||||
HttpClient.DefaultRequestHeaders.Add("User-Agent", $"XAML-Map-Control/{typeof(ImageLoader).Assembly.GetName().Version}");
|
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<ImageSource> LoadImageAsync(byte[] buffer)
|
public static async Task<ImageSource> LoadImageAsync(byte[] buffer)
|
||||||
{
|
{
|
||||||
using var stream = new MemoryStream(buffer);
|
using var stream = new MemoryStream(buffer);
|
||||||
|
|
@ -52,7 +57,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
image = await LoadImageAsync(uri.OriginalString);
|
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);
|
var buffer = await GetHttpContent(uri, progress);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
await tile.LoadImageAsync(() => tileSource.LoadImageAsync(tile.ZoomLevel, tile.Column, tile.Row)).ConfigureAwait(false);
|
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);
|
await tile.LoadImageAsync(() => tileSource.LoadImageAsync(uri)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
xmlStream = File.OpenRead(uri.LocalPath);
|
xmlStream = File.OpenRead(uri.LocalPath);
|
||||||
}
|
}
|
||||||
else if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
|
else if (uri.IsHttp())
|
||||||
{
|
{
|
||||||
defaultUri = uri.OriginalString.Split('?')[0];
|
defaultUri = uri.OriginalString.Split('?')[0];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue