mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-08 16:05:50 +00:00
Updated TileSources
This commit is contained in:
parent
44d48eadde
commit
1222a4a8c2
5 changed files with 61 additions and 148 deletions
49
MapControl/Shared/UriTileSource.cs
Normal file
49
MapControl/Shared/UriTileSource.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public class UriTileSource : TileSource
|
||||
{
|
||||
private readonly string uriFormat;
|
||||
|
||||
public UriTileSource(string uriTemplate)
|
||||
{
|
||||
uriFormat = uriTemplate
|
||||
.Replace("{z}", "{0}")
|
||||
.Replace("{x}", "{1}")
|
||||
.Replace("{y}", "{2}")
|
||||
.Replace("{s}", "{3}");
|
||||
|
||||
if (Subdomains == null && uriTemplate.Contains("{s}"))
|
||||
{
|
||||
Subdomains = ["a", "b", "c"]; // default OpenStreetMap subdomains
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public class TmsTileSource(string uriTemplate) : UriTileSource(uriTemplate)
|
||||
{
|
||||
public override Uri GetUri(int zoomLevel, int column, int row)
|
||||
{
|
||||
return base.GetUri(zoomLevel, column, (1 << zoomLevel) - 1 - row);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue