protected override WmsParams ValidateParams(IContextRequest request, int targetSrid) { WmsParams @params = ValidateCommons(request, targetSrid); // code specific for GetMap Color backColor; bool transparent = String.Equals(request.GetParam("TRANSPARENT"), "TRUE", Case); if (!transparent) { string bgcolor = request.GetParam("BGCOLOR"); if (bgcolor != null) { try { backColor = ColorTranslator.FromHtml(bgcolor); } catch { string s = String.Format("Invalid parameter BGCOLOR: {0}", bgcolor); throw new WmsInvalidParameterException(s); } } else { backColor = Color.White; } } else { backColor = Color.Transparent; } @params.BackColor = backColor; return(@params); }
private Size GetSize(WmsParams @params) { if (Description.MaxWidth > 0 && @params.Width > Description.MaxWidth) { throw new WmsOperationNotSupportedException("Parameter WIDTH too large"); } if (Description.MaxHeight > 0 && @params.Height > Description.MaxHeight) { throw new WmsOperationNotSupportedException("Parameter HEIGHT too large"); } return(new Size(@params.Width, @params.Height)); }
public override IHandlerResponse Handle(Map map, IContextRequest request) { WmsParams @params = ValidateParams(request, TargetSrid(map)); map.Size = new Size(@params.Width, @params.Height); map.ZoomToBox(@params.BBOX); string[] requestLayers = @params.QueryLayers.Split(new[] { ',' }); AbstractGetFeatureInfoResponse info = CreateFeatureInfo(map, requestLayers, @params.X, @params.Y, @params.FeatureCount, @params.CqlFilter, _params.PixelSensitivity, _params.IntersectDelegate); if (_params.Encoding != null) info.Charset = _params.Encoding.WebName; return info; }
protected override WmsParams ValidateParams(IContextRequest request, int targetSrid) { WmsParams @params = ValidateCommons(request, targetSrid); // code specific for GetFeatureInfo string queryLayers = request.GetParam("QUERY_LAYERS"); if (queryLayers == null) throw new WmsParameterNotSpecifiedException("QUERY_LAYERS"); @params.QueryLayers = queryLayers; string infoFormat = request.GetParam("INFO_FORMAT"); if (infoFormat == null) throw new WmsParameterNotSpecifiedException("INFO_FORMAT"); @params.InfoFormat = infoFormat; // parameters X&Y are not part of the 1.3.0 specification, // but are included for backwards compatability with 1.1.1 // (OpenLayers likes it when used together with wms1.1.1 services) // we will assume that Openlayers is used by default // so check X&Y first string x = request.GetParam("X") ?? request.GetParam("I"); if (x == null) throw new WmsParameterNotSpecifiedException("I"); string y = request.GetParam("Y") ?? request.GetParam("J"); if (y == null) throw new WmsParameterNotSpecifiedException("J"); float cx; if (!Single.TryParse(x, out cx)) throw new WmsInvalidParameterException("Invalid parameters for X / I"); @params.X = cx; float cy; if (!Single.TryParse(y, out cy)) throw new WmsInvalidParameterException("Invalid parameters for Y / J"); @params.Y = cy; string featureCount = request.GetParam("FEATURE_COUNT"); int fc = Int32.TryParse(featureCount, out fc) ? Math.Max(fc, 1) : 1; @params.FeatureCount = fc; return @params; }
public override IHandlerResponse Handle(Map map, IContextRequest request) { WmsParams @params = ValidateParams(request, TargetSrid(map)); map.BackColor = @params.BackColor; // get the image format requested ImageCodecInfo imageEncoder = GetEncoderInfo(@params.Format); Size size = GetSize(@params); map.Size = size; Envelope bbox = @params.BBOX; double sizeRatio = size.Width / (double)size.Height; double bboxRatio = bbox.Width / bbox.Height; map.PixelAspectRatio = sizeRatio / bboxRatio; map.Center = bbox.Centre; map.Zoom = bbox.Width; // set Styles for layerNames // first, if the request == STYLES=, set all the vectorlayers with Themes not null the Theme to the first theme from Themes string ptheme = @params.Styles; string players = @params.Layers; string cqlFilter = @params.CqlFilter; if (!String.IsNullOrEmpty(players)) { string[] layerNames = GetLayerNames(map, players); // we have a known set of layerNames in request // so we will set each layer to its default theme // and disable the layer, layers will be enabled // later as per the request foreach (ILayer layer in map.Layers) { VectorLayer vectorLayer = layer as VectorLayer; SetDefaultThemeForLayer(vectorLayer); layer.Enabled = false; } Dictionary <string, string> themeTable = new Dictionary <string, string>(); BuildThemeLookup(ptheme, layerNames, themeTable); // since we have layerNames specified // enable only those layerNames for (int j = 0; j < layerNames.Length; j++) { string layerName = layerNames[j]; ILayer layer = GetMapLayerByName(map, layerName); // set layer on/off layer.Enabled = true; // check if a styles have been specified for layers if (themeTable.Count > 0) { string themeName = themeTable[layerName]; // do nothing if themeName is empty if (!string.IsNullOrEmpty(themeName)) { // is this a vector layer at all VectorLayer vectorLayer = layer as VectorLayer; // does it have several themes to choose from // TODO -> Refactor VectorLayer.Themes to Rendering.Thematics.ThemeList : ITheme if (vectorLayer != null && vectorLayer.Themes != null && vectorLayer.Themes.Count > 0) { // we need to a case invariant comparison for themeName Dictionary <string, ITheme> themeDict = new Dictionary <string, ITheme>(vectorLayer.Themes, new StringComparerIgnoreCase()); if (!themeDict.ContainsKey(themeName)) { throw new WmsStyleNotDefinedException("Style not advertised for this layer"); } vectorLayer.Theme = themeDict[themeName]; } } } if (!String.IsNullOrEmpty(cqlFilter)) { ApplyCqlFilter(cqlFilter, layer); } } } // render map Image img = map.GetMap(); return(new GetMapResponse(img, imageEncoder)); }
private Size GetSize(WmsParams @params) { if (Description.MaxWidth > 0 && @params.Width > Description.MaxWidth) throw new WmsOperationNotSupportedException("Parameter WIDTH too large"); if (Description.MaxHeight > 0 && @params.Height > Description.MaxHeight) throw new WmsOperationNotSupportedException("Parameter HEIGHT too large"); return new Size(@params.Width, @params.Height); }