コード例 #1
0
        /// <summary>
        /// 绘制对象 张琪  20110628
        /// </summary>
        /// <param name="pGeometry">对象</param>
        /// <param name="pColor">颜色</param>
        /// <param name="lSize">绘制的大小</param>
        /// <param name="sName">名称</param>
        /// <param name="pScene"></param>
        /// <param name="pGroup"></param>
        public static void AddSimpleGraphic(IGeometry pGeometry, IRgbColor pColor, int lSize, string sName, IMap pMap, IGroupElement pGroup)
        {
            if (pGeometry == null)
            {
                return;
            }
            IElement pElement = null;

            //ISymbol pSym;
            //根据绘制的对象类型对IElement进行不同的定义
            switch (pGeometry.GeometryType.ToString())
            {
            case "esriGeometryPoint":
                pElement = new MarkerElementClass();
                IMarkerElement      pPointElement = pElement as IMarkerElement;
                ISimpleMarkerSymbol pMSym         = new SimpleMarkerSymbolClass();
                pMSym.Color = pColor;
                pMSym.Size  = lSize;
                pMSym.Style = esriSimpleMarkerStyle.esriSMSCircle;
                IMarkerSymbol pMarkerSymbol = pMSym as IMarkerSymbol;
                pPointElement.Symbol = pMarkerSymbol;
                break;

            case "esriGeometryPolyline":
                pElement = new LineElementClass();
                ILineElement      pLineElement = pElement as ILineElement;
                ISimpleLineSymbol pLSym        = new SimpleLineSymbolClass();
                pLSym.Width = lSize;
                pLSym.Style = esriSimpleLineStyle.esriSLSSolid;
                pLSym.Color = pColor;
                ILineSymbol pLineSymbol = pLSym as ILineSymbol;
                pLineElement.Symbol = pLineSymbol;
                break;

            case "esriGeometryPolygon":
                ISimpleLineSymbol pOutlineSym = new SimpleLineSymbolClass();
                pOutlineSym.Color = pColor;
                pOutlineSym.Width = lSize;
                pOutlineSym.Style = esriSimpleLineStyle.esriSLSSolid;
                if (sName == "_ReferancePlane_")
                {
                    pColor.Transparency = Convert.ToByte(Convert.ToInt32(255 / 2));
                }
                pElement = new PolygonElementClass();
                IFillShapeElement pPolygonElement = pElement as IFillShapeElement;
                IFillSymbol       pFSym           = new SimpleFillSymbolClass();
                pFSym.Color = pColor;
                ILineSymbol pLineSymbol1 = pOutlineSym as ILineSymbol;
                pFSym.Outline          = pLineSymbol1;
                pPolygonElement.Symbol = pFSym;
                break;

            default:
                break;
            }
            pElement.Geometry = pGeometry;
            IElementProperties pElemProps = pElement as IElementProperties;

            pElemProps.Name = sName;
            if (pGroup == null)
            {
                IGraphicsContainer pGCon = pMap.BasicGraphicsLayer as IGraphicsContainer;
                pGCon.AddElement(pElement, 0);
            }
            else
            {
                pGroup.AddElement(pElement);
            }
        }
コード例 #2
0
ファイル: MeasureArea.cs プロジェクト: zhongshuiyuan/gews
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (Button == 2)
            {
                return;
            }
            IPoint pt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

            pt = GIS.GraphicEdit.SnapSetting.getSnapPoint(pt);
            IGraphicsContainer graphicContainer = m_hookHelper.ActiveView.GraphicsContainer;
            IEnvelope          pEnvBounds       = null;

            //获取上一次轨迹线的范围,以便确定刷新范围
            try
            {
                if (m_TracePolygon != null)
                {
                    m_TracePolygon.QueryEnvelope(pEnvBounds);
                    pEnvBounds.Expand(4, 4, true); //矩形框向四周扩大4倍(大于2倍就行),目的是为了保证有充足的刷新区域
                }
                else
                {
                    pEnvBounds = m_hookHelper.ActiveView.Extent;
                }
            }
            catch
            {
                pEnvBounds = m_hookHelper.ActiveView.Extent;
            }

            #region 启动画面
            if (m_NewPolygonFeedback == null)
            {
                //移除element
                RemoveElements();
                //刷新
                m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                Application.DoEvents();

                m_NewPolygonFeedback = new NewPolygonFeedbackClass();

                //必须先得到symbol,后设置symbol
                ISimpleLineSymbol simpleLineSymbol = m_NewPolygonFeedback.Symbol as ISimpleLineSymbol;
                simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                simpleLineSymbol.Width = 2;
                simpleLineSymbol.Color = TransColorToAEColor(Color.Blue);

                m_simpleFillSymbol.Outline = simpleLineSymbol;

                m_NewPolygonFeedback.Display = m_hookHelper.ActiveView.ScreenDisplay;
                m_NewPolygonFeedback.Start(pt);
            }
            else
            {
                m_NewPolygonFeedback.AddPoint(pt);
            }


            if (m_ptCollection == null)
            {
                m_ptCollection = new PolylineClass();
            }
            //记录节点
            object obj = Type.Missing;
            m_ptCollection.AddPoint(pt, ref obj, ref obj);

            #endregion

            #region 绘制结点

            try
            {
                IElement vertexElement = createElement_x(pt);
                //
                graphicContainer = m_hookHelper.ActiveView as IGraphicsContainer;

                //g.AddElement(vertexElement, 0);
                //g.MoveElementToGroup(vertexElement, m_VertexElement);

                m_VertexElement.AddElement(vertexElement);
                //刷新
                m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, vertexElement, pEnvBounds);
            }
            catch
            { }
            #endregion

            try
            {
                if (m_ptCollection.PointCount >= 2)
                {
                    IPoint fromPt = m_ptCollection.get_Point(m_ptCollection.PointCount - 2); //倒数第二个点
                    IPoint toPt   = m_ptCollection.get_Point(m_ptCollection.PointCount - 1); //最后第一个点
                    ILine  line   = new LineClass();
                    line.PutCoords(fromPt, toPt);

                    #region 绘制轨迹线

                    try
                    {
                        object             missing = Type.Missing;
                        ISegmentCollection segColl = new PolylineClass();
                        segColl.AddSegment(line as ISegment, ref missing, ref missing);

                        IPolyline polyline = new PolylineClass();
                        polyline = segColl as IPolyline;
                        IElement traceElement = createElement_x(polyline);

                        //graphicContainer = m_hookHelper.ActiveView as IGraphicsContainer;
                        m_TraceElement.AddElement(traceElement);

                        m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, traceElement, pEnvBounds);
                    }
                    catch
                    { }
                    #endregion

                    #region 计算单线的长度,并将结果显示在单线中点偏上上面
                    //try
                    //{
                    //    double angle = line.Angle;
                    //    if ((angle > (Math.PI / 2) && angle < (Math.PI)) || (angle > -Math.PI && angle < -(Math.PI / 2))) // 大于90度小于等于180
                    //        angle += Math.PI;

                    //    //标注点Y值偏移量
                    //    double d_OffsetY = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromPoints(9);

                    //    //标注点
                    //    double d_CenterX = (fromPt.X + toPt.X) / 2;
                    //    double d_CenterY = (fromPt.Y + toPt.Y) / 2 + d_OffsetY; //向上偏移

                    //    IPoint labelPt = new PointClass();
                    //    labelPt.PutCoords(d_CenterX, d_CenterY);

                    //    ITextElement txtElement = CreateTextElement(line.Length.ToString("0.00"));

                    //    IElement labelelement = txtElement as IElement;
                    //    labelelement.Geometry = labelPt;
                    //    object oElement = (object)labelelement;

                    //    //根据角度旋转
                    //    TransformByRotate(ref oElement, labelPt, angle);

                    //    ////添加到GraphicsContainer
                    //    //g.AddElement(labelelement, 0);

                    //    ////移到m_LabelElement组中
                    //    //g.MoveElementToGroup(labelelement, m_LabelElement);

                    //    //添加到组
                    //    m_LabelElement.AddElement(labelelement);

                    //    //刷新
                    //    m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, labelelement, pEnvBounds);
                    //}
                    //catch
                    //{ }
                    #endregion
                }
            }
            catch
            { }

            m_frmMeasureResult.PolygonResultChange();
        }
コード例 #3
0
ファイル: Utils3D.cs プロジェクト: secondii/Yutai
        public static IElement AddSimpleGraphic(IGeometry igeometry_0, IRgbColor irgbColor_0, int int_0, string string_0, object object_0)
        {
            IElement element = null;
            IElement result;

            if (igeometry_0.IsEmpty)
            {
                result = null;
            }
            else
            {
                esriGeometryType geometryType = igeometry_0.GeometryType;
                IElement         element2;
                switch (geometryType)
                {
                case esriGeometryType.esriGeometryPoint:
                {
                    element2 = new MarkerElement();
                    IMarkerElement markerElement = element2 as IMarkerElement;
                    markerElement.Symbol = new SimpleMarkerSymbol
                    {
                        Color = irgbColor_0,
                        Size  = (double)int_0,
                        Style = esriSimpleMarkerStyle.esriSMSCircle
                    };
                    goto IL_132;
                }

                case esriGeometryType.esriGeometryMultipoint:
                    break;

                case esriGeometryType.esriGeometryPolyline:
                {
                    element2 = new LineElement();
                    ILineElement lineElement = element2 as ILineElement;
                    lineElement.Symbol = new SimpleLineSymbol
                    {
                        Width = (double)int_0,
                        Color = irgbColor_0,
                        Style = esriSimpleLineStyle.esriSLSSolid
                    };
                    goto IL_132;
                }

                case esriGeometryType.esriGeometryPolygon:
                {
                    ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol();
                    simpleLineSymbol.Width = (double)int_0;
                    simpleLineSymbol.Color = irgbColor_0;
                    simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                    element2 = new PolygonElement();
                    IFillShapeElement fillShapeElement = element2 as IFillShapeElement;
                    fillShapeElement.Symbol = new SimpleFillSymbol
                    {
                        Color   = irgbColor_0,
                        Outline = simpleLineSymbol
                    };
                    goto IL_132;
                }

                default:
                    if (geometryType == esriGeometryType.esriGeometryMultiPatch)
                    {
                        element2 = new MultiPatchElement();
                        IFillShapeElement fillShapeElement2 = element2 as IFillShapeElement;
                        IFillSymbol       symbol            = fillShapeElement2.Symbol;
                        symbol.Color             = irgbColor_0;
                        fillShapeElement2.Symbol = symbol;
                        goto IL_132;
                    }
                    break;
                }
                result = element;
                return(result);

IL_132:
                Utils3D.MakeZMAware(igeometry_0, true);
                element2.Geometry = igeometry_0;
                IElementProperties elementProperties = element2 as IElementProperties;
                elementProperties.Name = string_0;
                if (object_0 is IGraphicsContainer3D)
                {
                    IGraphicsContainer3D graphicsContainer3D = object_0 as IGraphicsContainer3D;
                    graphicsContainer3D.AddElement(element2);
                }
                else if (object_0 is IScenePlugin)
                {
                    IGraphicsContainer3D graphicsContainer3D2 = (object_0 as IScenePlugin).Scene.BasicGraphicsLayer as IGraphicsContainer3D;
                    graphicsContainer3D2.AddElement(element2);
                }
                else if (object_0 is IGroupElement)
                {
                    IGroupElement groupElement = object_0 as IGroupElement;
                    groupElement.AddElement(element2);
                }
                result = element2;
            }
            return(result);
        }