C# ArcGIS Server9.3 显示图例

ContractedBlock.gif ExpandedBlockStart.gif Code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer;

using Teleware.WebGIS.GISUtils;

///<summary>
/// AJAXShowLegend 的摘要说明
/// </summary>

//InitialToolbar();
//初始化图例
//ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality mapFunc = Map1.GetFunctionality(SessionDataManager.SystemMapResourceName) as ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality;
//string[] layerids, strlayernames;
//mapFunc.GetLayers(out layerids, out strlayernames);
//legendlayers.Items.Add("选择图层");
//legendlayers.Items.Add("显示全部图例");
//for (int i = 0; i < strlayernames.Length; i++)
//    {
//        legendlayers.Items.Add(strlayernames[i]);
//  }
//legendlayers.Attributes.Add("onchange", "javascript:Showlayerlegend(LegendShowPanel_legendlayers.value)");
//初始化行政区查询框
//XzqList.Items.Add("市级行政区");


public class ShowLegend: IAJAXServerProcess
{
    
#region IAJAXServerProcess 成员
    
public string ProcessMessage(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map Map1, string commandName, string[] parameters)
    {
        
if (parameters.Length < 1return "";
        
string layerName = parameters[0];
        
return CreateLayerLegend(Map1, layerName);
    }
    
#endregion

    
private string CreateLayerLegend(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map Map1,string layername)
    {
        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality mapFunc 
= Map1.GetFunctionality(SessionDataManager.SystemMapResourceName) as ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality;

        
//LayerDescription[] layerdescriptions= mapFunc.MapDescription.LayerDescriptions;
        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal mapresource = mapFunc.Resource as ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal;
        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapTocFunctionality maptocfunc 
= new ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapTocFunctionality("sss", mapresource);
        ESRI.ArcGIS.ADF.Web.TocDataFrame[] tocdataframe 
= maptocfunc.GetMapContents(mapFunc.Name, ESRI.ArcGIS.ADF.Web.WebImageFormat.JPG, truetrue);
        ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode node1 
= new ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode();
        ESRI.ArcGIS.ADF.Web.TocLayer ptoclayer;
        ESRI.ArcGIS.ADF.Web.UI.WebControls.FloatingPanel QueryResultShowPanel 
= Map1.FindControl("LegendShowPanel"as ESRI.ArcGIS.ADF.Web.UI.WebControls.FloatingPanel;
        PlaceHolder pplaceholder 
= QueryResultShowPanel.FindControl("PlaceHolder2"as PlaceHolder;
        
if (tocdataframe.Length > 0)
        {
            System.Collections.IEnumerator ptocenum 
= tocdataframe[0].GetEnumerator();

            HtmlTable htable 
= new HtmlTable();

            
if (layername != "显示全部图例")
            {
                
//显示所选图层图例
                while (ptocenum.MoveNext())
                {
                    ptoclayer 
= (ESRI.ArcGIS.ADF.Web.TocLayer)ptocenum.Current;
                    
if (ptoclayer.Name == layername)
                    {
                        CreateSomeLayerLegend(ptoclayer, htable);
                        
break;
                    }
                }
            }
            
else
            {
                
//显示全部图层图例
                while (ptocenum.MoveNext())
                {
                    ptoclayer 
= (ESRI.ArcGIS.ADF.Web.TocLayer)ptocenum.Current;
                    CreateSomeLayerLegend(ptoclayer, htable);
                }
            }

            pplaceholder.Controls.Add(htable);
            
//QueryResultShowPanel.ShowFloatingPanel();
            QueryResultShowPanel.Refresh();
            
//legendlayers.Text = layername;

        }
        
//return QueryResultShowPanel.CallbackResults.ToString();
        Map1.CallbackResults.CopyFrom(QueryResultShowPanel.CallbackResults);
        
return Map1.CallbackResults.ToString();

    }

    
private void CreateSomeLayerLegend(ESRI.ArcGIS.ADF.Web.TocLayer ptoclayer, HtmlTable htable)
    {
        HtmlTableCell hcell 
= new HtmlTableCell();
        HtmlTableRow hrow 
= new HtmlTableRow();
        hcell.InnerText 
= ptoclayer.Name;
        hrow.Cells.Add(hcell);
        htable.Rows.Add(hrow);
        System.Collections.IEnumerator ptocsymbolenum 
= ptoclayer.GetTocSymbolGroups();
        
while (ptocsymbolenum.MoveNext())
        {
            ESRI.ArcGIS.ADF.Web.TocSymbolGroup group 
= ptocsymbolenum.Current as ESRI.ArcGIS.ADF.Web.TocSymbolGroup;
            
foreach (ESRI.ArcGIS.ADF.Web.TocSymbol symbol in group)
            {
                ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode node2 
= new ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode();
                HtmlImage himage 
= new HtmlImage();
                himage.Src 
= symbol.Image.Url;
                hcell 
= new HtmlTableCell();
                hrow 
= new HtmlTableRow();
                hcell.Controls.Add(himage);
                hrow.Cells.Add(hcell);
                hcell 
= new HtmlTableCell();
                
if (symbol.Label == "<all other values>")
                    hcell.InnerText 
= "其它";
                
else
                    hcell.InnerText 
= symbol.Label;
                hrow.Cells.Add(hcell);
                htable.Rows.Add(hrow);
            }
        }
    }
}

转载于:https://www.cnblogs.com/liugt/archive/2009/07/09/1519947.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值