コード例 #1
0
        private void GetMap(NameValueCollection requestParams, Stream responseOutputStream, ref string responseContentType)
        {
            #region Verify the request

            if (requestParams["LAYERS"] == null)
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Required parameter LAYERS not specified.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            if (requestParams["STYLES"] == null)
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Required parameter STYLES not specified.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            if (requestParams["SRS"] == null)
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Required parameter SRS not specified.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            else
            {
                string authCode = "EPSG:-1";
                if (!string.IsNullOrEmpty(_map.CoodrinateSystemWKT))
                {
                    IInfo coordinateSystem =
                        CoordinateSystemWktDeserializer.Parse(_map.CoodrinateSystemWKT);
                    authCode = coordinateSystem.Authority + ":" + coordinateSystem.AuthorityCode.ToString();
                }

                if (requestParams["SRS"] != authCode)
                {
                    WmsException(WmsExceptionCode.InvalidSRS,
                                 "SRS is not supported",
                                 responseOutputStream,
                                 ref responseContentType);
                    return;
                }
            }
            if (requestParams["BBOX"] == null)
            {
                WmsException(WmsExceptionCode.InvalidDimensionValue,
                             "Required parameter BBOX not specified.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            if (requestParams["WIDTH"] == null)
            {
                WmsException(WmsExceptionCode.InvalidDimensionValue,
                             "Required parameter WIDTH not specified.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            if (requestParams["HEIGHT"] == null)
            {
                WmsException(WmsExceptionCode.InvalidDimensionValue,
                             "Required parameter HEIGHT not specified.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            if (requestParams["FORMAT"] == null)
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Required parameter FORMAT not specified.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            #endregion

            #region Render Settings

            Color backColor = Color.White;

            if (_map.CosmeticRaster.Visible)
            {
                //Cosmetic layer all broken, this does not allow its use.
                WmsException(WmsExceptionCode.NotApplicable,
                             "WMS  not support this settings rendering.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }


            if (string.Compare(requestParams["TRANSPARENT"], "TRUE", _ignoreCase) == 0)
            {
                backColor = Color.Transparent;
            }
            else if (requestParams["BGCOLOR"] != null)
            {
                try
                {
                    backColor = ColorTranslator.FromHtml("#" + requestParams["BGCOLOR"]);
                }
                catch
                {
                    WmsException(WmsExceptionCode.NotApplicable,
                                 "Parameter BGCOLOR has wrong value.",
                                 responseOutputStream,
                                 ref responseContentType);
                    return;
                }
            }


            ImageCodecInfo imageEncoder = getEncoderInfo(requestParams["FORMAT"]);
            if (imageEncoder == null)
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Wrong mime-type in FORMAT parameter.",
                             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,
                             "WIDTH parameter value 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,
                             "HEIGHT parameter value is too large.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            BoundingRectangle originalBbox = ParseBbox(requestParams["bbox"]);
            if (originalBbox == null)
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Wrong BBOX parameter.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            #endregion

            //Selected by default.
            bool[] _defaultVisibility = new bool[_map.Layers.Count()];

            int j = 0;
            foreach (LayerBase layer in _map.Layers)
            {
                _defaultVisibility[j] = layer.Visible;
                layer.Visible         = false; //Turning off all the layers.
                j++;
            }

            lock (_syncRoot)
            {
                LayerBase[] useLayers   = null;
                int[]       indexLayers = null;
                #region Checking layers of inquiry

                if (!string.IsNullOrEmpty(requestParams["LAYERS"]))
                {
                    #region Getting layers of inquiry

                    string[] layers = requestParams["LAYERS"].Split(new[] { ',' });
                    if (_description.LayerLimit > 0)
                    {
                        if (layers.Length == 0 && _map.Layers.Count > _description.LayerLimit ||
                            layers.Length > _description.LayerLimit)
                        {
                            WmsException(WmsExceptionCode.OperationNotSupported,
                                         "The number of layers in the query exceeds the limit of layers in the WMS.",
                                         responseOutputStream,
                                         ref responseContentType);
                            return;
                        }
                    }

                    #endregion

                    useLayers   = new LayerBase[layers.Length];
                    indexLayers = new int[layers.Length];
                    for (int i = 0; i < layers.Length; i++)
                    {
                        var layer     = layers[i];
                        var findLayer = false;
                        for (int k = 0; k < _map.Layers.Count; k++)
                        {
                            if (string.Equals(_map.Layers[k].Alias, layer,
                                              StringComparison.InvariantCultureIgnoreCase))
                            {
                                useLayers[i]   = _map.Layers[k];
                                indexLayers[i] = k;
                                findLayer      = true;
                                break;
                            }
                        }


                        if (!findLayer)
                        {
                            WmsException(WmsExceptionCode.LayerNotDefined,
                                         "Layer \"" + layer + "\" not found.",
                                         responseOutputStream,
                                         ref responseContentType);
                            return;
                        }
                    }

                    Array.Sort(indexLayers, useLayers);
                }

                #endregion

                BoundingRectangle bboxWithGutters = (BoundingRectangle)originalBbox.Clone();
                bboxWithGutters.Grow((double)GutterSize * originalBbox.Width / (double)width);

                try
                {
                    using (Image bmp = GetImage(width, height, backColor, useLayers, bboxWithGutters))
                    {
                        EncoderParameters encoderParams = new EncoderParameters(1);
                        encoderParams.Param[0] = new EncoderParameter(
                            System.Drawing.Imaging.Encoder.Quality, (long)_imageQuality);

                        using (MemoryStream ms = new MemoryStream())
                        {
                            bmp.Save(ms, imageEncoder, encoderParams);
                            byte[] buffer = ms.ToArray();
                            responseContentType = imageEncoder.MimeType;
                            responseOutputStream.Write(buffer, 0, buffer.Length);
                        }
                    }
                }
                catch (Exception except)
                {
                    WmsException(WmsExceptionCode.NotApplicable, except.Message, responseOutputStream, ref responseContentType);
                    return;
                }

                for (j = 0; j < _map.Layers.Count(); j++) // Restore everything as it was.
                {
                    _map.Layers[j].Visible = _defaultVisibility[j];
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Overrides CheckRequestParams of MapServerBase
        /// </summary>
        /// <param name="requestParams"></param>
        /// <param name="responseOutputStream"></param>
        /// <param name="responseContentType"></param>
        /// <param name="originalBbox"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        protected override void CheckRequestParams(NameValueCollection requestParams, Stream responseOutputStream,
                                                   ref string responseContentType, out BoundingRectangle originalBbox, out int width, out int height)
        {
            originalBbox = null;
            width        = 0;
            height       = 0;

            #region Checks the special params of WMS request

            if (requestParams["BBOX"] == null)
            {
                WmsException(WmsExceptionCode.InvalidDimensionValue,
                             "Required parameter BBOX is not specified.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            if (requestParams["WIDTH"] == null)
            {
                WmsException(WmsExceptionCode.InvalidDimensionValue,
                             "Required parameter WIDTH is not specified.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            if (requestParams["HEIGHT"] == null)
            {
                WmsException(WmsExceptionCode.InvalidDimensionValue,
                             "Required parameter HEIGHT is not specified.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            if (requestParams["SRS"] == null)
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Required parameter SRS not specified.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }
            else
            {
                string authCode = "EPSG:-1";
                if (!string.IsNullOrEmpty(_map.CoodrinateSystemWKT))
                {
                    IInfo coordinateSystem =
                        CoordinateSystemWktDeserializer.Parse(_map.CoodrinateSystemWKT);
                    authCode = coordinateSystem.Authority + ":" + coordinateSystem.AuthorityCode.ToString();
                }

                if (requestParams["SRS"] != authCode)
                {
                    WmsException(WmsExceptionCode.InvalidSRS,
                                 "SRS is not supported",
                                 responseOutputStream,
                                 ref responseContentType);
                    return;
                }
            }

            #endregion

            #region Tries to parse the special params of WMS request

            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,
                             "WIDTH parameter value 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,
                             "HEIGHT parameter value is too large.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            originalBbox = ParseBbox(requestParams["bbox"]);

            if (originalBbox == null)
            {
                WmsException(WmsExceptionCode.NotApplicable,
                             "Wrong BBOX parameter.",
                             responseOutputStream,
                             ref responseContentType);
                return;
            }

            #endregion
        }
コード例 #3
0
        private static XmlNode GenerateCapabilityNode(Map map, WmtsServiceDescription serviceDescription, XmlDocument capabilities)
        {
            string OnlineResource = string.Empty; // !!!!!!!!!!!! Доработать!

            XmlNode CapabilityNode      = capabilities.CreateNode(XmlNodeType.Element, "Capability", wmtsNamespaceURI);
            XmlNode RequestNode         = capabilities.CreateNode(XmlNodeType.Element, "Request", wmtsNamespaceURI);
            XmlNode GetCapabilitiesNode = capabilities.CreateNode(XmlNodeType.Element, "GetCapabilities",
                                                                  wmtsNamespaceURI);

            GetCapabilitiesNode.AppendChild(createElement("Format", "text/xml", capabilities, false, wmtsNamespaceURI));
            GetCapabilitiesNode.AppendChild(GenerateDCPTypeNode(capabilities, OnlineResource));
            RequestNode.AppendChild(GetCapabilitiesNode);

            XmlNode getMapNode = capabilities.CreateNode(XmlNodeType.Element, "GetTile", wmtsNamespaceURI);

            // поддерживаемые форматы изображений
            foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders())
            {
                getMapNode.AppendChild(createElement("Format", encoder.MimeType, capabilities, false, wmtsNamespaceURI));
            }

            getMapNode.AppendChild(GenerateDCPTypeNode(capabilities, OnlineResource));

            RequestNode.AppendChild(getMapNode);
            CapabilityNode.AppendChild(RequestNode);
            XmlElement exceptionNode = capabilities.CreateElement("Exception", wmtsNamespaceURI);

            exceptionNode.AppendChild(createElement("Format", "text/xml", capabilities, false, wmtsNamespaceURI));
            CapabilityNode.AppendChild(exceptionNode); //Add supported exception types

            // список слоев
            XmlNode layerRootNode = capabilities.CreateNode(XmlNodeType.Element, "Layer", wmtsNamespaceURI);

            layerRootNode.AppendChild(createElement("Title", "MapAround", capabilities, false, wmtsNamespaceURI));

            string srs = "EPSG:-1";

            if (!string.IsNullOrEmpty(map.CoodrinateSystemWKT))
            {
                ICoordinateSystem coordinateSystem =
                    (ICoordinateSystem)CoordinateSystemWktDeserializer.Parse(map.CoodrinateSystemWKT);

                srs = coordinateSystem.Authority + ":" + coordinateSystem.AuthorityCode;
            }

            layerRootNode.AppendChild(createElement("SRS", srs, capabilities, false,
                                                    wmtsNamespaceURI));

            if (serviceDescription.Tile != null &&
                !serviceDescription.Tile.IsEmpty())
            {
                layerRootNode.AppendChild(GenerateTileElement(serviceDescription.Tile, srs, capabilities));
            }

            foreach (LayerBase layer in map.Layers)
            {
                layerRootNode.AppendChild(getWmtsLayerNode(serviceDescription, layer, capabilities));
            }

            CapabilityNode.AppendChild(layerRootNode);

            return(CapabilityNode);
        }