在ArcGIS中,我们使用的制图控件除了MapControl之外,还有PageLayoutControl,用于页面布局和制图,生成一幅成品地图。

PageLayoutControl 封装了PageLayout对象,提供布局视图中控制元素的属性和方法,其中包括图形的位置属性、标尺和对齐网格的设置,以及确定页面显示在屏幕上的方法。

我们将实现在布局视图下的添加图例、指北针、比例尺和文本的操作。

添加地图元素

/// <summary>
/// 添加地图元素
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 添加地图元素ToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
//排除数据视图下不能插入
if (tabControl1.SelectedIndex == )
{
return;
}
//使用UID识别操作命令
UID uid = new UIDClass();
if (e.ClickedItem.Text != "")
{
//e是鼠标操作所返回的对象, 携带了相关的操作信息
switch (e.ClickedItem.Text)
{
case "图例":
//定义好UID的样式为Carto.legend
uid.Value = "ESRICarto.legend";
//调用自定义方法AddElementInpageLayer, 下同
AddElementInPageLayer(uid);
break;
case "指北针":
//定义好UID的样式为Carto.MarkerNorthArrow
uid.Value = "ESRICarto.MarkerNorthArrow";
AddElementInPageLayer(uid);
break;
case "比例尺":
//定义好UID的样式为ESRICarto.ScaleLine ??
AddScalebar(axPageLayoutControl1.PageLayout, axPageLayoutControl1.ActiveView.FocusMap);
break;
case "文本":
TextInput txtInput = new TextInput();
txtInput.ShowDialog();
//调用自定义方法加入图名
AddTextElement(axPageLayoutControl1, txtInput.Fontsize, txtInput.ThimaticMapName);
break;
default:
break;
}
}
}

1、图例或指北针

/// <summary>
/// 添加图例或指北针——根据UID元素添加相应的元素
/// </summary>
/// <param name="uid"></param>
private void AddElementInPageLayer(UID uid)
{
//提供对控制图形容器的成员的访问。
IGraphicsContainer graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer;
//提供对成员的访问, 控制map元素的对象, IMapFrame是地图浏览栏对象的默认接口
//通过FindFrame方法, 查找axPageLayoutControl1中屏幕包含指定对象的框架
IMapFrame mapFrame = graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IMapFrame;
//提供对成员的访问, 控制地图环绕元素映射的接口, 是附属物框架的对象的默认接口
//通过CreateSurroundFrame方法创建基于当前地图框下的一个新地图环绕元素(如图例、指北针)
IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);
//IElement是所有图形元素和框架元素类都要实现的接口
//将mapSurroundFrame强转成IElement类型
IElement element = mapSurroundFrame as IElement;
//实例化一个包络线
IEnvelope envelope = new EnvelopeClass();
//设定坐标
envelope.PutCoords(, , , );
//设置元素中的几何形状
element.Geometry = envelope;
try
{
//提供对控制图例的成员的访问。
ILegend legend = (ILegend)mapSurroundFrame.MapSurround;
legend.Title = "图例";
}
catch
{ }
graphicsContainer.AddElement(element, );
//设置元素将在axPageLayoutControl屏幕上显示图形
element.Activate(axPageLayoutControl1.ActiveView.ScreenDisplay);
//部分刷新
axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}

2、比例尺

/// <summary>
/// 添加比例尺
/// </summary>
/// <param name="pageLayout"></param>
/// <param name="map"></param>
private void AddScalebar(IPageLayout pageLayout, IMap map)
{
if (pageLayout == null || map == null)
{
return;//当pageLayerout和map为空时返回
}
//实例化一个包络线
IEnvelope envelope = new EnvelopeClass();
//设定坐标
envelope.PutCoords(, , , );
//实例化一个uid
IUID uid = new UIDClass();
//将uid设置为ESRICarto.scalebar
uid.Value = "ESRICarto.scalebar";
//提供对控制图形容器的成员的访问
IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;
//查找map中指定对象的框架
IMapFrame mapFrame = graphicsContainer.FindFrame(map) as IMapFrame;
//创建基于当前地图框下的一个新地图环绕元素
IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as UID, null);
//元素属性
IElementProperties pElePro;
//实例化一个比例尺对象
IScaleBar markerScaleBar = new AlternatingScaleBarClass();
//可以有多种比例尺类型
markerScaleBar.Division = ;
markerScaleBar.Divisions = ;
markerScaleBar.LabelPosition = esriVertPosEnum.esriAbove;
markerScaleBar.Map = map;
markerScaleBar.Subdivisions = ;
markerScaleBar.UnitLabel = "";
markerScaleBar.UnitLabelGap = ;
markerScaleBar.UnitLabelPosition = esriScaleBarPos.esriScaleBarAbove; //位于比例尺上方
markerScaleBar.Units = esriUnits.esriKilometers; //千米
mapSurroundFrame.MapSurround = markerScaleBar;
//将mapSurroundFrame强转为IElementProperties
pElePro = mapSurroundFrame as IElementProperties;
//设置元素Name属性
pElePro.Name = "my scale";
//添加元素至axPageLayoutControl1
axPageLayoutControl1.AddElement(mapSurroundFrame as IElement, envelope, Type.Missing, Type.Missing, );
//部分刷新
axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, Type.Missing, null);
}

3、文本

/// <summary>
/// 添加文本
/// </summary>
/// <param name="axPageLayoutControl1">目标PageLayoutControl的Name属性</param>
/// <param name="fontsize">字体尺寸</param>
/// <param name="thimaticMapName">图名</param>
private void AddTextElement(AxPageLayoutControl axPageLayoutControl1, decimal fontsize, string thimaticMapName)
{
//创建PageLayout对象
IPageLayout pPageLayout = axPageLayoutControl1.PageLayout;
//将PageLayout强转成IActiveView
IActiveView pAV = (IActiveView)pPageLayout;
//将PageLayout强转成IGraphicsContainer
IGraphicsContainer graphicsContainer = (IGraphicsContainer)pPageLayout;
//实例化文本元素
ITextElement pTextElement = new TextElementClass();
//实例化字体元素
IFontDisp pFont = new StdFontClass() as IFontDisp;
pFont.Bold = true;
pFont.Name = "宋体";
pFont.Size = fontsize;
//实例化IRgbColor
IRgbColor pColor = new RgbColorClass();
pColor.Red = ;
pColor.Green = ;
pColor.Blue = ;
//实例化文本符号
ITextSymbol pTextSymbol = new TextSymbolClass();
pTextSymbol.Color = (IColor)pColor;
pTextSymbol.Font = pFont;
//赋值元素文本和符号
pTextElement.Text = thimaticMapName;
pTextElement.Symbol = pTextSymbol;
//实例化一个点
IPoint pPoint = new PointClass();
pPoint.X = ;
pPoint.Y = ;
//实例化一个元素
IElement pElement = (IElement)pTextElement;
pElement.Geometry = (IGeometry)pPoint;
graphicsContainer.AddElement(pElement, );
//真正实现部分刷新
pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
核心AddElementInPageLayer(UID uid)函数总结:

谢谢观看!本人初学GIS二次开发,如果有不对的地方,请多多包涵!

ArcGIS Engine添加地图元素的实现的更多相关文章

  1. C#+ArcGIS Engine 获取地图中选中的要素

    转自 C#+ArcGIS Engine 获取地图中选中的要素 C#+ArcGIS Engine 获取地图中选中的要素 提供一种简单遍历获取地图中选中要素的方法,代码如下: List<IFeatu ...

  2. Arcgis Engine 添加一个Symbol符号样式步骤

    public static void DrawPictureMarkerSymbol(IGlobe globe, String layerName) { //添加一个图层 ESRI.ArcGIS.Ca ...

  3. arcgis engine - 添加图例,指北针.

    esri帮助提供了使用比例尺的方法: Working with map surrounds 主要代码为: public void AddMapSurround(IPageLayout pageLayo ...

  4. ArcGIS Engine 添加SDE数据库

    public void AddSDELayer(bool ChkSdeLinkModle){  //定义一个属性   IPropertySet propset = new PropertySetCla ...

  5. ArcGIS Engine开发之地图基本操作(3)

    地图数据的加载 一.加载Shapefile数据 Shapefile文件是目前主流的一种空间数据的文件存储方式,也是不同GIS软件进行数据格式转换常用的中间格式.加载Shapefile数据的方式有两种: ...

  6. 《ArcGIS Engine+C#实例开发教程》第六讲 右键菜单添加与实现

    原文:<ArcGIS Engine+C#实例开发教程>第六讲 右键菜单添加与实现 摘要:在这一讲中,大家将实现TOCControl控件和主地图控件的右键菜单.在AE开发中,右键菜单有两种实 ...

  7. 《ArcGIS Engine+C#实例开发教程》第二讲 菜单的添加及其实现

    原文:<ArcGIS Engine+C#实例开发教程>第二讲 菜单的添加及其实现 摘要:在上一讲中,我们实现了应用程序基本框架,其中有个小错误,在此先跟大家说明下.在“属性”选项卡中,我们 ...

  8. 使用XAML在WPF项目中承载ArcGIS Engine地图控件开发

    原文 http://blog.csdn.net/flexmapserver/article/details/5868882 用Windows Form进行ArcGIS Engine二次开发时常见的形式 ...

  9. ArcGIS Engine开发之地图基本操作(4)

    ArcGIS Engine开发中数据库的加载 1.加载个人地理数据库数据 个人地理数据库(Personal Geodatabase)使用Miscrosoft Access文件(*.mdb)进行空间数据 ...

随机推荐

  1. 23种设计模式之抽象工厂(Abstract Factory Pattern)

    抽象工厂 当想创建一组密不可分的对象时,工厂方法似乎就不够用了 抽象工厂是应对产品族概念的.应对产品族概念而生,增加新的产品线很容易,但是无法增加新的产品.比如,每个汽车公司可能要同时生产轿车.货车. ...

  2. POJ 2533——Longest Ordered Subsequence(DP)

    链接:http://poj.org/problem?id=2533 题解 #include<iostream> using namespace std; ]; //存放数列 ]; //b[ ...

  3. Docker Registry 管理镜像

    一.使用Docker Registry管理镜像 a.登陆docker hub  https://www.docker.com/products/docker-hub b.创建仓库 c.推送镜像   打 ...

  4. MongoDB 学习笔记之 检测存储引擎

    检测存储引擎: db.serverStatus().storageEngine db.serverStatus().wiredTiger (转)WiredTiger测试结果 单纯写的测试结果 结论:W ...

  5. A Deep Neural Network Approach To Speech Bandwidth Expansion

    题名:一种用于语音带宽扩展的深度神经网络方法 作者:Kehuang Li:Chin-Hui Lee 2015年出来的 摘要 本文提出了一种基于深度神经网络(DNN)的语音带宽扩展(BWE)方法.利用对 ...

  6. Io流的概述

    Io流的概述IO: I输入(Input),O 输出(Output)1.什么是IO流? 数据流,IO是严格的“水流模型” 所以IO流是用来读写数据,或者传输数据. 注意:File只能操作文件对象本身,而 ...

  7. VMware ESXI6.0服务器安装系列:U盘安装问题汇总之网卡驱动安装

    本文转载至:http://blog.51cto.com/huanwenli/1749298 在给物理服务器安装ESXI的过程中经常会遇到网卡驱动问题,如果是买的是Dell.HP.IBM等厂商的服务器, ...

  8. angular之跨域

    一.什么是跨域? 跨域是指一个域下的文档或者脚本去请求另一个域下的资源.(广义) 广义的跨域: 1.资源跳转:链接跳转.重定向.表单提交. 2.资源嵌入:<link>.<script ...

  9. (未完)经典Web漏洞实战演练靶场笔记

    记录下自己写的经典Web漏洞靶场的write up,包括了大部分的经典Web漏洞实战场景,做个笔记. 0x01 任意文件下载漏洞 if(!empty($_GET['filename'])){ $fil ...

  10. Python之单例模式的多种实现

    单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在.当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场. ...