예제 #1
0
        /// <summary>
        /// 完成新建对象,取得绘制的对象,并添加到图层中
        /// 建议在Map.DblClick或Map.MouseDown(Button = 2)事件中调用本方法
        /// </summary>
        public void NewFeatureEnd()
        {
            IGeometry        pGeom = null;
            IPointCollection pPointCollection;
            object           obj = Type.Missing;

            try
            {
                if (m_pFeedback is INewMultiPointFeedback)
                {
                    INewMultiPointFeedback pMPFeed = (INewMultiPointFeedback)m_pFeedback;
                    pMPFeed.Stop();
                    pGeom = (IGeometry)m_pPointCollection;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PointClass() as IGeometryCollection;
                    }

                    m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                }
                else if (m_pFeedback is INewLineFeedback)
                {
                    INewLineFeedback pLineFeed = (INewLineFeedback)m_pFeedback;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PolylineClass() as IGeometryCollection;
                    }

                    IPolyline pPolyLine = pLineFeed.Stop();

                    pPointCollection = (IPointCollection)pPolyLine;
                    if (pPointCollection.PointCount < 2)
                    {
                        MessageBox.Show("至少输入两个节点");
                    }
                    else
                    {
                        pGeom = (IGeometry)pPointCollection;
                    }

                    m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                }
                else if (m_pFeedback is INewPolygonFeedback)
                {
                    INewPolygonFeedback pPolyFeed = (INewPolygonFeedback)m_pFeedback;

                    if (m_GeometryCollection == null)
                    {
                        m_GeometryCollection = new PolygonClass() as IGeometryCollection;
                    }

                    IPolygon pPolygon;
                    pPolygon = pPolyFeed.Stop();
                    if (pPolygon != null)
                    {
                        pPointCollection = (IPointCollection)pPolygon;
                        if (pPointCollection.PointCount < 3)
                        {
                            MessageBox.Show("至少输入三个节点");
                        }
                        else
                        {
                            pGeom = (IGeometry)pPointCollection;
                        }

                        m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection);
                    }
                }
                if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    IPolyline pline = MyMapHelp.PolygonToPolyline(m_GeometryCollection as IPolygon);
                    CreateFeature(pline as IGeometry);
                }
                else
                {
                    CreateFeature(m_GeometryCollection as IGeometry);
                }
                m_pFeedback          = null;
                m_bInUse             = false;
                m_GeometryCollection = null;
            }
            catch (Exception e)
            {
                m_pFeedback          = null;
                m_bInUse             = false;
                m_GeometryCollection = null;
                Console.WriteLine(e.Message.ToString());
            }
        }