• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ArcEngine创建IElement简单例子C#代码

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

代码下载地址:https://files.cnblogs.com/ogis/MapControlApplication2.rar

以下几个函数功能主要是向地图中添加IElement,一共四个函数:

GetColor,CreateSimpleLineSymbol,CreateSimpleFillSymbol,AddCreateElement

功能函数:AddCreateElement

调用例子:

ISymbol pSymbol = AEUtil.CreateSimpleFillSymbol(Color.Red, 100, esriSimpleFillStyle.esriSFSCross);
AEUtil.AddCreateElement(pFeature.ShapeCopy,   m_MapControl.ActiveView, pSymbol, fucosKey);
      

通过red green blue 三色创建IRgbColor 

 public static IRgbColor GetColor(int r, int g, int b)
        {
            RgbColor color = new RgbColor();
            color.Red = r;
            color.Green = g;
            color.Blue = b;
            return color;
        }

 

创建简单线Symbol  输入参数 color-颜色,width-宽度,style-线型,有七种线型可选

  esriSLSSolid 
  esriSLSDash 
  esriSLSDot
  esriSLSDashDot
  esriSLSDashDotDot 
  esriSLSNull 
  esriSLSInsideFrame

 

        public static ISymbol CreateSimpleLineSymbol(Color color, int width, esriSimpleLineStyle style)
        {
            ISimpleLineSymbol pSimpleLineSymbol;
            pSimpleLineSymbol = new SimpleLineSymbol();
            pSimpleLineSymbol.Width = width;
            pSimpleLineSymbol.Color = GetColor(color.R, color.G, color.B);
            pSimpleLineSymbol.Style = style;
            return (ISymbol)pSimpleLineSymbol;

        }

创建面填充ISymbol对象.   fillColor-颜色,oLineWidth-外廓线宽,fillStyle-填充类型,有以下可选

  esriSFSSolid
  esriSFSNull 
  esriSFSHollow
  esriSFSHorizontal
  esriSFSVertical
  esriSFSForwardDiagonal
  esriSFSBackwardDiagonal
  esriSFSCross
  esriSFSDiagonalCross

 

 


        public static ISymbol CreateSimpleFillSymbol(Color fillColor, int oLineWidth, esriSimpleFillStyle fillStyle)
        {
            ISimpleFillSymbol pSimpleFillSymbol;
            pSimpleFillSymbol = new SimpleFillSymbol();
            pSimpleFillSymbol.Style = fillStyle;
            pSimpleFillSymbol.Color = GetColor(fillColor.R, fillColor.G, fillColor.B);
            pSimpleFillSymbol.Outline = (ILineSymbol)CreateSimpleLineSymbol(fillColor, 1, esriSimpleLineStyle.esriSLSDash);
            return (ISymbol)pSimpleFillSymbol;

        }

 

  函数实现向地图中添加元素,pGeometry-元素形状,pActiveView-地图视图,pSymbol-符号,key-元素属性

        public static IElement AddCreateElement(IGeometry pGeometry, IActiveView pActiveView, ISymbol pSymbol, string key)
        {
            try
            {
                IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;
                IElement pElement = null;
                ILineElement pLineElement = null;
                IFillShapeElement pFillShapeElement = null;
                IMarkerElement pMarkerElement = null;
                ICircleElement pCircleElement = null;
                IElementProperties pElmentProperties = null;
                switch (pGeometry.GeometryType)
                {

                    case esriGeometryType.esriGeometryEnvelope:
                        {
                            pElement = new RectangleElement();
                            pElement.Geometry = pGeometry;
                            pFillShapeElement = (IFillShapeElement)pElement;
                            pFillShapeElement.Symbol = (IFillSymbol)pSymbol;
                            break;
                        }
                    case esriGeometryType.esriGeometryPolyline:
                        {
                            pElement = new LineElement();
                            pElement.Geometry = pGeometry;

                            pLineElement = (ILineElement)pElement;
                            pLineElement.Symbol = (ILineSymbol)pSymbol;
                            break;
                        }
                    case esriGeometryType.esriGeometryLine:
                        {
                            pElement = new LineElement();
                            pElement.Geometry = pGeometry;

                            pLineElement = (ILineElement)pElement;
                            pLineElement.Symbol = (ILineSymbol)pSymbol;
                            break;
                        }
                    case esriGeometryType.esriGeometryPolygon:
                        {
                            pElement = new PolygonElement();
                            pElement.Geometry = pGeometry;
                            pFillShapeElement = (IFillShapeElement)pElement;

                            pFillShapeElement.Symbol = (IFillSymbol)pSymbol;
                            break;
                        }
                    case esriGeometryType.esriGeometryMultipoint:
                    case esriGeometryType.esriGeometryPoint:
                        {
                            pElement = new MarkerElement();
                            pElement.Geometry = pGeometry;

                            pMarkerElement = (IMarkerElement)pElement;

                            pMarkerElement.Symbol = (IMarkerSymbol)pSymbol;
                            break;
                        }
                    case esriGeometryType.esriGeometryCircularArc:
                        {
                            pElement = new CircleElementClass();
                            pElement.Geometry = pGeometry;

                            pCircleElement = (ICircleElement)pElement;
                            break;
                        }
                    default:
                        pElement = null;
                        break;
                }

                if (pElement != null)
                {
                    pElmentProperties = pElement as IElementProperties;
                    pElmentProperties.Name = key;

                    pGraphicsContainer.AddElement(pElement, 0);
                    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, pGeometry.Envelope);
                    return pElement;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#主窗体更新子窗体进程间通信发布时间:2022-07-10
下一篇:
C#数字转换成百分比数发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap