mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 22:46:58 +00:00
Version 4.12.2 Fixed local file handling for UWP. All relative paths relative to ms-appx:
This commit is contained in:
parent
26bf0b5005
commit
c28387f87c
14 changed files with 172 additions and 192 deletions
|
|
@ -28,11 +28,6 @@ namespace MapControl
|
|||
return bitmapImage;
|
||||
}
|
||||
|
||||
public static Task<ImageSource> LoadImageAsync(Stream stream)
|
||||
{
|
||||
return Task.Run(() => LoadImage(stream));
|
||||
}
|
||||
|
||||
public static ImageSource LoadImage(byte[] buffer)
|
||||
{
|
||||
using (var stream = new MemoryStream(buffer))
|
||||
|
|
@ -41,26 +36,9 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
public static Task<ImageSource> LoadImageAsync(byte[] buffer)
|
||||
{
|
||||
return Task.Run(() => LoadImage(buffer));
|
||||
}
|
||||
|
||||
private static async Task<ImageSource> LoadImageAsync(HttpContent content)
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
await content.CopyToAsync(stream);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
return await LoadImageAsync(stream);
|
||||
}
|
||||
}
|
||||
|
||||
private static ImageSource LoadLocalImage(Uri uri)
|
||||
public static ImageSource LoadImage(string path)
|
||||
{
|
||||
ImageSource image = null;
|
||||
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
|
|
@ -73,9 +51,30 @@ namespace MapControl
|
|||
return image;
|
||||
}
|
||||
|
||||
private static Task<ImageSource> LoadLocalImageAsync(Uri uri)
|
||||
public static Task<ImageSource> LoadImageAsync(Stream stream)
|
||||
{
|
||||
return Task.Run(() => LoadLocalImage(uri));
|
||||
return Task.Run(() => LoadImage(stream));
|
||||
}
|
||||
|
||||
public static Task<ImageSource> LoadImageAsync(byte[] buffer)
|
||||
{
|
||||
return Task.Run(() => LoadImage(buffer));
|
||||
}
|
||||
|
||||
public static Task<ImageSource> LoadImageAsync(string path)
|
||||
{
|
||||
return Task.Run(() => LoadImage(path));
|
||||
}
|
||||
|
||||
private static async Task<ImageSource> LoadImageAsync(HttpContent content)
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
await content.CopyToAsync(stream);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
return LoadImage(stream);
|
||||
}
|
||||
}
|
||||
|
||||
internal class HttpStreamResponse
|
||||
|
|
@ -96,7 +95,7 @@ namespace MapControl
|
|||
|
||||
try
|
||||
{
|
||||
using (var responseMessage = await HttpClient.GetAsync(uri))
|
||||
using (var responseMessage = await HttpClient.GetAsync(uri).ConfigureAwait(false))
|
||||
{
|
||||
if (responseMessage.IsSuccessStatusCode)
|
||||
{
|
||||
|
|
@ -106,7 +105,7 @@ namespace MapControl
|
|||
if (ImageAvailable(responseMessage.Headers))
|
||||
{
|
||||
stream = new MemoryStream();
|
||||
await responseMessage.Content.CopyToAsync(stream);
|
||||
await responseMessage.Content.CopyToAsync(stream).ConfigureAwait(false);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
maxAge = responseMessage.Headers.CacheControl?.MaxAge;
|
||||
|
|
|
|||
|
|
@ -11,18 +11,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 bitmapSource = imageSource as BitmapSource;
|
||||
var bitmap = image as BitmapSource;
|
||||
|
||||
if (bitmapSource != null && !bitmapSource.IsFrozen && bitmapSource.IsDownloading)
|
||||
if (bitmap != null && !bitmap.IsFrozen && bitmap.IsDownloading)
|
||||
{
|
||||
bitmapSource.DownloadCompleted += BitmapDownloadCompleted;
|
||||
bitmapSource.DownloadFailed += BitmapDownloadFailed;
|
||||
bitmap.DownloadCompleted += BitmapDownloadCompleted;
|
||||
bitmap.DownloadFailed += BitmapDownloadFailed;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -34,25 +34,25 @@ namespace MapControl
|
|||
Image.Opacity = 1d;
|
||||
}
|
||||
|
||||
Image.Source = imageSource;
|
||||
Image.Source = image;
|
||||
}
|
||||
|
||||
private void BitmapDownloadCompleted(object sender, EventArgs e)
|
||||
{
|
||||
var bitmapSource = (BitmapSource)sender;
|
||||
var bitmap = (BitmapSource)sender;
|
||||
|
||||
bitmapSource.DownloadCompleted -= BitmapDownloadCompleted;
|
||||
bitmapSource.DownloadFailed -= BitmapDownloadFailed;
|
||||
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
|
||||
bitmap.DownloadFailed -= BitmapDownloadFailed;
|
||||
|
||||
FadeIn();
|
||||
}
|
||||
|
||||
private void BitmapDownloadFailed(object sender, ExceptionEventArgs e)
|
||||
{
|
||||
var bitmapSource = (BitmapSource)sender;
|
||||
var bitmap = (BitmapSource)sender;
|
||||
|
||||
bitmapSource.DownloadCompleted -= BitmapDownloadCompleted;
|
||||
bitmapSource.DownloadFailed -= BitmapDownloadFailed;
|
||||
bitmap.DownloadCompleted -= BitmapDownloadCompleted;
|
||||
bitmap.DownloadFailed -= BitmapDownloadFailed;
|
||||
|
||||
Image.Source = null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,10 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public static ObjectCache Cache { get; set; } = MemoryCache.Default;
|
||||
|
||||
|
||||
private async Task LoadCachedTileImageAsync(Tile tile, Uri uri, string cacheKey)
|
||||
{
|
||||
ImageSource image = null;
|
||||
DateTime expiration;
|
||||
var cacheBuffer = GetCachedImage(cacheKey, out expiration);
|
||||
|
||||
|
|
@ -44,7 +46,7 @@ namespace MapControl
|
|||
{
|
||||
using (var stream = response.Stream)
|
||||
{
|
||||
LoadTileImage(tile, stream);
|
||||
image = ImageLoader.LoadImage(stream);
|
||||
SetCachedImage(cacheKey, stream, GetExpiration(response.MaxAge));
|
||||
}
|
||||
}
|
||||
|
|
@ -53,26 +55,28 @@ namespace MapControl
|
|||
|
||||
if (cacheBuffer != null) // cached image not expired or download failed
|
||||
{
|
||||
using (var stream = new MemoryStream(cacheBuffer))
|
||||
{
|
||||
LoadTileImage(tile, stream);
|
||||
}
|
||||
image = ImageLoader.LoadImage(cacheBuffer);
|
||||
}
|
||||
|
||||
if (image != null)
|
||||
{
|
||||
SetTileImage(tile, image);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadTileImageAsync(Tile tile, TileSource tileSource)
|
||||
{
|
||||
SetTileImage(tile, await tileSource.LoadImageAsync(tile.XIndex, tile.Y, tile.ZoomLevel).ConfigureAwait(false));
|
||||
var image = await tileSource.LoadImageAsync(tile.XIndex, tile.Y, tile.ZoomLevel).ConfigureAwait(false);
|
||||
|
||||
if (image != null)
|
||||
{
|
||||
SetTileImage(tile, image);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadTileImage(Tile tile, Stream stream)
|
||||
private void SetTileImage(Tile tile, ImageSource image)
|
||||
{
|
||||
SetTileImage(tile, ImageLoader.LoadImage(stream));
|
||||
}
|
||||
|
||||
private void SetTileImage(Tile tile, ImageSource imageSource)
|
||||
{
|
||||
tile.Image.Dispatcher.InvokeAsync(() => tile.SetImage(imageSource));
|
||||
tile.Image.Dispatcher.InvokeAsync(() => tile.SetImage(image));
|
||||
}
|
||||
|
||||
private static byte[] GetCachedImage(string cacheKey, out DateTime expiration)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue