示例#1
0
        /// <summary>
        /// Occurs when this tool is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add ToolDeleteTINNode.OnClick implementation
            IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;

            if (pMapCtr != null)
            {
                pMovePtFeedBack.Display = pMapCtr.ActiveView.ScreenDisplay;
                IPoint pt = new PointClass();
                pMovePtFeedBack.Start(pt, pt);
            }
        }
示例#2
0
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            IPoint        point        = new PointClass();
            IFeatureClass featureClass = null;

            if (m_Feature == null)
            {
                return;
            }
            switch (strOperator)
            {
            case "move":
                //将当前鼠标位置的点转换为地图上的坐标
                point = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
                if (m_Feature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                {
                    //设置显示对象,并启动移动
                    m_MovePointFeedback.Display = m_activeView.ScreenDisplay;
                    m_MovePointFeedback.Start(m_Feature.Shape as IPoint, point);
                }
                else if (m_Feature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                {
                    //设置显示对象,并启动移动
                    m_MoveLineFeedback.Display = m_activeView.ScreenDisplay;
                    m_MoveLineFeedback.Start(m_Feature.Shape as IPolyline, point);
                }
                else if (m_Feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                {
                    //设置显示对象,并启动移动
                    m_MovePolygonFeedback.Display = m_activeView.ScreenDisplay;
                    m_MovePolygonFeedback.Start(m_Feature.Shape as IPolygon, point);
                }
                break;
            }
        }
        public void FeatureMoveMouseDown(int x, int y)
        {
            if (MyselectedLayer == null)
            {
                return;
            }
            if ((MyselectedLayer as IGeoFeatureLayer) == null)
            {
                return;
            }

            IFeatureLayer featureLayer = MyselectedLayer as IFeatureLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;

            if (featureClass == null)
            {
                return;
            }

            if (MyselectedFeature.Count < 1)
            {
                return;
            }
            IFeature  feature   = MyselectedFeature[0];
            IGeometry startGeom = feature.Shape;

            IPoint point = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

            try
            {
                switch (featureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPoint:
                    MyfeedBack         = new MovePointFeedbackClass();
                    MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                    IMovePointFeedback pointMoveFeedback = MyfeedBack as IMovePointFeedback;
                    pointMoveFeedback.Start(startGeom as IPoint, point);
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    MyfeedBack         = new MoveLineFeedbackClass();
                    MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                    IMoveLineFeedback lineMoveFeedback = MyfeedBack as IMoveLineFeedback;
                    lineMoveFeedback.Start(startGeom as IPolyline, point);
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    MyfeedBack         = new MovePolygonFeedbackClass();
                    MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                    IMovePolygonFeedback polygonMoveFeedback = MyfeedBack as IMovePolygonFeedback;
                    polygonMoveFeedback.Start(startGeom as IPolygon, point);
                    break;

                default:
                    break;
                }
            }
            catch { return; }
        }
示例#4
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ModifyShape.OnMouseDown implementation

            m_MapControl.Map.ClearSelection();
            m_MapControl.ActiveView.Refresh();
            SelectMouseDown(X, Y);
            IEnumFeature pSelected = (IEnumFeature)m_MapControl.Map.FeatureSelection;
            IFeature     pFeature  = pSelected.Next();

            if (pFeature == null)
            {
                return;
            }
            IActiveView pActiveView = m_MapControl.ActiveView;
            IPoint      pPoint      = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

            //设置捕捉容差
            double       tol          = ConvertPixelsToMapUnits(pActiveView, 4);
            IGeometry    pGeom        = pFeature.Shape;
            IObjectClass pObjectClass = pFeature.Class;

            m_EditFeature = pFeature;

            switch (pGeom.GeometryType)
            {
            case esriGeometryType.esriGeometryPoint:
                m_Feedback         = new MovePointFeedbackClass();
                m_Feedback.Display = pActiveView.ScreenDisplay;
                IMovePointFeedback pPointMove = (IMovePointFeedback)m_Feedback;
                pPointMove.Start((IPoint)pGeom, pPoint);
                break;

            case esriGeometryType.esriGeometryPolyline:
                m_Feedback         = new MoveLineFeedbackClass();
                m_Feedback.Display = pActiveView.ScreenDisplay;
                IMoveLineFeedback m_MoveLineFeedback = (IMoveLineFeedback)m_Feedback;
                m_MoveLineFeedback.Start((IPolyline)pGeom, pPoint);
                break;

            case esriGeometryType.esriGeometryPolygon:
                m_Feedback         = new MovePolygonFeedbackClass();
                m_Feedback.Display = pActiveView.ScreenDisplay;
                IMovePolygonFeedback m_MovePolygonFeedback = (IMovePolygonFeedback)m_Feedback;
                m_MovePolygonFeedback.Start((IPolygon)pGeom, pPoint);
                break;
            }
        }
示例#5
0
 private void buttonXOK_Click(object sender, EventArgs e)
 {
     if (m_pTinEdit != null && m_pTinNode != null)
     {
         m_pTinEdit.SetNodeZ(m_pTinNode.Index, dHeight);
     }
     if (m_pMapCtr != null)
     {
         m_pMapCtr.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null);
     }
     if (pMovePtFeedBack != null)
     {
         IPoint pt = new PointClass();
         pMovePtFeedBack.Start(pt, pt);
     }
     setBttonEnable(false);
 }
示例#6
0
        public void CreateMarkerElement(IPoint point)
        {
            IActiveView        activeView        = this.axMapControl1.ActiveView;
            IGraphicsContainer graphicsContainer = axMapControl1.Map as IGraphicsContainer;
            //建立一个marker元素
            IMarkerElement      markerElement      = new MarkerElement() as IMarkerElement;
            ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol();
            //符号化元素
            IRgbColor rgbColor1 = new RgbColor();

            rgbColor1.Red            = 255;
            rgbColor1.Blue           = 0;
            rgbColor1.Green          = 0;
            simpleMarkerSymbol.Color = rgbColor1;
            IRgbColor rgbColor2 = new RgbColor();

            rgbColor2.Red                   = 0;
            rgbColor2.Blue                  = 255;
            rgbColor2.Green                 = 0;
            simpleMarkerSymbol.Outline      = true;
            simpleMarkerSymbol.OutlineColor = rgbColor2 as IColor;
            simpleMarkerSymbol.OutlineSize  = 1;
            simpleMarkerSymbol.Size         = 5;
            simpleMarkerSymbol.Style        = esriSimpleMarkerStyle.esriSMSCircle;
            ISymbol symbol = simpleMarkerSymbol as ISymbol;

            symbol.ROP2          = esriRasterOpCode.esriROPNotXOrPen;
            markerElement.Symbol = simpleMarkerSymbol;
            m_element            = markerElement as IElement;
            m_element.Geometry   = point as IGeometry;
            graphicsContainer.AddElement(m_element, 0);
            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, m_element, null);
            IGeometry geometry = m_element.Geometry;

            movePointFeedback.Display = activeView.ScreenDisplay;
            movePointFeedback.Symbol  = simpleMarkerSymbol as ISymbol;
            movePointFeedback.Start(geometry as IPoint, point);
        }
示例#7
0
        /// <summary>
        /// Occurs when this tool is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add ToolSplitLine.OnClick implementation
            //Find the Modify Feature task and set it as the current task
            IEngineEditTask editTask = m_engineEditor.GetTaskByUniqueName("ControlToolsEditing_ModifyFeatureTask");

            m_engineEditor.CurrentTask = editTask;

            IEngineEditLayers editLayers = m_editLayer;

            snapEnvironment = m_engineEditor as IEngineSnapEnvironment;
            pt = new PointClass();
            //Check the user is editing; otherwise, there will be no snap agent loaded.
            if (editLayers.TargetLayer == null)
            {
                System.Windows.Forms.MessageBox.Show("Please start an edit session");
                return;
            }

            ////Create a feature snap agent.
            IEngineFeatureSnapAgent featureSnapAgent  = new EngineFeatureSnap();
            IFeatureClass           layerFeatureClass = editLayers.TargetLayer.FeatureClass;

            featureSnapAgent.FeatureClass = layerFeatureClass;
            featureSnapAgent.HitType      = esriGeometryHitPartType.esriGeometryPartBoundary;

            //Activate only the snap agent for the target layer.
            snapEnvironment.AddSnapAgent(featureSnapAgent);
            pMPfeedback         = new MovePointFeedbackClass();
            pMPfeedback.Display = m_hookHelper.ActiveView.ScreenDisplay;
            pMPfeedback.Start(pt, pt);

            IToolbarBuddy toolbarbuddy = (IToolbarBuddy)((IToolbarControl)m_hookHelper.Hook).Buddy;

            oldtool = toolbarbuddy.CurrentTool;
        }
        public bool EditFeature(int x, int y, IGeometry geometry)
        {
            GetFeatureOnMouseDown(x, y);
            SelectOnMouseDown();
            if (MyselectedFeature.Count < 1)
            {
                return(false);
            }
            if (geometry == null)
            {
                return(false);
            }

            IPoint pHitPoint = null;
            double hitDist = 0, tol = 0;
            int    vertexIndex = 0, vertexOffset = 0, numVertices = 0, partIndex = 0;
            bool   vertex = false;

            IFeature editedFeature = MyselectedFeature[0];
            IPoint   point         = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

            tol = ConvertPixelsToMapUnits(4);
            //IGeometry pGeo = editedFeature.Shape;
            //m_EditingFeature = editedFeature;

            try
            {
                switch (geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryPoint:
                    MyfeedBack         = new MovePointFeedbackClass();
                    MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                    IMovePointFeedback pointMove = MyfeedBack as IMovePointFeedback;
                    pointMove.Start(geometry as IPoint, point);
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    if (TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex))
                    {
                        if (!vertex)
                        {
                            IGeometryCollection geometryColl = geometry as IGeometryCollection;
                            IPath            path            = geometryColl.get_Geometry(partIndex) as IPath;
                            IPointCollection pointColl       = path as IPointCollection;
                            numVertices = pointColl.PointCount;
                            object missing = Type.Missing;

                            if (vertexIndex == 0)
                            {
                                object start = 1 as object;
                                pointColl.AddPoint(point, ref start, ref missing);
                            }
                            else
                            {
                                object objVertexIndex = vertexIndex as object;
                                pointColl.AddPoint(point, ref missing, ref objVertexIndex);
                            }
                            TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex);
                        }
                        MyfeedBack         = new LineMovePointFeedbackClass();
                        MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                        ILineMovePointFeedback lineMove = MyfeedBack as ILineMovePointFeedback;
                        lineMove.Start(geometry as IPolyline, vertexIndex, point);
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    if (TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex))
                    {
                        if (!vertex)
                        {
                            IGeometryCollection geometryColl = geometry as IGeometryCollection;
                            IPath            path            = geometryColl.get_Geometry(partIndex) as IPath;
                            IPointCollection pointColl       = path as IPointCollection;
                            numVertices = pointColl.PointCount;
                            object missing = Type.Missing;
                            if (vertexIndex == 0)
                            {
                                object start = 1 as object;
                                pointColl.AddPoint(point, ref start, ref missing);
                            }
                            else
                            {
                                object objVertexIndex = vertexIndex as object;
                                pointColl.AddPoint(point, ref missing, ref objVertexIndex);
                            }
                            TestGeometryHit(tol, point, geometry, ref pHitPoint, ref hitDist, ref partIndex, ref vertexOffset, ref vertexIndex, ref vertex);
                        }
                        MyfeedBack         = new PolygonMovePointFeedbackClass();
                        MyfeedBack.Display = MyMapControl.ActiveView.ScreenDisplay;
                        IPolygonMovePointFeedback polyMove = MyfeedBack as IPolygonMovePointFeedback;
                        polyMove.Start(geometry as IPolygon, vertexIndex + vertexOffset, point);
                    }
                    else
                    {
                        return(false);
                    }
                    break;

                default:
                    break;
                }
            }
            catch { return(false); }
            return(true);
        }
示例#9
0
        int m_flag = 0;                                                        //有无捕捉到点


        //鼠标移动触发函数
        private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
        {
            statusBarXY.Text = string.Format("{0}, {1}  {2}", e.mapX.ToString("#######.##"), e.mapY.ToString("#######.##"), axMapControl1.MapUnits.ToString().Substring(4));

            //橡皮条实现
            IPoint p_point = new PointClass();

            p_point.PutCoords(e.mapX, e.mapY);
            if (this.m_DisplayFeedback != null)
            {
                this.m_DisplayFeedback.MoveTo(p_point);
            }
            //Snap功能实现
            if (miStartSnap.Checked)
            {
                //检测GraphicsContainer中是否已加入m_element_snap和m_textelement
                if (m_flag != 0)
                {
                    m_flag = 0;
                    axMapControl1.ActiveView.GraphicsContainer.DeleteElement(m_element_snap);
                    axMapControl1.ActiveView.GraphicsContainer.DeleteElement((IElement)m_textelement);
                }
                //初始化记录用p_layer/m_snapPoint/m_currentPoint
                ILayer p_Layer = axMapControl1.get_Layer(0);
                m_snapPoint = null;
                m_currentPoint.PutCoords(e.mapX, e.mapY);
                //历遍所有图层捕捉boundary
                for (int i = 0; i < axMapControl1.LayerCount; i++)
                {
                    //记录当前被测试的layer并转化为IFeatureLayer
                    ILayer        p_testLayer    = axMapControl1.get_Layer(i);
                    IFeatureLayer p_featureLayer = p_testLayer as IFeatureLayer;
                    //鼠标光标自动捕获顶点
                    m_snapPoint = Snapping(e.mapX, e.mapY, p_featureLayer);
                    //判断是否捕捉到点
                    if (m_snapPoint != null)
                    {
                        //如果捕捉到点就记录该图层并跳出循环
                        p_Layer = p_testLayer;
                        break;
                    }
                }
                //判断是否捕捉到点
                if (m_snapPoint != null)
                {
                    //生成图层提示气泡并加入GraghicsContainer
                    m_textelement = createTextElement(e.mapX, e.mapY, p_Layer.Name);
                    axMapControl1.ActiveView.GraphicsContainer.AddElement(m_textelement as IElement, 1);
                    //建立element高亮选择点并加入GraphicsContainer
                    ISymbol p_symbol = CreateMarkerElement(m_currentPoint, p_Layer);
                    axMapControl1.ActiveView.GraphicsContainer.AddElement(m_element_snap, 0);
                    //标记为已加入
                    m_flag++;
                    //设置m_movePointFeedback
                    IGeometry p_geometry = m_element_snap.Geometry;
                    m_movePointFeedback.Display = axMapControl1.ActiveView.ScreenDisplay;
                    m_movePointFeedback.Symbol  = p_symbol;
                    m_movePointFeedback.Start(p_geometry as IPoint, m_currentPoint);
                    //移动element至捕捉到的点
                    ElementMoveTo(m_snapPoint);
                }
            }
        }
示例#10
0
        /// <summary>
        /// 编辑当前图层中鼠标击中的地图对象(开始编辑),
        /// 如果为点对象,可进行位置移动,如果为线对象或面对象,可进行节点编辑
        /// 建议在Map.MouseDown事件中调用本方法
        /// </summary>
        /// <param name="x">鼠标X坐标,屏幕坐标</param>
        /// <param name="y">鼠标Y坐标,屏幕坐标</param>
        /// <returns></returns>
        public void  EditFeatureMouseDown(int x, int y)
        {
            IGeometryCollection pGeomColn;
            IPointCollection    pPointColn;
            IObjectClass        pObjectClass;
            IFeature            pFeature;
            IGeometry           pGeom;

            IPath  pPath;
            IPoint pHitPoint = null;
            IPoint pPoint    = null;
            Double hitDist   = 0.0;
            double tol;
            int    vertexIndex = 0;
            int    numVertices;
            int    partIndex = 0;
            bool   vertex    = false;

            try
            {
                m_pMap.ClearSelection();

                // 取得鼠标击中的第一个对象
                SelectMouseDown(x, y);
                IEnumFeature pSelected = (IEnumFeature)m_pMap.FeatureSelection;
                pFeature = pSelected.Next();
                if (pFeature == null)
                {
                    return;
                }

                IActiveView pActiveView = (IActiveView)m_pMap;
                pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

                // 节点空间查询容差
                tol = ConvertPixelsToMapUnits(pActiveView, 4.0);

                pGeom          = pFeature.Shape;
                pObjectClass   = pFeature.Class;
                m_pEditFeature = pFeature;
                object objNull = Missing.Value;
                object objBefore, objAfter;

                switch (pGeom.GeometryType)
                {
                case esriGeometryType.esriGeometryPoint:
                    m_pFeedback         = new MovePointFeedbackClass();
                    m_pFeedback.Display = pActiveView.ScreenDisplay;
                    IMovePointFeedback pPointMove = (IMovePointFeedback)m_pFeedback;
                    pPointMove.Start((IPoint)pGeom, pPoint);
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    if (TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex))
                    {
                        if (!vertex)
                        {
                            pGeomColn   = (IGeometryCollection)pGeom;
                            pPath       = (IPath)pGeomColn.get_Geometry(partIndex);
                            pPointColn  = (IPointCollection)pPath;
                            numVertices = pPointColn.PointCount;

                            if (vertexIndex == 0)
                            {
                                objBefore = (object)(vertexIndex + 1);
                                pPointColn.AddPoint(pPoint, ref objBefore, ref objNull);
                            }
                            else
                            {
                                objAfter = (object)vertexIndex;
                                pPointColn.AddPoint(pPoint, ref objNull, ref objAfter);
                            }

                            TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex);
                        }
                        m_pFeedback         = new LineMovePointFeedbackClass();
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                        ILineMovePointFeedback pLineMove = (ILineMovePointFeedback)m_pFeedback;
                        pLineMove.Start((IPolyline)pGeom, vertexIndex, pPoint);

//							m_pSelectionTracker = new LineTrackerClass();
//							m_pSelectionTracker.Display = pActiveView.ScreenDisplay ;
//							m_pSelectionTracker.Geometry = pGeom;
//							m_pSelectionTracker.ShowHandles = true;
//							m_pSelectionTracker.QueryResizeFeedback(ref m_pFeedback);
//							m_pSelectionTracker.OnMouseDown(1,0,x,y);
                    }
                    else
                    {
                        return;
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    if (TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex))
                    {
                        if (!vertex)
                        {
                            pGeomColn   = (IGeometryCollection)pGeom;
                            pPath       = (IPath)pGeomColn.get_Geometry(partIndex);
                            pPointColn  = (IPointCollection)pPath;
                            numVertices = pPointColn.PointCount;

                            if (vertexIndex == 0)
                            {
                                objBefore = (object)(vertexIndex + 1);
                                pPointColn.AddPoint(pPoint, ref objBefore, ref objNull);
                            }
                            else
                            {
                                objAfter = (object)vertexIndex;
                                pPointColn.AddPoint(pPoint, ref objNull, ref objAfter);
                            }

                            TestGeometryHit(tol, pPoint, pFeature, pHitPoint, hitDist, out partIndex, out vertexIndex, out vertex);
                        }

                        m_pFeedback         = new PolygonMovePointFeedbackClass();
                        m_pFeedback.Display = pActiveView.ScreenDisplay;
                        IPolygonMovePointFeedback pPolyMove = (IPolygonMovePointFeedback)m_pFeedback;
                        pPolyMove.Start((IPolygon)pGeom, vertexIndex, pPoint);
                    }
                    else
                    {
                        return;
                    }
                    break;
                }
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                return;
            }
        }