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

30 lines
866 B
C#
Raw Normal View History

2025-02-27 18:46:32 +01:00
using System;
namespace MapControl
{
2017-08-04 21:38:58 +02:00
public class BingMapsTileSource : TileSource
{
2022-11-22 19:15:34 +01:00
public override Uri GetUri(int column, int row, int zoomLevel)
{
2020-10-23 23:35:48 +02:00
Uri uri = null;
if (UriTemplate != null && Subdomains != null && Subdomains.Length > 0 && zoomLevel > 0)
{
2022-11-22 19:15:34 +01:00
var subdomain = Subdomains[(column + row) % Subdomains.Length];
2020-10-23 23:35:48 +02:00
var quadkey = new char[zoomLevel];
2022-11-22 19:15:34 +01:00
for (var z = zoomLevel - 1; z >= 0; z--, column /= 2, row /= 2)
2020-10-23 23:35:48 +02:00
{
2022-11-22 19:15:34 +01:00
quadkey[z] = (char)('0' + 2 * (row % 2) + (column % 2));
2020-10-23 23:35:48 +02:00
}
uri = new Uri(UriTemplate
2020-10-23 23:35:48 +02:00
.Replace("{subdomain}", subdomain)
.Replace("{quadkey}", new string(quadkey)));
}
2020-10-23 23:35:48 +02:00
return uri;
}
}
}