你的位置:首页 > ASP.net教程

[ASP.net教程]定制 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();

        }