-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tms.cs
38 lines (33 loc) · 1.1 KB
/
Tms.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Net;
using System.Text.RegularExpressions;
namespace RiverTrace
{
class Tms : ImageSource
{
private string tileUrl;
private WebClient wc;
public Tms(string tileUrl)
{
this.tileUrl = tileUrl;
Match match = Regex.Match(tileUrl, "\\{switch:(([^,}]),?)+}");
if (match.Success)
{
var capt = match.Groups[2].Captures;
this.tileUrl = tileUrl.Replace(match.Value,
capt[new Random().Next(capt.Count)].Value);
}
wc = new WebClient();
}
public byte[] GetTile(int tileIndexX, int tileIndexY, int zoom)
{
string finalUrl = tileUrl.
Replace("{x}", tileIndexX.ToString()).
Replace("{y}", tileIndexY.ToString()).
Replace("{-y}", ((1 << zoom) - tileIndexY - 1).ToString()).
Replace("{zoom}", zoom.ToString());
byte[] data = wc.DownloadData(finalUrl);
return data;
}
}
}