mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 15:05:50 +00:00
Version 4.10.0: Updated target framework versions. Cleanup of TypeConverters, ImageLoader, MBTileSource.
This commit is contained in:
parent
63a4c1f0a7
commit
6a1653056f
36 changed files with 272 additions and 292 deletions
69
MapControl/Shared/ImageLoader.cs
Normal file
69
MapControl/Shared/ImageLoader.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2018 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
#if WINDOWS_UWP
|
||||
using Windows.Web.Http;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
#else
|
||||
using System.Net.Http;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public static partial class ImageLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// The HttpClient instance used when image data is downloaded from a web resource.
|
||||
/// </summary>
|
||||
public static HttpClient HttpClient { get; set; } = new HttpClient();
|
||||
|
||||
public static async Task<ImageSource> LoadImageAsync(Uri uri, bool isTileImage)
|
||||
{
|
||||
ImageSource imageSource = null;
|
||||
|
||||
if (!uri.IsAbsoluteUri || uri.Scheme == "file")
|
||||
{
|
||||
imageSource = await LoadLocalImageAsync(uri);
|
||||
}
|
||||
else if (uri.Scheme == "http")
|
||||
{
|
||||
imageSource = await LoadHttpImageAsync(uri, isTileImage);
|
||||
}
|
||||
else
|
||||
{
|
||||
imageSource = new BitmapImage(uri);
|
||||
}
|
||||
|
||||
return imageSource;
|
||||
}
|
||||
|
||||
public static async Task<ImageSource> LoadHttpImageAsync(Uri uri, bool isTileImage)
|
||||
{
|
||||
ImageSource imageSource = null;
|
||||
|
||||
using (var response = await HttpClient.GetAsync(uri))
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
Debug.WriteLine("ImageLoader: {0}: {1} {2}", uri, (int)response.StatusCode, response.ReasonPhrase);
|
||||
}
|
||||
else if (!isTileImage || IsTileAvailable(response.Headers))
|
||||
{
|
||||
using (var stream = await GetResponseStreamAsync(response.Content))
|
||||
{
|
||||
imageSource = await CreateImageSourceAsync(stream);
|
||||
}
|
||||
}
|
||||
|
||||
return imageSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue