Exemple #1
0
        public override void ProcessRequest(HttpContext context)
        {
            try
            {
                string s = context.Request.Params["BBOX"];
                if (String.IsNullOrEmpty(s))
                {
                    WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter BBOX not specified", context);
                    return;
                }

                Map         map  = this.GetMap(context.Request);
                bool        flip = map.Layers[0].TargetSRID == 4326;
                BoundingBox bbox = WmsServer.ParseBBOX(s, flip);
                if (bbox == null)
                {
                    WmsException.ThrowWmsException("Invalid parameter BBOX", context);
                    return;
                }

                string ls = context.Request.Params["LAYERS"];
                if (!String.IsNullOrEmpty(ls))
                {
                    string[] layers = ls.Split(',');
                    foreach (ILayer layer in map.Layers)
                    {
                        if (!layers.Contains(layer.LayerName))
                        {
                            layer.Enabled = false;
                        }
                    }
                }

                IEnumerable <GeoJSON> items  = GetData(map, bbox);
                StringWriter          writer = new StringWriter();
                GeoJSONWriter.Write(items, writer);
                string buffer = writer.ToString();

                context.Response.Clear();
                context.Response.ContentType  = "text/json";
                context.Response.BufferOutput = true;
                context.Response.Write(buffer);
                context.Response.Flush();
                context.Response.SuppressContent = true;
                context.ApplicationInstance.CompleteRequest();
                //context.Response.End();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                throw;
            }
        }
Exemple #2
0
        public override void ProcessRequest(HttpContext context)
        {
            try
            {
                string s = context.Request.Params["BBOX"];
                if (String.IsNullOrEmpty(s))
                {
                    WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter BBOX not specified");
                    return;
                }

                BoundingBox bbox = WmsServer.ParseBBOX(s);
                if (bbox == null)
                {
                    WmsException.ThrowWmsException("Invalid parameter BBOX");
                    return;
                }

                Map map = this.GetMap(context.Request);
                IEnumerable <GeoJSON> items = this.GetData(map, bbox);

                StringWriter writer = new StringWriter();
                GeoJSONWriter.Write(items, writer);
                string buffer = writer.ToString();

                context.Response.Clear();
                context.Response.ContentType  = "text/json";
                context.Response.BufferOutput = true;
                context.Response.Write(buffer);
                context.Response.End();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
                throw;
            }
        }