本文整理汇总了C#中SharpMap.Render方法的典型用法代码示例。如果您正苦于以下问题:C# SharpMap.Render方法的具体用法?C# SharpMap.Render怎么用?C# SharpMap.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpMap
的用法示例。
在下文中一共展示了SharpMap.Render方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseQueryString
//.........这里部分代码省略.........
{
try { map.BackColor = System.Drawing.ColorTranslator.FromHtml(context.Request.Params["BGCOLOR"]); }
catch { WmsException.ThrowWmsException("Invalid parameter BGCOLOR"); return; };
}
else
map.BackColor = System.Drawing.Color.White;
//Get the image format requested
System.Drawing.Imaging.ImageCodecInfo imageEncoder = GetEncoderInfo(context.Request.Params["FORMAT"]);
if (imageEncoder == null)
{
WmsException.ThrowWmsException("Invalid MimeType specified in FORMAT parameter");
return;
}
//Parse map size
int width = 0;
int height = 0;
if (!int.TryParse(context.Request.Params["WIDTH"], out width))
{
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Invalid parameter WIDTH");
return;
}
else if (description.MaxWidth > 0 && width > description.MaxWidth)
{
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.OperationNotSupported, "Parameter WIDTH too large");
return;
}
if (!int.TryParse(context.Request.Params["HEIGHT"], out height))
{
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Invalid parameter HEIGHT");
return;
}
else if (description.MaxHeight > 0 && height > description.MaxHeight)
{
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.OperationNotSupported, "Parameter HEIGHT too large");
return;
}
map.Size = new System.Drawing.Size(width, height);
IEnvelope bbox = ParseBBOX(context.Request.Params["bbox"]);
if (bbox == null)
{
WmsException.ThrowWmsException("Invalid parameter BBOX");
return;
}
map.PixelAspectRatio = ((double)width / (double)height) / (bbox.Width / bbox.Height);
map.Center = bbox.Centre;
map.Zoom = bbox.Width;
//Set layers on/off
if (!String.IsNullOrEmpty(context.Request.Params["LAYERS"])) //If LAYERS is empty, use default layer on/off settings
{
string[] layers = context.Request.Params["LAYERS"].Split(new char[] { ',' });
if(description.LayerLimit>0)
{
if (layers.Length == 0 && map.Layers.Count > description.LayerLimit ||
layers.Length > description.LayerLimit)
{
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.OperationNotSupported, "Too many layers requested");
return;
}
}
foreach (SharpMap.Layers.ILayer layer in map.Layers)
layer.Enabled = false;
foreach (string layer in layers)
{
//SharpMap.Layers.ILayer lay = map.Layers.Find(delegate(SharpMap.Layers.ILayer findlay) { return findlay.LayerName == layer; });
SharpMap.Layers.ILayer lay = null;
for (int i = 0; i < map.Layers.Count; i++)
if (String.Equals(map.Layers[i].Name, layer, StringComparison.InvariantCultureIgnoreCase))
lay = map.Layers[i];
if (lay == null)
{
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.LayerNotDefined, "Unknown layer '" + layer + "'");
return;
}
else
lay.Enabled = true;
}
}
//Render map
System.Drawing.Image img = map.Render();
//Png can't stream directy. Going through a memorystream instead
System.IO.MemoryStream MS = new System.IO.MemoryStream();
img.Save(MS, imageEncoder, null);
img.Dispose();
byte[] buffer = MS.ToArray();
context.Response.Clear();
context.Response.ContentType = imageEncoder.MimeType;
context.Response.OutputStream.Write(buffer, 0, buffer.Length);
context.Response.End();
}
else
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.OperationNotSupported, "Invalid request");
}