public void ConfigureMap(Map map) { if (WmsMode == WmsMode.Capabilites) { return; } if (this.Crs != "EPSG:" + map.Layers[0].SRID.ToString()) { WmsException.ThrowWmsException(WmsExceptionCode.InvalidCRS, "CRS not supported"); } map.Size = this.OutputSize; map.BackColor = this.BackgroundColor; map.ZoomToBox(this.RealWorldBounds); foreach (ILayer l in map.Layers) { l.Enabled = false; } foreach (string layerName in this.EnabledLayerNames) { map.GetLayerByName(layerName).Enabled = true; } }
public void ConfigureRenderer(WmsMapRequestConfig requestConfig, WmsRenderer renderer) { renderer.Context = requestConfig.Context; renderer.ServiceDescription = requestConfig.Description; renderer.RenderMode = requestConfig.WmsMode; if (requestConfig.WmsMode == WmsMode.Capabilites) { return; } ImageCodecInfo codecInfo = DefaultImageRenderer.FindCodec(requestConfig.MimeType); if (codecInfo == null) { WmsException.ThrowWmsException(string.Format("Invalid MimeType specified in FORMAT parameter. {0} not found", requestConfig.MimeType)); } renderer.ImageCodec = codecInfo; }
public virtual WmsMapRequestConfig CreateConfig(HttpContext context) { WmsMapRequestConfig config = new WmsMapRequestConfig(); config.ServiceDescription = Description; config.CacheKey = CreateCacheKey(context); bool ignorecase = true; if (context.Request.Params["REQUEST"] == null) { WmsException.ThrowWmsException("Required parameter REQUEST not specified"); } //Check if version is supported if (context.Request.Params["VERSION"] != null) { if (String.Compare(context.Request.Params["VERSION"], "1.3.0", ignorecase) != 0) { WmsException.ThrowWmsException("Only version 1.3.0 supported"); } } else //Version is mandatory if REQUEST!=GetCapabilities. Check if this is a capabilities request, since VERSION is null { if (String.Compare(context.Request.Params["REQUEST"], "GetCapabilities", ignorecase) != 0) { WmsException.ThrowWmsException("VERSION parameter not supplied"); } } if (String.Compare(context.Request.Params["REQUEST"], "GetCapabilities", ignorecase) == 0) { //Service parameter is mandatory for GetCapabilities request if (context.Request.Params["SERVICE"] == null) { WmsException.ThrowWmsException("Required parameter SERVICE not specified"); } if (String.Compare(context.Request.Params["SERVICE"], "WMS") != 0) { WmsException.ThrowWmsException( "Invalid service for GetCapabilities Request. Service parameter must be 'WMS'"); } config.WmsMode = WmsMode.Capabilites; config.MimeType = "text/xml"; return(config); } if (String.Compare(context.Request.Params["REQUEST"], "GetMap", ignorecase) != 0) { WmsException.ThrowWmsException("Invalid REQUEST parameter"); } config.WmsMode = WmsMode.Map; //Check for required parameters if (context.Request.Params["LAYERS"] == null) { WmsException.ThrowWmsException("Required parameter LAYERS not specified"); } config.EnabledLayerNames = new List <string>(context.Request.Params["LAYERS"].Split(',')); if (context.Request.Params["STYLES"] == null) { WmsException.ThrowWmsException("Required parameter STYLES not specified"); } if (context.Request.Params["CRS"] == null) { WmsException.ThrowWmsException("Required parameter CRS not specified"); } config.Crs = context.Request.Params["CRS"]; config.BaseSrid = config.Crs; if (context.Request.Params["BBOX"] == null) { WmsException.ThrowWmsException(WmsExceptionCode.InvalidDimensionValue, "Required parameter BBOX not specified"); } if (context.Request.Params["WIDTH"] == null) { WmsException.ThrowWmsException(WmsExceptionCode.InvalidDimensionValue, "Required parameter WIDTH not specified"); } if (context.Request.Params["HEIGHT"] == null) { WmsException.ThrowWmsException(WmsExceptionCode.InvalidDimensionValue, "Required parameter HEIGHT not specified"); } if (context.Request.Params["FORMAT"] == null) { WmsException.ThrowWmsException("Required parameter FORMAT not specified"); } Color bkgnd = Color.White; //Set background color of map if (String.Compare(context.Request.Params["TRANSPARENT"], "TRUE", ignorecase) == 0) { bkgnd = Color.Transparent; } else if (context.Request.Params["BGCOLOR"] != null) { try { bkgnd = ColorTranslator.FromHtml(context.Request.Params["BGCOLOR"]); } catch { WmsException.ThrowWmsException("Invalid parameter BGCOLOR"); } ; } config.BackgroundColor = ViewConverter.Convert(bkgnd); config.MimeType = context.Request.Params["FORMAT"]; //Parse map size int width = 0; int height = 0; if (!int.TryParse(context.Request.Params["WIDTH"], out width)) { WmsException.ThrowWmsException(WmsExceptionCode.InvalidDimensionValue, "Invalid parameter WIDTH"); } else if (Description.MaxWidth > 0 && width > Description.MaxWidth) { WmsException.ThrowWmsException(WmsExceptionCode.OperationNotSupported, "Parameter WIDTH too large"); } if (!int.TryParse(context.Request.Params["HEIGHT"], out height)) { WmsException.ThrowWmsException(WmsExceptionCode.InvalidDimensionValue, "Invalid parameter HEIGHT"); } else if (Description.MaxHeight > 0 && height > Description.MaxHeight) { WmsException.ThrowWmsException(WmsExceptionCode.OperationNotSupported, "Parameter HEIGHT too large"); } config.OutputSize = new Size2D(width, height); if (context.Request.Params["BBOX"] == null) { WmsException.ThrowWmsException("Invalid parameter BBOX"); } config.RealWorldBounds = UrlUtility.ParseExtents(new GeometryServices()[config.Crs], context.Request.Params["BBOX"]); return(config); }