You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
5.4 KiB
120 lines
5.4 KiB
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<IDataCatalogService>(); |
|
|
|
string strMxdPath = Path.Combine(SysAppPath.GetCurrentAppPath() + "工作空间DTBJK\\初始化工程模板\\LatersToXMLForDTBJK" + ".xml"); |
|
if (File.Exists(strMxdPath)) |
|
StrLayerInfo = SerializeAPI.DeserializeToObject2<LayerCfg>(strMxdPath); |
|
if (_DataCatalog == null || HookHelper == null || ProInfo == null || StrLayerInfo == null) |
|
return; |
|
object pTargetObj = HookHelper.GetCustomProperty(); |
|
if (pTargetObj is IGroupLayer) |
|
{ |
|
if (ProInfo.ProjType == EnumProjType.BHTBTQ && _DataCatalog != null) |
|
{ |
|
_DataCatalog.RemoveLayer(pTargetObj as ILayer); |
|
_DataCatalog.UpdateTree(); |
|
HookHelper.FocusMap.DeleteLayer(pTargetObj as ILayer); |
|
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(pTargetObj as ILayer); |
|
LayerCfg rootLayer = _DataCatalog.CurrentLayers as LayerCfg; |
|
List<LayerCfg> AllLayers = rootLayer.GetAllItem(); |
|
GroupLayerInfo = AllLayers.FirstOrDefault(f => f.LayerName == (pTargetObj as ILayer).Name); |
|
if (ContainsLayerRecursive(StrLayerInfo.Layers, (pTargetObj as ILayer).Name)) |
|
{ |
|
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((pTargetObj as ILayer).Name); |
|
if (parent != null) |
|
{ |
|
_DataCatalog.RemoveLayer(parent); |
|
_DataCatalog.UpdateTree(); |
|
} |
|
} |
|
_DataCatalog.UpdateTree(); |
|
HookHelper.FocusMap.DeleteLayer(pTargetObj as ILayer); |
|
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; |
|
} |
|
} |
|
|
|
private bool ContainsLayerRecursive(IEnumerable<LayerCfg> layers, string targetName) |
|
{ |
|
return layers?.Any(layer => layer.LayerName == targetName || (layer.Layers != null && ContainsLayerRecursive(layer.Layers, targetName))) ?? false; |
|
} |
|
|
|
|
|
public override void OnCreate(object Hook) |
|
{ |
|
if (HookHelper == null) |
|
{ |
|
HookHelper = new HookHelper |
|
{ |
|
Hook = Hook |
|
}; |
|
} |
|
} |
|
} |
|
}
|
|
|