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. kubernetes 查看pod 的容器日志

    1.pod若处于运行状态,则通过kubectl logs 即可 # 查看指定pod的日志 kubectl logs <pod_name> kubectl logs -f <pod_n ...

  2. Linux Hardening Guide

    文章转载自:https://madaidans-insecurities.github.io/guides/linux-hardening.html 1. Choosing the right Lin ...

  3. FEX-EMU Wine踩坑记录

    FEX是一个用于在ARM64平台运行X86软件的工具,比较成熟,但是网上资料很少,所以就写了这篇FEX运行Wine踩坑记录. Termux的Fex不能用(2022年5月) 要在debian系统安装fe ...

  4. vue项目使用.env文件配置全局环境变量

    一.env文件的认识: (1).env 文件主要的作用是存储环境变量,也就是会随着环境变化的东西,比如数据库的用户名.密码.缓存驱动.时区,还有静态文件的存储路径之类的.因为这些信息应该是和环境绑定的 ...

  5. Hbase之命令

    Hbase之命令 -- 查询数据量 hbase org.apache.hadoop.hbase.mapreduce.RowCounter '{namespaceName:tablename}' cou ...

  6. 【杂谈】2021-CSP退役记

    Part1:复赛前一周 感觉复赛来的好快...... 我还没 颓够 准备好就来了QAQ 根据模拟赛 爆零 的光辉事迹,这次复赛我特别慌,虽然但是还是不想复习 但无所谓了,复赛一下子就只剩一天了 Par ...

  7. springboot+redis+虚拟机 springboot连接linux虚拟机中的redis服务

    文章目录 1.前提条件:确保虚拟机开启.并且连接到redis 2.新建立一个springboot项目,创建项目时勾选web选项 3.在pom中引入redis依赖 4.在application.prop ...

  8. vue3中$attrs的变化与inheritAttrs的使用

    在vue3中的$attrs的变化 $listeners已被删除合并到$attrs中. $attrs现在包括class和style属性. 也就是说在vue3中$listeners不存在了.vue2中$l ...

  9. jmeter中获取token和cookie

    ## 登录获取token 1.添加请求 1.1 输入接口中需要携带的参数的值 2.正则表达式提取器提取出值 3.输入token数据 "token":"(.+?)" ...

  10. Pipeline流水线设计的最佳实践

    谈到到DevOps,持续交付流水线是绕不开的一个话题,相对于其他实践,通过流水线来实现快速高质量的交付价值是相对能快速见效的,特别对于开发测试人员,能够获得实实在在的收益.很多文章介绍流水线,不管是j ...