目的:
1.arcgis server9.2 ADF实现GraphicsLayer的保存和读取显示

准备工作:
1.用ArcGis Server Manager或者ArcCatalog发布一个叫usa的Map Service,并且把这个Service启动起来。
完成后的效果图:

ArcGIS.Server.9.2.DotNet保存GraphicsLayer
开始:
1.新建名为SaveGraphicsLayer的ASP.NET Web应用程序,在页面上添加MapResourceManager1、Map1、Toolbar1、Toc1控件。
2.MapResourceManager1添加两个MapResourceItem,上面的一个名为myGraphicsLayer,DataSourceType为GraphicsLayer用来显示GraphicsLayer数据,下面一个名为usa,DataSourceType为ArcGIS Server Local,就是用来显示上面发布的usa的Map Service。其他的控件做相应是设置工作。
3.在Toolbar1中除了添加MapZoomIn、MapZoomOut、MapPan、MapFullExtent功能以外在添加一个Tool用来实现在地图上添加点,就是在myGraphicsLayer中显示,关于这个Tool的html代码如下:

1ArcGIS.Server.9.2.DotNet保存GraphicsLayer<esri:Tool ClientAction="Point" JavaScriptFile="" Name="AddGraphicPoint" ServerActionAssembly="SaveGraphicsLayer" ServerActionClass="SaveGraphicsLayer.ElementGraphicTool" Text="Add Graphic Point" ToolTip="Add Graphic Point" />
4.添加ElementGraphicTool.cs文件类用来实现上面的这个Tool的功能,在地图上点击然后添加一个黑色圆点的功能,具体不多解释了可以参考前面的例子ArcGIS.Server.9.2.DotNet自带例子分析(三、一)  ,代码如下:
 1ArcGIS.Server.9.2.DotNet保存GraphicsLayernamespace SaveGraphicsLayer
 2
5.这样就完成了在地图的GraphicsLayer添加点的功能,接下来我们要实现保存GraphicsLayer内容到数据库或者xml等,也能从数据库或者xml文件把保存的内容取出来显示。
6.首先在页面上添加两个button的input控件,一个是保存
GraphicsLayer,一个是把保存的GraphicsLayer取出来显示。具体html代码如下:
1ArcGIS.Server.9.2.DotNet保存GraphicsLayer<input id="saveGraphicsLayer" type="button" onclick='sGraphicsLayer()' value="保存GraphicsLayer" /><br />
2ArcGIS.Server.9.2.DotNet保存GraphicsLayer    <input id="getGraphicsLayer" type="button" onclick='gGraphicsLayer()' value="取出GraphicsLayer" />
7. 切换到Default.aspx.cs页,同以前一样需要实现ICallbackEventHandler接口,实现GetCallbackResult()和RaiseCallbackEvent(string eventArgument)两方法,具体代码如下:
 1ArcGIS.Server.9.2.DotNet保存GraphicsLayerpublic partial class _Default : System.Web.UI.Page, ICallbackEventHandler
 2}
8.接下来切换到Default页面的html视图,编写两个button的input控件的js脚本,代码和说明如下:
 1ArcGIS.Server.9.2.DotNet保存GraphicsLayer<script>
 2ArcGIS.Server.9.2.DotNet保存GraphicsLayer    //保存GraphicsLayer
 3ArcGIS.Server.9.2.DotNet保存GraphicsLayer    function sGraphicsLayer()
 4script>
9.当点击两个button的input控件时执行的sGraphicsLayer()和gGraphicsLayer()方法会请求服务端,由服务端进行处理,所以需要在cs端添加相应的处理代码,全部代码说明如下:
  1ArcGIS.Server.9.2.DotNet保存GraphicsLayernamespace SaveGraphicsLayer
  2
10.这样就可以运行测试效果,首先点击Toolbar1上的Add Graphic Point工具然后在地图上点击添加2个点,然后点击<保存GraphicsLayer>的按钮就会提示保“存成功!”,然后继续点击Add Graphic Point工具,继续在地图上添加3个点这样地图上就有5个点了,然后点击<取出GraphicsLayer>按钮这样地图上有回复到2原先保存的那2个点,测试成功。

相关文章:

  • 2021-07-09
  • 2021-10-25
  • 2021-08-26
  • 2021-09-03
  • 2022-02-28
  • 2022-02-07
  • 2022-01-26
  • 2021-07-26
猜你喜欢
  • 2022-02-07
  • 2022-02-13
  • 2022-03-07
  • 2022-02-17
  • 2021-11-26
  • 2022-02-08
  • 2021-07-19
相关资源
相似解决方案