|
|
|
|
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.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using UIShell.OSGi;
|
|
|
|
|
|
|
|
|
|
namespace Kingo.Plugin.MapView.Commands
|
|
|
|
|
{
|
|
|
|
|
//[PathAttribute("Kingo.Plugin.MapView.Commands.CmdRemoveLayer")]
|
|
|
|
|
public class CmdRemoveLayer : BaseMapMenuCommand
|
|
|
|
|
{
|
|
|
|
|
public override void OnClick()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (m_hookHelper == null) return;
|
|
|
|
|
|
|
|
|
|
object layer = m_hookHelper.GetCustomProperty();
|
|
|
|
|
if (layer is ILayer)
|
|
|
|
|
{
|
|
|
|
|
if (MessageHelper.ShowYesNoAndTips("是否确定移除该图层?") == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
ILayer layerTemp = layer as ILayer;
|
|
|
|
|
IDataCatalogService _DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>();
|
|
|
|
|
if (_DataCatalog == null) return;
|
|
|
|
|
List<LayerCfg> Layers = (_DataCatalog.CurrentLayers as LayerCfg).GetAllItem();
|
|
|
|
|
LayerCfg info2 = Layers.FirstOrDefault(x => x.LayerName == layerTemp.Name);
|
|
|
|
|
LayerCfg infoTemp = Layers.FirstOrDefault(x => x.ID == info2.PID);
|
|
|
|
|
infoTemp.Layers.Remove(info2);
|
|
|
|
|
_DataCatalog.UpdateTree();
|
|
|
|
|
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProject" });
|
|
|
|
|
|
|
|
|
|
m_hookHelper.FocusMap.DeleteLayer(layer as ILayer);
|
|
|
|
|
m_hookHelper.ActiveView.Refresh();
|
|
|
|
|
//Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "RefreshLayer" });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnCreate(object Hook)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (m_hookHelper == null)
|
|
|
|
|
{
|
|
|
|
|
m_hookHelper = new HookHelper();
|
|
|
|
|
m_hookHelper.Hook = Hook;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("加载 移除图层 命令时发生异常,异常信息如下:");
|
|
|
|
|
LogAPI.Debug(ex);
|
|
|
|
|
LogAPI.Debug("异常信息结束");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Enabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return ReomveISEnabled();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ReomveISEnabled()
|
|
|
|
|
{
|
|
|
|
|
bool iSEnabled = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
object layer = m_hookHelper.GetCustomProperty();
|
|
|
|
|
if (layer is ILayer)
|
|
|
|
|
{
|
|
|
|
|
IFeatureLayer featurelayer = layer as IFeatureLayer;
|
|
|
|
|
if (featurelayer is ESRI.ArcGIS.Geodatabase.IDataset)
|
|
|
|
|
{
|
|
|
|
|
ESRI.ArcGIS.Geodatabase.IDataset dataset = featurelayer as ESRI.ArcGIS.Geodatabase.IDataset;
|
|
|
|
|
string layername = dataset.BrowseName;
|
|
|
|
|
if (layername == "BHTB" || layername == "DHCG")
|
|
|
|
|
{
|
|
|
|
|
iSEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
iSEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
iSEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
return iSEnabled;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug(ex.Message);
|
|
|
|
|
return iSEnabled;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|