Пример #1
0
        protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            IMxDocument pMxDoc = ArcMap.Application.Document as IMxDocument;

            IRubberBand pRabber = new RubberPolygon();

            //get polygon from screen
            IPolygon pPolygon = pRabber.TrackNew(pMxDoc.ActiveView.ScreenDisplay, null) as IPolygon;

            //get cordinate from hard coded
            //IPolygon pPolygon ;

            //IPoint pPoint1 = new Point();
            //pPoint1.X = -120.730273;
            //pPoint1.Y = 224.928212;

            //IPoint pPoint2 = new Point();
            //pPoint2.X = -25.280158;
            //pPoint2.Y = 27942068.023;

            //IPoint pPoint3 = new Point();
            //pPoint3.X = -117.895121;
            //pPoint3.Y = 150.269211;



            //IPointCollection pPointCollection = new Polygon();
            //pPointCollection.AddPoint(pPoint1);
            //pPointCollection.AddPoint(pPoint2);
            //pPointCollection.AddPoint(pPoint3);
            //pPointCollection.AddPoint(pPoint1);

            //pPolygon = pPointCollection as IPolygon;


            ////fix when draw wrong draw
            //IArea pArea = pPolygon as IArea;
            //if (pArea.Area < 0)
            //{
            //    pPolygon.ReverseOrientation();
            //}


            IFeatureLayer  pFlayer = pMxDoc.FocusMap.Layer[0] as IFeatureLayer;
            IDataset       pDS     = pFlayer.FeatureClass as IDataset;
            IWorkspaceEdit pWSE    = pDS.Workspace as IWorkspaceEdit;

            pWSE.StartEditing(false);
            pWSE.StartEditOperation();

            IFeature pFeature = pFlayer.FeatureClass.CreateFeature();

            pFeature.Shape = pPolygon;
            pFeature.Store();

            pWSE.StopEditOperation();
            pWSE.StopEditing(true);

            pMxDoc.ActiveView.Refresh();
        }
Пример #2
0
        public void createDrawPolygon()
        {
            // 创建图形
            IPolygon    pPolygon    = new Polygon() as IPolygon;
            IRubberBand pRubberBand = new RubberPolygon();

            pPolygon = (IPolygon)pRubberBand.TrackNew(axMapControl1.ActiveView.ScreenDisplay, null);
            // 创建符号
            ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbol();

            pSimpleLineSymbol.Width = 2;
            pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
            //pSimpleLineSymbol.Color = GetRGBColor(46, 24, 63);// Common.GetRGBColor(46, 24, 63);

            ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbol();

            //pSimpleFillSymbol.Color = GetRGBColor(11, 200, 145);
            pSimpleFillSymbol.Outline = pSimpleLineSymbol;
            // 创建Element并赋值图形和符号
            IFillShapeElement pPolygonElement = new PolygonElement() as IFillShapeElement;
            IElement          pElement        = (IElement)pPolygonElement;

            pElement.Geometry      = pPolygon;
            pPolygonElement.Symbol = pSimpleFillSymbol;

            // 添加到IGraphicsContainer容器
            IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)axMapControl1.Map;

            pGraphicsContainer.AddElement((IElement)pPolygonElement, 0);
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Пример #3
0
        public override void OnMouseDown(
			int button,
			int shift,
			int x,
			int y
			)
        {
            try
            {

                IPolygon pPoly;
                IGraphicsContainer pGraCont;
                IRubberBand pRubberPoly;

                // QI for the IGraphicsContainerSelect interface on the document's activeview
                pGraCont = (IGraphicsContainer)ext.FocusMap;

                // Create a new RubberPolygon
                pRubberPoly = new RubberPolygon();

                // Check which mouse button was pressed...
                if (1 == button)
                { // If button 1 (left) then create a new polygon (TrackNew)

                    // Return a new Polygon from the tracker object using TrackNew
                    pPoly = (IPolygon)pRubberPoly.TrackNew(((IActiveView)pGraCont).ScreenDisplay, null);
                    if (pPoly != null)
                    {
                        pPoly.SpatialReference = this.ext.FocusMap.SpatialReference;

                        if (see == null)
                        {
                            see = new SEE();
                        }
                        see.Expand(pPoly, this.ext);

                        SEEUserInterfaceUtils.updateAcetate(see, featureClass, ext);

                        if (SEEUserInterfaceUtils.isUserDone())
                        {
                            var geometryCollection = see.Shape as IGeometryCollection;
                            bool isMulti = geometryCollection != null && geometryCollection.GeometryCount > 1;

                            if (isMulti)
                            {
                                MessageBox.Show("Multipolygons cannot be processed with SUITT at this time. Please ensure your SEE Area of Interest is a single polygon feature.");
                            }
                            else finishTransaction();
                        }
                    }
                }

                // Refresh the activeview
                ((IActiveView)ext.FocusMap).Refresh();

            }
            catch (CancelException ex)
            {
                Logger.Write("User Canceled SEE Operation: " + ex.Message + Environment.NewLine + ex.StackTrace);
                // cancelled

                in_click = false;
                this.endHourGlass();

                app.CurrentTool = null;
            }
            catch (HandledException he)
            {
                Logger.Write(he);
                in_click = false;
                this.endHourGlass();

                app.CurrentTool = null;
            }
            catch (Exception e)
            {

                MessageBox.Show(e.Message + " : " + e.StackTrace,
                    "EXCEPTION", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                in_click = false;

                if (this.ext.TransactionManager.Current() != null)
                {
                    try
                    {
                        this.ext.TransactionManager.Close();
                    }
                    catch (Exception ex)
                    {
                        // ignored
                        System.Diagnostics.Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); //ajw: added
                    }
                }

                this.endHourGlass();
            }
            finally
            {
                app.CurrentTool = null;
            }
        }