public override string GetTileUrl(int level, int row, int col)
{
// Select a subdomain based on level/row/column so that it will always
// be the same for a specific tile. Multiple subdomains allows the user
// to load more tiles simultaneously. To take advantage of the browser cache
// the following expression also makes sure that a specific tile will always
// hit the same subdomain.
if (level + col + row < 0 || _templateUrl == null) return null;
string levelValue = null;
if (LevelValues != null && LevelValues.Length > level)
levelValue = LevelValues[level];
if (string.IsNullOrEmpty(levelValue))
levelValue = level.ToString(CultureInfo.InvariantCulture);
string subDomain = _subDomains != null && _subDomains.Length > 0
? _subDomains[(level + col + row)%_subDomains.Length]
: null;
string url = _templateUrl.Replace("{level}", levelValue)
.Replace("{row}", row.ToString(CultureInfo.InvariantCulture))
.Replace("{col}", col.ToString(CultureInfo.InvariantCulture));
if (subDomain != null)
url = url.Replace("{subDomain}", subDomain);
return url;
}