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 KGIS.Framework.OpenData.Control; using KGIS.Framework.OpenData.InterFace; using KGIS.Framework.AE; using KGIS.Framework.Utils; using KGIS.Framework.Utils.Helper; using KGIS.Framework.OpenData.Filter; using System.Windows.Forms; using Kingo.Plugin.MakeTaskPackage.Model; using KGIS.Framework.Maps; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.DataSourcesGDB; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Display; using KGIS.Framework.Platform; using static Kingo.Plugin.MakeTaskPackage.Model.MakeTaskPackageModel; namespace Kingo.Plugin.MakeTaskPackage.View { /// /// FrmAddListLayer.xaml 的交互逻辑 /// public partial class FrmAddListLayer : BaseWindow { public List groupNameList = null; public List exportDataList = null; public OutputPath outPutPathCfg = null; public bool isWRJRWB { get; set; }//是否选择的是无人机任务包 public int selectedRWDCZTInx = 1; public Action Refresh; public FrmAddListLayer() { InitializeComponent(); } private void FrmAddListLayer_Loaded(object sender, RoutedEventArgs e) { try { List layerList = MapsManager.Instance.MapService.GetAllLayerInMap(); if (layerList != null && layerList.Count != 0) { foreach (var item in layerList) { LayerDic layerDic = new LayerDic(); if (item.FeatureClass != null) layerDic.CODE = (item.FeatureClass as IDataset).BrowseName; layerDic.NAME = item.Name; this.cobLayer.Items.Add(layerDic); } } List groupNameList = this.exportDataList.FindAll(x => x.IsLayerGroup == true); if (groupNameList != null) { foreach (var item in groupNameList) { this.cobLayerGroup.Items.Add(item); } } this.cobJZRW.Items.Add("是"); this.cobJZRW.Items.Add("否"); //this.cobJZRW.SelectedIndex = 1;//默认不是举证任务 if (this.isWRJRWB == true) { this.cobJZRW.SelectedIndex = 0; this.cobJZRW.IsEnabled = false; } else { this.cobJZRW.SelectedIndex = 1; this.cobJZRW.IsEnabled = true; } } catch (Exception ex) { LogAPI.Debug("获取图层数据或者分组数据失败:" + ex); MessageHelper.Show("获取图层数据或者分组数据失败:" + ex); } } /// /// 选择图层路径 /// /// /// private void btnSelectLayerPath_Click(object sender, RoutedEventArgs e) { try { OpenDataDialog pDialog = new OpenDataDialog(); ISpatialDataObjectFilter pOFilter; pOFilter = new FilterDatasetsAndLayers(); pDialog.AddFilter(pOFilter, true); pDialog.Title = "选择添加的数据"; if (this.isWRJRWB) pDialog.AllowMultiSelect = false; else pDialog.AllowMultiSelect = true; pDialog.RestoreLocation = true; pDialog.StartLocation = pDialog.FinalLocation; DialogResult dialogResult = pDialog.ShowDialog(); if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0) { string layerPath = string.Empty; string layerName = string.Empty; foreach (ISpatialDataObject distObj in pDialog.Selection) { layerPath += distObj.FullName + ";"; layerName += distObj.Name + ";"; } LayerDic dic = new LayerDic(); dic.CODE = layerName; dic.NAME = layerPath; dic.SpatialDataList = pDialog.Selection; this.cobLayer.Items.Add(dic); this.cobLayer.SelectedItem = dic; } } catch (Exception ex) { LogAPI.Debug("选择图层失败:" + ex); MessageHelper.Show("选择图层失败:" + ex); } } /// /// 确定 /// /// /// private void btnOK_Click(object sender, RoutedEventArgs e) { try { if (this.cobLayer.SelectedItem == null) { MessageHelper.Show("请先选择图层路径!"); return; } MakeTaskPackageModel groupNameModel = null; if (this.cobLayerGroup.SelectedItem != null) { groupNameModel = this.cobLayerGroup.SelectedItem as MakeTaskPackageModel; } MakeTaskPackageModel mobiledata = null; if (groupNameModel != null) { mobiledata = new MakeTaskPackageModel(); mobiledata.IsCheck = groupNameModel.IsCheck; mobiledata.IsSlice = groupNameModel.IsSlice; mobiledata.FileName = groupNameModel.FileName; mobiledata.FileAliasName = groupNameModel.FileAliasName; mobiledata.Type = groupNameModel.Type; mobiledata.Layer = groupNameModel.Layer; mobiledata.LayerIndex = groupNameModel.LayerIndex; mobiledata.ExcState = groupNameModel.ExcState; mobiledata.ID = groupNameModel.ID; mobiledata.PID = groupNameModel.PID; mobiledata.IsLayerGroup = groupNameModel.IsLayerGroup; } LayerDic selectmodel = this.cobLayer.SelectedItem as LayerDic; ILayer grouplayer = null; List rasterLayerList = new List(); if (selectmodel != null) { if (selectmodel.NAME.Contains(";")) { string[] layerArr = selectmodel.NAME.Split(';'); for (int i = 0; i < layerArr.Length; i++) { string path = layerArr[i]; if (!string.IsNullOrWhiteSpace(path)) { ISpatialDataObject distObj = selectmodel.SpatialDataList[i]; if (distObj == null) continue; //if (groupNameModel != null) //{ // grouplayer = groupNameModel.Layer as ILayer; //} ILayerFactoryHelper m_LayerFactoryHelper = new LayerFactoryHelperClass(); //层厂帮手创建从名字对象层的正确类型返回枚举的层 IEnumLayer pEnumLayer = m_LayerFactoryHelper.CreateLayersFromName((distObj.DatasetName as IName)); ILayer pLayer; pEnumLayer.Reset(); List layerList = new List(); //通过循环的枚举和添加的每个层 while ((pLayer = pEnumLayer.Next()) != null) { layerList.Add(pLayer); if (pLayer is IRasterLayer) rasterLayerList.Add(pLayer as IRasterLayer); } AddLayer(layerList, mobiledata, i, distObj.FullName); } } if (mobiledata != null) { if (rasterLayerList != null && rasterLayerList.Count != 0 && layerArr.Length != 0 && rasterLayerList.Count == layerArr.Length - 1) { mobiledata.Type = "瓦片"; mobiledata.Make = "未制作"; mobiledata.Layer = rasterLayerList; mobiledata.ExcState = ExcStateEnum.Loading; if (outPutPathCfg != null) { mobiledata.OutPath = outPutPathCfg.RootDirectory; mobiledata.TaskName = outPutPathCfg.TaskName; mobiledata.CfgFileName = outPutPathCfg.ProfileName; } else { mobiledata.OutPath = @"Kingoit\phonemap_wydh\projects"; mobiledata.TaskName = "县级数据"; mobiledata.CfgFileName = "layerConfig.xml"; } } else { mobiledata.Type = "图层组"; mobiledata.Make = ""; mobiledata.ExcState = ExcStateEnum.NoImport; } } if (groupNameModel != null) this.exportDataList.Remove(groupNameModel); if (mobiledata != null) this.exportDataList.Add(mobiledata); } else { IFeatureLayer featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName(selectmodel.NAME); if (featureLayer != null) { //if (groupNameModel != null) //{ // grouplayer = groupNameModel.Layer as ILayer; //} List layerList = new List(); layerList.Add(featureLayer as ILayer); AddLayer(layerList, mobiledata, 0, ""); } } } Refresh?.Invoke(); this.Close(); } catch (Exception ex) { LogAPI.Debug("添加图层失败:" + ex); MessageHelper.Show("添加图层失败:" + ex); } } private void AddLayer(List layerList, MakeTaskPackageModel groupNameModel, int index, string layerSource) { try { if (layerList.Count != 0) { int layerIndex = 0; foreach (var item in layerList) { List groupNameList = null; if (groupNameModel != null) groupNameList = this.exportDataList.FindAll(x => x.PID == groupNameModel.ID); if (groupNameList != null && groupNameList.Count != 0) { layerIndex = groupNameList.Count; } else { layerIndex = index; } int pid = 0; int mapGroupIndex = -1; string mapGroupName = "其他"; if (groupNameModel != null) { mapGroupIndex = groupNameModel.LayerIndex; mapGroupName = groupNameModel.FileAliasName; pid = groupNameModel.ID; } var maxIdModel = 0; if (this.exportDataList != null && this.exportDataList.Count > 0) maxIdModel = this.exportDataList.Max(x => x.ID); maxIdModel++; MakeTaskPackageModel mobiledata = new MakeTaskPackageModel(); mobiledata.IsCheck = true; mobiledata.IsSlice = false; mobiledata.FileName = (item as IDataset).BrowseName; mobiledata.FileAliasName = item.Name; mobiledata.Make = "未制作"; mobiledata.LayerIndex = layerIndex; if (item is IRasterLayer) { List rasterList = new List(); rasterList.Add(item as IRasterLayer); mobiledata.Layer = rasterList; mobiledata.Type = "瓦片"; } else { mobiledata.Layer = item; mobiledata.Type = "矢量"; } mobiledata.MapGroupIndex = mapGroupIndex; if (this.cobJZRW.SelectedItem.ToString() == "是") { mobiledata.Type = "举证任务"; if (mobiledata.FileName == "JCTB" || mobiledata.FileAliasName == "监测图斑") { string where = string.Empty; int sfjzIndex = (item as IFeatureLayer).FeatureClass.FindField("SFJZ"); int rwdcztIndex = (item as IFeatureLayer).FeatureClass.FindField("RWDCZT"); if (sfjzIndex != -1) { where = string.Format("SFJZ='1'"); } if (this.selectedRWDCZTInx == 0 && rwdcztIndex != -1) where = string.Format("({0} and RWDCZT='已制作')", where); else if (this.selectedRWDCZTInx == 1 && rwdcztIndex != -1) where = string.Format("({0} and (RWDCZT is null or RWDCZT=''))", where); mobiledata.FilterWhere = where; } } if (outPutPathCfg != null) { mobiledata.OutPath = outPutPathCfg.RootDirectory; mobiledata.TaskName = outPutPathCfg.TaskName; mobiledata.CfgFileName = outPutPathCfg.ProfileName; } else { mobiledata.OutPath = @"Kingoit\phonemap_wydh\projects"; mobiledata.TaskName = "县级数据"; mobiledata.CfgFileName = "layerConfig.xml"; } mobiledata.MapGroupName = mapGroupName; mobiledata.ID = maxIdModel; mobiledata.PID = pid; mobiledata.LayerSource = layerSource; this.exportDataList.Add(mobiledata); } } } catch (Exception ex) { LogAPI.Debug("添加图层失败:" + ex); MessageHelper.Show("添加图层失败:" + ex); } } /// /// 取消 /// /// /// private void btnCancel_Click(object sender, RoutedEventArgs e) { try { this.Close(); } catch (Exception ex) { LogAPI.Debug("关闭添加列表图层界面失败:" + ex); MessageHelper.Show("关闭添加列表图层界面失败:" + ex); } } public class LayerDic { public string CODE { get; set; } public string NAME { get; set; } public List SpatialDataList { get; set; } } } }