程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 定制 ArcEngine 要素編輯工具,arcengine編輯工具

定制 ArcEngine 要素編輯工具,arcengine編輯工具

編輯:C#入門知識

定制 ArcEngine 要素編輯工具,arcengine編輯工具


來自:http://blog.sina.com.cn/s/blog_4d780fc10101d2d5.html

先初步了解到大概用到的下面的接口和類:

IEngineEditor

IEngineEditTask

IEngineEditLayers

IEngineEditEvents

IEngineEditProperties

ControlsEditingSketchToolClass

ControlsEditingEditToolClass

ControlsEditingCopyCommandClass

ControlsEditingPasteCommandClass

ControlsEditingClearCommandClass

現在使用 IEngineEditor、IEngineEditTask、IEngineEditLayers這三個接口,再加上Command命令和Tool可以是實現新建要素、復制、剪切、黏貼、刪除、移動要素。

下面說明一下我實現新建圖形功能的思路:

1、根據workspace和map開啟編輯。

2、設置目標圖層。

3、設置編輯操作的任務類型。

4、激活SletchTool,ControlsEditingSketchToolClass。

5、這時就可以在AxMapControl中畫圖形了。圖形的點線面類型,SletchTool工具會根據目標圖層的類型自動識別。

使用了全局變量IEngineEditor,保證在其他的模塊該變量的值

private IEngineEditor m_EngineEditor = new EngineEditorClass();

  private void btnNewFeature_Click(object sender, EventArgs e)

      {

if(m_engineEditor.EditState==esriEngineEditState.esriEngineStateNotEditing)     

        {

                //Start editing the workspace of the first feature layer found. 

                //設置編輯的WorkSpace和編輯對象圖層    

                ILayer currentLayer = mMap.get_Layer(0);

                if (currentLayer is IFeatureLayer)

                {

                    IFeatureLayer featureLayer = currentLayer as IFeatureLayer;

                    IDataset dataset = featureLayer.FeatureClass as IDataset;

                    IWorkspace workspace = dataset.Workspace;

                    m_engineEditor.StartEditing(workspace, mMap.Map);

                    ((IEngineEditLayers)m_engineEditor).SetTargetLayer(featureLayer, 0);

                    SetCurrentTask(ref   m_engineEditor,  "新建要素");

                }

}

     }

         ///

        /// 設置編輯的任務類型

        ///

        ///

        /// 自己命名的任務名稱

      public static void SetCurrentTask(ref IEngineEditor pEngineEditor, string taskName)

        {

            IEngineEditTask edittask;

            if (pEngineEditor.EditState == esriEngineEditState.esriEngineStateEditing)

            {

                switch (taskName)

                {

                    case "新建要素":

                        edittask = pEngineEditor.GetTaskByUniqueName("ControlToolsEditing_CreateNewFeatureTask");

                        if (edittask != null)

                        {

                            pEngineEditor.CurrentTask = edittask;

                        }

                        break;

                    case "修改圖形":

                        edittask=pEngineEditor.GetTaskByUniqueName("ReshapePolylineEditTask_Reshape Polyline_CSharp");

                        if (edittask != null)

                        {

                            pEngineEditor.CurrentTask = edittask;

                        }

                        break;

                    case "修改要素":

                        edittask= pEngineEditor.GetTaskByUniqueName("ControlToolsEditing_ModifyFeatureTask");

                        if (edittask != null)

                        {

                            pEngineEditor.CurrentTask = edittask;

                        }

                        break;

                }

            }

        }

刪除、復制、黏貼的功能,將m_EngineEditor 置於開啟編輯的狀態後,直接調用下面的命令就好了

ControlsEditingEditToolClass  //用於選擇要素對像

ControlsEditingCopyCommandClass

ControlsEditingPasteCommandClass

ControlsEditingClearCommandClass

 

撤銷和重做的功能

       ///

        /// 撒消編輯

        ///

        /// IMap 地圖對象

        public void MapUndoEdit(IMap m_pMap)

        {

            IEngineEditProperties ep = new EngineEditorClass();

            ILayer m_pCurrentLayer = ep.TargetLayer;

            if (m_pCurrentLayer == null) return;

            IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer;

            IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass;

            if (pDataset == null) return;

           

            IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace;

            bool bHasUndos = false;

            pWorkspaceEdit.HasUndos(ref bHasUndos);

            if (bHasUndos)

                pWorkspaceEdit.UndoEditOperation();

            IActiveView pActiveView = (IActiveView)m_pMap;

            pActiveView.Refresh();

        }

 

        ///

        /// 重做

        ///

        /// IMap 地圖對象

        public void MapRedoEdit(IMap m_pMap)

        {

            IEngineEditProperties ep = new EngineEditorClass();

            ILayer m_pCurrentLayer = ep.TargetLayer;

            if (m_pCurrentLayer == null) return;

            IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer;

            IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass;

            if (pDataset == null) return;

            IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace;

            bool bHasUndos = false;

            pWorkspaceEdit.HasUndos(ref bHasUndos);

            if (bHasUndos)

                pWorkspaceEdit.RedoEditOperation();

            IActiveView pActiveView = (IActiveView)m_pMap;

            pActiveView.Refresh();

        }  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved