Esempio n. 1
0
        public object Clone()
        {
            OGCLayer newLayer = new OGCLayer();
            newLayer._baseExtent = this._baseExtent;
            newLayer._childLayers = this._childLayers;
            newLayer._Fields = this._Fields;
            newLayer._id = this._id;
            newLayer._isVisible = this._isVisible;
            newLayer._maxscale = this._maxscale;
            newLayer._minscale = this._minscale;
            newLayer._name = this._name;
            newLayer._type = this._type;
            newLayer.LegendUrl = this.LegendUrl;
            newLayer.Style = this.Style;

            return newLayer;
        }
Esempio n. 2
0
        internal static GISLayerInfo Create(XElement layer)
        {
            GISEnvelope env = new GISEnvelope();
            OGCLayer service = new OGCLayer();

            foreach (XElement el in layer.Elements())
            {
                if (el.Name == "Name")
                {
                    service._id = el.Value;
                }
                else if (el.Name == "Title")
                {
                    service._name = el.Value;
                }
                else if (el.Name == "SRS")
                {
                    env.CoordinateSystem = el.Value;
                }
                else if (el.Name == "LatLonBoundingBox")
                {
                    env.minX = double.Parse(el.Attribute("minx").Value);
                    env.maxX = double.Parse(el.Attribute("maxx").Value);
                    env.minY = double.Parse(el.Attribute("miny").Value);
                    env.maxY = double.Parse(el.Attribute("maxy").Value);
                }
                else if (el.Name == "BoundingBox")
                {
                    env.minX = double.Parse(el.Attribute("minx").Value);
                    env.maxX = double.Parse(el.Attribute("maxx").Value);
                    env.minY = double.Parse(el.Attribute("miny").Value);
                    env.maxY = double.Parse(el.Attribute("maxy").Value);
                    env.CoordinateSystem = el.Attribute("SRS").Value;
                }
                else if (el.Name == "Style")
                {
                    OGCStyle style = new OGCStyle() { Name = el.Element("Name").Value };
                    style.Abstract = el.Elements(XName.Get("Abstract")).First().Value;
                    style.Title = el.Elements(XName.Get("Title")).First().Value;

                    if (el.Elements(XName.Get("LegendURL")).Count() > 0)
                    {
                        style.LegendURL = GetHrefFromResource(el.Elements(XName.Get("LegendURL")).First());
                    }

                    service.Style.Add(style);
                }
            }

            service._baseExtent = env;
            return service;
        }
Esempio n. 3
0
        private bool ProcessServiceReturn(string responseString)
        {
            _requestProcessing = false;

            //      <BoundingBox SRS="EPSG:4269" minx="-180" miny="-90" maxx="180" maxy="90"/>
            //<Layer queryable="1">
            //  <Name>world_countries_label</Name>
            //  <Title>Map Background - World Countries Labels</Title>
            //  <SRS>EPSG:4326</SRS>
            //  <LatLonBoundingBox minx="-180" miny="-90" maxx="180" maxy="90"/>
            //</Layer>
            try
            {
                string baseTag = "WMT_MS_Capabilities";
                string xnamespace = string.Empty;

                int idx = responseString.IndexOf("<WMT_MS_Capabilities");

                if (idx < 0)
                {
                    idx = responseString.IndexOf("<WMS_Capabilities");
                    baseTag = "WMS_Capabilities";
                    xnamespace = "http://www.opengis.net/wms";
                }

                XElement document = XElement.Parse(responseString.Substring(idx), LoadOptions.SetBaseUri);

                IEnumerable<XElement> serviceElements = document.Elements(XName.Get("Capability", xnamespace)).First().Elements(XName.Get("Layer", xnamespace));

                if (serviceElements.Count() == 1 && serviceElements.First().Elements(XName.Get("Layer", xnamespace)).Count() == 0)
                {
                }
                else if (serviceElements.Count() == 1 && serviceElements.First().Elements(XName.Get("Layer", xnamespace)).First().Elements(XName.Get("Layer", xnamespace)).Count() > 0)
                {
                    serviceElements = serviceElements.First().Elements(XName.Get("Layer", xnamespace));
                }

                _Server._services.Clear();

                foreach (XElement selement in serviceElements)
                {
                    GISService newSvc = new OGCService(selement.Elements(XName.Get("Title", xnamespace)).First().Value) { _description = selement.Elements(XName.Get("Title", xnamespace)).First().Value };
                    newSvc.BaseExtent = GetExtentFromElement(selement, xnamespace);

                    var layers = selement.Elements(XName.Get("Layer", xnamespace));

                    if (layers.Count() > 0)
                    {
                        foreach (XElement element in layers)
                        {
                            //                        <Layer queryable="1">
                            //  <Name>world_countries_label</Name>
                            //  <Title>Map Background - World Countries Labels</Title>
                            //  <SRS>EPSG:4326</SRS>
                            //  <LatLonBoundingBox minx="-180" miny="-90" maxx="180" maxy="90" />
                            //</Layer>

                            if (element.Descendants(XName.Get("Name", xnamespace)).Count() > 0)
                            {
                                GISLayerInfo layer = new OGCLayer(element.Descendants(XName.Get("Title", xnamespace)).First().Value, element.Descendants(XName.Get("Name", xnamespace)).First().Value);

                                if (element.Attribute(XName.Get("queryable", xnamespace)) != null)
                                {
                                    layer.IsQueryable = element.Attribute(XName.Get("queryable", xnamespace)).Value == "1";
                                }

                                layer.BaseExtent = GetExtentFromElement(element, xnamespace);

                                newSvc.BaseLayers.Add(layer);
                            }
                            else if (element.Descendants(XName.Get("Layer", xnamespace)).Count() > 0)
                            {
                                IEnumerable<XElement> childElements = element.Descendants(XName.Get("Layer", xnamespace));

                                foreach (XElement childElement in childElements)
                                {
                                    GISLayerInfo layer = new OGCLayer(element.Descendants(XName.Get("Title", xnamespace)).First().Value, childElement.Descendants(XName.Get("Name", xnamespace)).First().Value);

                                    if (childElement.Attribute(XName.Get("queryable", xnamespace)) != null)
                                    {
                                        layer.IsQueryable = childElement.Attribute(XName.Get("queryable", xnamespace)).Value == "1";
                                    }

                                    layer.BaseExtent = GetExtentFromElement(childElement, xnamespace);

                                    newSvc.BaseLayers.Add(layer);
                                }
                            }
                        }
                    }
                    else if (selement.Descendants().Count() > 0)
                    {
                        GISLayerInfo layer = new OGCLayer(selement.Descendants(XName.Get("Title", xnamespace)).First().Value, selement.Descendants(XName.Get("Name", xnamespace)).First().Value);

                        if (selement.Attribute(XName.Get("queryable", xnamespace)) != null)
                        {
                            layer.IsQueryable = selement.Attribute(XName.Get("queryable", xnamespace)).Value == "1";
                        }

                        layer.BaseExtent = GetExtentFromElement(selement, xnamespace);

                        newSvc.BaseLayers.Add(layer);
                    }
                    else
                    {
                        GISLayerInfo layer = new OGCLayer(newSvc._serviceName, newSvc._serviceId == null ? newSvc._serviceName : newSvc._serviceId);

                        layer.BaseExtent = GetExtentFromElement(selement, xnamespace);

                        newSvc.BaseLayers.Add(layer);
                    }

                    if (newSvc.Id == null) newSvc._serviceId = newSvc.Name;
                    _Server._services.Add(newSvc);
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }