public void AddCreateElement(IGeometry pCircularArc, IActiveView pAV) { IFillShapeElement pElemFillShp; IElement pElem; ISimpleFillSymbol pSFSym; ISegmentCollection pSegColl = new PolygonClass(); object missing = Type.Missing; ISegment segement = (ISegment)pCircularArc; pSegColl.AddSegment(segement, missing, missing); pElem = new CircleElementClass(); pElem.Geometry = (IGeometry)pSegColl; pElemFillShp = (IFillShapeElement)pElem; pSFSym = new SimpleFillSymbolClass(); Color color = ColorTranslator.FromHtml(SystemInfo.Instance.FillColor); IColor pColor = new RgbColorClass(); pColor.RGB = color.B * 65536 + color.G * 256 + color.R; pSFSym.Color = pColor; pSFSym.Style = esriSimpleFillStyle.esriSFSSolid; pElemFillShp.Symbol = pSFSym; pGraphicsContainer = pAV as IGraphicsContainer; pGraphicsContainer.AddElement(pElem, 0); }
/// <summary> /// 构造函数 /// </summary> /// <param name="_mapControl">地图控件</param> /// <param name="element">图元</param> public EditCircle(AxMapControl _mapControl, IMFElement element) { mapControl = _mapControl; markerList = new List <EditMarker>(); circleElement = element as CircleElementClass; circleArcMap = circleElement as Circle_ArcMap; }
private void AddCircleElement(IGeometry pGeo, IActiveView pAv) { ISegmentCollection pSegColl; pSegColl = new PolygonClass(); object Missing1 = Type.Missing; object Missing2 = Type.Missing; pSegColl.AddSegment(pGeo as ISegment, ref Missing1, ref Missing2); ISimpleLineSymbol pLineSym; pLineSym = new SimpleLineSymbolClass(); pLineSym.Color = getRGB(110, 22, 125); pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; ISimpleFillSymbol pSimpleFillSym; pSimpleFillSym = new SimpleFillSymbolClass(); pSimpleFillSym.Color = getRGB(66, 55, 145); pSimpleFillSym.Outline = pLineSym; pSimpleFillSym.Style = esriSimpleFillStyle.esriSFSCross; IElement pPolygonEle; pPolygonEle = new CircleElementClass(); pPolygonEle.Geometry = pSegColl as IGeometry; IFillShapeElement pFillEle; pFillEle = pPolygonEle as IFillShapeElement; pFillEle.Symbol = pSimpleFillSym; IGraphicsContainer pGraphicsContainer; pGraphicsContainer = pAv as IGraphicsContainer; pGraphicsContainer.AddElement(pFillEle as IElement, 0); pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void AddCircleElement(IGeometry pCircularArc, IActiveView pAV) { IFillShapeElement pElemFillShp; IElement pElem; ISimpleFillSymbol pSFSym; IGraphicsContainer pGraphicsContainer; pElem = new CircleElementClass(); pElem.Geometry = (IGeometry)pCircularArc; pElemFillShp = (IFillShapeElement)pElem; pSFSym = new SimpleFillSymbolClass(); Color color = ColorTranslator.FromHtml(SystemInfo.Instance.FillColor); IColor pColor = new RgbColorClass(); pColor.RGB = color.B * 65536 + color.G * 256 + color.R; pSFSym.Color = pColor; pSFSym.Style = esriSimpleFillStyle.esriSFSDiagonalCross; ISimpleLineSymbol pSLSym = new SimpleLineSymbol(); pSLSym.Style = esriSimpleLineStyle.esriSLSSolid; pSLSym.Width = 1; pSLSym.Color = pColor; pSFSym.Outline = pSLSym; pElemFillShp.Symbol = pSFSym; pGraphicsContainer = pAV as IGraphicsContainer; pGraphicsContainer.AddElement(pElem, 0); }
/// <summary> /// 在图形容器中创建圆形元素 /// </summary> /// <param name="graphicsContainer">图形容器,新建的元素将添加到该图形容器中</param> /// <param name="circle">圆形,用于创建圆形元素</param> /// <returns></returns> public static IFillShapeElement CreateCircleElement(this IGraphicsContainer graphicsContainer, IGeometry circle) { IFillShapeElement circleElement = new CircleElementClass(); IElement element = (IElement)circleElement; element.Geometry = circle; graphicsContainer.AddElement(element, 0); return(circleElement); }
/// <summary> /// 创建图形元素 /// </summary> /// <param name="pGeometry">几何图形</param> /// <param name="lineColor">边框颜色</param> /// <param name="fillColor">填充颜色</param> /// <returns></returns> private static IElement CreateElement(IGeometry pGeometry, IRgbColor lineColor, IRgbColor fillColor) { if (pGeometry == null || lineColor == null || fillColor == null) { return(null); } IElement pElem = null; try { if (pGeometry is IEnvelope) { pElem = new RectangleElementClass(); } else if (pGeometry is IPolygon) { pElem = new PolygonElementClass(); } else if (pGeometry is ICircularArc) { ISegment pSegCircle = pGeometry as ISegment;//QI ISegmentCollection pSegColl = new PolygonClass(); object o = Type.Missing; pSegColl.AddSegment(pSegCircle, ref o, ref o); IPolygon pPolygon = pSegColl as IPolygon; pGeometry = pPolygon as IGeometry; pElem = new CircleElementClass(); } else if (pGeometry is IPolyline) { pElem = new LineElementClass(); } if (pElem == null) { return(null); } pElem.Geometry = pGeometry; IFillShapeElement pFElem = pElem as IFillShapeElement; ISimpleFillSymbol pSymbol = new SimpleFillSymbolClass(); pSymbol.Color = fillColor; pSymbol.Outline.Color = lineColor; pSymbol.Style = esriSimpleFillStyle.esriSFSCross; if (pSymbol == null) { return(null); } pFElem.Symbol = pSymbol; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(pElem); }
/// <summary> /// 创建图形元素 /// </summary> /// <param name="geometry">几何图形</param> /// <param name="lineColor">边界颜色</param> /// <param name="fillColor">填充颜色</param> /// <returns>图形元素</returns> public static IElement CreateElement(IGeometry geometry, IRgbColor lineColor, IRgbColor fillColor) { if (geometry == null || lineColor == null || fillColor == null) { return(null); } IElement element = null; // 判断图形的类型 if (geometry is IEnvelope) { element = new RectangleElementClass(); } else if (geometry is IPolygon) { element = new PolygonElementClass(); } else if (geometry is ICircularArc) { ISegment segment = geometry as ISegment; ISegmentCollection segmentCollection = new PolygonClass(); segmentCollection.AddSegment(segment, Type.Missing, Type.Missing); IPolygon polygon = segmentCollection as IPolygon; geometry = polygon as IGeometry; element = new CircleElementClass(); } else if (geometry is IPolyline) { element = new LineElementClass(); } if (element == null) { return(null); } element.Geometry = geometry; ISimpleFillSymbol symbol = new SimpleFillSymbolClass(); symbol.Outline.Color = lineColor; symbol.Color = fillColor; symbol.Style = esriSimpleFillStyle.esriSFSCross; if (symbol == null) { return(null); } IFillShapeElement fillShapeElement = element as IFillShapeElement; fillShapeElement.Symbol = symbol; return(element); }
/// <summary> /// 释放资源 /// </summary> public void Dispose() { circleElement = null; CommondExecutedEvent = null; layer = null; currentMarker = null; currentPoint = null; circleArcMap = null; markerList = null; centerMarker = null; mapControl = null; mapLogic = null; }
private void AddCircleElement() { IGeometry pGeometry = axMapControl1.TrackCircle(); if (pGeometry == null) { return; } ICircleElement pCircleElement = new CircleElementClass(); IElement pElement = pCircleElement as IElement; pElement.Geometry = pGeometry; AddElement(pElement); }
/// <summary> /// 移除图元 /// </summary> /// <param name="element">要移除的圆图元</param> /// <param name="layer">图元的所在图层</param> /// <returns></returns> public bool RemoveElement(Core.Interface.IMFElement element, ILayer layer) { if (element == null) { return(true); } CompositeGraphicsLayerClass graphicLayer = layer as CompositeGraphicsLayerClass; if (graphicLayer == null) { return(true); } CircleElementClass circleElement = element as CircleElementClass; graphicLayer.DeleteElement(circleElement); return(true); }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { IPoint point = this.m_mapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IGeometry geometry = null; IElement element = null; switch (this.DrawType) { case EnumDrawType.circle: if (this.m_circleFeedback != null) { ICircularArc circularArc = this.m_circleFeedback.Stop(); this.m_circleFeedback = null; if (circularArc == null || circularArc.IsPoint) { return; } geometry = MapAPI.ConvertCircularArcToPolygon(circularArc); element = new CircleElementClass(); } break; case EnumDrawType.square: if (this.m_rectangleFeedback != null) { geometry = this.m_rectangleFeedback.Stop(point); if ((geometry as IPointCollection).PointCount == 2) { this.m_rectangleFeedback = null; return; } this.m_rectangleFeedback = null; element = new PolygonElementClass(); } break; } if (geometry != null) { element.Geometry = geometry; this.AppendNodeToTreeList(element); } }
private int AddCepGraphic(IPoint point, IList <double> circleRadii) { //Create a new center point graphic IMarkerSymbol symbol = new SimpleMarkerSymbolClass(); symbol.Color = EsriColor(Defaults.CepCenterPointColor); symbol.Size = Defaults.CepCenterPointSize; IElement centerPoint = new MarkerElementClass(); ((IMarkerElement)centerPoint).Symbol = symbol; centerPoint.Geometry = point; //Create a graphic group and add the center point graphic IGroupElement group = new GroupElementClass(); group.AddElement(centerPoint); //Add the circles to the group for (int i = 0; i < circleRadii.Count; i++) { IConstructCircularArc arc = new CircularArcClass(); arc.ConstructCircle(point, circleRadii[i], false); IGeometry polygon = new PolygonClass(); ((ISegmentCollection)polygon).AddSegment((ISegment)arc); IElement circle = new CircleElementClass(); circle.Geometry = polygon; Color circleColor = Defaults.CepCircleOutlineColors.Length > i ? Defaults.CepCircleOutlineColors[i] : Defaults.CepCircleOutlineColors[Defaults.CepCircleOutlineColors.Length - 1]; double circleWidth = Defaults.CepCircleOutlineWidths.Length > i ? Defaults.CepCircleOutlineWidths[i] : Defaults.CepCircleOutlineWidths[Defaults.CepCircleOutlineWidths.Length - 1]; ((IFillShapeElement)circle).Symbol = GetCircleSymbol(circleColor, circleWidth); group.AddElement(circle); } //Give it the group an id number and add it to the graphics layer _elementId++; ((IElementProperties)group).CustomProperty = _elementId; ((IGraphicsContainer)GraphicsLayer).AddElement((IElement)group, 0); return(_elementId); }
private void drawCircle_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { this.type = 3; ICircleElement circleEle = new CircleElementClass(); pElement = circleEle as IElement; SimpleFillSymbol simpleFill = new SimpleFillSymbolClass(); simpleFill.Style = esriSimpleFillStyle.esriSFSNull; simpleFill.Color = GisClass.GetRgbColor(255, 0, 0); //设置边线颜色 ILineSymbol lineSymbol = new SimpleLineSymbol(); lineSymbol.Color = GisClass.GetRgbColor(255, 0, 0); IFillShapeElement shapeEle = pElement as IFillShapeElement; simpleFill.Outline = lineSymbol; shapeEle.Symbol = simpleFill; pGraphicsContainer.AddElement(pElement, 0); }
private IElement DrawCircle(double radius, double x, double y) { IPoint centralPoint = new PointClass(); centralPoint.PutCoords(x, y); // 创建园 ICircularArc circularArc = new CircularArcClass(); IConstructCircularArc construtionCircularArc = circularArc as IConstructCircularArc; construtionCircularArc.ConstructCircle(centralPoint, radius, true); ISegment pSegment1 = circularArc as ISegment; //通过ISegmentCollection构建Ring对象 ISegmentCollection pSegCollection = new RingClass(); object o = Type.Missing; //添加Segement对象即圆 pSegCollection.AddSegment(pSegment1, ref o, ref o); //QI到IRing接口封闭Ring对象,使其有效 IRing pRing = pSegCollection as IRing; pRing.Close(); //通过Ring对象使用IGeometryCollection构建Polygon对象 IGeometryCollection pGeometryColl = new PolygonClass(); pGeometryColl.AddGeometry(pRing, ref o, ref o); //构建一个CircleElement对象 IElement pElement = new CircleElementClass(); pElement.Geometry = pGeometryColl as IGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass(); //pFillSymbol.Color = pCircleColor; ILineSymbol pLineSymbol = new SimpleLineSymbolClass(); // pLineSymbol.Color = DefineColor(0, 255, 0); pFillSymbol.Outline = pLineSymbol; pFillShapeElement.Symbol = pFillSymbol; IFillShapeElement circleElement = pElement as IFillShapeElement; circleElement.Symbol = pFillSymbol; IGraphicsContainer pGC = this.axMapControl.ActiveView.GraphicsContainer; pGC.AddElement(pElement, 0); axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); return pElement; }
/// <summary> /// 把Geometry弄成一个element,添加到地图上 /// </summary> /// <param name="pGeometry"></param> private void AddElement(IGeometry pGeometry) { try { IElement pElement = null; ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 2; pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline = pSimpleLineSymbol; if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolyline)//多义线 { ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pSimpleLineSymbol; pElement = pLineElement as IElement; pElement.Geometry = pGeometry; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryCircularArc)//圆 { ISegmentCollection pSegmentCollection; pSegmentCollection = new PolygonClass(); object Missing = Type.Missing;//注意 pSegmentCollection.AddSegment(pGeometry as ISegment, ref Missing, ref Missing);//后两个参数必须是这样,帮助说的,为什么?? pElement = new CircleElementClass(); pElement.Geometry = pSegmentCollection as IGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryEnvelope)//矩形 { pElement = new RectangleElementClass(); pElement.Geometry = pGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolygon)//多边形 { pElement = new PolygonElementClass(); pElement.Geometry = pGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryBezier3Curve)//Bezier曲线 { pElement = new LineElementClass(); pElement.Geometry = pGeometry; ILineElement pLineElement = pElement as ILineElement; pLineElement.Symbol = pSimpleLineSymbol; } this.pGraphicContainer.AddElement(pElement, 0); this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 把Geometry弄成一个element,添加到地图上 /// </summary> /// <param name="pGeometry"></param> private void AddElement(IGeometry pGeometry) { try { IElement pElement = null; ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 2; pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline = pSimpleLineSymbol; if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolyline)//多义线 { ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pSimpleLineSymbol; pElement = pLineElement as IElement; pElement.Geometry = pGeometry; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryCircularArc)//圆 { ISegmentCollection pSegmentCollection; pSegmentCollection = new PolygonClass(); object Missing = Type.Missing; //注意 pSegmentCollection.AddSegment(pGeometry as ISegment, ref Missing, ref Missing); //后两个参数必须是这样,帮助说的,为什么?? pElement = new CircleElementClass(); pElement.Geometry = pSegmentCollection as IGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryEnvelope)//矩形 { pElement = new RectangleElementClass(); pElement.Geometry = pGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolygon)//多边形 { pElement = new PolygonElementClass(); pElement.Geometry = pGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryBezier3Curve)//Bezier曲线 { pElement = new LineElementClass(); pElement.Geometry = pGeometry; ILineElement pLineElement = pElement as ILineElement; pLineElement.Symbol = pSimpleLineSymbol; } this.pGraphicContainer.AddElement(pElement, 0); this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } }