Version 4.12.2 Fixed local file handling for UWP. All relative paths relative to ms-appx:

This commit is contained in:
ClemensF 2019-06-15 01:39:07 +02:00
parent 26bf0b5005
commit c28387f87c
14 changed files with 172 additions and 192 deletions

View file

@ -31,28 +31,18 @@ namespace MapControl
{
await stream.WriteAsync(buffer.AsBuffer());
stream.Seek(0);
return await LoadImageAsync(stream);
}
}
private static async Task<ImageSource> LoadImageAsync(IHttpContent content)
{
using (var stream = new InMemoryRandomAccessStream())
{
await content.WriteToStreamAsync(stream);
stream.Seek(0);
return await LoadImageAsync(stream);
}
}
private static async Task<ImageSource> LoadLocalImageAsync(Uri uri)
public static async Task<ImageSource> LoadImageAsync(string path)
{
ImageSource image = null;
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
if (File.Exists(path))
{
var file = await StorageFile.GetFileFromPathAsync(path);
var file = await StorageFile.GetFileFromPathAsync(Path.GetFullPath(path));
using (var stream = await file.OpenReadAsync())
{
@ -63,6 +53,17 @@ namespace MapControl
return image;
}
private static async Task<ImageSource> LoadImageAsync(IHttpContent content)
{
using (var stream = new InMemoryRandomAccessStream())
{
await content.WriteToStreamAsync(stream);
stream.Seek(0);
return await LoadImageAsync(stream);
}
}
internal class HttpBufferResponse
{
public readonly IBuffer Buffer;

View file

@ -12,18 +12,18 @@ namespace MapControl
{
public partial class Tile
{
public void SetImage(ImageSource imageSource, bool fadeIn = true)
public void SetImage(ImageSource image, bool fadeIn = true)
{
Pending = false;
if (fadeIn && FadeDuration > TimeSpan.Zero)
{
var bitmapImage = imageSource as BitmapImage;
var bitmap = image as BitmapImage;
if (bitmapImage?.UriSource != null)
if (bitmap?.UriSource != null)
{
bitmapImage.ImageOpened += BitmapImageOpened;
bitmapImage.ImageFailed += BitmapImageFailed;
bitmap.ImageOpened += BitmapImageOpened;
bitmap.ImageFailed += BitmapImageFailed;
}
else
{
@ -35,25 +35,25 @@ namespace MapControl
Image.Opacity = 1d;
}
Image.Source = imageSource;
Image.Source = image;
}
private void BitmapImageOpened(object sender, RoutedEventArgs e)
{
var bitmapImage = (BitmapImage)sender;
var bitmap = (BitmapImage)sender;
bitmapImage.ImageOpened -= BitmapImageOpened;
bitmapImage.ImageFailed -= BitmapImageFailed;
bitmap.ImageOpened -= BitmapImageOpened;
bitmap.ImageFailed -= BitmapImageFailed;
FadeIn();
}
private void BitmapImageFailed(object sender, ExceptionRoutedEventArgs e)
{
var bitmapImage = (BitmapImage)sender;
var bitmap = (BitmapImage)sender;
bitmapImage.ImageOpened -= BitmapImageOpened;
bitmapImage.ImageFailed -= BitmapImageFailed;
bitmap.ImageOpened -= BitmapImageOpened;
bitmap.ImageFailed -= BitmapImageFailed;
Image.Source = null;
}

View file

@ -27,6 +27,7 @@ namespace MapControl
/// </summary>
public static Caching.IImageCache Cache { get; set; }
private async Task LoadCachedTileImageAsync(Tile tile, Uri uri, string cacheKey)
{
var cacheItem = await Cache.GetAsync(cacheKey).ConfigureAwait(false);
@ -78,7 +79,13 @@ namespace MapControl
{
try
{
tile.SetImage(await loadImageFunc());
var image = await loadImageFunc();
if (image != null)
{
tile.SetImage(image);
}
tcs.SetResult(null);
}
catch (Exception ex)