mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-05 06:26:41 +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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue