mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 14:37:01 +00:00
Version 4.2.0
This commit is contained in:
parent
9f8ef8acb0
commit
fd02476c6b
17 changed files with 174 additions and 141 deletions
|
|
@ -61,7 +61,8 @@ namespace MapControl
|
|||
|
||||
try
|
||||
{
|
||||
var document = await XmlDocument.LoadFromUriAsync(new Uri(imageryMetadataUrl + "?output=xml&key=" + ApiKey));
|
||||
var uri = new Uri(imageryMetadataUrl + "?output=xml&key=" + ApiKey);
|
||||
var document = await XmlDocument.LoadFromUriAsync(uri);
|
||||
var imageryMetadata = document.DocumentElement.GetElementsByTagName("ImageryMetadata").OfType<XmlElement>().FirstOrDefault();
|
||||
|
||||
if (imageryMetadata != null)
|
||||
|
|
|
|||
|
|
@ -271,29 +271,25 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
var imageUpdated = false;
|
||||
ImageSource imageSource = null;
|
||||
|
||||
try
|
||||
{
|
||||
imageUpdated = UpdateImage(boundingBox);
|
||||
imageSource = GetImage(boundingBox);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine("MapImageLayer: " + ex.Message);
|
||||
}
|
||||
|
||||
if (!imageUpdated)
|
||||
{
|
||||
UpdateImage((BitmapSource)null);
|
||||
}
|
||||
UpdateImage(imageSource);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an image request Uri or a BitmapSource for the specified image bounding box.
|
||||
/// Must either call UpdateImage(Uri) or UpdateImage(BitmapSource) or return false on failure.
|
||||
/// Returns an ImageSource for the specified bounding box.
|
||||
/// </summary>
|
||||
protected abstract bool UpdateImage(BoundingBox boundingBox);
|
||||
protected abstract ImageSource GetImage(BoundingBox boundingBox);
|
||||
|
||||
private void SetTopImage(ImageSource imageSource)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,16 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
#if WINDOWS_UWP
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
#else
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
|
|
@ -85,6 +94,41 @@ namespace MapControl
|
|||
return getUri?.Invoke(x, y, zoomLevel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load a tile ImageSource asynchronously from GetUri(x, y, zoomLevel)
|
||||
/// </summary>
|
||||
public virtual async Task<ImageSource> LoadImageAsync(int x, int y, int zoomLevel)
|
||||
{
|
||||
ImageSource imageSource = null;
|
||||
|
||||
var uri = GetUri(x, y, zoomLevel);
|
||||
|
||||
if (uri != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!uri.IsAbsoluteUri || uri.Scheme == "file")
|
||||
{
|
||||
imageSource = await LoadLocalImageAsync(uri);
|
||||
}
|
||||
else if (uri.Scheme == "http")
|
||||
{
|
||||
imageSource = await LoadHttpImageAsync(uri);
|
||||
}
|
||||
else
|
||||
{
|
||||
imageSource = new BitmapImage(uri);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine("TileSource: {0}: {1}", uri, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return imageSource;
|
||||
}
|
||||
|
||||
private Uri GetBasicUri(int x, int y, int zoomLevel)
|
||||
{
|
||||
return new Uri(uriFormat
|
||||
|
|
|
|||
|
|
@ -10,9 +10,13 @@ using System.Threading.Tasks;
|
|||
#if WINDOWS_UWP
|
||||
using Windows.Data.Xml.Dom;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Xml;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
#endif
|
||||
|
||||
namespace MapControl
|
||||
|
|
@ -81,25 +85,25 @@ namespace MapControl
|
|||
set { SetValue(TransparentProperty, value); }
|
||||
}
|
||||
|
||||
protected override bool UpdateImage(BoundingBox boundingBox)
|
||||
protected override ImageSource GetImage(BoundingBox boundingBox)
|
||||
{
|
||||
if (ServerUri == null)
|
||||
{
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
var projectionParameters = ParentMap.MapProjection.WmsQueryParameters(boundingBox, Version);
|
||||
|
||||
if (string.IsNullOrEmpty(projectionParameters))
|
||||
{
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
UpdateImage(GetRequestUri("GetMap"
|
||||
var uri = GetRequestUri("GetMap"
|
||||
+ "&LAYERS=" + Layers + "&STYLES=" + Styles + "&FORMAT=" + Format
|
||||
+ "&TRANSPARENT=" + (Transparent ? "TRUE" : "FALSE") + "&" + projectionParameters));
|
||||
+ "&TRANSPARENT=" + (Transparent ? "TRUE" : "FALSE") + "&" + projectionParameters);
|
||||
|
||||
return true;
|
||||
return new BitmapImage(uri);
|
||||
}
|
||||
|
||||
public async Task<IList<string>> GetLayerNamesAsync()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,13 +11,6 @@ namespace MapControl
|
|||
{
|
||||
public partial class MapImageLayer
|
||||
{
|
||||
protected void UpdateImage(Uri uri)
|
||||
{
|
||||
UpdateImage(uri != null
|
||||
? BitmapFrame.Create(uri, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.OnDemand)
|
||||
: null);
|
||||
}
|
||||
|
||||
protected void UpdateImage(ImageSource imageSource)
|
||||
{
|
||||
SetTopImage(imageSource);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ using System.Windows;
|
|||
[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)]
|
||||
|
|
|
|||
|
|
@ -23,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(HttpResponseHeaders responseHeaders)
|
||||
{
|
||||
|
|
@ -32,51 +32,45 @@ namespace MapControl
|
|||
return !responseHeaders.TryGetValues("X-VE-Tile-Info", out tileInfo) || !tileInfo.Contains("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 Task<ImageSource> LoadLocalImageAsync(Uri uri)
|
||||
{
|
||||
ImageSource imageSource = null;
|
||||
|
||||
var uri = GetUri(x, y, zoomLevel);
|
||||
|
||||
if (uri != null)
|
||||
return Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
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 MemoryStream())
|
||||
{
|
||||
await response.Content.CopyToAsync(stream);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
var path = uri.IsAbsoluteUri ? uri.LocalPath : uri.OriginalString;
|
||||
|
||||
imageSource = await Task.Run(() => BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (File.Exists(path))
|
||||
{
|
||||
using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
imageSource = BitmapFrame.Create(uri, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
|
||||
return (ImageSource)BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
protected async Task<ImageSource> LoadHttpImageAsync(Uri uri)
|
||||
{
|
||||
using (var response = await HttpClient.GetAsync(uri))
|
||||
{
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
Debug.WriteLine("TileSource: {0}: {1}", uri, ex.Message);
|
||||
Debug.WriteLine("TileSource: {0}: {1} {2}", uri, (int)response.StatusCode, response.ReasonPhrase);
|
||||
}
|
||||
else if (TileAvailable(response.Headers))
|
||||
{
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
await response.Content.CopyToAsync(stream);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
return await Task.Run(() => BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return imageSource;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue