ArcGIS Server For ADF开发系列2
真的为如今学习ArcGIS Server的庆幸,有这么多的选择,ADF,Flex,javaScript,而且目前从论坛来看,各方面的资料也日益多了起来,但就我个人来说,其实学习ADF也是一个不错的选择,因为ADF在面对大型的系统时,还是绰绰可行,至于RIA方面,当然是目前的主流,但同时,你也得学习一门新的语言。
总的来说,不管是ADF,还是Flex,都不重要,重要的是你的学习目的和态度了。
废话少说,先开讲。
首先讲的最基本的功能,查询,当然也离不开Ajax,由于相对较而言,目前的ArcGIS Server 9.3的Ajax功能已经非常强大,网上的示例也非常多,比如:http://www.xiaoneng.czm.cn/?p=58#more-58 所以我也不多说,直接贴代码。先来看客户端的界面,
Ajax搜索相对而言,其实非常简单,其一般的代码模式基本如下:
前提,把下面这段放在页面代码中
1 protected void Page_PreRender(object sender, System.EventArgs eventArgs)
2 {
3 string scriptKeyCustom = "customDataItemScript";
4 if (!this.Page.ClientScript.IsClientScriptBlockRegistered(GetType(), scriptKeyCustom) &&
5 !ScriptManager1.IsInAsyncPostBack)
6 {
7 string scriptBlock = @"
8
9 function onLoadFunction(){{
10 Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(AsyncResponseHandler);
11 }}
12
13 function AsyncResponseHandler(sender, args) {{
14 var dataItems = args.get_dataItems();
15 if (dataItems['{0}'] != null)
16 ESRI.ADF.System.processCallbackResult(dataItems['{0}']);
17 }}
18
19 Sys.Application.add_init(onLoadFunction);";
20
21 // Insert the client ID of the page into the script block.
22 scriptBlock = string.Format(scriptBlock, Page.ClientID);
23 this.Page.ClientScript.RegisterStartupScript(GetType(), scriptKeyCustom, scriptBlock, true);
24 }
25
26 }
27
2 {
3 string scriptKeyCustom = "customDataItemScript";
4 if (!this.Page.ClientScript.IsClientScriptBlockRegistered(GetType(), scriptKeyCustom) &&
5 !ScriptManager1.IsInAsyncPostBack)
6 {
7 string scriptBlock = @"
8
9 function onLoadFunction(){{
10 Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(AsyncResponseHandler);
11 }}
12
13 function AsyncResponseHandler(sender, args) {{
14 var dataItems = args.get_dataItems();
15 if (dataItems['{0}'] != null)
16 ESRI.ADF.System.processCallbackResult(dataItems['{0}']);
17 }}
18
19 Sys.Application.add_init(onLoadFunction);";
20
21 // Insert the client ID of the page into the script block.
22 scriptBlock = string.Format(scriptBlock, Page.ClientID);
23 this.Page.ClientScript.RegisterStartupScript(GetType(), scriptKeyCustom, scriptBlock, true);
24 }
25
26 }
27
下面的基本步骤如下:
1、查找页面控件
1FloatingPanel fp = KMMap.Page.FindControl("FloatingPanel1") as FloatingPanel;
2 Label labeltxt = fp.FindControl("Label2") as Label;
3 labeltxt.Text = "本次查询总数为:" + recordcount.ToString() + "条记录";
4
5 DataList gl = fp.FindControl("DataList1") as DataList;
6 gl.DataSource = ds.Tables[0];
7 gl.DataBind();
8
2、构建回调内容
1 string returnstring = null;
2 using (System.IO.StringWriter sw = new System.IO.StringWriter())
3 {
4 HtmlTextWriter htw = new HtmlTextWriter(sw);
5 labeltxt.RenderControl(htw);
6 gl.RenderControl(htw);
7 AspNetPager1.RenderControl(htw);
8 htw.Flush();
9 returnstring = sw.ToString();
10 }
11
2 using (System.IO.StringWriter sw = new System.IO.StringWriter())
3 {
4 HtmlTextWriter htw = new HtmlTextWriter(sw);
5 labeltxt.RenderControl(htw);
6 gl.RenderControl(htw);
7 AspNetPager1.RenderControl(htw);
8 htw.Flush();
9 returnstring = sw.ToString();
10 }
11
3、回调页面
1 CallbackResult cr = new CallbackResult("div", "searchDiv", "innercontent", returnstring);
2 KMMap.CallbackResults.Add(cr);
3 ScriptManager1.RegisterDataItem(Page, KMMap.CallbackResults.ToString(), false);
4
客户端
所有版权归小能所有哦!!!