PageRenderTime 19ms CodeModel.GetById 10ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay.Maps/Servers/Network/OpenStreetMapServer.cs

#
C# | 76 lines | 55 code | 6 blank | 15 comment | 1 complexity | 0f3bde64611ff5936ce89092e3e9c73b MD5 | raw file
 1using System;
 2
 3namespace Microsoft.Research.DynamicDataDisplay.Charts.Maps.Network
 4{
 5	/// <summary>
 6	/// Sample network tile server, which downloads tile images from OpenStreetMap server.
 7	/// <remarks>
 8	/// OpenStreetMap - http://www.openstreetmap.org/
 9	/// Used here by permission of OpenStreetMap.
10	/// To use this sample server in your applications, you should read, agree and follow to
11	/// OpenStreetMap license.
12	/// Do not use this server too much - do not create high load on OpenStreetMap servers.
13	/// OpenStreetMap tile isage policy - http://wiki.openstreetmap.org/wiki/Tile_usage_policy
14	/// </remarks>
15	/// </summary>
16	public sealed class OpenStreetMapServer : NetworkTileServer
17	{
18		/// <summary>
19		/// Initializes a new instance of the <see cref="OpenStreetMapServer"/> class.
20		/// </summary>
21		public OpenStreetMapServer()
22		{
23			UriFormat = "http://{3}.{4}/{0}/{1}/{2}.png";
24			ServerName = "Open Street Maps";
25
26			XCycling = true;
27			MaxLatitude = 85.2878;
28			MinLevel = 0;
29			MaxLevel = 17;
30			MaxConcurrentDownloads = 3;
31			ServersNum = 3;
32			//todo determine max level
33		}
34
35		private OpenStreetMapRenderer renderer = OpenStreetMapRenderer.Mapnik;
36		public OpenStreetMapRenderer Renderer
37		{
38			get { return renderer; }
39			set
40			{
41				renderer = value;
42				RaiseChangedEvent();
43			}
44		}
45		
46		protected override string CreateRequestUriCore(TileIndex index)
47		{
48			int z = (int)index.Level;
49			int shift = MapTileProvider.GetSideTilesCount(z) / 2;
50			int x = index.X + shift;
51			int y = MapTileProvider.GetSideTilesCount(z) - 1 - index.Y - shift;
52
53			char serverIdx = (char)('a' + CurrentServer);
54			string uri = "";
55			switch (renderer)
56			{
57				case OpenStreetMapRenderer.Mapnik:
58					uri = "tile.openstreetmap.org";
59					break;
60				case OpenStreetMapRenderer.Osmarenderer:
61					uri = "tah.openstreetmap.org/Tiles/tile";
62					break;
63				case OpenStreetMapRenderer.CycleMap:
64					uri = "andy.sandbox.cloudmade.com/tiles/cycle";
65					break;
66				case OpenStreetMapRenderer.NoName:
67					uri = "tile.cloudmade.com/fd093e52f0965d46bb1c6c6281022199/3/256";
68					break;
69				default:
70					break;
71			}
72
73			return String.Format(UriFormat, z.ToString(), x.ToString(), y.ToString(), serverIdx.ToString(), uri);
74		}
75	}
76}