ArcGIS Mobile 9.4学习笔记四

  在上篇中我们可以看到,利用Mobile Project Center可以方便的创建直接可用的ArcGIS Mobile应用程序,这里我们介绍如何利用ArcGIS Mobile SDK把GIS功能嵌入到已有的移动设备应用程序中。首先利用Visual Studio创建一个智能设备项目,在VS2005新建项目对话框的左侧点击智能设备,在下面的子节点中选择项目平台(如Windows Mobile 6 Professional), 在VS2008新建项目对话框中,先在右上角选择.NET Framework 2.0,按确定按钮在随后出现的对话框中选择目标平台(如下左图),把一个Map控件拖到界面中,我们会发现一个MobileCache1控件自动添加到下面,项目的引用中也会自动添加程序集ESRI.ArcGIS.Mobile(如下右图)

Tips:如果一开始选错了目标平台也没关系,在解决方案资源管理器的项目上右击,然后选择“更改目标平台”命令,就可以修改到你期望的目标平台。

查看Map控件的DataSources属性,我们会发现MobileCache1 自动列在那里,如果没有列出,请自己添加(一般都是自动添加,除非你的RP。。。)

 

   在笔记二的最后一段我们通过属性对话框来进行参数设置,现在我们通过代码来进行同样的设置,为Form1添加Load事件,在其中添加如下代码:

ExpandedBlockStart.gif Form1_Load相应函数
 1           private   void  Form1_Load( object  sender, EventArgs e)
 2          {
 3               // Environment.GetFolderPath(Environment.SpecialFolder.Personal) ==  "\My Documents"
 4               this .mobileCache1.StoragePath  =   @" \My Documents\XYZ\MobileCache " ;
 5               if  ( ! this .mobileCache1.IsValid)
 6              {
 7                  MessageBox.Show( " Map Cache is not valid! " );
 8                   return ;
 9              }
10               if  ( this .mobileCache1  !=   null   &&   this .mobileCache1.IsOpen)
11              {  this .mobileCache1.Close(); }
12               try
13              {
14                   this .mobileCache1.Open(); // 原来9.3中CacheOpenMode枚举类型的参数取消了=。=
15              }
16               catch
17              {
18                  MessageBox.Show( " Cannot open map cache " );
19              }
20          }

       因为地图缓存是事先通过笔记一中介绍的Create Mobile Map这个GP工具生成(放在文件夹XYZ中),然后把文件夹拷贝到移动设备的My Documents文件夹下的,还有一种通过访问地图服务直接创建缓存的方法在下一篇介绍。既然说到文件拷贝,那就具体介绍下模拟器配置,点击VS“工具”菜单下的“设备仿真器模拟器”,在你期待的目标平台上右击,连接后插入底座(Cradle如下左图),就可以同步了,前提是你打开了ActiveSync的wcescomm.exe程序。现在在“我的电脑”目录下,打开“移动设备”,就可以把文件拷贝到你想要的位置。

Tips:要运用ArcGIS Mobile应用程序,需要把C:\Program Files\ArcGIS\Mobile9.4\Install下的ArcGISMobile.CAB或AGMRuntime.CAB拷贝到移动设备上并安装 

        现在实现地图的移动、放大、缩小等基本功能,点击Map控件的MapAction属性,弹出如上右图的编辑框,加入你想要的操作,如PanMapAction, ZoomInMapAction、ZoomOutMapAction等,为3个menuItem添加相应函数:

ExpandedBlockStart.gif 地图操作
 1           private   void  menuItemPan_Click( object  sender, EventArgs e)
 2          {
 3               this .map1.CurrentMapAction  =   this .map1.MapActions[ 0 ];
 4          }
 5 
 6           private   void  menuItemIn_Click( object  sender, EventArgs e)
 7          {
 8               this .map1.CurrentMapAction  =   this .map1.MapActions[ 1 ];
 9          }
10 
11           private   void  menuItemOut_Click( object  sender, EventArgs e)
12          {
13               this .map1.CurrentMapAction  =   this .map1.MapActions[ 2 ];
14          }

   最后,我们再实现一个Identify的功能,添加一个menuItem( menuItemIdentify),为其添加处理函数,并且为Map控件添加MouseDown的相应函数,代码如下:

ExpandedBlockStart.gif Identify
 1           private   void  menuItemIdentify_Click( object  sender, EventArgs e)
 2          {
 3               this .map1.CurrentMapAction  =   null ;
 4          }
 5 
 6           private   void  map1_MouseDown( object  sender, ESRI.ArcGIS.Mobile.MapMouseEventArgs e)
 7          {
 8               if  (map1.CurrentMapAction  !=   null )
 9              {  return ; }
10 
11              Cursor.Current  =  Cursors.WaitCursor;
12              MapMouseEventArgs me  =  e  as  MapMouseEventArgs;
13              Envelope qEnv  =   new  Envelope(me.MapCoordinate, me.MapCoordinate);
14 
15               double  mapTolerance  =  map1.ToMap( 3 );
16              qEnv.Resize(mapTolerance, mapTolerance);
17 
18              QueryFilter qFilter  =   new  QueryFilter(qEnv, GeometricRelationshipType.Intersect);
19 
20               string  txtResult  =   " Identify Results:  " ;
21               int  intFields;
22                   foreach  (MobileCacheLayer MCLayer  in  mobileCache1.Layers)
23                  {
24                       if  (MCLayer  is  FeatureLayer)
25                      {
26                          txtResult  +=   " \r\n Layer  "   +  MCLayer.Name;
27                          FeatureLayer FLayer;
28                          FLayer  =  (FeatureLayer)MCLayer;
29                           using  (FeatureDataReader featReader  =  FLayer.GetDataReader(qFilter))
30                          {
31                              intFields  =  featReader.FieldCount;
32                               while  (featReader.Read())
33                              {
34                                   for  ( int  i  =   0 ; i  <  intFields; i ++ )
35                                  { txtResult  +=   " \r\n "   +  featReader.GetName(i)  +   " "   +  featReader.GetValue(i).ToString(); }
36                              }
37                          }
38                      }
39                  }
40              Cursor.Current  =  Cursors.Default;
41              MessageBox.Show(txtResult.ToString());
42          }

 

 代码执行到32行的while (featReader.Read())时,此处耗费很多时间,本人开发环境是虚拟机+模拟器,所以显得更慢(Oh~,my bloom) 如果不报错,建议耐心等待,最终结果如下图:

  

更多关于ArcGIS Mobile的开发:http://www.cnblogs.com/ECNU-GIS-LIUJIE

转载于:https://www.cnblogs.com/ECNU-GIS-LIUJIE/archive/2010/03/04/1678117.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值