private void btnSave_Click(object sender, EventArgs e)
        {
            if (_metadata != null)
            {
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.Filter = "Xml Datei|*.xml";

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    XmlStream stream = new XmlStream("TileService");
                    _metadata.Save(stream);
                    stream.WriteStream(dlg.FileName);
                }
            }
        }
Пример #2
0
        public void Request(IServiceRequestContext context)
        {
            try
            {
                if (context == null || context.ServiceRequest == null || context.ServiceMap == null)
                {
                    return;
                }

                if (_mapServer == null)
                {
                    context.ServiceRequest.Response = "<FATALERROR>MapServer Object is not available!</FATALERROR>";
                    return;
                }

                TileServiceMetadata metadata = context.ServiceMap.MetadataProvider(_metaprovider) as TileServiceMetadata;
                if (metadata == null || metadata.Use == false)
                {
                    context.ServiceRequest.Response = "<ERROR>Service is not used with Tile Service</ERROR>";
                }

                string service = context.ServiceRequest.Service;
                string request = context.ServiceRequest.Request;
                if (request.ToLower().StartsWith("path="))
                {
                    request = request.Substring(5);
                }

                string[] args = request.Split('/');

                string command        = args[0].ToLower();
                bool   renderOnTheFly = false;
                if (command.Contains(":"))
                {
                    switch (command.Split(':')[1])
                    {
                    case "render":
                        renderOnTheFly = true;
                        break;
                    }

                    command = command.Split(':')[0];
                }

                switch (command)
                {
                case "metadata":
                    XmlStream stream = new XmlStream("metadata");
                    metadata.Save(stream);
                    StringWriter sw = new StringWriter();
                    stream.WriteStream(sw);
                    sw.Close();
                    context.ServiceRequest.Response = sw.ToString();
                    break;

                case "osm":
                case "tms":
                    if (args.Length == 4)
                    {
                        int epsg = int.Parse(args[1]);
                        if (metadata.EPSGCodes.Contains(epsg))
                        {
                            context.ServiceRequest.Response = TmsCapabilities(context, metadata, epsg);
                        }
                    }
                    else if (args.Length == 7)     // tms/srs/1.0.0/service/0/0/0.png
                    {
                        int    epsg   = int.Parse(args[1]);
                        double scale  = metadata.Scales[int.Parse(args[4])];
                        int    row    = (args[0] == "tms" ? int.Parse(args[5]) : int.Parse(args[6].Split('.')[0]));
                        int    col    = (args[0] == "tms" ? int.Parse(args[6].Split('.')[0]) : int.Parse(args[5]));
                        string format = ".png";
                        if (args[6].ToLower().EndsWith(".jpg"))
                        {
                            format = ".jpg";
                        }

                        GetTile(context, metadata, epsg, scale, row, col, format, (args[0] == "tms" ? GridOrientation.LowerLeft : GridOrientation.UpperLeft), renderOnTheFly);
                    }
                    else if (args.Length == 10)      // tms/srs/service/01/000/000/001/000/000/001.png
                    {
                        int    epsg   = int.Parse(args[1]);
                        double scale  = metadata.Scales[int.Parse(args[3])];
                        int    col    = int.Parse(args[4]) * 1000000 + int.Parse(args[5]) * 1000 + int.Parse(args[6]);
                        int    row    = int.Parse(args[7]) * 1000000 + int.Parse(args[8]) * 1000 + int.Parse(args[9].Split('.')[0]);
                        string format = ".png";
                        if (args[9].ToLower().EndsWith(".jpg"))
                        {
                            format = ".jpg";
                        }

                        GetTile(context, metadata, epsg, scale, row, col, format, (args[0] == "tms" ? GridOrientation.LowerLeft : GridOrientation.UpperLeft), renderOnTheFly);
                    }
                    break;

                case "init":
                    if (args.Length >= 5)
                    {
                        string cacheFormat = args[1].ToLower() == "compact" ? "compact" : "";
                        if (args[2].ToLower() != "ul" &&
                            args[2].ToLower() != "ll")
                        {
                            throw new ArgumentException();
                        }

                        int    epsg   = int.Parse(args[3]);
                        string format = "image/" + args[4].ToLower();
                        if (args[4].ToLower().EndsWith(".jpg"))
                        {
                            format = ".jpg";
                        }

                        WriteConfFile(context, metadata, cacheFormat, epsg, format,
                                      (args[2].ToLower() == "ul" ? GridOrientation.UpperLeft : GridOrientation.LowerLeft));
                    }
                    break;

                case "tile":
                    if (args.Length == 5)
                    {
                        int    epsg   = int.Parse(args[1]);
                        double scale  = GetScale(metadata, args[2]);    // double.Parse(args[2].Replace(",", "."), _nhi);
                        int    row    = int.Parse(args[3]);
                        int    col    = int.Parse(args[4].Split('.')[0]);
                        string format = ".png";
                        if (args[4].ToLower().EndsWith(".jpg"))
                        {
                            format = ".jpg";
                        }

                        GetTile(context, metadata, epsg, scale, row, col, format, GridOrientation.UpperLeft, renderOnTheFly);
                    }
                    else if (args.Length == 6)
                    {
                        if (args[1].ToLower() != "ul" &&
                            args[1].ToLower() != "ll")
                        {
                            throw new ArgumentException();
                        }

                        int    epsg   = int.Parse(args[2]);
                        double scale  = GetScale(metadata, args[3]);    // double.Parse(args[3].Replace(",", "."), _nhi);
                        int    row    = int.Parse(args[4]);
                        int    col    = int.Parse(args[5].Split('.')[0]);
                        string format = ".png";
                        if (args[5].ToLower().EndsWith(".jpg"))
                        {
                            format = ".jpg";
                        }

                        GetTile(context, metadata, epsg, scale, row, col, format,
                                (args[1].ToLower() == "ul" ? GridOrientation.UpperLeft : GridOrientation.LowerLeft), renderOnTheFly);
                    }
                    else if (args.Length >= 7)
                    {
                        string cacheFormat = args[1].ToLower();
                        if (args[2].ToLower() != "ul" &&
                            args[2].ToLower() != "ll")
                        {
                            throw new ArgumentException();
                        }

                        int    epsg   = int.Parse(args[3]);
                        double scale  = GetScale(metadata, args[4]);    // double.Parse(args[4].Replace(",", "."), _nhi);
                        int    row    = int.Parse(args[5]);
                        int    col    = int.Parse(args[6].Split('.')[0]);
                        string format = ".png";
                        if (args[6].ToLower().EndsWith(".jpg"))
                        {
                            format = ".jpg";
                        }

                        if (cacheFormat == "compact")
                        {
                            var boundingTiles = args.Length > 7 ? new BoundingTiles(args[7]) : null;

                            GetCompactTile(context, metadata, epsg, scale, row, col, format,
                                           (args[2].ToLower() == "ul" ? GridOrientation.UpperLeft : GridOrientation.LowerLeft), boundingTiles, renderOnTheFly);
                        }
                        else
                        {
                            GetTile(context, metadata, epsg, scale, row, col, format,
                                    (args[2].ToLower() == "ul" ? GridOrientation.UpperLeft : GridOrientation.LowerLeft), renderOnTheFly);
                        }
                    }
                    else
                    {
                        throw new ArgumentException();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                if (context != null && context.ServiceRequest != null)
                {
                    context.ServiceRequest.Response = "<Exception>" + ex.Message + "</Exception>";
                }
            }
        }