コード例 #1
0
		MapTile CheckTileInMemory(int m, int n, int level)
		{
			string key	= string.Format(ShortName + "{0:00}{1:0000}{2:0000}", level, m, n);
			string path = @"cache\" + Name + @"\" + key + ".jpg";

			if (!RamCache.ContainsKey(key)) {
				MapTile ct = new MapTile {
						Path		= path, 
						Url			= GenerateUrl(m, n, level), 
						LruIndex	= 0,
						Tile		= EmptyTile,
						X			= m,
						Y			= n,
						Zoom		= level
					};

				RamCache.Add(key, ct);

				cacheQueue.Enqueue(ct);
			}

			if (tileStreamingTask == null && !isDisposed) {
				tileStreamingTask = Task.Run(() => TileStreamingThreadFunc(killToken.Token), killToken.Token);
			}

			RamCache[key].LruIndex	= level;
			RamCache[key].Time		= 0.0f;

			return RamCache[key];
		}
コード例 #2
0
		public bool DownloadTile(MapTile tile)
		{
			try {
				var request = (HttpWebRequest) WebRequest.Create(tile.Url);
				
				request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvailable);
				request.Timeout				= TimeoutMs;
				request.UserAgent			= UserAgent;
				request.ReadWriteTimeout	= TimeoutMs * 6;
				request.Accept				= requestAccept;
				request.Referer				= RefererUrl;
				
				HttpWebResponse response = (HttpWebResponse) request.GetResponse();
				
				if (!Directory.Exists(@"cache\" + Name)) {
					Directory.CreateDirectory(@"cache\" + Name);
				}
				
				System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(response.GetResponseStream());
				bitmap.Save(tile.Path, System.Drawing.Imaging.ImageFormat.Jpeg);
				return true;
			} catch (Exception e) {
				Log.Warning(e.Message);
				return false;
			}
		}