コード例 #1
0
        /// <summary>
        /// 开始编辑按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStartEdit_Click(object sender, EventArgs e)
        {
            try
            {
                mEngineEditor     = new EngineEditorClass();
                mEngineEditTask   = mEngineEditor as IEngineEditTask;
                mEngineEditLayers = mEngineEditor as IEngineEditLayers;
                mMap        = MainMapControl.Map;
                mActiveView = mMap as IActiveView;
                mlistLayers = MapOperation.GetLayers(mMap);

                if (mlistLayers == null || mlistLayers.Count == 0)
                {
                    MessageBox.Show("请加载编辑图层!", "提示",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                mMap.ClearSelection();
                mActiveView.Refresh();
                InitComboBox(mlistLayers);
                ChangeButtonState(true);

                // 如果编辑已经开始,则直接退出
                if (mEngineEditor.EditState != esriEngineEditState.esriEngineStateNotEditing)
                {
                    return;
                }
                if (mCurrentLyr == null)
                {
                    return;
                }
                // 获取当前编辑图层工作空间
                IDataset   dataset   = mCurrentLyr.FeatureClass as IDataset;
                IWorkspace workspace = dataset.Workspace;
                // 设置编辑模式,如果是ArcSDE采用版本模式
                if (workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
                {
                    mEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned;
                }
                else
                {
                    mEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeNonVersioned;
                }
                // 设置编辑任务
                mEngineEditTask           = mEngineEditor.GetTaskByUniqueName("ControlToolsEditing_CreateNewFeatureTask");
                mEngineEditor.CurrentTask = mEngineEditTask;
                //是否可以进行撤销、恢复操作
                mEngineEditor.EnableUndoRedo(true);
                //开始编辑操作
                mEngineEditor.StartEditing(workspace, mMap);
            }
            catch (Exception ex)
            {
            }
        }