/// <summary>
        /// Creates the legend info from a layer info.
        /// </summary>
        /// <param name="layerInfo">The layer info.</param>
        /// <returns></returns>
        private static LayerLegendInfo CreateLegendInfo(WmsLayer.LayerInfo layerInfo)
        {
            List <LegendItemInfo> legendItemInfos = null;

            // If there is a legend url, create a legend item with the image
            if (!string.IsNullOrEmpty(layerInfo.LegendUrl))
            {
                legendItemInfos = new List <LegendItemInfo>
                {
                    new LegendItemInfo
                    {
                        ImageSource = new BitmapImage(new Uri(layerInfo.LegendUrl))
                    }
                };
            }

            return(new LayerLegendInfo
            {
                LayerDescription = layerInfo.Abstract,
                LayerName = layerInfo.Title,
                SubLayerID = layerInfo.SubLayerID,
                LayerLegendInfos = CreateLegendInfos(layerInfo.ChildLayers),
                MaximumScale = layerInfo.MaximumScale,
                MinimumScale = layerInfo.MinimumScale,
                LegendItemInfos = legendItemInfos
            });
        }
        private void SetVisibleLayers(WmsLayer.LayerInfo layerInfo)
        {
            if (Layers == null)
            {
                return;
            }

            bool visible = false;

            if (Layers.Contains(layerInfo.Name))
            {
                // the layer and all its children is visible
                visible = true;
                foreach (var child in Descendants(layerInfo.ChildLayers))
                {
                    child.Visible = true;
                }
            }
            else if (layerInfo.ChildLayers != null)
            {
                foreach (var child in layerInfo.ChildLayers)
                {
                    SetVisibleLayers(child);
                    visible |= child.Visible;                     // if a child is visible, all ascendants must be visible
                }
            }
            layerInfo.Visible = visible;
        }