Exemplo n.º 1
0
 public void CreateTile()
 {
     int x = 1;
     int y = 1;
     int z = 1;
     string fileName = "c:\\temp\\000.png";
     TileImage t = new TileImage(x, y, z, fileName);
     Assert.AreEqual(1, t.X);
 }
Exemplo n.º 2
0
        public virtual bool DownloadTile(int x, int y, int scale, string filename)
        {
            Int32 z = ConvertZoomToManifoldScale(scale);

            String strRequest;

            if (m_DefaultURL == m_strUrl)
            {
                //request image from standard request
                TileImage img = new TileImage(x, y, z, filename);
                img.Save();
                return(true);
            }
            else
            {
                //custom request
                strRequest  = m_strUrl + z.ToString(CultureInfo.InvariantCulture);
                strRequest += "/" + x.ToString(CultureInfo.InvariantCulture);
                strRequest += "/" + y.ToString(CultureInfo.InvariantCulture);
                strRequest += DefaultImageType;
                try
                {
                    // initialize request
                    HttpWebRequest request = CreateHttpRequest(strRequest, m_strProxyAddress, m_strProxyUserName, m_strProxyPassword);

                    // obtain response
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    // process response
                    String strType = response.ContentType;

                    Int32 nIndex = strType.IndexOf("image");
                    if (nIndex > -1)
                    {
                        Image       image       = Image.FromStream(response.GetResponseStream());
                        PixelFormat pixelFormat = image.PixelFormat;
                        Bitmap      bitmap      = new Bitmap(image);

                        if (filename != null && filename.Length != 0)
                        {
                            bitmap.Save(filename, ImageFormat.Png);
                        }
                    }
                    else
                    {
                        // read all data
                        StreamReader objReader = new StreamReader(response.GetResponseStream());
                        String       error     = objReader.ReadToEnd();
                        objReader.Close();

                        if (error == null || error.Length == 0)
                        {
                            error = "Can't obtain image from server";
                        }

                        m_Error = error + " tile:" + x.ToString() + "," + y.ToString() + "," + z.ToString();

                        response.Close();
                        return(false);
                    }

                    response.Close();

                    return(true);
                }
                catch (WebException we)
                {
                    m_Error = we.Message + " tile:" + x.ToString() + "," + y.ToString() + "," + z.ToString();
                    return(false);
                }
                catch (Exception e)
                {
                    m_Error = e.Message + "tile:" + x.ToString() + "," + y.ToString() + "," + z.ToString();
                    throw;
                }
            }
        }
Exemplo n.º 3
0
        public virtual bool DownloadTile(int _x, int _y, int _scale, string _filename)
        {
            Int32 z = ConvertZoomToManifoldScale(_scale);

            String strRequest;
            if (m_DefaultURL == m_strUrl)
            {
                //request image from standard request
                TileImage img = new TileImage(_x, _y, z, _filename);
                return true;

            }
            else
            {
                //custom request
                strRequest = m_strUrl + z.ToString(CultureInfo.InvariantCulture);
                strRequest += "/" + _x.ToString(CultureInfo.InvariantCulture);
                strRequest += "/" + _y.ToString(CultureInfo.InvariantCulture);
                strRequest += DefaultImageType;
                try
                {
                    // initialize request
                    HttpWebRequest request = CreateHttpRequest(strRequest, m_strProxyAddress, m_strProxyUserName, m_strProxyPassword);

                    // obtain response
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    // process response
                    String strType = response.ContentType;

                    Int32 nIndex = strType.IndexOf("image");
                    if (nIndex > -1)
                    {

                        Image image = Image.FromStream(response.GetResponseStream());
                        PixelFormat pixelFormat = image.PixelFormat;
                        Bitmap bitmap = new Bitmap(image);

                        if (_filename != null && _filename.Length != 0)
                            bitmap.Save(_filename, ImageFormat.Png);

                    }
                    else
                    {
                        // read all data
                        StreamReader objReader = new StreamReader(response.GetResponseStream());
                        String error = objReader.ReadToEnd();
                        objReader.Close();

                        if (error == null || error.Length == 0)
                            error = "Can't obtain image from server";

                        m_Error =  error + " tile:" + _x.ToString() + "," + _y.ToString() + "," + z.ToString();

                        response.Close();
                        return false;
                    }

                    response.Close();

                    return true;
                }
                catch (WebException we)
                {
                    m_Error = we.Message + " tile:" + _x.ToString() + "," + _y.ToString() + "," + z.ToString();
                    return false;
                }
                catch (Exception e)
                {
                    m_Error = e.Message + "tile:" + _x.ToString() + "," + _y.ToString() + "," + z.ToString();
                    throw;
                }

            }
        }
Exemplo n.º 4
0
        public override bool DownloadTile(int x, int y, int scale, string filename)
        {
            Int32 z = ConvertZoomToManifoldScale(scale);
            if (x == 0 && y == 0)
            {
                var image = new TileImage(x, y, z, filename);
                image.Save();

                return true;
            }

            //custom request
            string strRequest = m_strUrl + z.ToString(CultureInfo.InvariantCulture);
            strRequest += "/" + x.ToString(CultureInfo.InvariantCulture);
            strRequest += "/" + y.ToString(CultureInfo.InvariantCulture);
            strRequest += DefaultImageType;
            try
            {
                // initialize request
                HttpWebRequest request = CreateHttpRequest(strRequest, m_strProxyAddress, m_strProxyUserName, m_strProxyPassword);

                // obtain response
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                // process response
                String strType = response.ContentType;

                Int32 nIndex = strType.IndexOf("image");
                if (nIndex > -1)
                {

                    Image image = Image.FromStream(response.GetResponseStream());
                    Bitmap bitmap = new Bitmap(image);

                    if (!string.IsNullOrEmpty(filename))
                        bitmap.Save(filename, ImageFormat.Png);

                }
                else
                {
                    // read all data
                    StreamReader objReader = new StreamReader(response.GetResponseStream());
                    String error = objReader.ReadToEnd();
                    objReader.Close();

                    if (error.Length == 0)
                        error = "Can't obtain image from server";

                    Error = error + strRequest ;

                    response.Close();
                    return false;
                }

                response.Close();

                return true;
            }
            catch (WebException we)
            {
                Error = we.Message + strRequest;
                return false;
            }
            catch (Exception e)
            {
                Error = e.Message + strRequest;
                throw;
            }
        }