PureImage PureImageCache.GetImageFromCache(int type, GPoint pos, int zoom) { PureImage ret = null; try { string file = CacheLocation + Path.DirectorySeparatorChar + GMapProviders.TryGetProvider(type).Name + Path.DirectorySeparatorChar + zoom + Path.DirectorySeparatorChar + pos.Y + Path.DirectorySeparatorChar + pos.X + ".jpg"; if (File.Exists(file)) { using (BinaryReader sr = new BinaryReader(File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))) { byte[] tile = sr.ReadBytes((int)sr.BaseStream.Length); MemoryStream stm = new MemoryStream(tile, 0, tile.Length, false, true); ret = GMapImageProxy.Instance.FromStream(stm); if (ret != null) { ret.Data = stm; } } } } catch (Exception ex) { #if MONO Console.WriteLine("GetImageFromCache: " + ex.ToString()); #endif Debug.WriteLine("GetImageFromCache: " + ex.ToString()); ret = null; } return(ret); }
bool PureImageCache.PutImageToCache(byte[] tile, int type, GPoint pos, int zoom) { bool ret = true; if (Created) { try { string file = CacheLocation + Path.DirectorySeparatorChar + GMapProviders.TryGetProvider(type).Name + Path.DirectorySeparatorChar + zoom + Path.DirectorySeparatorChar + pos.Y + Path.DirectorySeparatorChar + pos.X + ".jpg"; string dir = Path.GetDirectoryName(file); Directory.CreateDirectory(dir); using (BinaryWriter sw = new BinaryWriter(File.OpenWrite(file))) { sw.Write(tile.ToArray()); } } catch (Exception ex) { #if MONO Console.WriteLine("PutImageToCache: " + ex.ToString()); #endif Debug.WriteLine("PutImageToCache: " + ex.ToString()); ret = false; } } return(ret); }
void ProcessRequest(object p) { try { using (var c = p as TcpClient) { using (var s = c.GetStream()) { using (var r = new StreamReader(s, Encoding.UTF8)) { string request = r.ReadLine(); if (!string.IsNullOrEmpty(request) && request.StartsWith("GET")) { //Debug.WriteLine("TileHttpHost: " + request); // http://localhost:88/88888/5/15/11 // GET /8888888888/5/15/11 HTTP/1.1 var rq = request.Split(' '); if (rq.Length >= 2) { var ids = rq[1].Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (ids.Length == 4) { int dbId = int.Parse(ids[0]); int zoom = int.Parse(ids[1]); int x = int.Parse(ids[2]); int y = int.Parse(ids[3]); var pr = GMapProviders.TryGetProvider(dbId); if (pr != null) { Exception ex; var img = GMaps.Instance.GetImageFrom(pr, new GPoint(x, y), zoom, out ex); if (img != null) { using (img) { s.Write(responseHeaderBytes, 0, responseHeaderBytes.Length); img.Data.WriteTo(s); } } } } } } } } c.Close(); } } catch (Exception ex) { Debug.WriteLine("TileHttpHost, ProcessRequest: " + ex); } //Debug.WriteLine("disconnected"); }
int PureImageCache.DeleteOlderThan(DateTime date, int?type) { int affectedRows = 0; if (!type.HasValue) { return(0); } string file = CacheLocation + Path.DirectorySeparatorChar + GMapProviders.TryGetProvider(type.Value).Name + Path.DirectorySeparatorChar; if (!Directory.Exists(file)) { return(0); } string[] files = Directory.GetFiles(file, "*.jpg", SearchOption.AllDirectories); foreach (var filen in files) { try { var fi = new FileInfo(filen); if (fi.CreationTime < date) { File.Delete(filen); affectedRows++; } } catch { } } files = Directory.GetFiles(file, "*.png", SearchOption.AllDirectories); foreach (var filen in files) { try { var fi = new FileInfo(filen); if (fi.CreationTime < date) { File.Delete(filen); affectedRows++; } } catch { } } return(affectedRows); }
public PureImage GetImageFromCache(int type, GPoint pos, int zoom) { if (!_地图字典.ContainsKey(type)) { _地图字典[type] = GMapProviders.TryGetProvider(type); } var __地图 = _地图字典[type]; var url = string.Format("{0}/{1}/{2}/{3}/{4}", _host, __地图.Name, zoom, pos.X, pos.Y); return(GetTileImageUsingHttp(url)); }
private void readJsonMap() { using (StreamReader reader = new StreamReader("Maps.json")) { string json = reader.ReadToEnd(); JArray list = JArray.Parse(json); foreach (JObject data in list.Children()) { mapModes.Add(new MapMode { Name = (string)data["Name"], MapProvider = GMapProviders.TryGetProvider((string)data["Type"]), MainMapMinZoom = (int)data["MainMapMinZoom"], MainMapMaxZoom = (int)data["MainMapMaxZoom"], MiniMapMinZoom = (int)data["MiniMapMinZoom"], MiniMapMaxZoom = (int)data["MiniMapMaxZoom"] }); } } }
private void changeMapProvider(string mapName) { if (mapName.StartsWith("AMap") || mapName.StartsWith("Baidu") || mapName.StartsWith("Sohu") || mapName.StartsWith("SoSo") ) { if (mapName.Equals("AMap", StringComparison.CurrentCultureIgnoreCase)) { gMap.MapProvider = AMap; } else if (mapName.Equals("AMapSatelite", StringComparison.CurrentCultureIgnoreCase)) { gMap.MapProvider = AMapSatelite; } else if (mapName.Equals("BaiduMap", StringComparison.CurrentCultureIgnoreCase)) { gMap.MapProvider = BaiduMap; } else if (mapName.Equals("BaiduSateliteMap", StringComparison.CurrentCultureIgnoreCase)) { gMap.MapProvider = BaiduSateliteMap; } else if (mapName.Equals("SohuMap", StringComparison.CurrentCultureIgnoreCase)) { gMap.MapProvider = SogouMap; } else if (mapName.Equals("SohuSateliteMap", StringComparison.CurrentCultureIgnoreCase)) { gMap.MapProvider = SogouSateliteMap; } else if (mapName.Equals("SosoMap", StringComparison.CurrentCultureIgnoreCase)) { gMap.MapProvider = SosoMap; } else if (mapName.Equals("SoSoSateliteMap", StringComparison.CurrentCultureIgnoreCase)) { gMap.MapProvider = SosoSateliteMap; } gMap.MaxZoom = 18; gMap.MapProvider.MaxZoom = gMap.MaxZoom; trackZoom.Maximum = gMap.MaxZoom; } else { gMap.MapProvider = GMapProviders.TryGetProvider(mapSource[mapName]); gMap.MaxZoom = 20; gMap.MapProvider.MaxZoom = gMap.MaxZoom; } trackZoom.Maximum = gMap.MaxZoom; if (gMap.Zoom > gMap.MaxZoom) { gMap.Zoom = gMap.MaxZoom; } lastMapProvider = gMap.MapProvider.Name; Tag = lastMapProvider; if (mapName.StartsWith("Open", StringComparison.CurrentCultureIgnoreCase)) { chkMapShift.Checked = false; } else { chkMapShift.Checked = true; } tsmiShiftMap.Checked = chkMapShift.Checked; MapShift = chkMapShift.Checked; //gMap.BoundsOfMap = latlng; }
public void ChangeMapType(string id) { mainMap.MapProvider = GMapProviders.TryGetProvider(new Guid(id)); }