using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Utils.Interface;
using KGIS.Framework.Views;
using Kingo.Plugin.MapView.Common;
using Kingo.Plugin.MapView.Enum;
using Kingo.Plugin.MapView.Model;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using UIShell.OSGi;
namespace Kingo.Plugin.MapView.Views
{
///
/// 工具条-属性查看 的交互逻辑
///
public partial class FrmFeatureAttributes : BaseWindow, INotifyPropertyChanged
{
private static IHookHelper m_hookHelper;
private IEngineEditor pEngineEditor = new EngineEditorClass();
private IProofManager ProofMgr = null;
private ISystemCfg SystemCfg = null;
///
/// 右键菜单
///
private new ContextMenu ContextMenu
{
get;
set;
}
private IMapService _MapService;
public FrmFeatureAttributes(IHookHelper hook, bool IsShowPhotoPanel = false, bool IsShowWYXXPanel = false)
{
m_hookHelper = hook;
_MapService = MapsManager.Instance.MapService;
InitializeComponent();
ProofMgr = BundleRuntime.Instance.GetFirstOrDefaultService();
SystemCfg = BundleRuntime.Instance.GetFirstOrDefaultService();
SystemCfg.Load();
_MapService.OnSelectionChanged += AxMapControl_OnSelectionChanged;
Platform.Instance.NotifyMsgEven2 += NotifyMsg_NotifyMsgEven;
this.Closed += (s, e) =>
{
_MapService.OnSelectionChanged -= AxMapControl_OnSelectionChanged;
Platform.Instance.NotifyMsgEven2 -= NotifyMsg_NotifyMsgEven;
};
List list = new List();
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", TargetPropertyName = "DLMC", TargetPropertyAliasName = "地类名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "TBXHDM", SourcePropertyAliasName = "图斑细化代码", TargetPropertyName = "TBXHMC", TargetPropertyAliasName = "图斑细化名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
list.Add(new Linkage() { SourcePropertyName = "TBXHDM", SourcePropertyAliasName = "图斑细化代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "LYXZFLBM", SourcePropertyAliasName = "利用现状分类编码", TargetPropertyName = "LYXZFLMC", TargetPropertyAliasName = "利用现状分类名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
list.Add(new Linkage() { SourcePropertyName = "LYXZFLBM", SourcePropertyAliasName = "利用现状分类编码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "ZZSXDM", SourcePropertyAliasName = "种植属性代码", TargetPropertyName = "ZZSXMC", TargetPropertyAliasName = "种植属性名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
list.Add(new Linkage() { SourcePropertyName = "ZZSXDM", SourcePropertyAliasName = "种植属性代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "GDLX", TargetPropertyAliasName = "耕地类型", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "GDPDJB", TargetPropertyAliasName = "耕地坡度级别", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "GDDB", TargetPropertyAliasName = "耕地等别", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "KCDLBM", TargetPropertyAliasName = "扣除地类编码", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "KCXS", TargetPropertyAliasName = "扣除系数", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "KCMJ", TargetPropertyAliasName = "扣除面积", TargetPropertyValue = "Auto", IsReadOnly = false });
list.Add(new Linkage() { SourcePropertyName = "QSDWDM", SourcePropertyAliasName = "权属单位代码", TargetPropertyName = "QSDWMC", TargetPropertyAliasName = "权属单位名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true });
list.Add(new Linkage() { SourcePropertyName = "QSDWDM", SourcePropertyAliasName = "权属单位代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "ZLDWDM", SourcePropertyAliasName = "坐落单位代码", TargetPropertyName = "ZLDWMC", TargetPropertyAliasName = "坐落单位名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true });
list.Add(new Linkage() { SourcePropertyName = "ZLDWDM", SourcePropertyAliasName = "坐落单位代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
//list.Add(new Linkage() { SourcePropertyName = "ZZZW", SourcePropertyAliasName = "种植作物", DisplayMemberPath = "DisplayName", ValuePath = "CODE", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
attrEdit.LinkageCfg = list.ToArray();
ContextMenu = new ContextMenu();
MenuItem menuItem = new MenuItem();
menuItem.Header = "删除";
menuItem.Click += new RoutedEventHandler(DeleteFeature_Click);
ContextMenu.Items.Add(menuItem);
attrEdit.m_hookHelper = m_hookHelper;
}
private void NotifyMsg_NotifyMsgEven(NotifyMsgPackage obj)
{
if (obj.MsgType == "RefreshFeatureAttribute")
{
BindData();
}
}
private void AxMapControl_OnSelectionChanged(object sender, object e)
{
BindData();
}
void BindData()
{
try
{
ClearData();
IMap map = m_hookHelper.FocusMap;
ISelection s = map.FeatureSelection;
IEnumFeatureSetup iEnumFeatureSetup = s as IEnumFeatureSetup;
iEnumFeatureSetup.AllFields = true;
IEnumFeature pEnumFeature = (IEnumFeature)iEnumFeatureSetup;
pEnumFeature.Reset();
IFeature f = null;
while ((f = pEnumFeature.Next()) != null)
{
IFeatureLayer player = MapsManager.Instance.MapService.GetFeatureLayerByName((f.Class as FeatureClass).BrowseName);
string layerName = player.Name;
TreeViewItem groupItem = null;
foreach (TreeViewItem tvItem in tvDataList.Items)
{
if ((tvItem.Tag as IFeatureClass).AliasName.ToString() == f.Class.AliasName && (tvItem.Tag as FeatureClass).Workspace.PathName == (f.Class as FeatureClass).Workspace.PathName)
{
groupItem = tvItem;
}
}
if (groupItem == null)
{
groupItem = new TreeViewItem();
groupItem.IsExpanded = true;
groupItem.Header = layerName;
groupItem.Tag = f.Class;
tvDataList.Items.Add(groupItem);
}
TreeViewItem item = new TreeViewItem();
item.Header = f.OID;
item.Tag = f;
groupItem.Items.Add(item);
}
if (tvDataList.Items != null && tvDataList.Items.Count > 0)
{
((tvDataList.Items[0] as TreeViewItem).Items[0] as TreeViewItem).IsSelected = true;
}
else
{
attrEdit.ClearData();
}
}
catch (Exception ex)
{
LogAPI.Debug("要素属性 绑定数据 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("要素属性 绑定数据 时异常信息结束");
MessageHelper.ShowError(ex.Message);
}
}
public void ClearData()
{
try
{
foreach (TreeViewItem item in tvDataList.Items)
{
if (item.Tag != null && (item.Tag as IFeatureClass) != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject((item.Tag as IFeatureClass));
}
}
tvDataList.Items.Clear();
}
catch (Exception ex)
{
LogAPI.Debug("要素属性 数据置空 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("要素属性 数据置空 时异常信息结束");
throw ex;
}
}
public void Identify(Dictionary> pFeatureList)
{
try
{
ClearData();
attrEdit.ClearData();
if (pFeatureList == null || pFeatureList.Count <= 0)
{
return;
}
foreach (var key in pFeatureList.Keys)
{
if (pFeatureList[key].Count == 0)
continue;
TreeViewItem groupItem = null;
if (groupItem == null)
{
groupItem = new TreeViewItem();
groupItem.IsExpanded = true;
groupItem.Header = key;
groupItem.Tag = pFeatureList[key][0].Class;
tvDataList.Items.Add(groupItem);
}
foreach (var f in pFeatureList[key])
{
TreeViewItem item = new TreeViewItem();
item.Header = f.OID;
item.Tag = f;
groupItem.Items.Add(item);
}
}
if (tvDataList.Items != null && tvDataList.Items.Count > 0)
{
((tvDataList.Items[0] as TreeViewItem).Items[0] as TreeViewItem).IsSelected = true;
}
else
{
attrEdit.ClearData();
}
}
catch (Exception ex)
{
LogAPI.Debug("要素属性 识别 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("要素属性 识别 时异常信息结束");
MessageHelper.ShowError(ex.Message);
}
}
private void tvDataList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs