1、如何获取MapSurround

和获取MapFrame类似,如果你已经获取指北针、比例尺等对象,可以通过IGraphicsContainer的FindFrame函数获取。如果没有,则通过IGraphicsContainer循环所有Element去判断即可。

2、添加MapSurround

指北针、比例尺、图例等都是MapSurround,我们以最简单的指北针为例,把MapSurround添加到PageLayout上。

var myGraphicsContainer = pLayoutApplication.PageLayout as IGraphicsContainer;
var myActiveView = pLayoutApplication.PageLayout as IActiveView;
var myMap = myActiveView.FocusMap;
var myMapFrame = myGraphicsContainer.FindFrame(myMap) as IMapFrame;
if (this._MapSurroundFrame == null)
{
this._MapSurroundFrame = new MapSurroundFrameClass();
var myMarkerNorthArrow = new MarkerNorthArrowClass();
var myMarkerSymbol = myMarkerNorthArrow.MarkerSymbol;
var myCharacterMarkerSymbol = myMarkerSymbol as ICharacterMarkerSymbol;
myCharacterMarkerSymbol.CharacterIndex = 177;
myMarkerNorthArrow.MarkerSymbol = myCharacterMarkerSymbol;
myMarkerNorthArrow.Size = 30;
this._MapSurroundFrame.MapSurround = myMarkerNorthArrow;
this._MapSurroundFrame.MapFrame = myMapFrame;
var myQuerySize = this._MapSurroundFrame.MapSurround as IQuerySize;
double myWidth = 0;
double myHeight = 0;
myQuerySize.QuerySize(ref myWidth, ref myHeight);
var myUnitConverter = new UnitConverterClass();
this.Width = Math.Round(myUnitConverter.ConvertUnits(myWidth, esriUnits.esriPoints, esriUnits.esriMillimeters), 1);
this.Height = Math.Round(myUnitConverter.ConvertUnits(myHeight, esriUnits.esriPoints, esriUnits.esriMillimeters), 1);
}
else
{
this._MapSurroundFrame.MapFrame = myMapFrame;
}
var myNewEnvelope = new EnvelopeClass
{
XMin = this.X,
YMin = this.Y,
Width = this.Width,
Height = this.Height
};
this.GetElment().Geometry = myNewEnvelope;
if (GraphicsContainerHelper.Contain(myGraphicsContainer, this.GetElment()) == false)
{
myGraphicsContainer.AddElement(this.GetElment(), 0);
}

添加MapSurround流程都是一样的,不同的地方主要是在实例化具体MapSurround的代码。例如指北针、比例尺、图例等。实例化比例尺的代码如下。

IGraphicsContainer myGraphicsContainer = pLayoutApplication.PageLayout as IGraphicsContainer;
if (this._MapSurroundFrame != null)
{
myGraphicsContainer.DeleteElement(this._MapSurroundFrame as IElement);
this._MapSurroundFrame = null;
} IActiveView myActiveView = pLayoutApplication.PageLayout as IActiveView;
IMap myMap = myActiveView.FocusMap;
IMapFrame myMapFrame = myGraphicsContainer.FindFrame(myMap) as IMapFrame; this._MapSurroundFrame = new MapSurroundFrameClass();
this._MapSurroundFrame.MapFrame = myMapFrame; //创建比例尺
this._ScaleBar = this.CreateScaleBar();
this._ScaleBar.Map = myMapFrame.Map;
this._ScaleBar.ResizeHint = esriScaleBarResizeHint.esriScaleBarFixed;
this._ScaleBar.LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisions;
this._MapSurroundFrame.MapSurround = this._ScaleBar; this._ScaleBar.BarHeight = this.BarHeight;
this._ScaleBar.Division = this.Division;
this._ScaleBar.Divisions = this.Divisions;
this._ScaleBar.Subdivisions = this.Subdivisions;
this._ScaleBar.DivisionsBeforeZero = this.DivisionsBeforeZero; this._ScaleBar.LabelPosition = this.LabelPosition;
this._ScaleBar.LabelGap = this.LabelGap;
ITextSymbol myLabelSymbol = new TextSymbolClass();
IFontDisp myFontDisp = myLabelSymbol.Font;
myFontDisp.Name = "Times New Roman";
myLabelSymbol.Font = myFontDisp;
myLabelSymbol.Size = this.LabelSize;
this._ScaleBar.LabelSymbol = myLabelSymbol; //pScaleBar的UnitLabel属性设置需要放在pScaleBar.Units设置代码之后。这样UnitLabel设置才有效果。
this._ScaleBar.Units = esriUnits.esriKilometers;
this._ScaleBar.UnitLabel = this.UnitLabel;
this._ScaleBar.UnitLabelGap = this.UnitLabelGap;
ITextSymbol myUnitLabelSymbol = new TextSymbolClass();
myFontDisp = myUnitLabelSymbol.Font;
myFontDisp.Name = "Times New Roman";
myUnitLabelSymbol.Font = myFontDisp;
myUnitLabelSymbol.Size = this.UnitLabelFontSize;
this._ScaleBar.UnitLabelSymbol = myUnitLabelSymbol;
this._ScaleBar.UnitLabelPosition = this.UnitLabelPosition; IScaleMarks myScaleMarks = this._ScaleBar as IScaleMarks;
myScaleMarks.MarkFrequency = esriScaleBarFrequency.esriScaleBarDivisionsAndSubdivisions;
myScaleMarks.MarkPosition = this.MarkPosition;
myScaleMarks.DivisionMarkHeight = this.DivisionMarkHeight;
ILineSymbol myDivisionMarkSymbol = new SimpleLineSymbolClass();
myDivisionMarkSymbol.Color = new RgbColorClass() { Red = 0, Green = 0, Blue = 0 };
myDivisionMarkSymbol.Width = this.DivisionMarkWidth;
myScaleMarks.DivisionMarkSymbol = myDivisionMarkSymbol;
myScaleMarks.SubdivisionMarkHeight = this.SubdivisionMarkHeight;
ILineSymbol mySubdivisionMarkSymbol = new SimpleLineSymbolClass();
mySubdivisionMarkSymbol.Color = new RgbColorClass() { Red = 0, Green = 0, Blue = 0 };
mySubdivisionMarkSymbol.Width = this.SubdivisionMarkWidth;
myScaleMarks.SubdivisionMarkSymbol = mySubdivisionMarkSymbol; IElement myElement = this._MapSurroundFrame as IElement;
IGeometry myGeometry = myElement.Geometry;
if (myGeometry != null && myGeometry.IsEmpty == false)
{
IEnvelope myGeometryEnvelope = myGeometry.Envelope;
this.Width = myGeometryEnvelope.Width;
this.Height = myGeometryEnvelope.Height;
}
IEnvelope myEnvelope = new EnvelopeClass();
myEnvelope.PutCoords(this.X, this.Y, this.X + this.Width, this.Y + this.Height);
myElement.Geometry = myEnvelope;
myGraphicsContainer.AddElement(this._MapSurroundFrame as IElement, 0); /// <summary>
/// 创建比例尺
/// </summary>
private IScaleBar CreateScaleBar()
{
IScaleBar myScaleBar;
if (this.BarType == "AlternatingScaleBar")
{
myScaleBar = new AlternatingScaleBar();
}
else if (this.BarType == "DoubleAlternatingScaleBar")
{
myScaleBar = new DoubleAlternatingScaleBar();
}
else if (this.BarType == "HollowScaleBar")
{
myScaleBar = new HollowScaleBar();
}
else if (this.BarType == "SteppedScaleLine")
{
myScaleBar = new SteppedScaleLine();
}
else
{
myScaleBar = new ScaleLine();
}
myScaleBar.Name = this.BarType;
return myScaleBar;
}

3、普通Element

继承IElement接口的类如下图所示。

这个列表中的Elment,除了MapFrame、MapSurroundFrame以及后面带()的外,其他的基本上都是我们常用的,例如点元素、线元素、面元素、圆元素、椭圆元素、各种图片元素等。

IElement有一个关键属性Geometry,如果是MarkerElement或者TextElement,那么Geometry就是IPoint类型,如果是LineElement,那么Geometry是IPolyline类型,PolygonElement的Geometry为IPolygon类型,图片Element一般传入IEnvelope。

一些特殊的Element例如椭圆的Geometry传什么呢?这样不确定的问题,我们可以去SDK帮助中查找,一般帮助中会解释的很清楚。

帮助中说的比较明确,可以传递IEnvelope,这样会在IEnvelope生成 一个椭圆。也可以传由EllipticArc组成的Polygon对象。不过我们一般会传IEnvelope,主要原因是简单直观。

除了Geometry外,很对图形状的元素包含Symbol属性。例如MarkerElement可设置IMarkerSymbol,TextElement可以设置ITextSymbol,IPolylineElement可设置ILineSymbol,PolygonElement、CircleElement和EllipseElement可以设置IFillSymbol。

ArcObjects SDK开发 014 MapSurround和普通Element的更多相关文章

  1. Kinect for Windows SDK开发学习相关资源

    Kinect for Windows SDK(K4W)将Kinect的体感操作带到了平常的应用学习中,提供了一种不同于传统的鼠标,键盘及触摸的无接触的交互方式,在某种程度上实现了自然交互界面的理想,即 ...

  2. 微信公众账号 Senparc.Weixin.MP SDK 开发教程 索引

    Senparc.Weixin.MP SDK从一开始就坚持开源的状态,这个过程中得到了许多朋友的认可和支持. 目前SDK已经达到比较稳定的版本,这个过程中我觉得有必要整理一些思路和经验,和大家一起分享. ...

  3. 高拍仪拍照SDK开发(良田影像S300L|S500L)

    高拍仪拍照SDK开发下载地址:点击下载 本SDK适用于:良田影像S300L|S500L 高拍仪如图: SDN开发包安装之后找到安装目录,如图: 大家找到各自需要的版本即可,需要注意的是如果需要上传图片 ...

  4. TortoiseSVN安装以及淘宝 TAE SDK 开发环境的搭建

    一.TortoiseSVN 的下载和安装 1.进入TortoiseSVN 官网下载地址http://tortoisesvn.net/downloads.html,根据自己的操作系统位数下载相应最新版本 ...

  5. SDK开发断点失效

    做SDK开发,一般会创建一个静态库工程,然后添加一个app的Target 可是,Xcode7创建的工程,app的Target中断点有效,能断住,为什么静态库的Target中的断点断不住呀. 断点断住发 ...

  6. Vmware Vsphere WebService SDK开发(第一讲)-基本知识学习

    刚开始这方面开发的时候,不知道如何下手,能够查到的资料特别少,而且看到很多网友和我一样也在找这方面的资料.接下来的一段时间我就结合自己所参与的项目,完成关于Vmware Vsphere WebServ ...

  7. 【转】微信公众账号 Senparc.Weixin.MP SDK 开发教程 索引

    微信公众账号 Senparc.Weixin.MP SDK 开发教程 索引 Senparc.Weixin.MP SDK从一开始就坚持开源的状态,这个过程中得到了许多朋友的认可和支持. 目前SDK已经达到 ...

  8. ArcObjects SDK(AE)10.1在vs2012安装的方法

    ArcObjects SDK(以下简称AO)10.1只支持vs2010,如果装了vs2012,再安装AO会提示一串鸡肠(英文),意思是AO10.1只支持vs2010 想在2012下安装,可以通过修改注 ...

  9. 微信公众账号 Senparc.Weixin.MP SDK 开发教程

    http://www.cnblogs.com/szw/archive/2013/05/14/weixin-course-index.html 微信公众账号 Senparc.Weixin.MP SDK ...

  10. Kinect for Windows SDK开发入门(一):开发环境配置

    [译]Kinect for Windows SDK开发入门(一):开发环境配置 前几天无意中看到微软发布了Kinect for windows sensor,进去看了一下Kinect应用的例子,发现K ...

随机推荐

  1. Gitlab备份以及恢复

    1.迁移准备工作和思路 从a服务器迁移到b服务器,由于Gitlab自身的兼容性问题,高版本的Gitlab无法恢复低版本备份的数据,需要注意在b服务器部署和a服务器一样版本的gitlab,部署好环境后开 ...

  2. C#-4 方法

    一 何为方法 方法是一块具有名称的代码,是类的函数成员. 方法主要分为方法头和方法体. void Method() { 语句1: 语句2: } 二 类型推断和var关键字 var sum = 15; ...

  3. 云原生强大且灵活的持续集成CI开源框架Tekton实战-上

    @ 目录 概述 定义 常见CICD工具 使用好处 组件 基本概念 安装 前提条件 安装Tekton Pipelines 创建并运行任务 安装Dashboard 安装Cli Pipelines示例演示 ...

  4. 关于IOC容器

    1.什么是 IOC (1)控制反转,把对象创建和对象之间的调用过程,交给 Spring 进行管理 (2)使用 IOC 目的:为了耦合度降低

  5. visual studio插件开发-Menu

    工欲善其事,必先利其器,作为程序员我们很大部分时间在和ide打交道,好的插件可以大大提高我们的编程效率,我开发过几个vs插件来解决一键生成dbmodels,快速部署到服务器,总结下来最关键的还是对于M ...

  6. Debian11管理员手册

    1 用户与群组数据库 用户清单通常保存在 /etc/passwd 文件内,把哈希编码后的密码保存在 /etc/shadow 文件内.这两个文件都是纯文本档,以简单的格式保存,可以用文本编辑器读取与修改 ...

  7. 并发编程之 ThreadLocal

    前言 了解过 SimpleDateFormat 时间工具类的朋友都知道,该工具类非常好用,可以利用该类可以将日期转换成文本,或者将文本转换成日期,时间戳同样也可以. 以下代码,我们采用通用的 Simp ...

  8. JMETER与它的组件们

    JSON提取器与Debug Sampler 我们平时会遇到很多JSON格式的接口返回,我们需要提取参数可以用JSON提取器,同时配合自带的调试器来进行调试.  JSON提取器 Name of crea ...

  9. 手把手教你使用LabVIEW实现Mask R-CNN图像实例分割

    前言 前面给大家介绍了使用LabVIEW工具包实现图像分类,目标检测,今天我们来看一下如何使用LabVIEW实现Mask R-CNN图像实例分割. 一.什么是图像实例分割? 图像实例分割(Instan ...

  10. Seata 1.5.2 源码学习

    文章有点长,我决定用半个小时来给您分享~ 基于Seata 1.5.2,项目中用 seata-spring-boot-starter 1. SeataDataSourceAutoConfiguratio ...