Common Custom data source
Common_CustomDataSource_CSharp\TiledMapDataSource_CSharp\MapTocFunctionality.cs
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.ADF.Web;

namespace TiledMapDataSource_CSharp
{
    public class MapTocFunctionality : IMapTocFunctionality
    {
        TileCacheInfo _tileCacheInfo =  null;
        public MapTocFunctionality(string name, MapResource resource, TileCacheInfo tileCacheInfo)
        {
            this.name = name;
            this.resource = resource;
            _tileCacheInfo = tileCacheInfo;
        }

        #region private member variables
        private string name = string.Empty;
        private IGISResource resource = null;
        private bool initialized = false;
        #endregion

        #region IMapTocFunctionality implementation
        public void SetLayerVisibility(string mapFunctionalityName, object layerID, bool visible)
        {
            MapFunctionality mapFunc = GetMapFunctionality(mapFunctionalityName);
            if (mapFunc == null)
                throw new ArgumentException("mapFunctionalityName");
            mapFunc.SetLayerVisibility(layerID.ToString(), visible);
        }

        public ESRI.ArcGIS.ADF.Web.TocDataFrame[] GetMapContents(string mapFunctionalityName, ESRI.ArcGIS.ADF.Web.WebImageFormat format, bool useMimeData, bool showAllDataFrames)
        {
            TocDataFrame[] tocDataFrames = new TocDataFrame[1];
            tocDataFrames[0] = new TocDataFrame(resource.Name);
            if (_tileCacheInfo.Layers != null)
            {
                foreach (KeyValuePair<string, string> kvp in _tileCacheInfo.Layers)
                {
                    TocLayer layer = new TocLayer();
                    layer.LayerName = kvp.Value;
                    layer.ID = kvp.Key;
                    layer.Name = kvp.Key;
                    layer.Visible = true;
                    layer.AllowVisibilityChange = false;                    
                    tocDataFrames[0].Add(layer);
                }
            }
            return tocDataFrames;
        }

        #endregion

        #region IGISFunctionality implementation
        System.Web.UI.WebControls.WebControl _webControl;

        public System.Web.UI.WebControls.WebControl WebControl
        {
            get { return _webControl; }
            set { _webControl = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public IGISResource Resource
        {
            get { return resource; }
            set { resource = value; }
        }

        public bool Initialized
        {
            get { return initialized; }
        }

        public void LoadState() { }

        public void Initialize()
        {
            initialized = true;
        }

        public void SaveState() { }


        public void Dispose()
        {
            initialized = false;
        }

        public bool Supports(string operation)
        {
            return true;
        }
        #endregion

        #region private methods
        private MapFunctionality GetMapFunctionality(string name)
        {
            MapFunctionality mapFunctionality = resource.Functionalities.Find(name) as MapFunctionality;
            return mapFunctionality;
        }
        #endregion
    }
}