zoukankan      html  css  js  c++  java
  • IElement

    AE中绘制图形元素的方法

    Element元素对象是一个非常庞杂的对象集合,主要分为两大部分:图形元素(Graphic Element)和框架元素(Frame Element);

    图形元素包括GroupElement、MarkerElement、LineElement、TextElement、DataElement、PictureElement、和FillShapeElement等对象,它们都是作为图形的形式而存在的。

    IElement是所有图形元素和框架元素都实现的接口,它可以确定元素的Geometry属性,Element是一个抽象类,IElement和ILineElement、ITextElement并不是父子关系,后者没有Geometry属性。

       要在视图绘制图形的方法:

    1 采用MapControl的DrawShape()方法。

    在MapControl控件中通过DrawShape方法绘制的图形,在视图中进行缩放操作之后就会消失,这是因为这些图形本质上都是缓存的,仅仅是暂时存在的。如果要保存这些元素,就需要使用Mxd文件。

        ISimpleFillSymbol pSymbol = new SimpleFillSymbolClass();

        pSymbol.Color = pColor;

        Object symbol = pSymbol;

        IGeometry pGeo=axMapControl1.DrawShape(pGeo,ref symbol);

    2 用IGraphicsContainer::AddElement把图形元素添加到视图并显示

       主要步骤:

       1 产生一个新的元素对象;

       2 确定元素显示时使用的Symbol(符号)和Geometry(几何对象);

       3用IGraphicsContainer::AddElement把图形元素添加到视图并显示

       4 刷新视图,让添加的元素可以显示出来。

    添加IMarkerElement对象和ILineElement对象

       以LineElement为例添加它到视图中需要两个接口:IElement和ILineElement,前者用于确定线元素的Geometry,后者确定Symbol。需要注意的什么类型的元素配对什么类型的Symbol,例如LineElement元素只能用修饰LineElement对象的符号,也只能用Line或者Polyline作为Geometry,MarkerElement也是一样的,使用的是Marker类型的Symbol和点作为它的Geometry。具体例子:

                    IMap pMap = axMapControl1.Map;

                    IActiveView pActive = pMap as IActiveView;

                    ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass();  //设置Symbol属性

                    pLineSymbol.Color = GetRGB(0, 255, 0);

                    pLineSymbol.Width = 3;

                    pGeo = axMapControl1.TrackLine();

                 

                    ILineElement pLineElement = new LineElementClass();    

                    IElement pEle = pLineElement as IElement;

                    pLineElement.Symbol = pLineSymbol;

                    pEle.Geometry = pGeo;

                    IGraphicsContainer pContainer = pMap as IGraphicsContainer;

                    pContainer.AddElement(pEle, 0);

                   pActive.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

      添加TextElement对象(用ITextElement接口定义了设置文字元素的属性,例如Text(字符)等

                    IMap pMap = axMapControl1.Map;

                    IActiveView pActiveView = pMap as IActiveView;

                    ITextElement pText = new TextElementClass();

                    pText.Text = "从今天开始你就是我的了就像驴子一样给你盖个章";

                    IElement pEle = pText as IElement;

                    IPoint point = new PointClass();

                    point.PutCoords(e.mapX-30, e.mapY+10);

                    IFormattedTextSymbol pTextSymbol =new TextSymbolClass();

                    ICallout pCallout = new BalloonCalloutClass();

                    pCallout.AnchorPoint = point;

                    pTextSymbol.Background = pCallout as ITextBackground;

                    pText.Symbol = pTextSymbol;

                    pEle.Geometry = point;

                    IGraphicsContainer pgraphic = axMapControl1.Map as IGraphicsContainer;

                    pgraphic.AddElement(pEle,0);

                    axMapControl1.Refresh();

    添加FillShapeElement对象

         FillShapeElement是一个抽象类,它的子类有CircleElement、EllipseElement、PolygonElement和RectangleElement。这些对象的共同特点是它们的Geometry属性都是一个封闭的二维图形。

         IFillShapeElement接口是所有FillShapeElement类都实现的接口,它定义了用于显示图形元素的Symbol属性,这个Symbol属性必须设置为IFillsymbol对象。

                   IMap pMap = axMapControl1.Map;

                    IActiveView pActiveView = pMap as IActiveView;

                    pGeo = axMapControl1.TrackPolygon();

                    ISimpleFillSymbol fillsymbol = new SimpleFillSymbolClass();

                    fillsymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross;

                    fillsymbol.Color = GetRGB(0, 255, 0);

                    IFillShapeElement pFillElement = new PolygonElementClass();

                    pFillElement.Symbol = fillsymbol;

                    IElement pEle = pFillElement as IElement;

                    pEle.Geometry = pGeo;

                    IGraphicsContainer pGraphics = pMap as IGraphicsContainer;

                    pGraphics.AddElement(pEle, 0);

    画出来的图像:

    PictureElement对象

       往PageLayout控件添加任意范围的图片,即用到该对象,一般的话,我们可以向PageLayOut中插入一张位图图片,这种图片其实就是一种图形元素,即PictureElement对象。
        PictureElement是一个抽象类,有两个子类BmpPictureElement和EmfPictureElement,IPictureElement是两个子类都实现的接口,使用它可以用于操作一个图片元素。
        public void ImportPictureFromFile ( string Name);获取一张图片;
        public bool MaintainAspectRatio {get; set;}该属性决定调整图片尺寸时是否保持其长宽比例
      具体实现往PageLayout控件添加图片例子:
          private void axPageLayoutControl1_OnMouseDown(object sender,  ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent e)
            {
                IPageLayout pPageLayout = axPageLayoutControl1.PageLayout;
                IGraphicsContainer pGraphic = pPageLayout as IGraphicsContainer;
                IActiveView pActiveView = pPageLayout as IActiveView;

                IGeometry pGeo = axPageLayoutControl1.TrackRectangle();
                IPictureElement pPictureElement = new BmpPictureElementClass();
                pPictureElement.ImportPictureFromFile(@"f:\TEST\test.bmp");
                pPictureElement.MaintainAspectRatio = true;
                IElement pEle = pPictureElement as IElement;
                pEle.Geometry = pGeo;

                pGraphic.AddElement(pEle, 0);
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null,null);

            }
    结果:
          

    转自:昵称:师士

     

  • 相关阅读:
    获取aspx页面执行时间完全解决方案
    WebForm中DataGrid的20篇经典文章
    不走寻常路 设计ASP.NET应用程序的七大绝招
    动态绑定dropdownlist 开始拣.NET
    Notes中几个处理多值域的通用函数
    Lotus开发之Lotus Notes中域的验证
    Undokumentierte @Formeln/LotusScript im Lotus Notes Client/Server
    domino server端的Notes.ini详解
    Lotus开发基本性能优化
    以Ajax方式显示Lotus Notes视图的javasript类库NotesView2
  • 原文地址:https://www.cnblogs.com/henyihanwobushi/p/2639888.html
Copyright © 2011-2022 走看看