当前位置: 首页 > news >正文

arcgis server for .NET学习转载8

http://www.cnblogs.com/hll2008/archive/2008/08/20/1272264.html

ArcGIS.Server.9.2.DotNet自带例子分析(四、一)

目的:
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。具体的代码如下:

ContractedBlock.gif ExpandedBlockStart.gif Code
 1ExpandedBlockStart.gifContractedBlock.gif<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AddDynamicData._Default" %>
 2
 3ExpandedBlockStart.gifContractedBlock.gif<%@ 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">&nbsp;</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的两种方式在前面的几篇中都有用到了,这次通过代码的方式动态的进行设置。
4.接下来页面切换到代码视图,老样子仍旧需要实现ICallbackEventHandler。在Page_Load事件中添加如下代码:
 1 // 客户端脚本段
 2          private   string  m_ADFCallbackFunctionString;
 3
 4          public   string  ADFCallbackFunctionString
 5 ExpandedBlockStart.gifContractedBlock.gif         {
 6            get
 7ExpandedSubBlockStart.gifContractedSubBlock.gif            {
 8                return m_ADFCallbackFunctionString;
 9            }

10            set
11ExpandedSubBlockStart.gifContractedSubBlock.gif            {
12                m_ADFCallbackFunctionString = value;
13            }

14        }

15
16          protected   void  Page_Load( object  sender, EventArgs e)
17 ExpandedBlockStart.gifContractedBlock.gif         {
18            //给CheckBox添加点击js事件
19            foreach (ListItem checkBox in CheckBoxList1.Items)
20ExpandedSubBlockStart.gifContractedSubBlock.gif            {
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代码:
 1 .
 2 ExpandedBlockStart.gifContractedBlock.gif < script  language ="javascript"  type ="text/javascript" >     
 3    function ChangeCheckContext(checkbox)
 4ExpandedSubBlockStart.gifContractedSubBlock.gif    {     
 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的两个方法,具体的代码和说明如下:
  1 // 处理结果返回给客户端
  2          public   string  GetCallbackResult()
  3 ExpandedBlockStart.gifContractedBlock.gif         {
  4            return m_CallbackResponse;
  5        }

  6 // 处理客户端请求
  7          public   void  RaiseCallbackEvent( string  eventArgs)
  8 ExpandedBlockStart.gifContractedBlock.gif         {
  9            //分割请求字符串
 10ExpandedSubBlockStart.gifContractedSubBlock.gif            char[] charToParse = ',' };
 11            string[] messages = eventArgs.Split(charToParse);
 12
 13            if (eventArgs.Contains("changeresource"))
 14ExpandedSubBlockStart.gifContractedSubBlock.gif            {
 15                //SourceType
 16                string dataSourceType = messages[1];
 17                //CheckBox是否选中
 18                bool isChecked = Boolean.Parse(messages[2]);
 19                //根据请求类型不同用不同的Resource
 20                switch (dataSourceType)
 21ExpandedSubBlockStart.gifContractedSubBlock.gif                {
 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 ExpandedBlockStart.gifContractedBlock.gif         {
 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)
 45ExpandedSubBlockStart.gifContractedSubBlock.gif            {
 46                //如果未勾选就删除未勾选的ResourceItem
 47                mapResourceItem = mapResourceItemCollection.Find(m_ResourceName);
 48                mapResourceItemCollection.Remove(mapResourceItem);
 49            }

 50            else
 51ExpandedSubBlockStart.gifContractedSubBlock.gif            {
 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)
 57ExpandedSubBlockStart.gifContractedSubBlock.gif                {
 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)
102ExpandedSubBlockStart.gifContractedSubBlock.gif                {
103                    Map1.PrimaryMapResource = mapResourceItem.Name;
104                    //初始化
105                    Map1.InitializeFunctionalities();
106                    Map1.InitializeTileFunctionalities();
107                }

108                else
109ExpandedSubBlockStart.gifContractedSubBlock.gif                {
110
111                    // 刷新地图显示
112                    if (Map1.ImageBlendingMode == ESRI.ArcGIS.ADF.Web.UI.WebControls.ImageBlendingMode.WebTier)
113ExpandedSubBlockStart.gifContractedSubBlock.gif                    {
114                        Map1.Refresh();
115                    }

116                    else
117ExpandedSubBlockStart.gifContractedSubBlock.gif                    {
118                        Map1.RefreshResource(mapResourceItem.Name);
119                    }

120                }

121            }

122
123            if (mapResourceCount < 1)
124ExpandedSubBlockStart.gifContractedSubBlock.gif            {
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 ExpandedBlockStart.gifContractedBlock.gif         {
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.这个例子相对比较简单具体实现看代码注释了。运行看效果。

转载于:https://www.cnblogs.com/liuyang-1037/archive/2009/08/31/1557344.html

相关文章:

  • Oracle12C新特性——cdb与pdb
  • [Script]采用Python创建当前日期文件夹
  • react-native 常见操作 及 git 补充
  • 关于 Out of Socket memory
  • 关于管理的那些事
  • 数据在网络7层中的传输过程
  • VTemplate模板引擎的使用--高级篇
  • 树莓派初次使用必装软件
  • dp递推题2010年吉林省省赛 1456: 逃票的chanming(3)
  • Brew平台音乐播放器Dream Player
  • bitnami忘记登录密码
  • 趋势图
  • MongoDB 自己定义函数
  • CSS教程:认真学习haslayout
  • Summary Day30
  • $translatePartialLoader加载失败及解决方式
  • 《Javascript高级程序设计 (第三版)》第五章 引用类型
  • 《用数据讲故事》作者Cole N. Knaflic:消除一切无效的图表
  • 「前端」从UglifyJSPlugin强制开启css压缩探究webpack插件运行机制
  • ComponentOne 2017 V2版本正式发布
  • GraphQL学习过程应该是这样的
  • Javascript设计模式学习之Observer(观察者)模式
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • Linux CTF 逆向入门
  • Promise初体验
  • supervisor 永不挂掉的进程 安装以及使用
  • Swoft 源码剖析 - 代码自动更新机制
  • tab.js分享及浏览器兼容性问题汇总
  • vue 配置sass、scss全局变量
  • 从 Android Sample ApiDemos 中学习 android.animation API 的用法
  • 从零到一:用Phaser.js写意地开发小游戏(Chapter 3 - 加载游戏资源)
  • 猴子数据域名防封接口降低小说被封的风险
  • 让你成为前端,后端或全栈开发程序员的进阶指南,一门学到老的技术
  • 设计模式走一遍---观察者模式
  • 使用 Node.js 的 nodemailer 模块发送邮件(支持 QQ、163 等、支持附件)
  • 数组大概知多少
  • ​iOS安全加固方法及实现
  • #162 (Div. 2)
  • #ifdef 的技巧用法
  • #我与Java虚拟机的故事#连载08:书读百遍其义自见
  • (C语言)编写程序将一个4×4的数组进行顺时针旋转90度后输出。
  • (附源码)计算机毕业设计ssm高校《大学语文》课程作业在线管理系统
  • (简单) HDU 2612 Find a way,BFS。
  • (篇九)MySQL常用内置函数
  • (七)Knockout 创建自定义绑定
  • (一)u-boot-nand.bin的下载
  • (转)fock函数详解
  • .【机器学习】隐马尔可夫模型(Hidden Markov Model,HMM)
  • .NET CORE 第一节 创建基本的 asp.net core
  • .net mvc 获取url中controller和action
  • .NET 中的轻量级线程安全
  • .Net程序帮助文档制作
  • .NET企业级应用架构设计系列之结尾篇
  • .NET下ASPX编程的几个小问题
  • .NET应用架构设计:原则、模式与实践 目录预览