arcgis server for net 对绑定toc的隐藏和控制

  大家好,好久更新,最近项目比较忙,在做MAP CACHE,几十G的数据出来了好几百万个文件,快吧系统折磨死了,呵呵,有机会会写一些心得发上来交流一下哦,下面是在图层控制中代码的诀窍!

 

参考列子

     HideLayer(Map1, "kuwait");

    private void HideLayer(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map map, string layerName)
    {
        // loop through all map services in the Map/MapResourceManager
        foreach (IMapFunctionality mapFunct in map.GetFunctionalities())
        {
            string layerId = GetLayerId(layerName, mapFunct);
            // Turn layer off if found
            if (!String.IsNullOrEmpty(layerId))
                mapFunct.SetLayerVisibility(layerId, false);
        }

        // find Toc buddied to the Map, if any
        Toc tocCtrl = FindControlOfType(typeof(Toc), Page.Controls) as Toc;
        if (tocCtrl != null && tocCtrl.BuddyControl == map.ID)
        {
            // Remove Toc nodes for layer in each resource, if found
            foreach (TreeViewPlusNode resource in tocCtrl.Nodes)
            {
                TreeViewPlusNode nodeToRemove = null;

                foreach (TreeViewPlusNode layerNode in resource.Nodes)
                {
                    TreeViewPlusNode matchNode = FindNodeRecursive(layerNode, layerName);
                    if (matchNode != null)
                    {
                        nodeToRemove = matchNode;
                        break;
                    }
                }
                if (nodeToRemove != null)
                    nodeToRemove.Remove();
            }
        }
    }
    private string GetLayerId(string layerName, IMapFunctionality mapFunctionality)
    {
        string layerId = String.Empty;

        // get layerIDs/names for the service
        string[] layerIDs, layerNames;
        mapFunctionality.GetLayers(out layerIDs, out layerNames);

        // loop through names, find matching ID
        for (int i = 0; i < layerIDs.Length; i++)
        {
            if (layerNames[i] == layerName)
            {
                layerId = layerIDs[i];
                break;
            }
        }
        return layerId;
    }

    public static System.Web.UI.Control FindControlOfType(Type type, ControlCollection controls)
    {
        // finds the first control matching the Type in the control collection
        foreach (System.Web.UI.Control ctl in controls)
        {
            if (type.IsInstanceOfType(ctl))
                return ctl;
            else if (ctl.HasControls())
            {
                System.Web.UI.Control childCtl = FindControlOfType(type, ctl.Controls);
                if (childCtl != null)
                    return childCtl;
            }
        }
        return null;
    }

    private TreeViewPlusNode FindNodeRecursive(TreeViewPlusNode node, string nodeName)
    {
        if (node.Text == nodeName)
            return node;

        foreach (TreeViewPlusNode node2 in node.Nodes)
        {
            TreeViewPlusNode childNode = FindNodeRecursive(node2, nodeName);
            if (childNode != null)
                return childNode;
        }
        return null;
    }

 

自己使用控制,我只想白一个服务里图层全部删除,比如遥感图小切片太多了,不让用户可以点击出来:-)

 

    protected void Page_PreRenderComplete(object sender, EventArgs e)
    {
        // If no tasks have been defined, hide the tasks panel
        //if (TaskMenu.Items.Count == 0)  Tasks_Menu_Panel.Visible = false;
        // check to see if any of the resource items are non-pooled
        if (!Page.IsCallback || !Page.IsPostBack)
        {
            //CloseHyperLink.Visible = HasNonPooledResources();
            OverviewMap ov = Page.FindControl("OverviewMap1") as OverviewMap;
            if (ov!=null && !OverviewMapResourceIsValid(ov))
                ov.OverviewMapResource = Map1.PrimaryMapResource;

            int tocnum = Toc1.Nodes[1].Nodes.Count;
            if (tocnum > 0) {
                for (int i = tocnum-1; i>-1; i--)
                {

                    Toc1.Nodes[1].Nodes[i].Remove();
                }
            
            //就以上这个代码,要放在这个方法里面,如果放在其他周期里的话,toc里的数据还没有加载上来..
            }


        }
        CopyrightTextHolder.Visible = HasCopyrightText();

    }

   

你可能感兴趣的:(server)