mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 14:08:32 +00:00
Version 4.2.0
This commit is contained in:
parent
9f8ef8acb0
commit
fd02476c6b
17 changed files with 174 additions and 141 deletions
|
|
@ -2,7 +2,6 @@
|
|||
// © 2017 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
|
@ -12,11 +11,6 @@ namespace MapControl
|
|||
{
|
||||
public partial class MapImageLayer
|
||||
{
|
||||
protected void UpdateImage(Uri uri)
|
||||
{
|
||||
UpdateImage(uri != null ? new BitmapImage(uri) : null);
|
||||
}
|
||||
|
||||
protected void UpdateImage(ImageSource imageSource)
|
||||
{
|
||||
SetTopImage(imageSource);
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyCompany("Clemens Fischer")]
|
||||
[assembly: AssemblyCopyright("© 2017 Clemens Fischer")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyVersion("4.1.0")]
|
||||
[assembly: AssemblyFileVersion("4.1.0")]
|
||||
[assembly: AssemblyVersion("4.2.0")]
|
||||
[assembly: AssemblyFileVersion("4.2.0")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@
|
|||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Streams;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
|
@ -21,7 +23,7 @@ namespace MapControl
|
|||
public static HttpClient HttpClient { get; set; } = new HttpClient();
|
||||
|
||||
/// <summary>
|
||||
/// Check HTTP response headers for tile unavailability, e.g. X-VE-Tile-Info=no-tile
|
||||
/// Check HTTP response headers for tile availability, e.g. X-VE-Tile-Info=no-tile
|
||||
/// </summary>
|
||||
public static bool TileAvailable(HttpResponseHeaderCollection responseHeaders)
|
||||
{
|
||||
|
|
@ -30,54 +32,50 @@ namespace MapControl
|
|||
return !responseHeaders.TryGetValue("X-VE-Tile-Info", out tileInfo) || tileInfo != "no-tile";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load a tile ImageSource asynchronously from GetUri(x, y, zoomLevel)
|
||||
/// </summary>
|
||||
public virtual async Task<ImageSource> LoadImageAsync(int x, int y, int zoomLevel)
|
||||
protected async Task<ImageSource> LoadLocalImageAsync(Uri uri)
|
||||
{
|
||||
ImageSource imageSource = null;
|
||||
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
|
||||
|
||||
var uri = GetUri(x, y, zoomLevel);
|
||||
|
||||
if (uri != null)
|
||||
if (!await Task.Run(() => File.Exists(path)))
|
||||
{
|
||||
try
|
||||
return null;
|
||||
}
|
||||
|
||||
var file = await StorageFile.GetFileFromPathAsync(path);
|
||||
|
||||
using (var stream = await file.OpenReadAsync())
|
||||
{
|
||||
var bitmapImage = new BitmapImage();
|
||||
await bitmapImage.SetSourceAsync(stream);
|
||||
|
||||
return bitmapImage;
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task<ImageSource> LoadHttpImageAsync(Uri uri)
|
||||
{
|
||||
using (var response = await HttpClient.GetAsync(uri))
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
if (uri.Scheme == "http")
|
||||
{
|
||||
using (var response = await HttpClient.GetAsync(uri))
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
Debug.WriteLine("TileSource: {0}: {1} {2}", uri, (int)response.StatusCode, response.ReasonPhrase);
|
||||
}
|
||||
else if (TileAvailable(response.Headers))
|
||||
{
|
||||
using (var stream = new InMemoryRandomAccessStream())
|
||||
{
|
||||
await response.Content.WriteToStreamAsync(stream);
|
||||
stream.Seek(0);
|
||||
|
||||
var bitmapImage = new BitmapImage();
|
||||
await bitmapImage.SetSourceAsync(stream);
|
||||
|
||||
imageSource = bitmapImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
imageSource = new BitmapImage(uri);
|
||||
}
|
||||
Debug.WriteLine("TileSource: {0}: {1} {2}", uri, (int)response.StatusCode, response.ReasonPhrase);
|
||||
}
|
||||
catch (Exception ex)
|
||||
else if (TileAvailable(response.Headers))
|
||||
{
|
||||
Debug.WriteLine("TileSource: {0}: {1}", uri, ex.Message);
|
||||
using (var stream = new InMemoryRandomAccessStream())
|
||||
{
|
||||
await response.Content.WriteToStreamAsync(stream);
|
||||
stream.Seek(0);
|
||||
|
||||
var bitmapImage = new BitmapImage();
|
||||
await bitmapImage.SetSourceAsync(stream);
|
||||
|
||||
return bitmapImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return imageSource;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue