二、Arcgis engine 您所在的位置:网站首页 ae中键控在哪 二、Arcgis engine

二、Arcgis engine

2024-05-30 10:58| 来源: 网络整理| 查看: 265

MapControl对应于ArcMap中的数据视图,它封装了Map对象,并提供了额外的属性、事件、方法用于:

管理控件的外观、显示属性和地图属性;添加并管理控件中的数据层(data layers);装载Map文档(mxd)到控件中;从其它应用程序拖放数据到控件中;使用鼠标拉绘几何形状并绘制到屏幕显示中。 MapControl实现的常用接口为IMapControlDefault(缺省接口,开发过程中使用该接口可保证总是访问最新版本的MapControl)和IMapControl4。 加载地图 [1] 无代码,直接利用控件加载 在窗体中添加AxToolbarControl、AxTOCControl和AxMapControl三个控件,有些时候不添加AxLienceControl控件运行会报错,所以也可添加一个Lience控件。在这里插入图片描述 ToolbarControl控件相当于ArcMap中的工具条,axTOCCoontrol控件则相当于ArcMap中左侧的布局视图,axMapControl控件则相当于ArcMap中的数据视图。右键axToolbarControl属性将Genneral选项卡中的Buddy,选择axMapControl1即与当前的axMapControl控件绑定起来,继续选中items,Add所需的工具到工具条中,如下图所示。在这里插入图片描述 同理,将左侧axTOCControl属性中的Buddy绑定axMapControl1。运行程序结果如下: 在这里插入图片描述 [2] 使用LoadMxFile加载 代码如下: System.Windows.Forms.OpenFileDialog openFileDialog1 = new OpenFileDialog();//新建一个openFileDialog实例 openFileDialog1.Title = "Open Map Document";//设置选择框的名称 openFileDialog1.Filter = "Map Documents(*.mxd)|*.mxd";//设置文件类型 openFileDialog1.ShowDialog(); string sFilePath = openFileDialog1.FileName;//存储文件路径 if (axMapControl1.CheckMxFile(sFilePath)) { axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;//MousePointer该值指示在运行时当du鼠标移动到对象的一个特定部分时,被显示的鼠标指针的类型。 axMapControl1.LoadMxFile(sFilePath, 0, Type.Missing);//如果选中的文档为合法文档,则调用LoadMxFile方法加载 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; } else { MessageBox.Show(sFilePath + "is not a valid ArcMap document"); return; }

在这里插入图片描述

[3] 使用IMapDocument接口加载 代码如下: IMapDocument m_MapDocument = new MapDocumentClass(); System.Windows.Forms.OpenFileDialog openFileDialog2 = new OpenFileDialog(); openFileDialog2.Title = "Open Map Document";//设置选择框的名称 openFileDialog2.Filter = "Map Documents(*.mxd)|*.mxd";//设置文件类型 openFileDialog2.ShowDialog(); string sFilePath = openFileDialog2.FileName;//存储文件路径 if (m_MapDocument.IsMapDocument[sFilePath])//判断文件类型 { m_MapDocument.Open(sFilePath, "");//加载地图文档 axMapControl1.Map = m_MapDocument.Map[0];//加载第一个地图,如需加载多个地图需要循环。 axMapControl1.Refresh();//刷新。 }

在这里插入图片描述 一些错误点:

m_MapDocument.IsMapDocument(sFilePath)处报错 可调用的成员“IMapDocument.IsMapDocument[string]”不能像方法一样使用。 改为m_MapDocument.IsMapDocument[sFilePath]即可, 原因:在C#中带有()的一般都作为方法,所以就会报错。

2.利用IMapDocument获取地图有两种写法: axMapControl1.Map = m_MapDocument.get_Map(0); axMapControl1.Map = m_MapDocument.Map[0];



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有