/// <summary> /// Request GetFeatureInfo /// </summary> protected override void GetFeatureInfo(NameValueCollection requestParams, Stream responseOutputStream, ref string responseContentType) { #region Processing Request GetFeatureInfo int featureCount = 1; if (requestParams["FEATURE_COUNT"] != null) { int.TryParse(requestParams["FEATURE_COUNT"], out featureCount); } int x = 0, y = 0; if (requestParams["X"] == null) { WmsException(WmsExceptionCode.NotApplicable, "Required parameter X undefined.", responseOutputStream, ref responseContentType); return; } else if (!int.TryParse(requestParams["X"], out x)) { WmsException(WmsExceptionCode.NotApplicable, "Parameter X has wrong value.", responseOutputStream, ref responseContentType); return; } if (requestParams["Y"] == null) { WmsException(WmsExceptionCode.NotApplicable, "Required parameter Y undefined.", responseOutputStream, ref responseContentType); return; } else if (!int.TryParse(requestParams["Y"], out y)) { WmsException(WmsExceptionCode.NotApplicable, "Parameter Y has wrong value.", responseOutputStream, ref responseContentType); return; } int width = 0; int height = 0; if (!int.TryParse(requestParams["WIDTH"], out width)) { WmsException(WmsExceptionCode.InvalidDimensionValue, "Parameter WIDTH has wrong value.", responseOutputStream, ref responseContentType); return; } else if (_description.MaxWidth > 0 && width > _description.MaxWidth) { WmsException(WmsExceptionCode.OperationNotSupported, "Parameter WIDTH is too large.", responseOutputStream, ref responseContentType); return; } if (!int.TryParse(requestParams["HEIGHT"], out height)) { WmsException(WmsExceptionCode.InvalidDimensionValue, "Parameter HEIGHT has wrong value.", responseOutputStream, ref responseContentType); return; } else if (_description.MaxHeight > 0 && height > _description.MaxHeight) { WmsException(WmsExceptionCode.OperationNotSupported, "Parameter HEIGHT is too large.", responseOutputStream, ref responseContentType); return; } BoundingRectangle bbox = ParseBbox(requestParams["bbox"]); if (bbox == null) { WmsException(WmsExceptionCode.NotApplicable, "Parameter BBOX has wrong value.", responseOutputStream, ref responseContentType); return; } string mimeTypeNeeded = "text/html"; if (requestParams["INFO_FORMAT"] != null) { mimeTypeNeeded = requestParams["INFO_FORMAT"]; } List <FeatureLayer> queryableLayers = new List <FeatureLayer>(); if (!string.IsNullOrEmpty(requestParams["LAYERS"])) { string[] layers = requestParams["LAYERS"].Split(new[] { ',' }); foreach (string layer in layers) { LayerBase l = null; int i; for (i = 0; i < _map.Layers.Count; i++) { if (string.Equals(_map.Layers[i].Alias, layer, StringComparison.InvariantCultureIgnoreCase)) { l = _map.Layers[i]; } } if (l == null) { WmsException(WmsExceptionCode.LayerNotDefined, "Layer \"" + layer + "\" not found.", responseOutputStream, ref responseContentType); return; } else if (!(l is FeatureLayer) || !((FeatureLayer)l).FeaturesSelectable) { WmsException(WmsExceptionCode.LayerNotQueryable, "Layer \"" + layer + "\" is not queryable.", responseOutputStream, ref responseContentType); return; } else { queryableLayers.Add((FeatureLayer)l); } } queryableLayers.Sort( (FeatureLayer l1, FeatureLayer l2) => _map.Layers.IndexOf(l1) > _map.Layers.IndexOf(l2) ? -1 : 1); List <Feature> selectedFeatures = new List <Feature>(); if (queryableLayers.Count > 0) { lock (_syncRoot) { // calculate the error of selection of point and line objects _map.SelectionPointRadius = _selectionMargin * bbox.Width / width; double resultX = bbox.Width / width * x + bbox.MinX; double resultY = bbox.MaxY - bbox.Height / height * y; ICoordinate point = PlanimetryEnvironment.NewCoordinate(resultX, resultY); ICoordinate tempPoint = PlanimetryEnvironment.NewCoordinate(x, y); if (_map.OnTheFlyTransform != null) { ICoordinate delta = PlanimetryEnvironment.NewCoordinate(tempPoint.X + _map.SelectionPointRadius, tempPoint.Y); IMathTransform inverseTransform = _map.OnTheFlyTransform.Inverse(); delta = PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(delta.Values())); _map.SelectionPointRadius = PlanimetryAlgorithms.Distance( PlanimetryEnvironment.NewCoordinate( inverseTransform.Transform(tempPoint.Values())), delta); } if (queryableLayers[0].Map.OnTheFlyTransform != null) { IMathTransform inverseTransform = queryableLayers[0].Map.OnTheFlyTransform.Inverse(); point = PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(point.Values())); } foreach (LayerBase l in queryableLayers) { FeatureLayer fl = l as FeatureLayer; if (fl != null) { Feature feature = null; fl.SelectObject(point, out feature); if (feature != null) { selectedFeatures.Add(feature); } if (selectedFeatures.Count == featureCount) { break; } } } } } WmsFeaturesInfoNeededEventArgs args = new WmsFeaturesInfoNeededEventArgs(selectedFeatures, mimeTypeNeeded, responseOutputStream, responseContentType); OnFeaturesInfoNeeded(args); responseContentType = args.ResponseContentType; return; } StringBuilder sb = new StringBuilder(); sb.Append("none"); byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString().ToCharArray()); responseOutputStream.Write(bytes, 0, bytes.Length); responseContentType = "text/html"; #endregion }
/// <summary> ///GetFeatureInfo request /// </summary> protected override void GetFeatureInfo(NameValueCollection requestParams, Stream responseOutputStream, ref string responseContentType) { #region Request processing GetFeatureInfo int x = 0, y = 0, featureCount = 1; int row, column; if (requestParams["FEATURE_COUNT"] != null) int.TryParse(requestParams["FEATURE_COUNT"], out featureCount); if (requestParams["I"] == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Required parameter I undefined.", responseOutputStream, ref responseContentType); return; } else if (!int.TryParse(requestParams["I"], out x)) { WmtsException(WmtsExceptionCode.NotApplicable, "Parameter I has wrong value.", responseOutputStream, ref responseContentType); return; } if (requestParams["J"] == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Required parameter J undefined.", responseOutputStream, ref responseContentType); return; } else if (!int.TryParse(requestParams["J"], out y)) { WmtsException(WmtsExceptionCode.NotApplicable, "Parameter J has wrong value.", responseOutputStream, ref responseContentType); return; } if (requestParams["TILEROW"] == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Required parameter TILEROW undefined.", responseOutputStream, ref responseContentType); return; } else if (!int.TryParse(requestParams["TILEROW"], out row)) { WmtsException(WmtsExceptionCode.NotApplicable, "Parameter TILEROW has wrong value.", responseOutputStream, ref responseContentType); return; } if (requestParams["TILECOL"] == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Required parameter TILECOL undefined.", responseOutputStream, ref responseContentType); return; } else if (!int.TryParse(requestParams["TILECOL"], out column)) { WmtsException(WmtsExceptionCode.NotApplicable, "Parameter TILECOL has wrong value.", responseOutputStream, ref responseContentType); return; } string mimeTypeNeeded = "text/html"; if (requestParams["INFO_FORMAT"] != null) mimeTypeNeeded = requestParams["INFO_FORMAT"]; Tile tile = new Tile(_map, (uint)row, (uint)column); //_description.Tile = tile; // //tile.PixelSize = _description.GetScaleDenominator(_description.ZoomLevel[tileMatrixName]); // //tile.ScaleDenominator = _description.GetPixelSize(_description.ZoomLevel[tileMatrixName]); // BoundingRectangle bbox = tile.BBox; int width = tile.Width, height = tile.Height; List<FeatureLayer> queryableLayers = new List<FeatureLayer>(); if (!string.IsNullOrEmpty(requestParams["LAYER"])) { string[] layers = requestParams["LAYER"].Split(new[] { ',' }); foreach (string layer in layers) { LayerBase l = null; int i; for (i = 0; i < _map.Layers.Count; i++) if (string.Equals(_map.Layers[i].Alias, layer, StringComparison.InvariantCultureIgnoreCase)) l = _map.Layers[i]; if (l == null) { WmtsException(WmtsExceptionCode.LayerNotDefined, "Layer \"" + layer + "\" not found.", responseOutputStream, ref responseContentType); return; } else if (!(l is FeatureLayer) || !((FeatureLayer)l).FeaturesSelectable) { WmtsException(WmtsExceptionCode.LayerNotQueryable, "Layer \"" + layer + "\" is not queryable.", responseOutputStream, ref responseContentType); return; } else queryableLayers.Add((FeatureLayer)l); } queryableLayers.Sort( (FeatureLayer l1, FeatureLayer l2) => _map.Layers.IndexOf(l1) > _map.Layers.IndexOf(l2) ? -1 : 1); List<Feature> selectedFeatures = new List<Feature>(); if (queryableLayers.Count > 0) { lock (_syncRoot) { // calculate the error of selection of point and line objects _map.SelectionPointRadius = _selectionMargin * bbox.Width / width; double resultX = bbox.Width / width * x + bbox.MinX; double resultY = bbox.MaxY - bbox.Height / height * y; ICoordinate point = PlanimetryEnvironment.NewCoordinate(resultX, resultY); ICoordinate tempPoint = PlanimetryEnvironment.NewCoordinate(x, y); if (_map.OnTheFlyTransform != null) { ICoordinate delta = PlanimetryEnvironment.NewCoordinate(tempPoint.X + _map.SelectionPointRadius, tempPoint.Y); IMathTransform inverseTransform = _map.OnTheFlyTransform.Inverse(); delta = PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(delta.Values())); _map.SelectionPointRadius = PlanimetryAlgorithms.Distance( PlanimetryEnvironment.NewCoordinate( inverseTransform.Transform(tempPoint.Values())), delta); } if (queryableLayers[0].Map.OnTheFlyTransform != null) { IMathTransform inverseTransform = queryableLayers[0].Map.OnTheFlyTransform.Inverse(); point = PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(point.Values())); } foreach (LayerBase l in queryableLayers) { FeatureLayer fl = l as FeatureLayer; if (fl != null) { Feature feature = null; fl.SelectObject(point, out feature); if (feature != null) selectedFeatures.Add(feature); if (selectedFeatures.Count == featureCount) break; } } } } WmsFeaturesInfoNeededEventArgs args = new WmsFeaturesInfoNeededEventArgs(selectedFeatures, mimeTypeNeeded, responseOutputStream, responseContentType); OnFeaturesInfoNeeded(args); responseContentType = args.ResponseContentType; return; } StringBuilder sb = new StringBuilder(); sb.Append("none"); byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString().ToCharArray()); responseOutputStream.Write(bytes, 0, bytes.Length); responseContentType = "text/html"; #endregion }
/// <summary> /// Request GetFeatureInfo /// </summary> protected override void GetFeatureInfo(NameValueCollection requestParams, Stream responseOutputStream, ref string responseContentType) { #region Processing Request GetFeatureInfo int featureCount = 1; if (requestParams["FEATURE_COUNT"] != null) int.TryParse(requestParams["FEATURE_COUNT"], out featureCount); int x = 0, y = 0; if (requestParams["X"] == null) { WmsException(WmsExceptionCode.NotApplicable, "Required parameter X undefined.", responseOutputStream, ref responseContentType); return; } else if (!int.TryParse(requestParams["X"], out x)) { WmsException(WmsExceptionCode.NotApplicable, "Parameter X has wrong value.", responseOutputStream, ref responseContentType); return; } if (requestParams["Y"] == null) { WmsException(WmsExceptionCode.NotApplicable, "Required parameter Y undefined.", responseOutputStream, ref responseContentType); return; } else if (!int.TryParse(requestParams["Y"], out y)) { WmsException(WmsExceptionCode.NotApplicable, "Parameter Y has wrong value.", responseOutputStream, ref responseContentType); return; } int width = 0; int height = 0; if (!int.TryParse(requestParams["WIDTH"], out width)) { WmsException(WmsExceptionCode.InvalidDimensionValue, "Parameter WIDTH has wrong value.", responseOutputStream, ref responseContentType); return; } else if (_description.MaxWidth > 0 && width > _description.MaxWidth) { WmsException(WmsExceptionCode.OperationNotSupported, "Parameter WIDTH is too large.", responseOutputStream, ref responseContentType); return; } if (!int.TryParse(requestParams["HEIGHT"], out height)) { WmsException(WmsExceptionCode.InvalidDimensionValue, "Parameter HEIGHT has wrong value.", responseOutputStream, ref responseContentType); return; } else if (_description.MaxHeight > 0 && height > _description.MaxHeight) { WmsException(WmsExceptionCode.OperationNotSupported, "Parameter HEIGHT is too large.", responseOutputStream, ref responseContentType); return; } BoundingRectangle bbox = ParseBbox(requestParams["bbox"]); if (bbox == null) { WmsException(WmsExceptionCode.NotApplicable, "Parameter BBOX has wrong value.", responseOutputStream, ref responseContentType); return; } string mimeTypeNeeded = "text/html"; if (requestParams["INFO_FORMAT"] != null) mimeTypeNeeded = requestParams["INFO_FORMAT"]; List<FeatureLayer> queryableLayers = new List<FeatureLayer>(); if (!string.IsNullOrEmpty(requestParams["LAYERS"])) { string[] layers = requestParams["LAYERS"].Split(new[] { ',' }); foreach (string layer in layers) { LayerBase l = null; int i; for (i = 0; i < _map.Layers.Count; i++) if (string.Equals(_map.Layers[i].Alias, layer, StringComparison.InvariantCultureIgnoreCase)) l = _map.Layers[i]; if (l == null) { WmsException(WmsExceptionCode.LayerNotDefined, "Layer \"" + layer + "\" not found.", responseOutputStream, ref responseContentType); return; } else if (!(l is FeatureLayer) || !((FeatureLayer)l).FeaturesSelectable) { WmsException(WmsExceptionCode.LayerNotQueryable, "Layer \"" + layer + "\" is not queryable.", responseOutputStream, ref responseContentType); return; } else queryableLayers.Add((FeatureLayer)l); } queryableLayers.Sort( (FeatureLayer l1, FeatureLayer l2) => _map.Layers.IndexOf(l1) > _map.Layers.IndexOf(l2) ? -1 : 1); List<Feature> selectedFeatures = new List<Feature>(); if (queryableLayers.Count > 0) { lock (_syncRoot) { // calculate the error of selection of point and line objects _map.SelectionPointRadius = _selectionMargin * bbox.Width / width; double resultX = bbox.Width / width * x + bbox.MinX; double resultY = bbox.MaxY - bbox.Height / height * y; ICoordinate point = PlanimetryEnvironment.NewCoordinate(resultX, resultY); ICoordinate tempPoint = PlanimetryEnvironment.NewCoordinate(x, y); if (_map.OnTheFlyTransform != null) { ICoordinate delta = PlanimetryEnvironment.NewCoordinate(tempPoint.X + _map.SelectionPointRadius, tempPoint.Y); IMathTransform inverseTransform = _map.OnTheFlyTransform.Inverse(); delta = PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(delta.Values())); _map.SelectionPointRadius = PlanimetryAlgorithms.Distance( PlanimetryEnvironment.NewCoordinate( inverseTransform.Transform(tempPoint.Values())), delta); } if (queryableLayers[0].Map.OnTheFlyTransform != null) { IMathTransform inverseTransform = queryableLayers[0].Map.OnTheFlyTransform.Inverse(); point = PlanimetryEnvironment.NewCoordinate(inverseTransform.Transform(point.Values())); } foreach (LayerBase l in queryableLayers) { FeatureLayer fl = l as FeatureLayer; if (fl != null) { Feature feature = null; fl.SelectObject(point, out feature); if (feature != null) selectedFeatures.Add(feature); if (selectedFeatures.Count == featureCount) break; } } } } WmsFeaturesInfoNeededEventArgs args = new WmsFeaturesInfoNeededEventArgs(selectedFeatures, mimeTypeNeeded, responseOutputStream, responseContentType); OnFeaturesInfoNeeded(args); responseContentType = args.ResponseContentType; return; } StringBuilder sb = new StringBuilder(); sb.Append("none"); byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString().ToCharArray()); responseOutputStream.Write(bytes, 0, bytes.Length); responseContentType = "text/html"; #endregion }
/// <summary> /// Вызвать событие FeaturesInfoNeeded /// </summary> /// <param name="args"></param> protected void OnFeaturesInfoNeeded(WmsFeaturesInfoNeededEventArgs args) { if (FeaturesInfoNeeded != null) FeaturesInfoNeeded(this, args); }