public async Task <ActionResult> GetFeatureInfo(string serviceName, string layer, string style, string tileMatrixSet, string tileMatrix, int tileRow, int tileCol, int j, int i) { GetTile getTile = new GetTile() { service = "WMTS", version = "1.0.0", Layer = layer, Style = style, TileMatrixSet = tileMatrixSet, TileMatrix = tileMatrix, TileRow = tileRow, TileCol = tileCol }; string infoFormat = "application/xml"; GetFeatureInfo getFeatureInfo = new GetFeatureInfo() { service = "WMTS", version = "1.0.0", I = i, J = j, GetTile = getTile, InfoFormat = infoFormat }; var result = await GetFeatureInfo(serviceName, getFeatureInfo); return(result); }
static HardwareCapabilities() { EmitterContext context = new EmitterContext(); Operand featureInfo = context.CpuId(); context.Return(featureInfo); ControlFlowGraph cfg = context.GetControlFlowGraph(); OperandType[] argTypes = new OperandType[0]; GetFeatureInfo getFeatureInfo = Compiler.Compile <GetFeatureInfo>( cfg, argTypes, OperandType.I64, CompilerOptions.HighCq); _featureInfo = getFeatureInfo(); }
public async Task <JsonResult> Post([FromBody] GetFeatureInfo info) { string result = ""; // Create the web request System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(info.address); // Get response try { using (System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse()) { // Get the response stream System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("ISO-8859-1")); // Read the whole contents and return as a string result = reader.ReadToEnd(); return(Json(result)); } } catch { //using (var client = new System.Net.Http.HttpClient()) //{ // client.BaseAddress = new System.Uri(info.address); // client.DefaultRequestHeaders.Accept.Clear(); // client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); // System.Net.Http.HttpResponseMessage response = await client.GetAsync(info.address); // if (response.IsSuccessStatusCode) // { // string responseString = response.Content.ReadAsStringAsync().Result; // return Json(Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(responseString)); // } //} return(Json(result)); } }
private async Task <ContentResult> GetFeatureInfo(string serviceName, GetFeatureInfo getFeatureInfo) { GetTile getTile = getFeatureInfo.GetTile; string content = null; ExceptionReport exception = null; int statusCode = 200; #region Validate parameters if (string.IsNullOrWhiteSpace(serviceName)) { exception = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "serviceName", exceptionText: "Bad request"); statusCode = 400; goto Exception; } string serviceType = getTile.service; if (string.IsNullOrWhiteSpace(serviceType)) { exception = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "service", exceptionText: "Bad request"); statusCode = 400; goto Exception; } if (serviceType != "wmts") { exception = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request"); statusCode = 400; goto Exception; } string version = getTile.version; if (string.IsNullOrWhiteSpace(version)) { exception = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "version", exceptionText: "Bad request"); statusCode = 400; goto Exception; } if (version != "1.0.0") { exception = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request"); statusCode = 400; goto Exception; } string layerName = getTile.Layer; if (string.IsNullOrWhiteSpace(layerName)) { exception = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "layer", exceptionText: "Bad request"); statusCode = 400; goto Exception; } string style = getTile.Style; if (string.IsNullOrWhiteSpace(style)) { exception = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "style", exceptionText: "Bad request"); statusCode = 400; goto Exception; } string format = getTile.Format; if (string.IsNullOrWhiteSpace(format)) { exception = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "format", exceptionText: "Bad request"); statusCode = 400; goto Exception; } string tileMatrixSet = getTile.TileMatrixSet; if (string.IsNullOrWhiteSpace(tileMatrixSet)) { exception = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "tileMatrixSet", exceptionText: "Bad request"); statusCode = 400; goto Exception; } string tileMatrix = getTile.TileMatrix; if (string.IsNullOrWhiteSpace(tileMatrix)) { exception = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "tileMatrix", exceptionText: "Bad request"); statusCode = 400; goto Exception; } ServiceRecord serviceRecord = await GetServiceRecord(serviceName, version); if (serviceRecord == null) { exception = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request"); statusCode = 400; goto Exception; } if (!System.IO.File.Exists(serviceRecord.Path)) { exception = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error"); statusCode = 500; goto Exception; } LayerRecord layerRecord = await GetLayerRecord(serviceRecord, layerName); if (layerRecord == null) { exception = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request"); statusCode = 400; goto Exception; } if (!System.IO.File.Exists(layerRecord.Path)) { exception = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error"); statusCode = 500; goto Exception; } #endregion GetCapabilities getCapabilities = new GetCapabilities(); IWmtsService wmts1Service = GetWmts1Service(version); Capabilities capabilities = wmts1Service.GetCapabilities(serviceRecord.Path, getCapabilities); if (capabilities == null) { exception = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error"); statusCode = 500; goto Exception; } LayerType layerType = capabilities.Contents?.DatasetDescriptionSummary?.FirstOrDefault(x => x.Identifier?.Value == layerName && x is LayerType) as LayerType; if (layerType == null) { exception = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error"); statusCode = 500; goto Exception; } if (!layerType.Format.Contains(format)) { exception = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "format", exceptionText: "Bad request"); statusCode = 400; goto Exception; } if (layerType.TileMatrixSetLink == null || layerType.TileMatrixSetLink.Length == 0) { exception = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error"); statusCode = 500; goto Exception; } string layerTileMatrixSetStr = layerType.TileMatrixSetLink[0].TileMatrixSet; if (layerTileMatrixSetStr != null) { TileMatrixSet layerTileMatrixSet = capabilities.Contents.TileMatrixSet?.FirstOrDefault(x => x.Identifier?.Value == layerTileMatrixSetStr); if (layerTileMatrixSet != null) { TileMatrix layerTileMatrix = layerTileMatrixSet.TileMatrix?.FirstOrDefault(x => x.Identifier.Value == getTile.TileMatrix); if (layerTileMatrix != null) { bool ret = layerTileMatrix.TopLeftCorner.ToPosition(out double left, out double top); if (!ret) { exception = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error"); statusCode = 500; goto Exception; } BoundingBoxType boundingBoxType = layerType.BoundingBox?.Length > 0 ? layerType.BoundingBox[0] : layerType.WGS84BoundingBox?.Length > 0 ? layerType.WGS84BoundingBox[0] : null; if (boundingBoxType == null) { exception = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error"); statusCode = 500; goto Exception; } bool ret1 = boundingBoxType.LowerCorner.ToPosition(out double xMin, out double yMin); bool ret2 = boundingBoxType.UpperCorner.ToPosition(out double xMax, out double yMax); if (!ret1 || !ret2) { exception = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error"); statusCode = 500; goto Exception; } double tileXMin = 0, tileYMin = 0, tileXMax = 0, tileYMax = 0; int tileWidth = Convert.ToInt32(layerTileMatrix.TileWidth); int tileHeight = Convert.ToInt32(layerTileMatrix.TileHeight); tileXMin = left + getTile.TileCol * tileWidth * layerTileMatrix.ScaleDenominator; tileXMax = left + (getTile.TileCol + 1) * tileWidth * layerTileMatrix.ScaleDenominator; tileYMax = top - getTile.TileRow * tileHeight * layerTileMatrix.ScaleDenominator; tileYMin = top - (getTile.TileRow + 1) * tileHeight * layerTileMatrix.ScaleDenominator; if (tileXMax <= xMin || tileXMin >= xMax || tileYMax <= yMin || tileYMin >= yMax) { exception = ExceptionReportHelper.GetExceptionReport("TileOutOfRange", exceptionText: "Bad request"); statusCode = 400; goto Exception; } if (getFeatureInfo.I < 0 || getFeatureInfo.I >= tileWidth || getFeatureInfo.J < 0 || getFeatureInfo.J >= tileHeight) { exception = ExceptionReportHelper.GetExceptionReport("PointIJOutOfRange", exceptionText: "Bad request"); statusCode = 400; goto Exception; } } } } FeatureInfoResponse featureInfoResponse = wmts1Service.GetFeatureInfo(serviceRecord.Path, getFeatureInfo); content = XmlHelper.XmlSerialize(featureInfoResponse, Encoding, null); goto Success; Exception: content = XmlHelper.XmlSerialize(exception, Encoding, null); Success: ContentResult result = new ContentResult() { StatusCode = statusCode, Content = content }; return(result); }
internal void Init(string CapabilitiesString, WFSDataset wfsDataset) { try { _themes = new List <IWebServiceTheme>(); XmlDocument doc = new XmlDocument(); doc.LoadXml(CapabilitiesString); XmlNode CapabilitiesNode = doc.SelectSingleNode("WMT_MS_Capabilities/Capability"); _getCapabilities = new GetCapabilities(CapabilitiesNode.SelectSingleNode("Request/GetCapabilities")); _getMap = new GetMap(CapabilitiesNode.SelectSingleNode("Request/GetMap")); _getFeatureInfo = new GetFeatureInfo(CapabilitiesNode.SelectSingleNode("Request/GetFeatureInfo")); _describeLayer = new DescribeLayer(CapabilitiesNode.SelectSingleNode("Request/DescribeLayer")); _getLegendGraphic = new GetLegendGraphic(CapabilitiesNode.SelectSingleNode("Request/GetLegendGraphic")); _getStyles = new GetStyles(CapabilitiesNode.SelectSingleNode("Request/GetStyles")); _exceptions = new WMSExceptions(CapabilitiesNode.SelectSingleNode("Exception")); _userDefinedSymbolization = new UserDefinedSymbolization(CapabilitiesNode.SelectSingleNode("UserDefinedSymbolization")); XmlNode service = CapabilitiesNode.SelectSingleNode("Layer"); XmlNode title = service.SelectSingleNode("Title"); if (title != null) { _name = title.InnerText; } _srs = new SRS(service); this.SRSCode = _srs.Srs[_srs.SRSIndex]; foreach (XmlNode layer in service.SelectNodes("Layer")) { string name = "", Title = ""; XmlNode nameNode = layer.SelectSingleNode("Name"); XmlNode titleNode = layer.SelectSingleNode("Title"); if (nameNode == null) { continue; } name = Title = nameNode.InnerText; if (titleNode != null) { Title = titleNode.InnerText; } XmlNodeList styles = layer.SelectNodes("Style"); WFSFeatureClass wfsFc = null; if (wfsDataset != null) { IDatasetElement wfsElement = wfsDataset[name]; if (wfsElement != null && wfsElement.Class is WFSFeatureClass) { wfsFc = wfsElement.Class as WFSFeatureClass; } } if (styles.Count == 0) { IClass wClass = null; if (wfsFc != null) { wClass = wfsFc; } else if (layer.Attributes["queryable"] != null && layer.Attributes["queryable"].Value == "1") { wClass = new WMSQueryableThemeClass(_dataset, name, String.Empty, layer, _getFeatureInfo, _srs, _exceptions); } else { wClass = new WMSThemeClass(_dataset, name, String.Empty, layer); } IWebServiceTheme theme; if (wClass is WFSFeatureClass) { theme = new WebServiceTheme2( wClass, Title, name, true, this); } else { theme = new WebServiceTheme( wClass, Title, name, true, this ); } _themes.Add(theme); } else { foreach (XmlNode style in styles) { string sName = "", sTitle = ""; XmlNode sNameNode = style.SelectSingleNode("Name"); XmlNode sTitleNode = style.SelectSingleNode("Title"); if (sNameNode == null) { continue; } sName = sTitle = sNameNode.InnerText; if (sTitleNode != null) { sTitle = sTitleNode.InnerText; } IClass wClass = null; if (wfsFc is WFSFeatureClass) { wClass = wfsFc; ((WFSFeatureClass)wClass).Style = sName; } else if (layer.Attributes["queryable"] != null && layer.Attributes["queryable"].Value == "1") { wClass = new WMSQueryableThemeClass(_dataset, name, sName, layer, _getFeatureInfo, _srs, _exceptions); } else { wClass = new WMSThemeClass(_dataset, name, sName, layer); } IWebServiceTheme theme; if (wClass is WFSFeatureClass) { theme = new WebServiceTheme2( wClass, Title + " (Style=" + sTitle + ")", name, true, this); } else { theme = new WebServiceTheme( wClass, Title + " (Style=" + sTitle + ")", name, true, this ); } _themes.Add(theme); } } } doc = null; } catch (Exception ex) { string errMsg = ex.Message; } }
public override FeatureInfoResponse GetFeatureInfo(Capabilities capabilities, string path, GetFeatureInfo getFeatureInfo) { FeatureInfoResponse featureInfoResponse = null; if (capabilities == null || string.IsNullOrEmpty(path) || getFeatureInfo == null) { return(featureInfoResponse); } LayerFactory layerFactory = new LayerFactory(); #region 验证getTile参数 GetTile getTile = getFeatureInfo.GetTile; LayerType layerType = capabilities.GetLayerType(getTile.Layer); if (layerType == null) { return(featureInfoResponse); } TileMatrixSet tileMatrixSet = capabilities.GetTileMatrixSet(getTile.TileMatrixSet); if (tileMatrixSet == null) { return(featureInfoResponse); } TileMatrix tileMatrix = tileMatrixSet.GetTileMatrix(getTile.TileMatrix); if (tileMatrix == null) { return(featureInfoResponse); } BoundingBoxType boundingBoxType = layerType.BoundingBox.FirstOrDefault(); if (boundingBoxType == null) { return(featureInfoResponse); } bool ret = boundingBoxType.LowerCorner.ToPosition(out double xMin, out double yMin); if (!ret) { return(featureInfoResponse); } ret = boundingBoxType.UpperCorner.ToPosition(out double xMax, out double yMax); if (!ret) { return(featureInfoResponse); } bool isDegree = tileMatrixSet.GetIsDegreeByLocalDb(); tileMatrix.GetTileIndex(isDegree, xMin, yMax, out int startCol, out int startRow); int matrixWidth = Convert.ToInt32(tileMatrix.MatrixWidth); int matrixHeight = Convert.ToInt32(tileMatrix.MatrixHeight); if (getTile.TileCol < startCol || getTile.TileCol >= startCol + matrixWidth || getTile.TileRow < startRow || getTile.TileRow >= startRow + matrixHeight) { return(featureInfoResponse); } if (!layerType.Style.Any(x => x.Identifier.Value == getTile.Style)) { return(featureInfoResponse); } #endregion #region 验证getFeatureInfo参数 int tileWidth = Convert.ToInt32(tileMatrix.TileWidth); int tileHeight = Convert.ToInt32(tileMatrix.TileHeight); if (getFeatureInfo.J < 0 || getFeatureInfo.J >= tileHeight || getFeatureInfo.I < 0 || getFeatureInfo.I >= tileWidth) { return(featureInfoResponse); } #endregion using (var dataSource = LayerFactory.OpenDataSource(path)) { if (dataSource == null) { return(featureInfoResponse); } using (var layer = dataSource.GetLayerByName(getTile.Layer)) { if (layer == null) { return(featureInfoResponse); } tileMatrix.GetFeatureInfoBoundary(isDegree, getTile.TileRow, getTile.TileCol, getFeatureInfo.J, getFeatureInfo.I, out double ftInfoXMin, out double ftInfoYMin, out double ftInfoXMax, out double ftInfoYMax); layer.SetSpatialFilterRect(ftInfoXMin, ftInfoYMin, ftInfoXMax, ftInfoYMax); FeatureCollectionType featureCollectionType = new FeatureCollectionType(); featureInfoResponse = new FeatureInfoResponse() { Item = featureCollectionType }; var ft = layer.GetNextFeature(); while (ft != null) { ft = layer.GetNextFeature(); //todo添加查询的feature } } } return(featureInfoResponse); }
/// <summary> /// Generates a WMS 1.3.0 compliant response based on a <see cref="SharpMap.Map"/> and the current HttpRequest. /// </summary> /// <remarks> /// <para> /// The Web Map Server implementation in SharpMap requires v1.3.0 compatible clients, /// and support the basic operations "GetCapabilities" and "GetMap" /// as required by the WMS v1.3.0 specification. SharpMap does not support the optional /// GetFeatureInfo operation for querying. /// </para> /// <example> /// Creating a WMS server in ASP.NET is very simple using the classes in the SharpMap.Web.Wms namespace. /// <code lang="C#"> /// void page_load(object o, EventArgs e) /// { /// //Get the path of this page /// string url = (Request.Url.Query.Length>0?Request.Url.AbsoluteUri.Replace(Request.Url.Query,""):Request.Url.AbsoluteUri); /// SharpMap.Web.Wms.Capabilities.WmsServiceDescription description = /// new SharpMap.Web.Wms.Capabilities.WmsServiceDescription("Acme Corp. Map Server", url); /// /// // The following service descriptions below are not strictly required by the WMS specification. /// /// // Narrative description and keywords providing additional information /// description.Abstract = "Map Server maintained by Acme Corporation. Contact: [email protected]. /// High-quality maps showing roadrunner nests and possible ambush locations."; /// description.Keywords.Add("bird"); /// description.Keywords.Add("roadrunner"); /// description.Keywords.Add("ambush"); /// /// //Contact information /// description.ContactInformation.PersonPrimary.Person = "John Doe"; /// description.ContactInformation.PersonPrimary.Organisation = "Acme Inc"; /// description.ContactInformation.Address.AddressType = "postal"; /// description.ContactInformation.Address.Country = "Neverland"; /// description.ContactInformation.VoiceTelephone = "1-800-WE DO MAPS"; /// //Impose WMS constraints /// description.MaxWidth = 1000; //Set image request size width /// description.MaxHeight = 500; //Set image request size height /// /// //Call method that sets up the map /// //We just add a dummy-size, since the wms requests will set the image-size /// SharpMap.Map myMap = MapHelper.InitializeMap(new System.Drawing.Size(1,1)); /// /// //Parse the request and create a response /// SharpMap.Web.Wms.WmsServer.ParseQueryString(myMap,description); /// } /// </code> /// </example> /// </remarks> /// <param name="map">Map to serve on WMS</param> /// <param name="description">Description of map service</param> ///<param name="pixelSensitivity">Tolerance for GetFeatureInfo requests</param> ///<param name="intersectDelegate">Delegate for Getfeatureinfo intersecting, when null, the WMS will default to ICanQueryLayer implementation</param> public static void ParseQueryString(Map map, Capabilities.WmsServiceDescription description, int pixelSensitivity, InterSectDelegate intersectDelegate) { _pixelSensitivity = pixelSensitivity; _intersectDelegate = intersectDelegate; if (map == null) throw (new ArgumentException("Map for WMS is null")); if (map.Layers.Count == 0) throw (new ArgumentException("Map doesn't contain any layers for WMS service")); if (HttpContext.Current == null) throw new ApplicationException("An attempt was made to access the WMS server outside a valid HttpContext"); HttpContext context = HttpContext.Current; //IgnoreCase value should be set according to the VERSION parameter //v1.3.0 is case sensitive, but since it causes a lot of problems with several WMS clients, we ignore casing anyway. const bool ignorecase = true; //Collect parameters string request = context.Request.Params["REQUEST"]; string version = context.Request.Params["VERSION"]; //Check for required parameters //Request parameter is mandatory if (request == null) { WmsException.ThrowWmsException("Required parameter REQUEST not specified"); return; } //Check if version is supported if (version != null) { if (String.Compare(version, "1.3.0", ignorecase) != 0) { WmsException.ThrowWmsException("Only version 1.3.0 supported"); return; } } else { //Version is mandatory if REQUEST!=GetCapabilities. Check if this is a capabilities request, since VERSION is null if (String.Compare(request, "GetCapabilities", ignorecase) != 0) { WmsException.ThrowWmsException("VERSION parameter not supplied"); return; } } HandlerParams @params = new HandlerParams(context, map, description, ignorecase); GetFeatureInfoParams infoParams = new GetFeatureInfoParams(_pixelSensitivity, _intersectDelegate); IWmsHandler handler = null; if (String.Compare(request, "GetCapabilities", ignorecase) == 0) handler = new GetCapabilities(@params); else if (String.Compare(request, "GetFeatureInfo", ignorecase) == 0) handler = new GetFeatureInfo(@params, infoParams); else if (String.Compare(request, "GetMap", ignorecase) == 0) handler = new GetMap(@params); if (handler == null) { WmsException.ThrowWmsException( WmsException.WmsExceptionCode.OperationNotSupported, String.Format("Invalid request: {0}", request)); } else handler.Handle(); }
public abstract FeatureInfoResponse GetFeatureInfo(string path, GetFeatureInfo getFeatureInfo);
public override FeatureInfoResponse GetFeatureInfo(string path, GetFeatureInfo getFeatureInfo) { throw new NotImplementedException(); }
public abstract FeatureInfoResponse GetFeatureInfo(Capabilities capabilities, string path, GetFeatureInfo getFeatureInfo);
/// <summary> /// Generates a WMS 1.3.0 compliant response based on a <see cref="SharpMap.Map"/> and the current HttpRequest. /// </summary> /// <remarks> /// <para> /// The Web Map Server implementation in SharpMap requires v1.3.0 compatible clients, /// and support the basic operations "GetCapabilities" and "GetMap" /// as required by the WMS v1.3.0 specification. SharpMap does not support the optional /// GetFeatureInfo operation for querying. /// </para> /// <example> /// Creating a WMS server in ASP.NET is very simple using the classes in the SharpMap.Web.Wms namespace. /// <code lang="C#"> /// void page_load(object o, EventArgs e) /// { /// //Get the path of this page /// string url = (Request.Url.Query.Length>0?Request.Url.AbsoluteUri.Replace(Request.Url.Query,""):Request.Url.AbsoluteUri); /// SharpMap.Web.Wms.Capabilities.WmsServiceDescription description = /// new SharpMap.Web.Wms.Capabilities.WmsServiceDescription("Acme Corp. Map Server", url); /// /// // The following service descriptions below are not strictly required by the WMS specification. /// /// // Narrative description and keywords providing additional information /// description.Abstract = "Map Server maintained by Acme Corporation. Contact: [email protected]. /// High-quality maps showing roadrunner nests and possible ambush locations."; /// description.Keywords.Add("bird"); /// description.Keywords.Add("roadrunner"); /// description.Keywords.Add("ambush"); /// /// //Contact information /// description.ContactInformation.PersonPrimary.Person = "John Doe"; /// description.ContactInformation.PersonPrimary.Organisation = "Acme Inc"; /// description.ContactInformation.Address.AddressType = "postal"; /// description.ContactInformation.Address.Country = "Neverland"; /// description.ContactInformation.VoiceTelephone = "1-800-WE DO MAPS"; /// //Impose WMS constraints /// description.MaxWidth = 1000; //Set image request size width /// description.MaxHeight = 500; //Set image request size height /// /// //Call method that sets up the map /// //We just add a dummy-size, since the wms requests will set the image-size /// SharpMap.Map myMap = MapHelper.InitializeMap(new System.Drawing.Size(1,1)); /// /// //Parse the request and create a response /// SharpMap.Web.Wms.WmsServer.ParseQueryString(myMap,description); /// } /// </code> /// </example> /// </remarks> /// <param name="map">Map to serve on WMS</param> /// <param name="description">Description of map service</param> ///<param name="pixelSensitivity">Tolerance for GetFeatureInfo requests</param> ///<param name="intersectDelegate">Delegate for Getfeatureinfo intersecting, when null, the WMS will default to ICanQueryLayer implementation</param> public static void ParseQueryString(Map map, Capabilities.WmsServiceDescription description, int pixelSensitivity, InterSectDelegate intersectDelegate) { _pixelSensitivity = pixelSensitivity; _intersectDelegate = intersectDelegate; if (map == null) { throw (new ArgumentException("Map for WMS is null")); } if (map.Layers.Count == 0) { throw (new ArgumentException("Map doesn't contain any layers for WMS service")); } if (HttpContext.Current == null) { throw new ApplicationException("An attempt was made to access the WMS server outside a valid HttpContext"); } HttpContext context = HttpContext.Current; //IgnoreCase value should be set according to the VERSION parameter //v1.3.0 is case sensitive, but since it causes a lot of problems with several WMS clients, we ignore casing anyway. const bool ignorecase = true; //Collect parameters string request = context.Request.Params["REQUEST"]; string version = context.Request.Params["VERSION"]; //Check for required parameters //Request parameter is mandatory if (request == null) { WmsException.ThrowWmsException("Required parameter REQUEST not specified"); return; } //Check if version is supported if (version != null) { if (String.Compare(version, "1.3.0", ignorecase) != 0) { WmsException.ThrowWmsException("Only version 1.3.0 supported"); return; } } else { //Version is mandatory if REQUEST!=GetCapabilities. Check if this is a capabilities request, since VERSION is null if (String.Compare(request, "GetCapabilities", ignorecase) != 0) { WmsException.ThrowWmsException("VERSION parameter not supplied"); return; } } HandlerParams @params = new HandlerParams(context, map, description, ignorecase); GetFeatureInfoParams infoParams = new GetFeatureInfoParams(_pixelSensitivity, _intersectDelegate); IWmsHandler handler = null; if (String.Compare(request, "GetCapabilities", ignorecase) == 0) { handler = new GetCapabilities(@params); } else if (String.Compare(request, "GetFeatureInfo", ignorecase) == 0) { handler = new GetFeatureInfo(@params, infoParams); } else if (String.Compare(request, "GetMap", ignorecase) == 0) { handler = new GetMap(@params); } if (handler == null) { WmsException.ThrowWmsException( WmsException.WmsExceptionCode.OperationNotSupported, String.Format("Invalid request: {0}", request)); } else { handler.Handle(); } }