public WmsServiceViewModel GetLayers(string wmsUrl)
        {
            WmsServiceViewModel serviceModel = new WmsServiceViewModel();

            if (!wmsUrl.EndsWith("?"))
            {
                wmsUrl = wmsUrl + "?";
            }
            wmsUrl = wmsUrl + "service=wms&request=GetCapabilities";

            XDocument xmlDocument = XDocument.Load(wmsUrl);

            XElement root = xmlDocument.Element(WMS + "WMS_Capabilities");
            if (root != null)
            {
                WmsGetCapabilities13Parser parser = new WmsGetCapabilities13Parser();
                serviceModel = parser.Parse(xmlDocument);
                if (serviceModel.SupportsEnglishGetCapabilities)
                {
                    XDocument getCapabilitiesEnglish = XDocument.Load(wmsUrl + "&language=eng");
                    Dictionary<string, Dictionary<string, string>> englishInformation = parser.ParseEnglishGetCapabilities(getCapabilitiesEnglish);
                    serviceModel.AppendEnglishInformation(englishInformation);
                }
            }
            else
            {
                root = xmlDocument.Element("WMT_MS_Capabilities");
                if (root != null)
                {
                    serviceModel = new WmsGetCapabilities11Parser().Parse(xmlDocument);
                }
            }

            return serviceModel;
        }
        public void ShouldParseLayerGroupsFromWms1_1_GetCapabilitiesDocument()
        {
            XDocument doc = XDocument.Parse(xmlFile);
            WmsServiceViewModel serviceModel = new WmsGetCapabilities11Parser().Parse(doc);

            Assert.NotNull(serviceModel.Layers, "No layers found");
            Assert.AreEqual(26, serviceModel.Layers.Count, "Should have many layers");
        }
Esempio n. 3
0
        public WmsServiceViewModel GetLayers(string wmsUrl)
        {
            if (!string.IsNullOrWhiteSpace(wmsUrl))
            {
                WmsServiceViewModel serviceModel = new WmsServiceViewModel();

                XDocument xmlDocument = XDocument.Load(wmsUrl);

                XElement root = xmlDocument.Element(WMS + "WMS_Capabilities");
                if (root != null)
                {
                    WmsGetCapabilities13Parser parser = new WmsGetCapabilities13Parser();
                    serviceModel = parser.Parse(xmlDocument);
                    if (serviceModel.SupportsEnglishGetCapabilities)
                    {
                        XDocument getCapabilitiesEnglish = XDocument.Load(wmsUrl + "&language=eng");
                        Dictionary <string, Dictionary <string, string> > englishInformation = parser.ParseEnglishGetCapabilities(getCapabilitiesEnglish);
                        serviceModel.AppendEnglishInformation(englishInformation);
                    }
                }
                else
                {
                    root = xmlDocument.Element("WMT_MS_Capabilities");
                    if (root != null)
                    {
                        serviceModel = new WmsGetCapabilities11Parser().Parse(xmlDocument);
                    }
                }

                return(serviceModel);
            }
            else
            {
                return(null);
            }
        }