Repository navigation
Expand file tree
/
Copy pathTiandituTileSource.cs
More file actions
60 lines (52 loc) · 1.79 KB
/
Copy pathTiandituTileSource.cs
File metadata and controls
60 lines (52 loc) · 1.79 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Globalization;
using WPFDevelopers.Controls;
namespace WPFDevelopers.Samples.ExampleViews
{
public sealed class TiandituTileSource : MapTileSource
{
private readonly string _layer;
private readonly int _serverIndex;
private readonly string _token;
public TiandituTileSource(string layer = "vec_c", int serverIndex = 0, string token = "")
{
_layer = string.IsNullOrWhiteSpace(layer) ? "vec_c" : layer;
_serverIndex = serverIndex;
_token = token ?? string.Empty;
}
public string Layer
{
get { return _layer; }
}
public string Token
{
get { return _token; }
}
public override Uri GetTileUri(int x, int y, int zoomLevel)
{
if (string.IsNullOrWhiteSpace(_layer) || string.IsNullOrWhiteSpace(_token))
{
return null;
}
var server = _serverIndex % 4;
var wmtsLayer = _layer;
var underscoreIndex = wmtsLayer.IndexOf('_');
if (underscoreIndex >= 0)
{
wmtsLayer = wmtsLayer.Substring(0, underscoreIndex);
}
var tokenQuery = "&tk=" + Uri.EscapeDataString(_token);
var url = string.Format(
CultureInfo.InvariantCulture,
"https://t{0}.tianditu.gov.cn/{1}/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER={2}&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILECOL={3}&TILEROW={4}&TILEMATRIX={5}{6}",
server,
_layer,
wmtsLayer,
x,
y,
zoomLevel,
tokenQuery);
return new Uri(url, UriKind.Absolute);
}
}
}