2017-06-25 23:05:48 +02:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2019-03-27 18:39:59 +01:00
|
|
|
|
// © 2019 Clemens Fischer
|
2014-10-19 21:50:23 +02:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
2017-08-04 21:38:58 +02:00
|
|
|
|
public class BingMapsTileSource : TileSource
|
2014-10-19 21:50:23 +02:00
|
|
|
|
{
|
2015-11-28 21:09:25 +01:00
|
|
|
|
private readonly string[] subdomains;
|
2014-10-19 21:50:23 +02:00
|
|
|
|
|
|
|
|
|
|
public BingMapsTileSource(string uriFormat, string[] subdomains)
|
|
|
|
|
|
: base(uriFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.subdomains = subdomains;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Uri GetUri(int x, int y, int zoomLevel)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (zoomLevel < 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var subdomain = subdomains[(x + y) % subdomains.Length];
|
|
|
|
|
|
var quadkey = new char[zoomLevel];
|
|
|
|
|
|
|
|
|
|
|
|
for (var z = zoomLevel - 1; z >= 0; z--, x /= 2, y /= 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
quadkey[z] = (char)('0' + 2 * (y % 2) + (x % 2));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-09 20:04:44 +02:00
|
|
|
|
return new Uri(UriFormat
|
|
|
|
|
|
.Replace("{subdomain}", subdomain)
|
|
|
|
|
|
.Replace("{quadkey}", new string(quadkey)));
|
2014-10-19 21:50:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|