1、三、源程序代码 . 7四、心得体会 . 14一、程序运行演示1. 新建项目文件,并实现 file 中的基本功能,显示地图基本要素。如图 1图 12. 在工具栏加载按钮, 按钮功能是对当前视图缩小 3 倍;在工具栏加载工具, 工具功能在地图上标注当前日期。如图 22图 2按钮实现缩小 3 倍功能操作,如图 3图 33.点击地图节点,弹出如图 4,图 5 菜单并实现菜单中的内容:图 43图 54. 点击图层节点,弹出如图 6 菜单并需要实现菜单中的内容图 65. 点击 Legend Class ,弹出符号选择对话框,该对话框供用户按需要选择符号并进行更改。如图 74图 76.打开图层属性表,用户选
2、择某条记录,可弹出如图 8,9 所示的右键菜单,并实现右键菜单中的内容5图 8图 9二、问题及解决方案问题 1.VS2008 与2010 之间要进行格式转换, 按照所导向的步骤进行, 否则程序将无法正常运行,出现错误问题 2. 构建好基本框架后,地图文档中要素显示出现问题。此问题要添加 licence 控件,否则无法显示地图要素。问题 3. 使用 Toolbar 和 Toc功能时无法进行操作此问题应在属性设置时建立关联功能。问题 4. 程序 Program文件中要添加相应功能键语句,否则将无法实现功能。问题 5. 引用接口,方法,例如 ADF,要添加相应的引用,否则程序出现错误。问题6. 在实
3、现两个自定义按钮与工具时,遇到的问题:先直接引用现有项未实现,发现缺少一些东西,后自己直接创建的 Basetool 和Basecomman类d ;在代码中报错,重新生成解决方案后顺利解决这个问题。问题7. 在实现地图和图层节点的右键功能时,遇到琐碎的问题,在这个过程中直接引用老师所给的几个类,但是报错,是因为命名空间未做修改;缺少引用,需要根据错误提示添加相应的引用6三、源程序代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Dra
4、wing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Runtime.InteropServices;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.ADF;using ESRI.ArcGIS.SystemUI;using ESRI.ArcGIS.Display;namespace WindowsFormsAp
5、plication2public partial class MainForm : Form#region class private membersprivate IMapControl3 m_mapControl = null;private string m_mapDocumentName = string.Empty;#endregionIMapDocument m_MapDocument = new MapDocument();#region class constructorprivate ITOCControl2 m_tocControl;private IToolbarMenu
6、 m_menuMap;private IToolbarMenu m_menuLayer;private ZoomIn3XCMD1 test = new ZoomIn3XCMD1();public MainForm()InitializeComponent();private void newDocumentToolStripMenuItem_Click(object sender, EventArgs e)7ICommand command = new CreateNewDocument();command.OnCreate(m_mapControl.Object);command.OnCli
7、ck();private void openDocumentToolStripMenuItem_Click(object sender, EventArgs e)openFileDialog1.Title = Save Map Document As;openFileDialog1.Filter = Map Documents (*.mxd)|*.mxdopenFileDialog1.ShowDialog();string sFilePath = openFileDialog1.FileName;if (axMapControl1.CheckMxFile(sFilePath)axMapCont
8、rol1.MousePointer =esriControlsMousePointer.esriPointerHourglass;axMapControl1.LoadMxFile(sFilePath, 0, Type.Missing);esriControlsMousePointer.esriPointerDefault;elseMessageBox.Show(sFilePath + is not a valid ArcMap document);return;private void MainForm_Load(object sender, EventArgs e)/get the MapC
9、ontrolm_mapControl = (IMapControl3)axMapControl1.Object;/disable the Save menu (since there is no document yet)this.menuSaveDoc.Enabled = false;/ 定义地图右键菜单,图层右键菜单m_tocControl = (ITOCControl2)axTOCControl1.Object;/ 添加菜单到地图节点m_menuMap = new ToolbarMenu();8m_menuMap.AddItem(esriControls.ControlsAdddataC
10、ommand, -1, 0, false,esriCommandStyles.esriCommandStyleTextOnly);m_menuMap.AddItem(new LayerVisibility(), 1, 1, false,m_menuMap.AddItem(new LayerVisibility(), 2, 2, false,/ 添加菜单到图层节点m_menuLayer = new ToolbarMenu();m_menuLayer.AddItem(new OpenAttributeTableCmd(), -1, 0, false,esriCommandStyles.esriCo
11、mmandStyleIconAndText);/ 右键添加属性表m_menuLayer.AddItem(new RemoveLayer(), 1, 1, false,m_menuLayer.AddItem(new RemoveLayer(), 1, 2, true,m_menuLayer.AddItem(new ScaleThresholds(), 2, 3, false,m_menuLayer.AddItem(new ScaleThresholds(), 3, 4, false,m_menuLayer.AddItem(new LayerSelectable(), 1, 5, true,m_menuLayer.AddItem(new LayerSelectable(), 2, 6, false,m_menuLayer.AddItem(new ZoomToLayer(), -1, 7, true,/Set the hook of each menum_menuLayer.SetHook(m_mapControl);m_menuMap.SetHook(m_mapControl);axToolbarControl1.AddItem(test, -1, -1, true, 0,esriCommandStyles.esriCommandStyleI
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1