目的:
1.arcgis server9.2 ADF的DynamicData,动态的设置Resource。
准备工作:
1.用ArcGis Server Manager或者ArcCatalog发布一个叫world的Map Service,并且把这个Service启动起来。
2.用ArcGis Server Manager或者ArcCatalog发布一个叫usa的Map Service,并且把这个Service启动起来。
3.找到DeveloperKit\SamplesNET\Server\Web_Applications目录下的Common_AddDynamicDataCSharp.zip。
开始:
1.新建名为AddDynamicData的ASP.NET Web应用程序。
2.在页面上添加MapResourceManager1,不做任何设置;添加Map1,MapResourceManager属性为MapResourceManager1;添加Toc1,BuddyControl属性为Map1;添加一个CheckBoxList1,添加2个ListItem分别为ArcGIS Server Local和ArcGIS Server Internet。具体的代码如下:
Code
1<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AddDynamicData._Default" %>
2
3<%@ Register Assembly="ESRI.ArcGIS.ADF.Web.UI.WebControls, Version=9.2.4.1420, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86"
4 Namespace="ESRI.ArcGIS.ADF.Web.UI.WebControls" TagPrefix="esri" %>
5
6<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
7
8<html xmlns="http://www.w3.org/1999/xhtml" >
9<head runat="server">
10 <title>无标题页</title>
11</head>
12<body>
13 <form id="form1" runat="server">
14 <div>
15 <table width="623" border="1" cellspacing="0" cellpadding="0">
16 <tr>
17 <td width="391">
18 <esri:Toolbar ID="Toolbar1" runat="server" BuddyControlType="Map" Group="Toolbar1_Group"
19 Height="50px" ToolbarItemDefaultStyle-BackColor="White" ToolbarItemDefaultStyle-Font-Names="Arial"
20 ToolbarItemDefaultStyle-Font-Size="Smaller" ToolbarItemDisabledStyle-BackColor="White"
21 ToolbarItemDisabledStyle-Font-Names="Arial" ToolbarItemDisabledStyle-Font-Size="Smaller"
22 ToolbarItemDisabledStyle-ForeColor="Gray" ToolbarItemHoverStyle-BackColor="White"
23 ToolbarItemHoverStyle-Font-Bold="True" ToolbarItemHoverStyle-Font-Italic="True"
24 ToolbarItemHoverStyle-Font-Names="Arial" ToolbarItemHoverStyle-Font-Size="Smaller"
25 ToolbarItemSelectedStyle-BackColor="White" ToolbarItemSelectedStyle-Font-Bold="True"
26 ToolbarItemSelectedStyle-Font-Names="Arial" ToolbarItemSelectedStyle-Font-Size="Smaller"
27 WebResourceLocation="/aspnet_client/ESRI/WebADF/" Width="400px">
28 <ToolbarItems>
29 <esri:Tool ClientAction="DragRectangle" DefaultImage="esriZoomIn.gif" HoverImage="esriZoomInU.gif"
30 JavaScriptFile="" Name="MapZoomIn" SelectedImage="esriZoomInD.gif" ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls"
31 ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapZoomIn" Text="Zoom In"
32 ToolTip="Zoom In" />
33 <esri:Tool ClientAction="DragRectangle" DefaultImage="esriZoomOut.gif" HoverImage="esriZoomOutU.gif"
34 JavaScriptFile="" Name="MapZoomOut" SelectedImage="esriZoomOutD.gif" ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls"
35 ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapZoomOut" Text="Zoom Out"
36 ToolTip="Zoom Out" />
37 <esri:Tool ClientAction="DragImage" DefaultImage="esriPan.gif" HoverImage="esriPanU.gif"
38 JavaScriptFile="" Name="MapPan" SelectedImage="esriPanD.gif" ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls"
39 ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapPan" Text="Pan"
40 ToolTip="Pan" />
41 <esri:Command ClientAction="" DefaultImage="esriFullExt.gif" HoverImage="esriFullExtU.gif"
42 JavaScriptFile="" Name="MapFullExtent" SelectedImage="esriFullExtD.gif" ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls"
43 ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapFullExtent" Text="Full Extent"
44 ToolTip="Full Extent" />
45 </ToolbarItems>
46 <BuddyControls>
47 <esri:BuddyControl Name="Map1" />
48 </BuddyControls>
49 </esri:Toolbar>
50 </td>
51 <td width="110"> </td>
52 </tr>
53 <tr>
54 <td>
55 <esri:Map ID="Map1" runat="server" Height="429px" Width="505px" MapResourceManager="MapResourceManager1">
56 </esri:Map>
57 </td>
58 <td valign="top">
59 <esri:Toc ID="Toc1" runat="server" BuddyControl="Map1" />
60 <asp:CheckBoxList ID="CheckBoxList1" runat="server" Style="left: 481px; top: 267px">
61 <asp:ListItem>ArcGIS Server Local</asp:ListItem>
62 <asp:ListItem>ArcGIS Server Internet</asp:ListItem>
63 </asp:CheckBoxList>
64 </td>
65 </tr>
66 </table>
67 <!--显示载入中的小图标 -->
68 <div id="BusyIndicator" style="z-index: 100; left: 17px; width: 14px; position: absolute; top: 389px; height: 15px; visibility: hidden"><img src="images/callbackActivityIndicator.gif" /></div>
69 </div>
70 <esri:MapResourceManager ID="MapResourceManager1" runat="server">
71 </esri:MapResourceManager>
72 </form>
73</body>
74</html>
3.通过勾选页面上的CheckBox来选择不同的MapResource,这里提供了ArcGIS Server Local和ArcGIS Server Internet的选择,没有像样例还提供ArcIMS,因为本来人没有装ArcIMS。至于ArcGIS Server Local和ArcGIS Server Internet的两种方式在前面的几篇中都有用到了,这次通过代码的方式动态的进行设置。1<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AddDynamicData._Default" %>
2
3<%@ Register Assembly="ESRI.ArcGIS.ADF.Web.UI.WebControls, Version=9.2.4.1420, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86"
4 Namespace="ESRI.ArcGIS.ADF.Web.UI.WebControls" TagPrefix="esri" %>
5
6<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
7
8<html xmlns="http://www.w3.org/1999/xhtml" >
9<head runat="server">
10 <title>无标题页</title>
11</head>
12<body>
13 <form id="form1" runat="server">
14 <div>
15 <table width="623" border="1" cellspacing="0" cellpadding="0">
16 <tr>
17 <td width="391">
18 <esri:Toolbar ID="Toolbar1" runat="server" BuddyControlType="Map" Group="Toolbar1_Group"
19 Height="50px" ToolbarItemDefaultStyle-BackColor="White" ToolbarItemDefaultStyle-Font-Names="Arial"
20 ToolbarItemDefaultStyle-Font-Size="Smaller" ToolbarItemDisabledStyle-BackColor="White"
21 ToolbarItemDisabledStyle-Font-Names="Arial" ToolbarItemDisabledStyle-Font-Size="Smaller"
22 ToolbarItemDisabledStyle-ForeColor="Gray" ToolbarItemHoverStyle-BackColor="White"
23 ToolbarItemHoverStyle-Font-Bold="True" ToolbarItemHoverStyle-Font-Italic="True"
24 ToolbarItemHoverStyle-Font-Names="Arial" ToolbarItemHoverStyle-Font-Size="Smaller"
25 ToolbarItemSelectedStyle-BackColor="White" ToolbarItemSelectedStyle-Font-Bold="True"
26 ToolbarItemSelectedStyle-Font-Names="Arial" ToolbarItemSelectedStyle-Font-Size="Smaller"
27 WebResourceLocation="/aspnet_client/ESRI/WebADF/" Width="400px">
28 <ToolbarItems>
29 <esri:Tool ClientAction="DragRectangle" DefaultImage="esriZoomIn.gif" HoverImage="esriZoomInU.gif"
30 JavaScriptFile="" Name="MapZoomIn" SelectedImage="esriZoomInD.gif" ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls"
31 ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapZoomIn" Text="Zoom In"
32 ToolTip="Zoom In" />
33 <esri:Tool ClientAction="DragRectangle" DefaultImage="esriZoomOut.gif" HoverImage="esriZoomOutU.gif"
34 JavaScriptFile="" Name="MapZoomOut" SelectedImage="esriZoomOutD.gif" ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls"
35 ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapZoomOut" Text="Zoom Out"
36 ToolTip="Zoom Out" />
37 <esri:Tool ClientAction="DragImage" DefaultImage="esriPan.gif" HoverImage="esriPanU.gif"
38 JavaScriptFile="" Name="MapPan" SelectedImage="esriPanD.gif" ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls"
39 ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapPan" Text="Pan"
40 ToolTip="Pan" />
41 <esri:Command ClientAction="" DefaultImage="esriFullExt.gif" HoverImage="esriFullExtU.gif"
42 JavaScriptFile="" Name="MapFullExtent" SelectedImage="esriFullExtD.gif" ServerActionAssembly="ESRI.ArcGIS.ADF.Web.UI.WebControls"
43 ServerActionClass="ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.MapFullExtent" Text="Full Extent"
44 ToolTip="Full Extent" />
45 </ToolbarItems>
46 <BuddyControls>
47 <esri:BuddyControl Name="Map1" />
48 </BuddyControls>
49 </esri:Toolbar>
50 </td>
51 <td width="110"> </td>
52 </tr>
53 <tr>
54 <td>
55 <esri:Map ID="Map1" runat="server" Height="429px" Width="505px" MapResourceManager="MapResourceManager1">
56 </esri:Map>
57 </td>
58 <td valign="top">
59 <esri:Toc ID="Toc1" runat="server" BuddyControl="Map1" />
60 <asp:CheckBoxList ID="CheckBoxList1" runat="server" Style="left: 481px; top: 267px">
61 <asp:ListItem>ArcGIS Server Local</asp:ListItem>
62 <asp:ListItem>ArcGIS Server Internet</asp:ListItem>
63 </asp:CheckBoxList>
64 </td>
65 </tr>
66 </table>
67 <!--显示载入中的小图标 -->
68 <div id="BusyIndicator" style="z-index: 100; left: 17px; width: 14px; position: absolute; top: 389px; height: 15px; visibility: hidden"><img src="images/callbackActivityIndicator.gif" /></div>
69 </div>
70 <esri:MapResourceManager ID="MapResourceManager1" runat="server">
71 </esri:MapResourceManager>
72 </form>
73</body>
74</html>
4.接下来页面切换到代码视图,老样子仍旧需要实现ICallbackEventHandler。在Page_Load事件中添加如下代码:
1
//
客户端脚本段
2 private string m_ADFCallbackFunctionString;
3
4 public string ADFCallbackFunctionString
5 {
6 get
7 {
8 return m_ADFCallbackFunctionString;
9 }
10 set
11 {
12 m_ADFCallbackFunctionString = value;
13 }
14 }
15
16 protected void Page_Load( object sender, EventArgs e)
17 {
18 //给CheckBox添加点击js事件
19 foreach (ListItem checkBox in CheckBoxList1.Items)
20 {
21 checkBox.Attributes.Add("onclick", "ChangeCheckContext(this)");
22 }
23 //生成客户端脚本段
24 m_ADFCallbackFunctionString = Page.ClientScript.GetCallbackEventReference(this, "message", "processCallbackResult", "context", "postBackError", true);
25 }
26
5.在上面的代码中给CheckBox添加了ChangeCheckContext(this)脚本函数,所以需要在页面中添加这个函数,切换到html视图然后在最后添加如下的js代码:
2 private string m_ADFCallbackFunctionString;
3
4 public string ADFCallbackFunctionString
5 {
6 get
7 {
8 return m_ADFCallbackFunctionString;
9 }
10 set
11 {
12 m_ADFCallbackFunctionString = value;
13 }
14 }
15
16 protected void Page_Load( object sender, EventArgs e)
17 {
18 //给CheckBox添加点击js事件
19 foreach (ListItem checkBox in CheckBoxList1.Items)
20 {
21 checkBox.Attributes.Add("onclick", "ChangeCheckContext(this)");
22 }
23 //生成客户端脚本段
24 m_ADFCallbackFunctionString = Page.ClientScript.GetCallbackEventReference(this, "message", "processCallbackResult", "context", "postBackError", true);
25 }
26
1
.
2 < script language ="javascript" type ="text/javascript" >
3 function ChangeCheckContext(checkbox)
4 {
5 //显示载入中的小图标
6 document.getElementById('BusyIndicator').style.visibility = 'visible';
7 //获取checkbox的显示文
8 var val = checkbox.nextSibling.innerText;
9 var ischecked = checkbox.checked;
10 context = "cb";
11 var message = "changeresource,";
12 message += val + ',' + ischecked;
13 //执行回调请求服务端
14 <%= ADFCallbackFunctionString%>
15 }
16 </ script >
17 </ form >
6.接下在服务端实现对
ChangeCheckContext(this)脚本函数请求处理,主要的GetCallbackResult和RaiseCallbackEvent的两个方法,具体的代码和说明如下:
2 < script language ="javascript" type ="text/javascript" >
3 function ChangeCheckContext(checkbox)
4 {
5 //显示载入中的小图标
6 document.getElementById('BusyIndicator').style.visibility = 'visible';
7 //获取checkbox的显示文
8 var val = checkbox.nextSibling.innerText;
9 var ischecked = checkbox.checked;
10 context = "cb";
11 var message = "changeresource,";
12 message += val + ',' + ischecked;
13 //执行回调请求服务端
14 <%= ADFCallbackFunctionString%>
15 }
16 </ script >
17 </ form >
1
//
处理结果返回给客户端
2 public string GetCallbackResult()
3 {
4 return m_CallbackResponse;
5 }
6 // 处理客户端请求
7 public void RaiseCallbackEvent( string eventArgs)
8 {
9 //分割请求字符串
10 char[] charToParse = { ',' };
11 string[] messages = eventArgs.Split(charToParse);
12
13 if (eventArgs.Contains("changeresource"))
14 {
15 //SourceType
16 string dataSourceType = messages[1];
17 //CheckBox是否选中
18 bool isChecked = Boolean.Parse(messages[2]);
19 //根据请求类型不同用不同的Resource
20 switch (dataSourceType)
21 {
22 case "ArcGIS Server Local":
23 m_ResourceName = AGSLocalName;
24 break;
25 case "ArcGIS Server Internet":
26 m_ResourceName = AGSInternetName;
27 break;
28 default:
29 break;
30 }
31 //更换Resource
32 MapResourceChange(isChecked);
33 }
34 }
35 // 更换Resource
36 void MapResourceChange( bool isChecked)
37 {
38 //获取当前MapResourceManager1的ResourceItems
39 ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemCollection<ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem> mapResourceItemCollection =MapResourceManager1.ResourceItems;
40
41 ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem mapResourceItem = null;
42 //获取当前MapResourceManager1的ResourceItems的数
43 int mapResourceCount = mapResourceItemCollection.Count;
44 if (!isChecked)
45 {
46 //如果未勾选就删除未勾选的ResourceItem
47 mapResourceItem = mapResourceItemCollection.Find(m_ResourceName);
48 mapResourceItemCollection.Remove(mapResourceItem);
49 }
50 else
51 {
52 //实例化ResourceItem
53 mapResourceItem = new ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem();
54 ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemDefinition definition =new ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemDefinition();
55
56 switch (m_ResourceName)
57 {
58 case (AGSLocalName)://设置本地Resource名称
59 //Name
60 mapResourceItem.Name = AGSLocalName;
61 //Data Source
62 definition.DataSourceDefinition = "jh-53a435fbc0e8";
63 //Type
64 definition.DataSourceType = "ArcGIS Server Local";
65 //Resource
66 definition.ResourceDefinition = "Layers@usa";
67 break;
68 case (AGSInternetName)://设置Internet Resource名称
69 //Name
70 mapResourceItem.Name = AGSInternetName;
71 //Data Source
72 definition.DataSourceDefinition = "http://jh-53a435fbc0e8/arcgis/services/";
73 //Type
74 definition.DataSourceType = "ArcGIS Server Internet";
75 //Identity
76 Identity id = new Identity("Administrator", "zsycl1231", "");
77 definition.Identity = id.ToString();
78 //Resource
79 definition.ResourceDefinition = "(default)@world";
80 break;
81 }
82
83 definition.DataSourceShared = true;
84 mapResourceItem.Parent = MapResourceManager1;
85 mapResourceItem.Definition = definition;
86
87 //mapResourceItem的展示设置
88 ESRI.ArcGIS.ADF.Web.DisplaySettings displaySettings = new ESRI.ArcGIS.ADF.Web.DisplaySettings();
89 displaySettings.Transparency = 50.0F;
90 displaySettings.Visible = true;
91 displaySettings.ImageDescriptor.TransparentColor = System.Drawing.Color.White;
92 displaySettings.ImageDescriptor.TransparentBackground = true;
93 mapResourceItem.DisplaySettings = displaySettings;
94
95 //把上面的MapResourceItem添加到MapResourceManager1
96 MapResourceManager1.ResourceItems.Insert(0, mapResourceItem);
97
98 //建立MapResource根据MapResourceManager1
99 ESRI.ArcGIS.ADF.Web.DataSources.IMapResource mapResource =MapResourceManager1.CreateResource(mapResourceItem);
100
101 if (mapResourceCount < 1)
102 {
103 Map1.PrimaryMapResource = mapResourceItem.Name;
104 //初始化
105 Map1.InitializeFunctionalities();
106 Map1.InitializeTileFunctionalities();
107 }
108 else
109 {
110
111 // 刷新地图显示
112 if (Map1.ImageBlendingMode == ESRI.ArcGIS.ADF.Web.UI.WebControls.ImageBlendingMode.WebTier)
113 {
114 Map1.Refresh();
115 }
116 else
117 {
118 Map1.RefreshResource(mapResourceItem.Name);
119 }
120 }
121 }
122
123 if (mapResourceCount < 1)
124 {
125 Map1.Extent = Map1.Extent.Expand(0.1);
126 }
127 //刷新Toc1
128 Toc1.Refresh();
129 ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult tocCallbackResult = RefreshControlHtml(Toc1);
130 Map1.CallbackResults.Add(tocCallbackResult);
131
132 // Convert the Map's collection of callback results to a string
133 m_CallbackResponse = Map1.CallbackResults.ToString();
134 }
135
136 private ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult RefreshControlHtml(Control control)
137 {
138 StringWriter stringWriter = new StringWriter();
139 HtmlTextWriter writer = new HtmlTextWriter(stringWriter);
140 control.RenderControl(writer);
141 string htmlContent = stringWriter.ToString();
142 stringWriter.Close();
143 return new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult(control, "content", htmlContent);
144 }
145
7.这个例子相对比较简单具体实现看代码注释了。运行看效果。2 public string GetCallbackResult()
3 {
4 return m_CallbackResponse;
5 }
6 // 处理客户端请求
7 public void RaiseCallbackEvent( string eventArgs)
8 {
9 //分割请求字符串
10 char[] charToParse = { ',' };
11 string[] messages = eventArgs.Split(charToParse);
12
13 if (eventArgs.Contains("changeresource"))
14 {
15 //SourceType
16 string dataSourceType = messages[1];
17 //CheckBox是否选中
18 bool isChecked = Boolean.Parse(messages[2]);
19 //根据请求类型不同用不同的Resource
20 switch (dataSourceType)
21 {
22 case "ArcGIS Server Local":
23 m_ResourceName = AGSLocalName;
24 break;
25 case "ArcGIS Server Internet":
26 m_ResourceName = AGSInternetName;
27 break;
28 default:
29 break;
30 }
31 //更换Resource
32 MapResourceChange(isChecked);
33 }
34 }
35 // 更换Resource
36 void MapResourceChange( bool isChecked)
37 {
38 //获取当前MapResourceManager1的ResourceItems
39 ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemCollection<ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem> mapResourceItemCollection =MapResourceManager1.ResourceItems;
40
41 ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem mapResourceItem = null;
42 //获取当前MapResourceManager1的ResourceItems的数
43 int mapResourceCount = mapResourceItemCollection.Count;
44 if (!isChecked)
45 {
46 //如果未勾选就删除未勾选的ResourceItem
47 mapResourceItem = mapResourceItemCollection.Find(m_ResourceName);
48 mapResourceItemCollection.Remove(mapResourceItem);
49 }
50 else
51 {
52 //实例化ResourceItem
53 mapResourceItem = new ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem();
54 ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemDefinition definition =new ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemDefinition();
55
56 switch (m_ResourceName)
57 {
58 case (AGSLocalName)://设置本地Resource名称
59 //Name
60 mapResourceItem.Name = AGSLocalName;
61 //Data Source
62 definition.DataSourceDefinition = "jh-53a435fbc0e8";
63 //Type
64 definition.DataSourceType = "ArcGIS Server Local";
65 //Resource
66 definition.ResourceDefinition = "Layers@usa";
67 break;
68 case (AGSInternetName)://设置Internet Resource名称
69 //Name
70 mapResourceItem.Name = AGSInternetName;
71 //Data Source
72 definition.DataSourceDefinition = "http://jh-53a435fbc0e8/arcgis/services/";
73 //Type
74 definition.DataSourceType = "ArcGIS Server Internet";
75 //Identity
76 Identity id = new Identity("Administrator", "zsycl1231", "");
77 definition.Identity = id.ToString();
78 //Resource
79 definition.ResourceDefinition = "(default)@world";
80 break;
81 }
82
83 definition.DataSourceShared = true;
84 mapResourceItem.Parent = MapResourceManager1;
85 mapResourceItem.Definition = definition;
86
87 //mapResourceItem的展示设置
88 ESRI.ArcGIS.ADF.Web.DisplaySettings displaySettings = new ESRI.ArcGIS.ADF.Web.DisplaySettings();
89 displaySettings.Transparency = 50.0F;
90 displaySettings.Visible = true;
91 displaySettings.ImageDescriptor.TransparentColor = System.Drawing.Color.White;
92 displaySettings.ImageDescriptor.TransparentBackground = true;
93 mapResourceItem.DisplaySettings = displaySettings;
94
95 //把上面的MapResourceItem添加到MapResourceManager1
96 MapResourceManager1.ResourceItems.Insert(0, mapResourceItem);
97
98 //建立MapResource根据MapResourceManager1
99 ESRI.ArcGIS.ADF.Web.DataSources.IMapResource mapResource =MapResourceManager1.CreateResource(mapResourceItem);
100
101 if (mapResourceCount < 1)
102 {
103 Map1.PrimaryMapResource = mapResourceItem.Name;
104 //初始化
105 Map1.InitializeFunctionalities();
106 Map1.InitializeTileFunctionalities();
107 }
108 else
109 {
110
111 // 刷新地图显示
112 if (Map1.ImageBlendingMode == ESRI.ArcGIS.ADF.Web.UI.WebControls.ImageBlendingMode.WebTier)
113 {
114 Map1.Refresh();
115 }
116 else
117 {
118 Map1.RefreshResource(mapResourceItem.Name);
119 }
120 }
121 }
122
123 if (mapResourceCount < 1)
124 {
125 Map1.Extent = Map1.Extent.Expand(0.1);
126 }
127 //刷新Toc1
128 Toc1.Refresh();
129 ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult tocCallbackResult = RefreshControlHtml(Toc1);
130 Map1.CallbackResults.Add(tocCallbackResult);
131
132 // Convert the Map's collection of callback results to a string
133 m_CallbackResponse = Map1.CallbackResults.ToString();
134 }
135
136 private ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult RefreshControlHtml(Control control)
137 {
138 StringWriter stringWriter = new StringWriter();
139 HtmlTextWriter writer = new HtmlTextWriter(stringWriter);
140 control.RenderControl(writer);
141 string htmlContent = stringWriter.ToString();
142 stringWriter.Close();
143 return new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult(control, "content", htmlContent);
144 }
145