ArcGIS.Server.9.2.DotNet自带例子分析(二、一)
目的:
1.arcgis server9.2 ADF的Callback机制。
准备工作:
1.用ArcGis Server Manager或者ArcCatalog发布一个叫world的Map Service,并且把这个Service启动起来。
2.找到DeveloperKit\SamplesNET\Server\Web_Applications目录下的Common_CallbackCsharp.zip。
开始:
1.新建名为Callback的ASP.NET Web应用程序。
2.在Default.aspx页面中加入MapResourceManager控件ID为MapResourceManager1,并且设置MapResourceItem的属性;Map控件ID为Map1,MapResourceManager属性为MapResourceManager1。具体过程可以参考ArcGIS.Server.9.2.DotNet自带例子分析(一、一);在地图控件的4个边分别添加LabelW、LabelN、LabelE、LabelS DIV控件,具体代码如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
1
protected void Map1_ExtentChanged(object sender, ESRI.ArcGIS.ADF.Web.UI.WebControls.ExtentEventArgs args)
2
{
3
//获取地图控件的框
4
ESRI.ArcGIS.ADF.Web.Geometry.Envelope env = args.NewExtent;
5
SortedList<string, string> slist = new SortedList<string, string>();
6
//最北的坐标
7
slist.Add("n", env.YMax.ToString("N"));
8
//最东的坐标
9
slist.Add("e", env.XMax.ToString("N"));
10
//最南的坐标
11
slist.Add("s", env.YMin.ToString("N"));
12
//最西的坐标
13
slist.Add("w", env.XMin.ToString("N"));
14![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
IEnumerator ide = slist.GetEnumerator();
16![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
foreach (KeyValuePair<string, string> key in slist)
18
{
19
object[] o = new object[1];
20
o[0] = key.Value.ToString();
21
//CallbackResult参数说明:控件类型如 div,控件id,内容类型,内容
22
//CallbackResult无刷新的更新页面内容
23
CallbackResult crn = new CallbackResult("div", "Label" + key.Key.ToString(), "innercontent", o);
24
Map1.CallbackResults.Add(crn);
25
}
26
}
4.在页面上添加Toolbar控件ID为Toolbar1,BuddyControls属性为Map1,同时添加ZoomIn、ZoomOut、Pan、FullExt四个Map Navigation按钮,然后添加一个Tool按钮Name属性为CenterAt,ClientAction属性为Point,ServerActionAssembly属性为Callback,ServerActionClass属性为Callback.CustomTool。具体的代码如下:![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
1
<esri:Toolbar ID="Toolbar1" runat="server" BuddyControlType="Map"
2![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
..
3
<esri:Tool ClientAction="Point" JavaScriptFile="" Name="CenterAt" ServerActionAssembly="Callback" ServerActionClass="Callback.CustomTool" />
4![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
..
5
</esri:Toolbar>
5.新建CustomTool.cs类,实现IMapServerToolAction接口具体的代码和说明如下:![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/dot.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/dot.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
1
namespace Callback
2
{
3
public class CustomTool : IMapServerToolAction
4
{
5
public void ServerAction(ToolEventArgs args)
6
{
7
Map map = (Map)args.Control;
8
PointEventArgs pargs = (PointEventArgs)args;
9
if (map != null && pargs != null)
10
{
11
//重新定位地图中心
12
map.CenterAt(pargs.ScreenPoint);
13
}
14
}
15
}
16
}
17![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6.这样重新定位地图中心的功能完成了,而已运行试验一下效果。 ![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7.在Default.aspx页面上添加一个Menu控件ID为Menu1,同时添加2个子项Asia和Africa,具体的代码如下:
1
<asp:Menu ID="Menu1" runat="server" BackColor="#B5C7DE" DynamicHorizontalOffset="2"
2
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" StaticSubMenuIndent="10px">
3
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
4
<DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
5
<DynamicMenuStyle BackColor="#B5C7DE" />
6
<StaticSelectedStyle BackColor="#507CD1" />
7
<DynamicSelectedStyle BackColor="#507CD1" />
8
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
9
<Items>
10
<asp:MenuItem Text="Zoom To" Value="Zoom To">
11
<asp:MenuItem Text="Asia" Value="Asia" NavigateUrl="javascript: ZoomToLocationClient('Asia');"></asp:MenuItem>
12
<asp:MenuItem Text="Africa" Value="Africa" NavigateUrl="javascript: ZoomToLocationClient('Africa');"></asp:MenuItem>
13
</asp:MenuItem>
14
</Items>
15
<StaticHoverStyle BackColor="#284E98" ForeColor="White" />
16
</asp:Menu>
8.实现上面菜单的javascript函数ZoomToLocationClient,在页面的结束处添加代码入下:![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
1
<form id="form1" runat="server">
2![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/dot.gif)
.
3
<script language="javascript">
4
//根据地名定位地图中心
5
function ZoomToLocationClient(val)
6
{
7
//暂空
8
}
9![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
</script>
11
</form>
9.Default.aspx切换到代码视图开始编写服务端的代码,实现无刷新必须实现System.Web.UI.ICallbackEventHandler接口,实现 ICallbackEventHandler接口就必须实现GetCallbackResult()和RaiseCallbackEvent(string eventArgument)这2个方法具体的代码和说明入下:![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
1
namespace Callback
2
{
3
public partial class _Default : System.Web.UI.Page,System.Web.UI.ICallbackEventHandler
4
{
5
//客户端脚本段
6
public string sCallBackFunctionInvocation;
7
//返回给客户端的内容
8
private string mapstring;
9![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
protected void Page_Load(object sender, EventArgs e)
11
{
12
//GetCallbackEventReference生成客户端脚本
13
sCallBackFunctionInvocation = Page.ClientScript.GetCallbackEventReference(this, "message", "processCallbackResult", "context", "postBackError", true);
14
}
15![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
protected void Map1_ExtentChanged(object sender, ESRI.ArcGIS.ADF.Web.UI.WebControls.ExtentEventArgs args)
17
{
18
//获取地图控件的框
19
ESRI.ArcGIS.ADF.Web.Geometry.Envelope env = args.NewExtent;
20
SortedList<string, string> slist = new SortedList<string, string>();
21
//最北的坐标
22
slist.Add("n", env.YMax.ToString("N"));
23
//最东的坐标
24
slist.Add("e", env.XMax.ToString("N"));
25
//最南的坐标
26
slist.Add("s", env.YMin.ToString("N"));
27
//最西的坐标
28
slist.Add("w", env.XMin.ToString("N"));
29![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
IEnumerator ide = slist.GetEnumerator();
31![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
foreach (KeyValuePair<string, string> key in slist)
33
{
34
object[] o = new object[1];
35
o[0] = key.Value.ToString();
36
//CallbackResult参数说明:控件类型如 div,控件id,内容类型如content, innercontent, javascript,image ,内容
37
//CallbackResult无刷新的更新页面内容
38
CallbackResult crn = new CallbackResult("div", "Label" + key.Key.ToString(), "innercontent", o);
39
Map1.CallbackResults.Add(crn);
40
}
41
}
42![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
ICallbackEventHandler 成员
58
}
59
}
60![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10.接下来要把服务端生成的脚本段sCallBackFunctionInvocation写入到页面中,Default.aspx切换到html视图在ZoomToLocationClient(val)方法中添加如下代码:![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
1
//根据地名定位地图中心
2
function ZoomToLocationClient(val)
3
{
4
var message = 'zoomtolocation';
5
message += ',' + val;
6
var context = 'Map1';
7
//把服务端的生成的脚本段sCallBackFunctionInvocation输出
8
//输出内容:WebForm_DoCallback('__Page',message,processCallbackResult,context,postBackError,true)
9
<%=sCallBackFunctionInvocation%>
10
}
11.这样Menu控件通过调用ZoomToLocationClient(val)方法请求服务端进行处理然后把处理结果反馈给客户端,由客户端的processCallbackResult方法进行页面显示的更新,关于这个方法具体的可以参考ArcGIS.Server.9.2.DotNet自带例子分析(一)。![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
12.接下来在RaiseCallbackEvent(string eventArgs)方法中处理ZoomToLocationClient(val)方法发起的请求,具体代码如下:
1
//接收客户端的请求,根据请求字符串eventArgument不同做不同的处理
2
public void RaiseCallbackEvent(string eventArgs)
3
{
4
if (eventArgs.Contains("zoomtopoint"))//根据坐标定位地图中心
5
{
6![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
}
8
else if (eventArgs.Contains("zoomtolocation"))//根据名称定位地图中心
9
{
10
ZoomToLocationServer(eventArgs);
11
}
12
}
13
//根据名称定位地图中心
14
public void ZoomToLocationServer(string ea)
15
{
16
//请求字符串分割处理
17
char[] parser_char = { ',' };
18
string[] messages = ea.Split(parser_char);
19
string location = messages[1];
20
double minx = 0;
21
double miny = 0;
22
double maxx = 0;
23
double maxy = 0;
24![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
bool validlocation = false;
26![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
//根据地点名称不同定位到不同的坐标
28
//这里为了方便直接给min和max赋值,在实际的开发中可以更加地点名称进行坐标的查询然后更加查询的坐标进行定位
29
switch (location)
30
{
31
case "Asia":
32
minx = -125.0;
33
miny = 30.0;
34
maxx = -110.0;
35
maxy = 45.0;
36
validlocation = true;
37
break;
38
case "Africa":
39
minx = -80.0;
40
miny = 40.0;
41
maxx = -70.0;
42
maxy = 45.0;
43
validlocation = true;
44
break;
45
default:
46
break;
47
}
48![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
if (validlocation)
50
{
51
ESRI.ArcGIS.ADF.Web.Geometry.Envelope new_extent = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minx, miny, maxx, maxy);
52
//设置当前地图的Extent
53
Map1.Extent = new_extent;
54
//把CallbackResults返回给客户端,让客户端更新地图显示
55
mapstring = Map1.CallbackResults.ToString();
56
}
57
else
58
{
59
mapstring = "";
60
}
61
}
13.这样就完成了根据名称定位地图中心的功能,接下来根据输入的坐标重新定位地图的中心,首先Default.aspx切换到html视图在最后的javascript中在添加一个ZoomToPointClient()方法,具体的代码和说明如下:![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
51
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
55
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
57
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
61
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
1
//根据坐标定位地图中心
2
function ZoomToPointClient()
3
{
4
//获取输入的x值
5
var x = document.getElementById('TextBoxX').value;
6
//获取输入的y值
7
var y = document.getElementById('TextBoxY').value;
8
//生成请求字符串
9
var message = 'zoomtopoint';
10
message += ',' + x + ',' + y;
11
var context = 'Map1';
12
//把服务端的生成的脚本段sCallBackFunctionInvocation输出
13
//输出内容:WebForm_DoCallback('__Page',message,processCallbackResult,context,postBackError,true)
14
<%=sCallBackFunctionInvocation%>
15
}
14.在页面上添加2个input输入框,ID分别为TextBoxX和TextBoxY用来输入xy的坐标,在添加一个button来执行上面的ZoomToPointClient()方法。具体代码和说明如下:![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
1
X:<input type="text" id="TextBoxX" style="width: 72px; left: 71px; top: 473px" />
2
Y:<input type="text" id="TextBoxY" style="width: 72px; left: 203px;top: 472px" />
3
<input type="button" value="Zoom To Point" onclick="ZoomToPointClient();" style="left: 318px; top: 470px; width: 150px" />
15.在服务端的RaiseCallbackEvent方法中添加对这个功能实现的代码,代码和说明如下:![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
1
//接收客户端的请求,根据请求字符串eventArgument不同做不同的处理
2
public void RaiseCallbackEvent(string eventArgs)
3
{
4
if (eventArgs.Contains("zoomtopoint"))//根据坐标定位地图中心
5
{
6
ZoomToPointServer(eventArgs);
7
}
8
else if (eventArgs.Contains("zoomtolocation"))//根据名称定位地图中心
9
{
10
ZoomToLocationServer(eventArgs);
11
}
12
}
13![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
private void ZoomToPointServer(string eventArgs)
15
{
16
//请求字符串分割处理
17
char[] parser_char = { ',' };
18
string[] messages = eventArgs.Split(parser_char);
19
double map_width_eight = Map1.Extent.Width / 8;
20
double x_center = Double.Parse(messages[1]);
21
double y_center = Double.Parse(messages[2]);
22![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
ESRI.ArcGIS.ADF.Web.Geometry.Envelope env = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(x_center - map_width_eight, y_center - map_width_eight, x_center + map_width_eight, y_center + map_width_eight);
24
Map1.Extent = env;
25![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
//把CallbackResults返回给客户端,让客户端更新地图显示
27
mapstring = Map1.CallbackResults.ToString();
28
}
29![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16.这样就完成了这个练习了,运行查看效果。![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/images/cnblogs_com/hll2008/fr43.jpg)