Arcgis Engine(ae)接口详解(8):临时元素(element)

                //主地图的地图(map)对象
                IMap map = null;
                IActiveView activeView = null;

                //IGraphicsContainer用于操作临时元素,可以通过map获取
                IGraphicsContainer gc = map as IGraphicsContainer;

                //删除所有临时元素
                gc.DeleteAllElements();
                activeView.Refresh();

                //画点的临时元素~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                IPoint point = new PointClass();
                point.PutCoords(100, 200);

                //首先定义点元素的样式
                //ISimpleMarkerSymbol意思是ISimple(简单的)Marker(点)Symbol(样式),MarkerSymbol处理simple的还有其他很多种,具体看IMarkerSymbol的实现类
                ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
                //点颜色
                simpleMarkerSymbol.Color = SymbolHelper.CreateColorByRgb(255, 0, 0);
                //点大小
                simpleMarkerSymbol.Size = 5;
                //IMarkerElement代表点元素, new MarkerElementClass()是实例化点元素
                IMarkerElement markerElement = new MarkerElementClass();
                //设置点样式
                markerElement.Symbol = simpleMarkerSymbol;

                //IElement是所有元素(element)的顶层接口
                IElement element = markerElement as IElement;
                //设置元素几何对象,因为是画点所以赋值一个点
                //通过观察之后的添加线和面元素可发现,几何对象赋值都在IElement接口,而样式(symbol)赋值都在各种类型元素的接口
                element.Geometry = point;

                //添加元素到地图,最后刷新,完成添加
                gc.AddElement(element, 0);
                activeView.Refresh();


                //画线的临时元素~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                //线的生成不是重点,这里就随便了
                IPolyline polyline = null;

                //定义线样式
                //ISimpleLineSymbol意思是ISimple(简单的)Line(线)Symbol(样式)
                ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
                //颜色
                simpleLineSymbol.Color = SymbolHelper.CreateColorByRgb(255, 0, 0);
                //线宽
                simpleLineSymbol.Width = 2;
                //ILineElement代表线元素, new LineElementClass()是实例化线元素
                ILineElement lineElement = new LineElementClass();
                //赋值线样式
                lineElement.Symbol = simpleLineSymbol;
                //IElement是所有元素(element)的顶层接口
                element = lineElement as IElement;
                //设置元素几何对象,因为是画线所以赋值一个线        
                element.Geometry = polyline;

                //添加元素到地图,最后刷新,完成添加
                gc.AddElement(element, 0);
                activeView.Refresh();


                //画面暂时略

                //以上是画临时元素的详细代码解析,在实际使用中,一般可以使用封装好的方法一行代码解决

                //画点
                DrawElementHelper.DrawPoint(map, point, 255, 0, 0, 3);

                //画线
                DrawElementHelper.DrawLine(map, polyline, 255, 0, 0, 3);

                //以上方法没有刷新,需另外调用刷新
                //PS:因此如果同时画多个元素,每次画都刷新会很卡
                activeView.Refresh();
原文地址:https://www.cnblogs.com/cannel/p/11074343.html