Esempio n. 1
0
        private void ParseCapabilities(XDocument xDoc)
        {
            //Get service info
            var info = (from Service in xDoc.Descendants("Service")
                        select new
            {
                Title = Service.Element("Title") == null ? null : Service.Element("Title").Value,
                Abstract = Service.Element("Abstract") == null ? null : Service.Element("Abstract").Value
            }).First();

            if (info != null)
            {
                this.Title = info.Title;
                //OnPropertyChanged("Title");
                this.Abstract = info.Abstract;
                //OnPropertyChanged("Abstract");
            }
            //Get a list of layers
            var layerList = from Layers in xDoc.Descendants("Layer")
                            where Layers.Descendants("Layer").Count() == 0
                            select new LayerInfo()
            {
                Name     = Layers.Element("Name") == null ? null : Layers.Element("Name").Value,
                Title    = Layers.Element("Title") == null ? null : Layers.Element("Title").Value,
                Abstract = Layers.Element("Abstract") == null ? null : Layers.Element("Abstract").Value
            };

            foreach (LayerInfo i in layerList)
            {
                this.LayerList.Add(i);
            }
            //OnPropertyChanged("LayerList");

            try
            {
                //Get endpoint for GetMap requests
                //I wish SL supported XPath...
                var capabilities   = (from c in xDoc.Descendants("Capability") select c).First();
                var request        = (from c in capabilities.Descendants("Request") select c).First();
                var GetMap         = (from c in request.Descendants("GetMap") select c).First();
                var DCPType        = (from c in request.Descendants("DCPType") select c).First();
                var HTTP           = (from c in request.Descendants("HTTP") select c).First();
                var Get            = (from c in request.Descendants("Get") select c).First();
                var OnlineResource = (from c in request.Descendants("OnlineResource") select c).First();
                var href           = OnlineResource.Attribute(XName.Get("href", "http://www.w3.org/1999/xlink"));
                httpGetResource = href.Value;
            }
            catch
            {               //Default to WMS url
                httpGetResource = this.Url;
            }
            //Get the full extent of all layers
            var box = (from Layers in xDoc.Descendants("LatLonBoundingBox")
                       select new
            {
                minx = double.Parse(Layers.Attribute("minx").Value),
                miny = double.Parse(Layers.Attribute("miny").Value),
                maxx = double.Parse(Layers.Attribute("maxx").Value),
                maxy = double.Parse(Layers.Attribute("maxy").Value)
            }).ToList();
            var minx = (from minmax in box select minmax.minx).Min();
            var miny = (from minmax in box select minmax.miny).Min();
            var maxx = (from minmax in box select minmax.maxx).Max();
            var maxy = (from minmax in box select minmax.maxy).Max();

            this.FullExtent = new Envelope(minx, miny, maxx, maxy)
            {
                SpatialReference = new SpatialReference(4326)
            };
        }