mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Removed Bing Maps support
This commit is contained in:
parent
2194f08a74
commit
321f5a9855
|
|
@ -1,113 +0,0 @@
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
#if WPF
|
|
||||||
using System.Windows;
|
|
||||||
#elif UWP
|
|
||||||
using Windows.UI.Xaml;
|
|
||||||
#elif WINUI
|
|
||||||
using Microsoft.UI.Xaml;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace MapControl
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Displays Bing Maps tiles. The static ApiKey property must be set to a Bing Maps API Key.
|
|
||||||
/// Tile image URLs and min/max zoom levels are retrieved from the Imagery Metadata Service
|
|
||||||
/// (see http://msdn.microsoft.com/en-us/library/ff701716.aspx).
|
|
||||||
/// </summary>
|
|
||||||
public class BingMapsTileLayer : MapTileLayer
|
|
||||||
{
|
|
||||||
public enum MapMode
|
|
||||||
{
|
|
||||||
Road, Aerial, AerialWithLabels
|
|
||||||
}
|
|
||||||
|
|
||||||
public BingMapsTileLayer()
|
|
||||||
{
|
|
||||||
MinZoomLevel = 1;
|
|
||||||
MaxZoomLevel = 21;
|
|
||||||
Loaded += OnLoaded;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string ApiKey { get; set; }
|
|
||||||
|
|
||||||
public MapMode Mode { get; set; }
|
|
||||||
public string Culture { get; set; }
|
|
||||||
public Uri LogoImageUri { get; private set; }
|
|
||||||
|
|
||||||
private async void OnLoaded(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
Loaded -= OnLoaded;
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(ApiKey))
|
|
||||||
{
|
|
||||||
var metadataUri = $"https://dev.virtualearth.net/REST/V1/Imagery/Metadata/{Mode}?output=xml&key={ApiKey}";
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var stream = await ImageLoader.HttpClient.GetStreamAsync(metadataUri))
|
|
||||||
{
|
|
||||||
ReadImageryMetadata(XDocument.Load(stream).Root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
ImageLoader.LoggerFactory?.CreateLogger<BingMapsTileLayer>()?.LogError(ex, "Failed loading metadata from {uri}", metadataUri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ImageLoader.LoggerFactory?.CreateLogger<BingMapsTileLayer>()?.LogError("Bing Maps API key required");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ReadImageryMetadata(XElement metadataResponse)
|
|
||||||
{
|
|
||||||
var ns = metadataResponse.Name.Namespace;
|
|
||||||
var metadata = metadataResponse.Descendants(ns + "ImageryMetadata").FirstOrDefault();
|
|
||||||
|
|
||||||
if (metadata != null)
|
|
||||||
{
|
|
||||||
var imageUrl = metadata.Element(ns + "ImageUrl")?.Value;
|
|
||||||
var subdomains = metadata.Element(ns + "ImageUrlSubdomains")?.Elements(ns + "string").Select(e => e.Value).ToArray();
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(imageUrl) && subdomains != null && subdomains.Length > 0)
|
|
||||||
{
|
|
||||||
var zoomMin = metadata.Element(ns + "ZoomMin")?.Value;
|
|
||||||
var zoomMax = metadata.Element(ns + "ZoomMax")?.Value;
|
|
||||||
|
|
||||||
if (zoomMin != null && int.TryParse(zoomMin, out int zoomLevel) && MinZoomLevel < zoomLevel)
|
|
||||||
{
|
|
||||||
MinZoomLevel = zoomLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (zoomMax != null && int.TryParse(zoomMax, out zoomLevel) && MaxZoomLevel > zoomLevel)
|
|
||||||
{
|
|
||||||
MaxZoomLevel = zoomLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(Culture))
|
|
||||||
{
|
|
||||||
Culture = CultureInfo.CurrentUICulture.Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
TileSource = new BingMapsTileSource
|
|
||||||
{
|
|
||||||
UriTemplate = imageUrl.Replace("{culture}", Culture),
|
|
||||||
Subdomains = subdomains
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var logoUri = metadataResponse.Element(ns + "BrandLogoUri");
|
|
||||||
|
|
||||||
if (logoUri != null)
|
|
||||||
{
|
|
||||||
LogoImageUri = new Uri(logoUri.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace MapControl
|
|
||||||
{
|
|
||||||
public class BingMapsTileSource : TileSource
|
|
||||||
{
|
|
||||||
public override Uri GetUri(int column, int row, int zoomLevel)
|
|
||||||
{
|
|
||||||
Uri uri = null;
|
|
||||||
|
|
||||||
if (UriTemplate != null && Subdomains != null && Subdomains.Length > 0 && zoomLevel > 0)
|
|
||||||
{
|
|
||||||
var subdomain = Subdomains[(column + row) % Subdomains.Length];
|
|
||||||
var quadkey = new char[zoomLevel];
|
|
||||||
|
|
||||||
for (var z = zoomLevel - 1; z >= 0; z--, column /= 2, row /= 2)
|
|
||||||
{
|
|
||||||
quadkey[z] = (char)('0' + 2 * (row % 2) + (column % 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
uri = new Uri(UriTemplate
|
|
||||||
.Replace("{subdomain}", subdomain)
|
|
||||||
.Replace("{quadkey}", new string(quadkey)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return uri;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#if WPF
|
#if WPF
|
||||||
|
|
@ -99,23 +97,15 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
if (responseMessage.IsSuccessStatusCode)
|
if (responseMessage.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
byte[] buffer = null;
|
byte[] buffer;
|
||||||
|
|
||||||
// Check for possibly unavailable Bing Maps tile.
|
if (progress != null && responseMessage.Content.Headers.ContentLength.HasValue)
|
||||||
//
|
|
||||||
if (!responseMessage.Headers.TryGetValues("X-VE-Tile-Info", out IEnumerable<string> tileInfo) ||
|
|
||||||
!tileInfo.Contains("no-tile"))
|
|
||||||
{
|
{
|
||||||
var content = responseMessage.Content;
|
buffer = await ReadAsByteArray(responseMessage.Content, progress).ConfigureAwait(false);
|
||||||
|
|
||||||
if (progress != null && content.Headers.ContentLength.HasValue)
|
|
||||||
{
|
|
||||||
buffer = await ReadAsByteArray(content, progress).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buffer = await content.ReadAsByteArrayAsync().ConfigureAwait(false);
|
buffer = await responseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response = new HttpResponse(buffer, responseMessage.Headers.CacheControl?.MaxAge);
|
response = new HttpResponse(buffer, responseMessage.Headers.CacheControl?.MaxAge);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue