//红色线 public static void ViewPolylines(IMapControl4 pMapControl, List <CPolyline> cpllt) { //设置线段属性 ILineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 1; pSimpleLineSymbol.Color = CHelpFunc.GenerateIRgbColor(255, 0, 0) as IColor; //生成线段 IElementCollection pEleCol = new ElementCollectionClass(); for (int i = 0; i < cpllt.Count; i++) { ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pSimpleLineSymbol; IElement pElement = pLineElement as IElement; pElement.Geometry = cpllt[i].pPolyline; pEleCol.Add(pElement, 0); } //显示线段 IGraphicsContainer pGra = pMapControl.Map as IGraphicsContainer; IActiveView pAv = pGra as IActiveView; pGra.AddElements(pEleCol, 5); pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
///<summary> ///添加临时元素到地图窗口上 ///</summary> ///<param name="pMapCtrl">地图控件</param> ///<param name="pEle">单个元素</param> ///<param name="pEleColl">元素集合</param> public void AddTempElement(AxMapControl pMapCtrl, IElement pEle, IElementCollection pEleColl) { try { IMap pMap = pMapCtrl.Map; IGraphicsContainer pGCs = pMap as IGraphicsContainer; if (pEle != null) { pGCs.AddElement(pEle, 0); } if (pEleColl != null) { if (pEleColl.Count > 0) { pGCs.AddElements(pEleColl, 0); } } IActiveView pAV = (IActiveView)pMap; //需要刷新才能即时显示 pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pAV.Extent); } catch (Exception Err) { MessageBox.Show(Err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void LabelQueryInfo(string name, string strContent, IPoint pt, IMap pMap, bool isRemoveLast) { //获取并激活Graphic标注图层 if (pt == null) { return; } IActiveView pActiveView = pMap as IActiveView; ICompositeGraphicsLayer pCompositeGraphicsLayer = pMap.BasicGraphicsLayer as ICompositeGraphicsLayer; //WeatherLabel标记组,通过ArcMap的Layers Properties的Annotation group可以看到 IGraphicsLayer pGraphicsLayer = pCompositeGraphicsLayer.FindLayer("WeatherLabel"); pMap.ActiveGraphicsLayer = pGraphicsLayer as ILayer; pGraphicsLayer.Activate(pActiveView.ScreenDisplay); IGraphicsContainer pGraphicsContainer = pGraphicsLayer as IGraphicsContainer;//转换到图形容器接口 IElementCollection pElementCollection = new ElementCollectionClass(); AddBalloonCalloutLabel(name, strContent, pt, pElementCollection);//我们需要一个新的私有函数来实现设置标签元素背景,BalloonCallout对象 //添加标注 if (isRemoveLast == true) { pGraphicsContainer.DeleteAllElements(); } pGraphicsContainer.AddElements(pElementCollection, 1000); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds); }