年度变更建库软件5.0版本
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.

223 lines
9.5 KiB

6 months ago
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using KGIS.Framework.AE.ExtensionMethod;
using KGIS.Framework.Commands;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.Plugin.DTBJK_XJ.View;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using UIShell.OSGi;
namespace Kingo.Plugin.DTBJK_XJ.Commands
{
/// <summary>
/// 大数据影像
/// </summary>
public class CmdMapDataImage : BaseMapMenuCommand
{
private UCMapDataImage uCMapDataImage = null;
LayerCfg rootLayer = null;
private ISystemCfg SystemCfg = null;
private SystemConfig2 Cfg = null;
IDataCatalogService _DataCatalog = null;
public override void OnClick()
{
try
{
if(SystemCfg == null)
SystemCfg = BundleRuntime.Instance.GetFirstOrDefaultService<ISystemCfg>();
if (Cfg == null && SystemCfg != null)
Cfg = SystemCfg.Load();
if (_DataCatalog == null)
_DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>();
if (m_hookHelper == null)
return;
object layerClass = m_hookHelper.GetCustomProperty();
if (layerClass == null) return;
string name = "";
if (layerClass as WMTSLayerClass != null)
name = (layerClass as WMTSLayerClass).Name;
else if (layerClass as WMTSLayer != null)
name = (layerClass as WMTSLayer).LayerName;
else
return;
if (name == "天地图1" || name == "天地图2" || name == "天地图3")
{
MessageHelper.ShowTips("请选择影像切片图层!");
return;
}
if (string.IsNullOrEmpty(UserLoginHelper.GetYXGroupLayerValueByAliasName(name)))
{
MessageHelper.ShowTips("请先设置WMTS服务地址!");
return;
}
uCMapDataImage = new UCMapDataImage(m_hookHelper, name);
uCMapDataImage.Closed += (s, e) =>
{
uCMapDataImage.CloseForm();
uCMapDataImage = null;
KGIS.Framework.Maps.MapsManager.Instance.MapService.getAxMapControl().CurrentTool = null;
};
uCMapDataImage.ShowInMainWindow();
//LoadImage();
}
catch (Exception ex)
{
LogAPI.Debug("大数据影像出现错误,可能的原因是::" + ex.Message);
LogAPI.Debug("大数据影像出现错误,可能的原因是::" + ex.StackTrace);
MessageHelper.ShowError("大数据影像出现错误,可能的原因是:" + ex.Message);
}
}
private void LoadImage()
{
////判断当前地图窗口是否存在“时间轴影像底图”图层,存在则不再添加
//IGroupLayer groupLayer = Kingo.KMapSDK.Common.CommonAPI.GetGroupLayerByName<IGroupLayer>(MapsManager.Instance.MapService.getAxMapControl().Map, Kingo.KMapSDK.Common.GlobalConfig.Instance.GroupName);
//if (groupLayer == null)
//{
// //初始化时间轴底图服务
// Kingo.KMapSDK.KMap.Instance.InitKMap(UserLoginHelper.GetYXGroupLayerValueByHeader(rootLayer.LayerName));
// //加载时间轴底图服务到地图窗口
// //MapsManager.Instance.MapService.getAxMapControl().AddLayer(Kingo.KMapSDK.KMap.Instance.KMapGroupLayer);
// if (Kingo.KMapSDK.KMap.Instance.KMapGroupLayer == null) return;
// object GroupLayerInfo = _DataCatalog.GetNodeByLayerName("影响切片");
// Dictionary<ILayer, ILayer> layers = new Dictionary<ILayer, ILayer>();
// if (Kingo.KMapSDK.KMap.Instance.KMapGroupLayer is ICompositeLayer)
// {
// layers = GetAllLayerInGroupLayer(Kingo.KMapSDK.KMap.Instance.KMapGroupLayer as ICompositeLayer, Kingo.KMapSDK.KMap.Instance.KMapGroupLayer);
// }
// else
// layers.Add(Kingo.KMapSDK.KMap.Instance.KMapGroupLayer, null);
// // 遍历字典输出键与值
// var fristChilds = layers.Where(a => a.Value == Kingo.KMapSDK.KMap.Instance.KMapGroupLayer).ToList();
// foreach (var fristChild in fristChilds)
// {
// LayerCfg fristChildLayerCfg = null;
// object tempGroupLayerInfo = GroupLayerInfo;
// var secondChilds = layers.Where(a => a.Key == fristChild.Key).ToList();
// if (secondChilds == null || secondChilds.Count == 0)
// {
// tempGroupLayerInfo = _DataCatalog.AddLayer(fristChild.Key, GroupLayerInfo);
// fristChildLayerCfg = new LayerCfg(node)
// {
// IsChecked = true,
// LayerName = fristChild.Key.Name,
// FcPath = UserLoginHelper.GetAppsetingValueByKey("JSYXUrl"),
// LayerType = EnumLayerType.WMTSLayer
// };
// Cfg.SJYXLayerLoadCfg.Add(fristChildLayerCfg);
// }
// }
// if (_DataCatalog != null)
// {
// _DataCatalog.UpdateTree();
// }
// Cfg.Save();
// Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProjectForNoEditor" });
// Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "InitProject" });
// //刷新地图窗口
// MapsManager.Instance.MapService.getAxMapControl().ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, MapsManager.Instance.MapService.getAxMapControl().Extent);
//}
}
public Dictionary<ILayer, ILayer> GetAllLayerInGroupLayer(ICompositeLayer groupLayer, ILayer parentLayer)
{
Dictionary<ILayer, ILayer> allLayers = new Dictionary<ILayer, ILayer>();
if (groupLayer != null && groupLayer.Count > 0)
{
for (int i = 0; i < groupLayer.Count; i++)
{
ILayer layer = groupLayer.get_Layer(i);
if (layer is ICompositeLayer && !(layer is ESRI.ArcGIS.Carto.IAnnotationLayer))
{
if (!allLayers.Keys.Contains(layer))
allLayers.Add(layer, parentLayer);
Dictionary<ILayer, ILayer> list = GetChildLayerInGroupLayer(layer as ICompositeLayer, layer);
foreach (var item in list)
{
if (!allLayers.Keys.Contains(item.Key))
{
allLayers.Add(item.Key, item.Value);
}
}
}
else
{
if (layer is ILayer)
{
if (!allLayers.Keys.Contains(layer))
allLayers.Add(layer, parentLayer);
}
}
}
}
return allLayers;
}
public Dictionary<ILayer, ILayer> GetChildLayerInGroupLayer(ICompositeLayer groupLayer, ILayer parentLayer)
{
Dictionary<ILayer, ILayer> allLayers = new Dictionary<ILayer, ILayer>();
if (groupLayer != null && groupLayer.Count > 0)
{
for (int i = 0; i < groupLayer.Count; i++)
{
ILayer layer = groupLayer.get_Layer(i);
if (layer is ICompositeLayer && !(layer is ESRI.ArcGIS.Carto.IAnnotationLayer))
{
if (!allLayers.Keys.Contains(layer))
allLayers.Add(layer, parentLayer);
}
else
{
if (layer is ILayer)
{
if (!allLayers.Keys.Contains(layer))
allLayers.Add(layer, parentLayer);
}
}
}
}
return allLayers;
}
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 KGIS.Framework.Maps.MapsManager.Instance.MapService.GetProjectInfo() == null ? false : true;
}
}
}
}