ArcGIS Mobile 9.4学习笔记四
来源:互联网 发布:c语言小写字母a转大写a 编辑:程序博客网 时间:2024/05/16 11:12
在上篇中我们可以看到,利用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事件,在其中添加如下代码:
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 }
Form1_Load相应函数
因为地图缓存是事先通过笔记一中介绍的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添加相应函数:
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的相应函数,代码如下:
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 }
Identify
代码执行到32行的while (featReader.Read())时,此处耗费很多时间,本人开发环境是虚拟机+模拟器,所以显得更慢(Oh~,my bloom) 如果不报错,建议耐心等待,最终结果如下图:
- ArcGIS Mobile 9.4学习笔记四
- ArcGIS Mobile 9.4学习笔记一
- ArcGIS Mobile 9.4学习笔记二
- ArcGIS Mobile 9.4学习笔记三
- ArcGIS Mobile 9.4学习笔记五
- ArcGIS Mobile 9.4学习笔记九之数据篇
- ArcGIS Mobile 9.4学习笔记十之GPS
- ArcGIS Mobile 9.4学习笔记七之Windows Mobile模拟器设置问题
- ArcGIS Mobile 9.4学习笔记六之What's new in 9.4
- ArcGIS Mobile 9.4学习笔记八之如何设计和创建移动地图
- ArcGIS mobile 开发笔记(一)
- jQuery Mobile 学习四
- jQuery Mobile学习笔记(四)——列表
- jQuery Mobile学习笔记(四)——列表
- ArcGIS Engine 10.0 for.NET开发学习笔记(四)
- JQuery Mobile学习笔记
- jquery mobile学习笔记
- jquery-mobile学习笔记
- 树的孩子兄弟存储结构
- ArcGIS Mobile 9.4学习笔记一
- 郁闷。。。
- ArcGIS Mobile 9.4学习笔记二
- ArcGIS Mobile 9.4学习笔记三
- ArcGIS Mobile 9.4学习笔记四
- 登山知多少?
- ArcGIS Mobile 9.4学习笔记五
- ArcGIS Mobile 9.4学习笔记六之What's new in 9.4
- ArcGIS Mobile 9.4学习笔记七之Windows Mobile模拟器设置问题
- ArcGIS Mobile 9.4学习笔记八之如何设计和创建移动地图
- ArcGIS Mobile 9.4学习笔记九之数据篇
- ArcGIS Mobile 9.4学习笔记十之GPS
- ubuntu10.04下解决声音问题(爆音,声音断断续续,时快时慢)