Version 4.10.0: Improved ImageLoader and MBTiles.

This commit is contained in:
ClemensF 2018-08-15 23:29:03 +02:00
parent eca9178971
commit bdcd2597a1
13 changed files with 403 additions and 339 deletions

View file

@ -5,6 +5,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;
@ -17,7 +18,52 @@ namespace MapControl
{
public static partial class ImageLoader
{
public static async Task<Tuple<IBuffer, TimeSpan?>> LoadHttpBufferAsync(Uri uri)
public static async Task<ImageSource> CreateImageSourceAsync(IRandomAccessStream stream)
{
var bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(stream);
return bitmapImage;
}
public static async Task<ImageSource> CreateImageSourceAsync(byte[] buffer)
{
using (var stream = new InMemoryRandomAccessStream())
{
await stream.WriteAsync(buffer.AsBuffer());
stream.Seek(0);
return await CreateImageSourceAsync(stream);
}
}
private static async Task<ImageSource> CreateImageSourceAsync(IHttpContent content)
{
using (var stream = new InMemoryRandomAccessStream())
{
await content.WriteToStreamAsync(stream);
stream.Seek(0);
return await CreateImageSourceAsync(stream);
}
}
private static async Task<ImageSource> LoadLocalImageAsync(Uri uri)
{
ImageSource imageSource = null;
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
if (File.Exists(path))
{
var file = await StorageFile.GetFileFromPathAsync(path);
using (var stream = await file.OpenReadAsync())
{
imageSource = await CreateImageSourceAsync(stream);
}
}
return imageSource;
}
internal static async Task<Tuple<IBuffer, TimeSpan?>> LoadHttpBufferAsync(Uri uri)
{
Tuple<IBuffer, TimeSpan?> result = null;
@ -52,49 +98,6 @@ namespace MapControl
return result;
}
public static async Task<ImageSource> LoadLocalImageAsync(Uri uri)
{
ImageSource imageSource = null;
try
{
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
if (File.Exists(path))
{
var file = await StorageFile.GetFileFromPathAsync(path);
using (var stream = await file.OpenReadAsync())
{
imageSource = await CreateImageSourceAsync(stream);
}
}
}
catch (Exception ex)
{
Debug.WriteLine("ImageLoader: {0}: {1}", uri, ex.Message);
}
return imageSource;
}
public static async Task<ImageSource> CreateImageSourceAsync(IRandomAccessStream stream)
{
var bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(stream);
return bitmapImage;
}
private static async Task<ImageSource> CreateImageSourceAsync(IHttpContent content)
{
using (var stream = new InMemoryRandomAccessStream())
{
await content.WriteToStreamAsync(stream);
stream.Seek(0);
return await CreateImageSourceAsync(stream);
}
}
private static bool IsTileAvailable(HttpResponseHeaderCollection responseHeaders)
{
return !responseHeaders.TryGetValue("X-VE-Tile-Info", out string tileInfo) || tileInfo != "no-tile";

View file

@ -6,7 +6,6 @@ using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Media.Imaging;
namespace MapControl
@ -28,8 +27,7 @@ namespace MapControl
}
else
{
Image.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation { From = 0d, To = 1d, Duration = FadeDuration, FillBehavior = FillBehavior.Stop });
Image.Opacity = 1d;
FadeIn();
}
}
else
@ -47,8 +45,7 @@ namespace MapControl
bitmapImage.ImageOpened -= BitmapImageOpened;
bitmapImage.ImageFailed -= BitmapImageFailed;
Image.BeginAnimation(UIElement.OpacityProperty, new DoubleAnimation { From = 0d, To = 1d, Duration = FadeDuration, FillBehavior = FillBehavior.Stop });
Image.Opacity = 1d;
FadeIn();
}
private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e)