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

364 lines
17 KiB

6 months ago
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.KMapSDK;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UIShell.OSGi;
namespace Kingo.Plugin.DTBJK_XJ.View
{
/// <summary>
/// UCMapDataImage.xaml 的交互逻辑
/// </summary>
public partial class UCMapDataImage : BaseWindow
{
private ISystemCfg SystemCfg = null;
private SystemConfig2 Cfg = null;
public string Url { get; set; }
public IHookHelper m_hookHelper { get; set; }
private IDataCatalogService _DataCatalog = null;
List<ImageSlicing> _ImageSlicings = new List<ImageSlicing>();
string layerName = "";
public UCMapDataImage(IHookHelper hookHelper, string layername)
{
InitializeComponent();
layerName = layername;
m_hookHelper = hookHelper;
SystemCfg = BundleRuntime.Instance.GetFirstOrDefaultService<ISystemCfg>();
Cfg = SystemCfg.Load();
if (_DataCatalog == null)
_DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>();
_ImageSlicings = UserLoginHelper.GetAllYXGroupLayer();
MapsManager.Instance.MapService.getAxMapControl().OnExtentUpdated += M_pAxMapControl_OnExtentUpdated;
}
public void CloseForm()
{
MapsManager.Instance.MapService.getAxMapControl().OnExtentUpdated -= M_pAxMapControl_OnExtentUpdated;
}
private void M_pAxMapControl_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)
{
try
{
this.comboxYearList.Items.Clear();
ImageSlicing currentImageSlicing = _ImageSlicings.FirstOrDefault(a => a.Alias == layerName);
if (currentImageSlicing == null) return;
//获取当前地图窗口视图范围内的影像时间列表
List<string> listYear = Kingo.KMapSDK.KMap.Instance.GetYear(currentImageSlicing, MapsManager.Instance.MapService.getAxMapControl().MapScale, MapsManager.Instance.MapService.getAxMapControl().ActiveView.Extent);
//获取当前地图窗口视图范围内的影像时间列表
//List<string> listYear = Kingo.KMapSDK.KMap.Instance.GetYear(MapsManager.Instance.MapService.getAxMapControl().MapScale, MapsManager.Instance.MapService.getAxMapControl().ActiveView.Extent);
if (listYear != null && listYear.Count > 0)
{
foreach (var item in listYear)
{
this.comboxYearList.Items.Add(item);
}
//时相下拉列表默认选择最后一个时间
this.comboxYearList.SelectedIndex = listYear.Count - 1;
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
LogAPI.Debug("地图刷新,大数据影像时间获取失败:" + ex.Message);
}
}
/// <summary>
/// 加载时间轴影像
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(UserLoginHelper.GetAppsetingValueByKey("JSYXUrl")))
{
MessageHelper.ShowTips("请先设置WMTS服务地址!");
return;
}
//判断当前地图窗口是否存在“时间轴影像底图”图层,存在则不再添加
IGroupLayer groupLayer = Kingo.KMapSDK.Common.CommonAPI.GetGroupLayerByName<IGroupLayer>(MapsManager.Instance.MapService.getAxMapControl().Map, Kingo.KMapSDK.Common.GlobalConfig.Instance.GroupName);
IDataCatalogService _DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>();
if (_DataCatalog == null) return;
if (groupLayer != null)
{
ILayer parent = MapsManager.Instance.MapService.GetGroupLayer(Kingo.KMapSDK.KMap.Instance.KMapGroupLayer.Name);
if (parent != null)
{
_DataCatalog.RemoveLayer(parent);
_DataCatalog.UpdateTree();
m_hookHelper.FocusMap.DeleteLayer(Kingo.KMapSDK.KMap.Instance.KMapGroupLayer);
m_hookHelper.ActiveView.Refresh();
}
}
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.GetAppsetingValueByKey("JSYXUrl"));
//加载时间轴底图服务到地图窗口
//MapsManager.Instance.MapService.getAxMapControl().AddLayer(Kingo.KMapSDK.KMap.Instance.KMapGroupLayer);
if (Kingo.KMapSDK.KMap.Instance.KMapGroupLayer == null) return;
Cfg.SJYXLayerLoadCfg.Clear();
IGroupLayer group = Kingo.KMapSDK.KMap.Instance.KMapGroupLayer as IGroupLayer;
ILayerGeneralProperties layerGeneralProperties = group as ILayerGeneralProperties;
layerGeneralProperties.LayerDescription = group.Name;
object GroupLayerInfo = _DataCatalog.AddLayer(group);
LayerCfg node = new LayerCfg()
{
IsChecked = true,
LayerName = Kingo.KMapSDK.KMap.Instance.KMapGroupLayer.Name,
FcPath = UserLoginHelper.GetAppsetingValueByKey("JSYXUrl"),
LayerType = EnumLayerType.GroupLayer
};
Cfg.SJYXLayerLoadCfg.Add(node);
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.Value == fristChild.Key).ToList();
if (secondChilds != null && secondChilds.Count > 0)
{
ILayer fristChildGroupLayer = new GroupLayer() { Name = fristChild.Key.Name };
ILayerGeneralProperties fristChildLayerGeneralProperties = fristChildGroupLayer as ILayerGeneralProperties;
fristChildLayerGeneralProperties.LayerDescription = fristChild.Key.Name;
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);
}
else
{
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);
}
foreach (var secondChild in secondChilds)
{
_DataCatalog.AddLayer(secondChild.Key, tempGroupLayerInfo);
LayerCfg secondLayerCfg = new LayerCfg(fristChildLayerCfg)
{
IsChecked = true,
LayerName = secondChild.Key.Name,
FcPath = UserLoginHelper.GetAppsetingValueByKey("JSYXUrl"),
LayerType = EnumLayerType.WMTSLayer
};
Cfg.SJYXLayerLoadCfg.Add(secondLayerCfg);
}
}
if (_DataCatalog != null)
{
_DataCatalog.UpdateTree();
}
//影像图层放在最后一层
List<LayerCfg> childlayers = (_DataCatalog.CurrentLayers as LayerCfg).Layers;
if (childlayers != null && childlayers.Count > 1)
{
LayerCfg firstlayerCfg = childlayers[0];
int lastIndx = childlayers.Count - 1;
for (int i = 0; i < lastIndx; i++)
{
childlayers[i] = childlayers[i + 1];
}
childlayers[lastIndx] = firstlayerCfg;
(_DataCatalog.CurrentLayers as LayerCfg).Layers = childlayers;
}
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;
}
/// <summary>
/// 前一时相:切换时间轴影像底图服务到前一个时相
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPreTime_Click(object sender, RoutedEventArgs e)
{
if (this.comboxYearList.SelectedIndex > 0)
{
this.comboxYearList.SelectedIndex = this.comboxYearList.SelectedIndex - 1;
}
}
/// <summary>
/// 后一时相::切换时间轴影像底图服务到后一个时相
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnNextTime_Click(object sender, RoutedEventArgs e)
{
try
{
if (this.comboxYearList.SelectedIndex < this.comboxYearList.Items.Count - 1)
{
this.comboxYearList.SelectedIndex = this.comboxYearList.SelectedIndex + 1;
}
}
catch (Exception ex)
{
MessageHelper.ShowError("下一时相失败:" + ex.Message);
LogAPI.Debug("下一时相失败:" + ex.Message);
}
}
/// <summary>
/// 设置影像路径
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSetting_Click(object sender, RoutedEventArgs e)
{
LayerCfg rootLayer = _DataCatalog.CurrentLayers as LayerCfg;
if (rootLayer == null) return;
UCMapImageSetting frmSetting = new UCMapImageSetting(rootLayer.LayerName);
frmSetting.WindowStartupLocation = WindowStartupLocation.CenterScreen;
frmSetting.Topmost = true;
if (frmSetting.ShowDialog() == true)
{
if (Url != null && Url.Equals(frmSetting.Url))
{
return;
}
//设置时间轴影像底图服务路径
if (!string.IsNullOrEmpty(frmSetting.Url) && frmSetting.Url.Contains("@"))
{
frmSetting.Url = frmSetting.Url.Split('@')[0];
}
UserLoginHelper.UpdateYXGroupLayerValueByName(rootLayer.LayerName, rootLayer.LayerName, frmSetting.Url);
//保存时间轴影像底图服务配置
Kingo.KMapSDK.Common.GlobalConfig.SaveInstance();
}
}
/// <summary>
/// 时相选择改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboxYearList_SelectedIndexChanged(object sender, RoutedEventArgs e)
{
try
{
ImageSlicing currentImageSlicing = _ImageSlicings.FirstOrDefault(a => a.Alias == layerName);
if (currentImageSlicing == null) return;
//设置时间轴影像底图服务展示日期
Kingo.KMapSDK.KMap.Instance.SetYear(currentImageSlicing, this.comboxYearList.SelectedItem.ToString());
//设置时间轴影像底图服务展示日期
//Kingo.KMapSDK.KMap.Instance.SetYear(this.comboxYearList.SelectedItem.ToString());
//刷新地图窗口
MapsManager.Instance.MapService.getAxMapControl().ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
}
catch (Exception ex)
{
MessageHelper.ShowError("时相选择改变事件失败:" + ex.Message);
LogAPI.Debug("时相选择改变事件失败:" + ex.Message);
}
}
}
}