XAML-Map-Control/MapControl/Shared/BingMapsTileSource.cs

35 lines
1 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2022-01-14 20:22:56 +01:00
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
namespace MapControl
{
2017-08-04 21:38:58 +02:00
public class BingMapsTileSource : TileSource
{
public override Uri GetUri(int x, int y, int zoomLevel)
{
2020-10-23 23:35:48 +02:00
Uri uri = null;
2022-08-19 08:38:48 +02:00
if (UriFormat != null && Subdomains != null && Subdomains.Length > 0 &&
x >= 0 && y >= 0 && zoomLevel > 0)
{
2020-10-23 23:35:48 +02:00
var subdomain = Subdomains[(x + y) % Subdomains.Length];
var quadkey = new char[zoomLevel];
2020-10-23 23:35:48 +02:00
for (var z = zoomLevel - 1; z >= 0; z--, x /= 2, y /= 2)
{
quadkey[z] = (char)('0' + 2 * (y % 2) + (x % 2));
}
2020-10-23 23:35:48 +02:00
uri = new Uri(UriFormat
.Replace("{subdomain}", subdomain)
.Replace("{quadkey}", new string(quadkey)));
}
2020-10-23 23:35:48 +02:00
return uri;
}
}
}