mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Version 4.10.0: Updated target framework versions. Cleanup of TypeConverters, ImageLoader, MBTileSource.
This commit is contained in:
parent
acf43d70ea
commit
1359cea83c
|
|
@ -28,17 +28,24 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
ImageSource imageSource = null;
|
ImageSource imageSource = null;
|
||||||
|
|
||||||
if (!uri.IsAbsoluteUri || uri.Scheme == "file")
|
try
|
||||||
{
|
{
|
||||||
imageSource = await LoadLocalImageAsync(uri);
|
if (!uri.IsAbsoluteUri || uri.Scheme == "file")
|
||||||
|
{
|
||||||
|
imageSource = await LoadLocalImageAsync(uri);
|
||||||
|
}
|
||||||
|
else if (uri.Scheme == "http")
|
||||||
|
{
|
||||||
|
imageSource = await LoadHttpImageAsync(uri);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
imageSource = new BitmapImage(uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (uri.Scheme == "http")
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
imageSource = await LoadHttpImageAsync(uri);
|
Debug.WriteLine("ImageLoader: {0}: {1}", uri, ex.Message);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
imageSource = new BitmapImage(uri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return imageSource;
|
return imageSource;
|
||||||
|
|
@ -48,19 +55,26 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
ImageSource imageSource = null;
|
ImageSource imageSource = null;
|
||||||
|
|
||||||
using (var response = await HttpClient.GetAsync(uri))
|
try
|
||||||
{
|
{
|
||||||
if (!response.IsSuccessStatusCode)
|
using (var response = await HttpClient.GetAsync(uri))
|
||||||
{
|
{
|
||||||
Debug.WriteLine("ImageLoader: {0}: {1} {2}", uri, (int)response.StatusCode, response.ReasonPhrase);
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("ImageLoader: {0}: {1} {2}", uri, (int)response.StatusCode, response.ReasonPhrase);
|
||||||
|
}
|
||||||
|
else if (IsTileAvailable(response.Headers))
|
||||||
|
{
|
||||||
|
imageSource = await CreateImageSourceAsync(response.Content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (IsTileAvailable(response.Headers))
|
|
||||||
{
|
|
||||||
imageSource = await CreateImageSourceAsync(response.Content);
|
|
||||||
}
|
|
||||||
|
|
||||||
return imageSource;
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("ImageLoader: {0}: {1}", uri, ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#if WINDOWS_UWP
|
#if WINDOWS_UWP
|
||||||
|
|
@ -112,19 +111,11 @@ namespace MapControl
|
||||||
public virtual async Task<ImageSource> LoadImageAsync(int x, int y, int zoomLevel)
|
public virtual async Task<ImageSource> LoadImageAsync(int x, int y, int zoomLevel)
|
||||||
{
|
{
|
||||||
ImageSource imageSource = null;
|
ImageSource imageSource = null;
|
||||||
|
|
||||||
var uri = GetUri(x, y, zoomLevel);
|
var uri = GetUri(x, y, zoomLevel);
|
||||||
|
|
||||||
if (uri != null)
|
if (uri != null)
|
||||||
{
|
{
|
||||||
try
|
imageSource = await ImageLoader.LoadImageAsync(uri);
|
||||||
{
|
|
||||||
imageSource = await ImageLoader.LoadImageAsync(uri);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Debug.WriteLine("TileSource: {0}: {1}", uri, ex.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return imageSource;
|
return imageSource;
|
||||||
|
|
|
||||||
|
|
@ -124,14 +124,7 @@ namespace MapControl
|
||||||
uri += "&FORMAT=" + Format;
|
uri += "&FORMAT=" + Format;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
imageSource = await ImageLoader.LoadImageAsync(new Uri(uri.Replace(" ", "%20")));
|
||||||
{
|
|
||||||
imageSource = await ImageLoader.LoadImageAsync(new Uri(uri.Replace(" ", "%20")));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Debug.WriteLine("WmsImageLayer: {0}: {1}", uri, ex.Message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return imageSource;
|
return imageSource;
|
||||||
|
|
|
||||||
|
|
@ -20,17 +20,25 @@ namespace MapControl
|
||||||
public static async Task<ImageSource> LoadLocalImageAsync(Uri uri)
|
public static async Task<ImageSource> LoadLocalImageAsync(Uri uri)
|
||||||
{
|
{
|
||||||
ImageSource imageSource = null;
|
ImageSource imageSource = null;
|
||||||
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
|
|
||||||
|
|
||||||
if (File.Exists(path))
|
try
|
||||||
{
|
{
|
||||||
var file = await StorageFile.GetFileFromPathAsync(path);
|
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
|
||||||
|
|
||||||
using (var stream = await file.OpenReadAsync())
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
imageSource = await CreateImageSourceAsync(stream);
|
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;
|
return imageSource;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,12 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public static partial class ImageLoader
|
public static partial class ImageLoader
|
||||||
{
|
{
|
||||||
public static Task<ImageSource> LoadLocalImageAsync(Uri uri)
|
public static ImageSource LoadLocalImage(Uri uri)
|
||||||
{
|
{
|
||||||
return Task.Run(() =>
|
ImageSource imageSource = null;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
ImageSource imageSource = null;
|
|
||||||
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
|
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
|
||||||
|
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
|
|
@ -31,9 +32,18 @@ namespace MapControl
|
||||||
imageSource = CreateImageSource(stream);
|
imageSource = CreateImageSource(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("ImageLoader: {0}: {1}", uri, ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
return imageSource;
|
return imageSource;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
public static Task<ImageSource> LoadLocalImageAsync(Uri uri)
|
||||||
|
{
|
||||||
|
return Task.Run(() => LoadLocalImage(uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<Tuple<MemoryStream, TimeSpan?>> LoadHttpStreamAsync(Uri uri)
|
public static async Task<Tuple<MemoryStream, TimeSpan?>> LoadHttpStreamAsync(Uri uri)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue