TileCook.WMSProvider.Render C# (CSharp) Method

Render() public method

public Render ( Envelope envelope, string format, int tileWidth, int tileHeight ) : byte[]
envelope Envelope
format string
tileWidth int
tileHeight int
return byte[]
        public byte[] Render(Envelope envelope, string format, int tileWidth, int tileHeight)
        {
            StringBuilder query = new StringBuilder();
            query.Append("request=GetMap");
            query.Append("&service=WMS");
            query.Append("&version=" + HttpUtility.UrlEncode(this._version));
            query.Append("&layers=" + HttpUtility.UrlEncode(this._layers));
            query.Append("&styles=" + HttpUtility.UrlEncode(this._styles));
            if (this._version.Equals("1.3.0")) { query.Append("&crs=" + HttpUtility.UrlEncode(this._crs)); }
            else { query.Append("&srs=" + HttpUtility.UrlEncode(this._crs)); }
            query.Append("&bbox=" + envelope.Minx.ToString() + "," + envelope.Miny.ToString() + "," + envelope.Maxx.ToString() + "," + envelope.Maxy.ToString());
            query.Append("&width=" + tileWidth.ToString());
            query.Append("&height=" + tileHeight.ToString());
            query.Append("&format=" + HttpUtility.UrlEncode(format));
            if (this._sld != null) { query.Append("&sld=" + HttpUtility.UrlEncode(this._sld)); }
            if (this._bgcolor != null) { query.Append("&bgcolor=" + HttpUtility.UrlEncode(this._bgcolor)); }
            if (this._transparent != null) { query.Append("&transparent=" + HttpUtility.UrlEncode(this._transparent)); }

            UriBuilder ub = new UriBuilder(this._url);
            ub.Query = query.ToString();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ub.Uri);
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        responseStream.CopyTo(ms);
                        return ms.ToArray();
                    }
                }
            }
        }