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 < 1) return "";
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, true, true);
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);
}
}
}
}
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 < 1) return "";
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, true, true);
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);
}
}
}
}