using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using KGIS.Framework.AE.ExtensionMethod; using KGIS.Framework.Maps; using KGIS.Framework.Platform; using KGIS.Framework.Utils; using KGIS.Framework.Utils.Helper; using Kingo.PluginServiceInterface; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using UIShell.OSGi; namespace Kingo.Plugin.MapView.Commands { public class CmdRemoveGroupLayer : BaseMapMenuCommand { private IEngineEditor m_Editor; public IHookHelper HookHelper { get; set; } private IDataCatalogService _DataCatalog = null; private LayerCfg StrLayerInfo = null; public override void OnClick() { if (m_Editor == null) m_Editor = new EngineEditorClass(); ProjectInfo ProInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; if (m_Editor.EditState != esriEngineEditState.esriEngineStateNotEditing) { MessageHelper.ShowTips("当前工程正处于编辑状态,关闭之前请先结束编辑!"); return; } if (MessageHelper.ShowYesNoAndTips("是否确定移除该分组?") == DialogResult.Yes) { if (_DataCatalog == null) _DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService(); string strMxdPath = Path.Combine(SysAppPath.GetCurrentAppPath() + "工作空间\\模板\\新建变更工程\\LayerSymbolCfg" + ".xml"); if (File.Exists(strMxdPath)) StrLayerInfo = SerializeAPI.DeserializeToObject2(strMxdPath); if (_DataCatalog == null || HookHelper == null || ProInfo == null || StrLayerInfo == null) return; object pTargetObj = HookHelper.GetCustomProperty(); if (pTargetObj is IGroupLayer) { ILayer layerQS = MapsManager.Instance.MapService.GetGroupLayer((pTargetObj as ILayerGeneralProperties).LayerDescription); if (layerQS == null) return; if (ProInfo.ProjType == EnumProjType.BHTBTQ && _DataCatalog != null) { _DataCatalog.RemoveLayer(layerQS); _DataCatalog.UpdateTree(); HookHelper.FocusMap.DeleteLayer(layerQS); HookHelper.ActiveView.Refresh(); Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "RefreshLayer" }); Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProject" }); return; } LayerCfg GroupLayerInfo = null; if (_DataCatalog != null) { _DataCatalog.GetNodeByLayer(layerQS); LayerCfg rootLayer = _DataCatalog.CurrentLayers as LayerCfg; List AllLayers = rootLayer.GetAllItem(); GroupLayerInfo = AllLayers.FirstOrDefault(f => f.LayerName == layerQS.Name); if (StrLayerInfo.Layers.FirstOrDefault(x => x.LayerName == layerQS.Name) != null) { MessageHelper.ShowWarning("基础配置图层分组不能移除!"); return; } if ("增量成果,增量图层".Contains(GroupLayerInfo.LayerName)) { MessageHelper.ShowWarning("基础配置图层分组不能移除!"); return; } //else if (GroupLayerInfo.LayerName == "变更数据") //{ // ProInfo.BGDatabase = ""; //} //GroupLayerInfo.Layers.Clear(); //AllLayers.RemoveAll(x => x.ID == GroupLayerInfo.ID); ILayer parent = MapsManager.Instance.MapService.GetGroupLayer(layerQS.Name); if (parent != null) { _DataCatalog.RemoveLayer(parent); _DataCatalog.UpdateTree(); } } _DataCatalog.UpdateTree(); HookHelper.FocusMap.DeleteLayer(layerQS); HookHelper.ActiveView.Refresh(); Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "RefreshLayer" }); Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProject" }); } } else { return; } } public override void OnCreate(object Hook) { if (HookHelper == null) { HookHelper = new HookHelper { Hook = Hook }; } } } }