如何实现临时的图形要素现实
一需求说明:
需要将处理结果进行显示出来,给自己或者用户看,而不需要存储下来。
二实现思路:
1.实例化Element ,之后将Element放到IGraphicsContainer中,再使用IActiveView刷新出来;
或者
2.实例化Element ,将Element放到IElementCollection中,再使用IGraphicsContainer和IActiveView加载刷新显示出来。
此处需要注意的是:如果需要将Line对象放进来之后进行临时显示的话,需要先将LINE转为Polyline之后再放进来,不然会提示“值不在范围内”。
- ISegmentCollection gc = new PolylineClass();
- gc.AddSegment(line as ISegment);
- IPolyline polyline = gc as IPolyline;
三代码参考:
//生成Element对象,存放到ElementCollection中
public IElementCollectionGeoColl = new ElementCollection();
ITextElement pele1 = new TextElementClass();
pele1.Text = "。";
pele1.ScaleText = true;
IPoint pTempPoint4 = newPointClass();
pTempPoint4.PutCoords(xLoc1, yLoc1);
IElement pElement1 = pele1 as IElement;
pElement1.Geometry =pTempPoint4;
GeoColl.Add(pElement1);
//将ElementCollection通过IGraphicsContainer和IActiveView加载刷新显示出来
IActiveView pActiveView =axMapControl1.Map as IActiveView;
IGraphicsContainerpGraphicsContainer = axMapControl1.Map as IGraphicsContainer;
pGraphicsContainer.AddElements(LocFactory.GeoColl, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);