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. 单台主机MySQL多实例部署

    二进制安装mysql-5.7.26 [root@mysql ~]# cd /server/tools/ [root@mysql tools]# ll total 629756 -rw-r--r-- 1 ...

  2. 内网横向渗透 之 ATT&CK系列一 之 横向渗透域主机

    前言 上一篇文章中已获取了关于域的一些基本信息,在这里再整理一下,不知道信息收集的小伙伴可以看回上一篇文章哦 域:god.org 域控 windows server 2008:OWA,192.168. ...

  3. echarts 饼图中间添加图片

    饼图添加图片只需要配置两部分 option = { graphic: { // 这个属性可以在饼图内部填充图片,文字等 elements: [{ type: 'image',//需要填充图片,配置im ...

  4. 2022.9.17 Java第二次课总结

    以下是本节课后的问题 首先是关于静态变量 在类中,使用 static 修饰符修饰的属性(成员变量)称为静态变量,也可以称为类变量,常量称为静态常量,方法称为静态方法或类方法,它们统称为静态成员,归整个 ...

  5. PAT520 钻石争霸赛 7-6 随机输一次

    #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1000; ll n ...

  6. 新零售SaaS架构:中央库存系统架构设计

    近年来,越来越多的零售企业大力发展全渠道业务.在销售额增长上,通过线上的小程序.直播.平台渠道等方式,拓展流量变现渠道.在会员增长方面,通过多样的互动方式,全渠道触达消费者,扩大会员规模.而全渠道的库 ...

  7. Invalid bound statement (not found)出现原因和解决方法

    Invalid bound statement (not found)出现原因和解决方法 前言: 想必各位小伙伴在码路上经常会碰到奇奇怪怪的事情,比如出现Invalid bound statement ...

  8. 【MySQL】02_子查询与多表查询

    子查询 指一个查询语句嵌套在另一个查询语句内部的查询,这个特性从MySQL 4.1开始引入. SQL 中子查询的使用大大增强了 SELECT 查询的能力,因为很多时候查询需要从结果集中获取数据,或者 ...

  9. JS中数值类型的本质

    一.JS中的数值类型 众所JS爱好友周知,JS中只有一个总的数值类型--number,它包含了整型.浮点型等数值类型.其中,浮点数的实现思想有点复杂,它把一个数拆成两部分来存储.第一部分是有效位数,也 ...

  10. Java Stream流的使用

    流相关的方法可以分为三种类型,分别是:获取Stream流.中间方法.终结方法.中间方法会返回当前流,可以方便的进行链式调用. 流不可重复使用,否则会报错: java.lang.IllegalState ...