//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Get the map tile image and stored in the map cache. * @param mtype the map tile (msn,yahoo etc). * @param X the X index of the map tile. * @param Y the Y index of the map tile. * @param zoomLevel current zoom level */ private void GetImage1(int mtype, int x, int y, int zoomLevel) { _mapType = mtype; _mapXIndex = x; _mapYIndex = y; _mapZoomLevel = zoomLevel; HttpStatusCode imgResponseCode = HttpStatusCode.NotFound; IsImagevalid = true; ImageArraySize = 0; HttpWebResponse httpWResp = null; try { string location = GetTileURL(mtype, x, y, NUMZOOMLEVELS - zoomLevel); _imgConn = (HttpWebRequest)WebRequest.Create(location); _imgConn.Proxy = WebRequest.DefaultWebProxy; _imgConn.Proxy.Credentials = CredentialCache.DefaultCredentials; //imgConn.Headers.Add("Accept", "image/png"); httpWResp = (HttpWebResponse)_imgConn.GetResponse(); imgResponseCode = httpWResp.StatusCode; } catch (Exception) { IsImagevalid = false; } if (imgResponseCode != HttpStatusCode.OK) { IsImagevalid = false; } if (IsImagevalid) { try { if (httpWResp != null) { int totalToReceive = (int)(httpWResp.ContentLength); TotaldownloadedBytes += totalToReceive; MapProgressInputStream stream = new MapProgressInputStream(httpWResp.GetResponseStream(), totalToReceive, _readListener, 1024); int totalToRead = totalToReceive;// (int)Math.Max(totalToReceive, stream.avaiable()); ImageArraySize = totalToRead; ImageArray = new byte[totalToRead]; stream.Read(ImageArray, 0, ImageArray.Length); stream.Close(); } } catch (Exception) { IsImagevalid = false; ImageArray = null; GC.Collect(); } } _imgConn = null; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 18JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Get the map tile image and stored in the map cache. * @param mtype the map tile (msn,yahoo etc). * @param X the X index of the map tile. * @param Y the Y index of the map tile. * @param zoomLevel current zoom level */ private void GetImage1(int mtype, int x, int y, int zoomLevel) { _mapType = mtype; _mapXIndex = x; _mapYIndex = y; _mapZoomLevel = zoomLevel; HttpStatusCode imgResponseCode = HttpStatusCode.NotFound; IsImagevalid = true; ImageArraySize = 0; HttpWebResponse httpWResp = null; try { string location = GetTileURL(mtype, x, y, NUMZOOMLEVELS - zoomLevel); _imgConn = (HttpWebRequest)WebRequest.Create(location); _imgConn.Proxy = WebRequest.DefaultWebProxy; _imgConn.Proxy.Credentials = CredentialCache.DefaultCredentials; //imgConn.Headers.Add("Accept", "image/png"); httpWResp = (HttpWebResponse)_imgConn.GetResponse(); imgResponseCode = httpWResp.StatusCode; } catch (Exception) { IsImagevalid = false; } if (imgResponseCode != HttpStatusCode.OK) { IsImagevalid = false; } if (IsImagevalid) { try { if (httpWResp != null) { int totalToReceive = (int)(httpWResp.ContentLength); TotaldownloadedBytes += totalToReceive; MapProgressInputStream stream = new MapProgressInputStream(httpWResp.GetResponseStream(), totalToReceive, _readListener, 1024); int totalToRead = totalToReceive;// (int)Math.Max(totalToReceive, stream.avaiable()); ImageArraySize = totalToRead; ImageArray = new byte[totalToRead]; stream.Read(ImageArray, 0, ImageArray.Length); stream.Close(); } } catch (Exception) { IsImagevalid = false; ImageArray = null; GC.Collect(); } } _imgConn = null; }