public override void Render(System.Drawing.Graphics g, Map map)
{
SharpMap.Web.Wms.Client.WmsOnlineResource resource = GetPreferredMethod();
Uri myUri = new Uri(GetRequestUrl(map.Envelope,map.Size));
System.Net.WebRequest myWebRequest = System.Net.WebRequest.Create(myUri);
myWebRequest.Method = resource.Type;
myWebRequest.Timeout = _TimeOut;
if (_Credentials != null)
myWebRequest.Credentials = _Credentials;
else
myWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
if (_Proxy != null)
myWebRequest.Proxy = _Proxy;
try
{
System.Net.HttpWebResponse myWebResponse = (System.Net.HttpWebResponse)myWebRequest.GetResponse();
System.IO.Stream dataStream = myWebResponse.GetResponseStream();
if (myWebResponse.ContentType.StartsWith("image"))
{
System.Drawing.Image img = System.Drawing.Image.FromStream(myWebResponse.GetResponseStream());
if (_ImageAttributes != null)
g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0,
img.Width, img.Height, GraphicsUnit.Pixel, this.ImageAttributes);
else
g.DrawImageUnscaled(img, 0, 0,map.Size.Width,map.Size.Height);
}
dataStream.Close();
myWebResponse.Close();
}
catch (System.Net.WebException webEx)
{
if (!_ContinueOnError)
throw (new SharpMap.Rendering.Exceptions.RenderException("There was a problem connecting to the WMS server when rendering layer '" + this.LayerName + "'", webEx));
else
//Write out a trace warning instead of throwing an error to help debugging WMS problems
System.Diagnostics.Trace.Write("There was a problem connecting to the WMS server when rendering layer '" + this.LayerName + "': " + webEx.Message);
}
catch (System.Exception ex)
{
if (!_ContinueOnError)
throw (new SharpMap.Rendering.Exceptions.RenderException("There was a problem rendering layer '" + this.LayerName + "'", ex));
else
//Write out a trace warning instead of throwing an error to help debugging WMS problems
System.Diagnostics.Trace.Write("There was a problem connecting to the WMS server when rendering layer '" + this.LayerName + "': " + ex.Message);
}
base.Render(g, map);
}