首页 > 其他分享 >ArcObjects SDK开发 014 MapSurround和普通Element

ArcObjects SDK开发 014 MapSurround和普通Element

时间:2022-12-10 16:44:22浏览次数:54  
标签:MapSurround ScaleBar ArcObjects Element ._ var new MapSurroundFrame

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接口的类如下图所示。

image1.png

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

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

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

image2.png

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

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

标签:MapSurround,ScaleBar,ArcObjects,Element,._,var,new,MapSurroundFrame
From: https://www.cnblogs.com/mytudousi/p/16971826.html

相关文章

  • element-ui upload自定义formdata上传文件和参数
     <el-uploadlist-type="text"action="":http-request="HandleHttpRequestDescFile":on-remove="handleRemoveDescFile":file-list="this.fileList"ref="upload"......
  • element-ui:多个el-dialog弹框切换会出现闪烁
    场景使用多个element-ui组件el-dialog弹框切换打开A弹框,点击关闭,紧接着打开B弹框会出现一个明显的闪烁解决给第一个弹框关闭加一点延迟//先打开另一个对话框this.BD......
  • vue之element-ui
    注意:命令行都要使用管理员模式运行第一步:创建vue工程下面处理项目,创建安装依赖等,都是在命令行进行处理。创建一个工程(vue)vueinitwebpackvue安装依赖,我们需要安装vue-ro......
  • elementui 根据条件动态绑定 input disabled 的值,实现输入框根据固定条件改变是否可以
    有时在表单里可能某些输入框需要根据另外一个输入框的值而改变显示的状态,时而可输入时而不可输入,可以利用vue的双向数据绑定的特点,监听输入框的值,如果输入框的值为某个固......
  • Element UI vue 上传文件、下载模板
    样式<el-uploadclass="upload-demo"action="/api/file/upload":on-remove="handleRemove"multipleref="uplpadFile":limit="1":on-ex......
  • vue+elementUI 使用腾讯地图
    OverridetheentrypointofanimageIntroducedinGitLabandGitLabRunner9.4.Readmoreaboutthe extendedconfigurationoptions.Beforeexplainingtheav......
  • element-ui表格组件的封装
    背景我们平常工作中需要用表格的形式来展示多行数据需求需求1:通过配置文件的形式来设置表格的列需求2:可以合并表头代码MyTable.vue<template><div><el-tabl......
  • element-plus 安装
    下载 element-plus快速搭建·​​https://github.com/element-plus/element-plus-vite-starter​​vuecreateelem-app     回车选vue3   之后一路回车cd到app目......
  • VUE element-ui表格 实现滚动到底部加载更多数据
    原文链接:https://blog.51cto.com/u_15301254/4842790vue:<el-tableheight="600":data="visibleData"......
  • 看文档elementui 转 element ui中的
    看文档elementUI文档 当中&是什么用途? 安然亦智css学习杂记 1、css中的&语法&是sass的语法,代表上一级选择器。例如:12345678.e......