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

55 lines
1.4 KiB
C#
Raw Normal View History

2025-12-02 15:29:45 +01:00
using System;
namespace MapControl
{
public class UriTileSource : TileSource
{
2025-12-02 16:41:20 +01:00
private string uriFormat;
2025-12-02 15:29:45 +01:00
2025-12-02 16:41:20 +01:00
public string UriTemplate
2025-12-02 15:29:45 +01:00
{
2025-12-27 21:24:01 +01:00
get;
2025-12-02 16:41:20 +01:00
set
2025-12-02 15:29:45 +01:00
{
2025-12-27 21:24:01 +01:00
field = value;
uriFormat = field
2025-12-02 16:41:20 +01:00
.Replace("{z}", "{0}")
.Replace("{x}", "{1}")
.Replace("{y}", "{2}")
.Replace("{s}", "{3}");
2025-12-27 21:24:01 +01:00
if (Subdomains == null && field.Contains("{s}"))
2025-12-02 16:41:20 +01:00
{
Subdomains = ["a", "b", "c"]; // default OpenStreetMap subdomains
}
2025-12-02 15:29:45 +01:00
}
}
public string[] Subdomains { get; set; }
public override Uri GetUri(int zoomLevel, int column, int row)
{
Uri uri = null;
if (uriFormat != null)
{
var uriString = Subdomains?.Length > 0
? string.Format(uriFormat, zoomLevel, column, row, Subdomains[(column + row) % Subdomains.Length])
: string.Format(uriFormat, zoomLevel, column, row);
uri = new Uri(uriString, UriKind.RelativeOrAbsolute);
}
return uri;
}
}
2025-12-02 16:41:20 +01:00
public class TmsTileSource : UriTileSource
2025-12-02 15:29:45 +01:00
{
public override Uri GetUri(int zoomLevel, int column, int row)
{
return base.GetUri(zoomLevel, column, (1 << zoomLevel) - 1 - row);
}
}
}