using DevExpress.XtraBars; using DevExpress.XtraEditors; using DevExpress.XtraTreeList; using DevExpress.XtraTreeList.Columns; using DevExpress.XtraTreeList.Nodes; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.SystemUI; using KGIS.Framework.AE; using KGIS.Framework.Commands; using KGIS.Framework.Maps; using KGIS.Framework.Menus.Entities; using KGIS.Framework.Menus.ServicesInvokes; using KGIS.Framework.Platform; using KGIS.Framework.Utils; using KGIS.Framework.Utils.ExtensionMethod; using KGIS.Framework.Utils.Helper; using KGIS.Framework.Views; using Kingo.Framework.LayerStyleConvert.Common; using Kingo.Framework.LayerStyleConvert.XSDClass; using Kingo.PluginServiceInterface; using Kingo.PluginServiceInterface.Helper; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using UIShell.OSGi; namespace Kingo.Plugin.MapView.Views.DataCalalog { public partial class UCLayerTree : UserControl, IDockPanel, IDataCatalogService { private ICommandManager _CmdManager; private IMapService _MapService; private ILayerPropertyService _LayerPropertyService = null; private EngineEditor _Edit = null; List _listCfg = null; public UCLayerTree() { InitializeComponent(); this.AllowDrop = true; this.trlProject.AllowDrop = true; this.trlProject.OptionsDragAndDrop.AcceptOuterNodes = true; Title = "图层目录"; DockWidth = 330; DefaultArea = KGIS.Framework.Views.DockStyle.DockLeft; DockAreas = KGIS.Framework.Views.DockStyle.DockLeft | KGIS.Framework.Views.DockStyle.DockRight | KGIS.Framework.Views.DockStyle.DockBottom | KGIS.Framework.Views.DockStyle.DockTop; ShowCloseButton = false; ShowAutoHideButton = true; //string strMxdPath = System.IO.Path.Combine(SysAppPath.GetCurrentAppPath() + "工作空间\\模板\\新建变更工程\\LayerSymbolCfg" + ".xml"); //if (File.Exists(strMxdPath)) //{ // LayerCfg StrLayerInfo = SerializeAPI.DeserializeToObject2(strMxdPath); // if (StrLayerInfo != null) // _listCfg = StrLayerInfo.GetAllItem(); //} bool IsOnlySave = false; _Edit = new EngineEditorClass(); _Edit.OnStopEditing += (b) => { if (mCurrentEditorNode == null) return; if (!IsOnlySave) { mCurrentEditorNode.SetValue("IsEdit", false); mCurrentEditorNode.SetValue("ImgIndex", 0); } IsOnlySave = false; }; _Edit.OnSaveEdits += () => { IsOnlySave = true; }; //打开折叠 trlProject.AfterExpand += (sender1, e1) => { try { //bool? IsExpanded = (bool?)e1.Node.GetValue("Expanded"); string name = e1.Node["LayerName"].ToTrim(); var item = Layers.FirstOrDefault(f => f.LayerName == name); if (item == null) return; item.Expanded = e1.Node.Expanded; } catch (Exception ex) { LogAPI.Debug(ex.Message); } }; //关闭折叠 trlProject.AfterCollapse += (sender2, e2) => { try { string layername = e2.Node["LayerName"].ToTrim(); var item = Layers.FirstOrDefault(f => f.LayerName == layername); item.Expanded = e2.Node.Expanded; } catch (Exception ex) { LogAPI.Debug(ex.Message); } }; trlProject.NodeCellStyle += (sender1, e1) => { try { //TreeListColumn column2 = trlProject.Columns.ColumnByName("LayerEditable"); bool? isEdit = e1.Node == null ? null : (bool?)e1.Node.GetValue("IsEdit"); if (isEdit == true && e1.Column.FieldName == "LayerName") { e1.Appearance.ForeColor = Color.Red; e1.Appearance.FontStyleDelta = FontStyle.Bold; } else if (e1.Column != null && e1.Column.FieldName == "LayerName" && isEdit == false) { e1.Appearance.ForeColor = Color.Black; e1.Appearance.FontStyleDelta = FontStyle.Regular; } } catch (Exception ex) { LogAPI.Debug(ex.Message); } }; Platform.Instance.NotifyMsgEven2 += (o) => { switch (o.MsgType) { case "RefreshLayer": //InitTreeNode(_MapService.getAxMapControl().Map); break; default: break; } }; } List Layers = new List(); private LayerCfg _CurrentLayers; public object CurrentLayers { get { return _CurrentLayers; } set { _CurrentLayers = value as LayerCfg; } } private void InitTreeNode(IMap pMap) { trlProject.Nodes.Clear(); Bitmap groupImg = new Bitmap(Image.FromFile(System.IO.Path.Combine(Application.StartupPath, "images", "grouplayer" + ".png")), 22, 16); _CurrentLayers = new LayerCfg { LayerName = pMap.Name, SymbolImg = groupImg, Visible = true, Data = pMap, LayerType = EnumLayerType.Map, Expanded = true }; for (int i = 0; i < pMap.LayerCount; i++) { ILayer layer = pMap.Layer[i]; EnumLayerType layerType = EnumLayerType.GroupLayer; bool isSeleable = false; string FcPath = string.Empty; string FcName = string.Empty; if (layer is IGroupLayer) { FcName = (layer as ILayerGeneralProperties).LayerDescription; } if (layer is IFeatureLayer) { isSeleable = (layer as IFeatureLayer).Selectable; layerType = EnumLayerType.FeatureLayer; FcPath = ((layer as IFeatureLayer).FeatureClass as FeatureClass).Workspace.PathName; FcName = ((layer as IFeatureLayer).FeatureClass as FeatureClass).BrowseName; } LayerCfg subLayerInfo = new LayerCfg(_CurrentLayers) { LayerName = layer.Name, Visible = layer.Visible, SymbolImg = groupImg, Selectable = isSeleable, LayerType = layerType, FcPath = FcPath, FcName = FcName, Data = layer, Expanded = Layers.FirstOrDefault(x => x.LayerName == layer.Name) != null ? Layers.FirstOrDefault(x => x.LayerName == layer.Name).Expanded : false }; _CurrentLayers.Layers.Add(subLayerInfo); CreateNodeByLayer(subLayerInfo); } Layers = _CurrentLayers.GetAllItem(); trlProject.ParentFieldName = "PID"; trlProject.KeyFieldName = "ID"; trlProject.CheckBoxFieldName = "Visible"; trlProject.ImageIndexFieldName = "ImgIndex"; trlProject.DataSource = Layers; RefreshLayerNode(); } public UCLayerTree(IBundleContext pContext, IMap pMap) : this() { //InitTreeNode(pMap); InitService(pContext); //axTOCControl1.OnDoubleClick += AxTOCControl1_OnDoubleClick; //axTOCControl1.OnMouseUp += _axTocCtrl_OnMouseUp; } private void InitService(IBundleContext context) { context.AddService(this); } private void CreateNodeByLayer(LayerCfg pLayerInfo) { try { //List nodes = trlProject.GetNodeList(); //TreeListNode pNode = nodes.FirstOrDefault(f => f.Tag == pLayer); //trlProject.FindNodeByFieldValue("NodeName", ""); ILayer mLayer = pLayerInfo.Data as ILayer; if (mLayer == null) return; if (mLayer is ICompositeLayer) { Bitmap groupImg = new Bitmap(Image.FromFile(System.IO.Path.Combine(Application.StartupPath, "images", "grouplayer" + ".png")), 22, 16); for (int i = 0; i < (mLayer as ICompositeLayer).Count; i++) { ILayer tempLayer = (mLayer as ICompositeLayer).Layer[i]; if (tempLayer is ICompositeLayer) { pLayerInfo.Layers.Add(new LayerCfg(pLayerInfo) { LayerName = tempLayer.Name, Visible = tempLayer.Visible, SymbolImg = groupImg, Selectable = Layers.FirstOrDefault(x => x.LayerName == tempLayer.Name) != null ? Layers.FirstOrDefault(x => x.LayerName == tempLayer.Name).Selectable : true, LayerType = EnumLayerType.GroupLayer, Data = tempLayer }); CreateNodeByLayer(pLayerInfo.Layers[pLayerInfo.Layers.Count - 1]); } else { ILayerEffects mLayerEffects = tempLayer as ILayerEffects; int Tran = 0; if (mLayerEffects != null) Tran = mLayerEffects.Transparency; Bitmap symbol = new Bitmap(22, 16); IGeoFeatureLayer fcLayer = tempLayer as IGeoFeatureLayer; if (fcLayer != null) { ISimpleRenderer render = fcLayer.Renderer as ISimpleRenderer; IUniqueValueRenderer un = null; if (render == null) { un = fcLayer.Renderer as IUniqueValueRenderer; } else if (render.Symbol != null) { symbol = PreViewFillSymbol(render.Symbol, 22, 16); } } byte[] bytes = null; if (symbol == null) { symbol = new Bitmap(22, 16); } MemoryStream ms = new MemoryStream(); symbol.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); bytes = ms.GetBuffer(); ms.Close(); EnumLayerType layerType = EnumLayerType.FeatureLayer; string FcPath = string.Empty; string FcName = string.Empty; if (tempLayer is IFeatureLayer) { FcPath = ((tempLayer as IFeatureLayer).FeatureClass as FeatureClass).Workspace.PathName; FcName = ((tempLayer as IFeatureLayer).FeatureClass as FeatureClass).BrowseName; } else if (tempLayer is IRasterLayer) { layerType = EnumLayerType.RasterLayer; FcPath = (tempLayer as IRasterLayer).FilePath; } else if (tempLayer is KOTilesLayer) { layerType = EnumLayerType.KOTilesLayer; FcPath = (tempLayer as KOTilesLayer).DBPath; } pLayerInfo.Layers.Add(new LayerCfg(pLayerInfo) { LayerName = tempLayer.Name, Visible = tempLayer.Visible, SymbolImg = symbol, Selectable = Layers.FirstOrDefault(x => x.LayerName == tempLayer.Name) != null ? Layers.FirstOrDefault(x => x.LayerName == tempLayer.Name).Selectable : true, Transparency = Tran, FcPath = FcPath, FcName = FcName, Data = tempLayer, LayerType = layerType }); } } } else { ILayerEffects mLayerEffects = mLayer as ILayerEffects; int Tran = 0; if (mLayerEffects != null) Tran = mLayerEffects.Transparency; //ID++; Bitmap symbol = new Bitmap(22, 16); IGeoFeatureLayer fcLayer = mLayer as IGeoFeatureLayer; if (fcLayer != null) { ISimpleRenderer render = fcLayer.Renderer as ISimpleRenderer; IUniqueValueRenderer un = null; if (render == null) { un = fcLayer.Renderer as IUniqueValueRenderer; } else { symbol = PreViewFillSymbol(render.Symbol, 22, 16); } } byte[] bytes = null; if (symbol == null) { symbol = new Bitmap(22, 16); } MemoryStream ms = new MemoryStream(); symbol.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); bytes = ms.GetBuffer(); ms.Close(); EnumLayerType layerType = EnumLayerType.FeatureLayer; string FcPath = string.Empty; string FcName = string.Empty; if (mLayer is IFeatureLayer) { FcPath = ((mLayer as IFeatureLayer).FeatureClass as FeatureClass).Workspace.PathName; FcName = ((mLayer as IFeatureLayer).FeatureClass as FeatureClass).BrowseName; } else if (mLayer is IRasterLayer) { layerType = EnumLayerType.RasterLayer; FcPath = (mLayer as IRasterLayer).FilePath; } else if (mLayer is KOTilesLayer) { layerType = EnumLayerType.KOTilesLayer; FcPath = (mLayer as KOTilesLayer).DBPath; } pLayerInfo.Layers.Add(new LayerCfg(pLayerInfo) { LayerName = mLayer.Name, Visible = mLayer.Visible, SymbolImg = symbol, Selectable = Layers.FirstOrDefault(x => x.LayerName == mLayer.Name) != null ? Layers.FirstOrDefault(x => x.LayerName == mLayer.Name).Selectable : true, Transparency = Tran, LayerType = layerType, FcPath = FcPath, FcName = FcName, Data = mLayer }); } } catch (Exception ex) { throw ex; } } private Bitmap PreViewFillSymbol(ISymbol pSymbol, int width, int height) { try { IStyleGalleryClass pStyleGalleryClass = new FillSymbolStyleGalleryClass(); if (pSymbol is ILineSymbol) { pStyleGalleryClass = new LineSymbolStyleGalleryClass(); } else if (pSymbol is IMarkerSymbol) { pStyleGalleryClass = new MarkerSymbolStyleGalleryClass(); } Bitmap img = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics gc = Graphics.FromImage(img); //SystemColors.Window IntPtr hdc = gc.GetHdc(); tagRECT rect = new tagRECT(); rect.left = 0; rect.top = 0; rect.right = width; rect.bottom = height; pStyleGalleryClass.Preview(pSymbol, hdc.ToInt32(), ref rect); //gc.Save(); gc.ReleaseHdc(hdc); gc.Dispose(); img.MakeTransparent(System.Drawing.Color.FromArgb(System.Drawing.SystemColors.Window.ToArgb())); //System.IO.FileStream s = File.Open(AppDomain.CurrentDomain.BaseDirectory + "Images\\" + pImgName + ".png",FileMode.Open); //s.Close(); //File.Delete(AppDomain.CurrentDomain.BaseDirectory + "Images\\" + pImgName + ".png"); //img.Save(AppDomain.CurrentDomain.BaseDirectory + "Images\\" + pImgName + ".png"); return img.Clone(new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.PixelFormat.Format32bppArgb); //return img.Clone(new System.Drawing.Rectangle(4, 4, width - 6, height - 6), System.Drawing.Imaging.PixelFormat.Format32bppArgb); } catch (Exception ex) { LogAPI.Debug(ex.Message); return null; } } #region IDockPanel接口属性 public Guid ID { get; set; } public KGIS.Framework.Views.DockStyle DockAreas { get; set; } public Size FloatSize { get; set; } public int DockWidth { get; set; } public int DockHeight { get; set; } public KGIS.Framework.Views.DockStyle DefaultArea { get; set; } public bool ShowCloseButton { get; set; } public bool ShowAutoHideButton { get; set; } public string Title { get; set; } #endregion #region IDataCatalogService 接口 /// /// 返回指定图层对应的节点 /// /// 图层对象 /// 图层节点 public object GetNodeByLayer(ILayer layer) { if (null == layer) return null; List nodes = trlProject.GetNodeList(); TreeListNode layerNode = null; foreach (TreeListNode node in nodes) { if (node["Data"] == layer) { layerNode = node; break; } } nodes.Clear(); return layerNode; } /// /// 返回父节点下与指定图层对应的节点 /// /// 父节点 /// 图层对象 /// 图层节点 public object GetNodeByLayer(object parentNode, ILayer layer) { if (null == layer) return null; TreeListNodes nodes = null; if (parentNode is TreeListNode) { nodes = (parentNode as TreeListNode).Nodes; } else { nodes = trlProject.Nodes; } foreach (TreeListNode node in nodes) { if (node["Data"] == layer) return node; } return null; } /// /// 返回工程树中指定图层名称的节点 /// /// 图层名称 /// 节点 public object GetNodeByLayerName(string layerName) { if (string.IsNullOrEmpty(layerName)) return null; List nodes = trlProject.GetNodeList(); TreeListNode featureNode = null; foreach (TreeListNode node in nodes) { //var ln = node["LayerName"]; if (layerName.Equals(node["LayerName"] as string, StringComparison.OrdinalIgnoreCase)) { featureNode = node; break; } } nodes.Clear(); return featureNode; } /// /// 返回工程树中可选择图层节点的集合 /// /// 节点集合 public object GetSelectableLayerNodes() { List selectableNodes = new List(); //TreeListColumn column1 = trlProject.Columns.ColumnByName("LayerType"); //TreeListColumn column2 = trlProject.Columns.ColumnByName("LayerSelectable"); List nodes = trlProject.GetNodeList(); object obj = null; foreach (TreeListNode node in nodes) { //obj = trlProject.GetRowCellValue(node, column1); obj = node["LayerType"]; if (null == obj) continue; obj = node["Selectable"]; //trlProject.GetRowCellValue(node, column2); if (null == obj || !(bool)obj) continue; selectableNodes.Add(node); } nodes.Clear(); return selectableNodes; } public object GetVisibleLayerNodes(object parentNode = null) { List selectableNodes = new List(); //TreeListColumn column1 = trlProject.Columns.ColumnByName("LayerType"); //TreeListColumn column2 = trlProject.Columns.ColumnByName("LayerSelectable"); TreeListNodes nodes = trlProject.Nodes;//.GetNodeList(); if (parentNode is TreeListNode) { nodes = (parentNode as TreeListNode).Nodes; } object obj = null; foreach (TreeListNode node in nodes) { //obj = trlProject.GetRowCellValue(node, column1); obj = node["LayerType"]; if (null == obj) continue; obj = node["Visible"]; //trlProject.GetRowCellValue(node, column2); if (null == obj || !(bool)obj) continue; selectableNodes.Add(node); } nodes.Clear(); return selectableNodes; } /// /// 返回工程树中选择节点的集合 /// /// 是否按节点索引排序 /// 节点集合 public object GetSelectedNodes(bool orderByIndex) { List nodes = new List(); for (int i = 0; i < trlProject.Selection.Count; i++) { nodes.Add(trlProject.Selection[i]); } if (orderByIndex) { nodes.Sort(delegate (TreeListNode a, TreeListNode b) { if (a.ParentNode == b.ParentNode) { if (null == a.ParentNode) { return trlProject.Nodes.IndexOf(a).CompareTo(trlProject.Nodes.IndexOf(b)); } else { return a.ParentNode.Nodes.IndexOf(a).CompareTo(b.ParentNode.Nodes.IndexOf(b)); } } else { return a.Id.CompareTo(b.Id); } }); } return nodes; } public object AddLayer(ILayer pLayer, object parentNode = null) { LayerCfg layer = null; if (parentNode is TreeListNode) { TreeListNode ParentNode = parentNode as TreeListNode; LayerCfg ParentLayer = Layers.FirstOrDefault(f => f.LayerName == ParentNode["LayerName"].ToTrim()); if (ParentLayer != null) { if (ParentLayer.Data is IGroupLayer) { (ParentLayer.Data as IGroupLayer).Add(pLayer); } layer = new LayerCfg(ParentLayer); ParentLayer.Layers.Insert(0, layer); } } else if (parentNode is LayerCfg) { LayerCfg ParentLayer = parentNode as LayerCfg; if (ParentLayer != null) { if (ParentLayer.Data is IGroupLayer) { (ParentLayer.Data as IGroupLayer).Add(pLayer); } layer = new LayerCfg(ParentLayer); ParentLayer.Layers.Insert(0, layer); } } else { if (_CurrentLayers == null) _CurrentLayers = new LayerCfg(); layer = new LayerCfg(_CurrentLayers); _CurrentLayers.Layers.Insert(0, layer); MapsManager.Instance.MapService.getAxMapControl().Map.AddLayer(pLayer); } #region 图层名称 layer.LayerName = pLayer.Name; #endregion #region 图层是否显示 layer.Visible = pLayer.Visible; #endregion #region 图层透明度 if (pLayer is ILayerEffects mLayerEffects) layer.Transparency = mLayerEffects.Transparency; #endregion #region 图层显示比例尺 layer.MinScale = pLayer.MinimumScale.ToInt(); layer.MaxScale = pLayer.MaximumScale.ToInt(); #endregion layer.Data = pLayer; if (pLayer is IFeatureLayer mFcLayer) { #region 图层要素是否可选择 layer.Selectable = mFcLayer.Selectable; #endregion #region 图层显示过滤条件 IFeatureLayerDefinition pFLDefinition = pLayer as IFeatureLayerDefinition; if (pFLDefinition != null) { layer.DefinitionExpression = pFLDefinition.DefinitionExpression; //Marshal.ReleaseComObject(pFLDefinition); } #endregion #region 图层样式 Renderer randerer = SymbolConvert.Instance().GetRenderer((pLayer as IGeoFeatureLayer).Renderer); LabelingInfo labelingInfo = null; LabelStyleConvert styleConvert = new LabelStyleConvert(); List labelInfo = styleConvert.EsriLabelToCustomLabels((pLayer as IGeoFeatureLayer).AnnotationProperties); if (labelInfo != null && labelInfo.Count > 0) labelingInfo = labelInfo[0]; if (labelingInfo != null) { AdvancedDrawingInfo adi = new AdvancedDrawingInfo(); adi.DrawingInfo.Renderer = randerer; adi.DrawingInfo.LabelingInfo = labelInfo; layer.Symbol = adi.ToJson(); } //LayerCfg layerCfg = _listCfg.FirstOrDefault(f => f.LayerName == pLayer.Name); //if (layerCfg != null) //{ // layer.Symbol = layerCfg.Symbol; // IFeatureRenderer render = GetSymbol(layerCfg.Symbol); // if (render != null) // (pLayer as IGeoFeatureLayer).Renderer = render; //} Bitmap symbol = new Bitmap(22, 16); IGeoFeatureLayer fcLayer = pLayer as IGeoFeatureLayer; if (fcLayer != null) { ISimpleRenderer render = fcLayer.Renderer as ISimpleRenderer; IUniqueValueRenderer un = null; if (render == null) { un = fcLayer.Renderer as IUniqueValueRenderer; Bitmap groupImg = new Bitmap(Image.FromFile(System.IO.Path.Combine(Application.StartupPath, "images", "DjtbLayer" + ".png")), 22, 16); symbol = groupImg;//图层多级图层显示 } else if (render.Symbol != null) { symbol = PreViewFillSymbol(render.Symbol, 22, 16); } } byte[] bytes = null; if (symbol == null) { symbol = new Bitmap(22, 16); } layer.SymbolImg = symbol; #endregion layer.LayerType = EnumLayerType.FeatureLayer; if ((pLayer as IFeatureLayer).FeatureClass != null) layer.FcPath = ((pLayer as IFeatureLayer).FeatureClass as FeatureClass).Workspace.PathName; if ((pLayer as IFeatureLayer).FeatureClass != null) layer.FcName = ((pLayer as IFeatureLayer).FeatureClass as FeatureClass).BrowseName; } else if (pLayer is IRasterLayer) { layer.LayerType = EnumLayerType.RasterLayer; layer.FcPath = (pLayer as IRasterLayer).FilePath; } else if (pLayer is WMTSLayer) { layer.LayerType = EnumLayerType.WMTSLayer; layer.FcPath = UserLoginHelper.GetYXGroupLayerValueByAliasName(layer.LayerName) == "" ? UserLoginHelper.GetAppsetingValueByKey("JSYXUrl") : UserLoginHelper.GetYXGroupLayerValueByAliasName(layer.LayerName); layer.FcName = pLayer.Name; } else if (pLayer is KOTilesLayer) { layer.LayerType = EnumLayerType.KOTilesLayer; layer.FcPath = (pLayer as KOTilesLayer).DBPath; layer.FcName = pLayer.Name; } else if (pLayer is IGroupLayer) { Bitmap groupImg = new Bitmap(Image.FromFile(System.IO.Path.Combine(Application.StartupPath, "images", "grouplayer" + ".png")), 22, 16); layer.LayerType = EnumLayerType.GroupLayer; layer.SymbolImg = groupImg; ILayerGeneralProperties layerGeneralProperties = pLayer as ILayerGeneralProperties; if (string.IsNullOrWhiteSpace(layer.FcName)) layer.FcName = layerGeneralProperties.LayerDescription; } return layer; } public object UpdateLayer(object pData) { if (pData is ILayer pLayer) { LayerCfg layer = Layers.FirstOrDefault(f => f.Data == pLayer); ; if (layer == null) return pData; #region 图层名称 layer.LayerName = pLayer.Name; #endregion #region 图层是否显示 layer.Visible = pLayer.Visible; #endregion #region 图层透明度 if (pLayer is ILayerEffects mLayerEffects) layer.Transparency = mLayerEffects.Transparency; #endregion #region 图层显示比例尺 layer.MinScale = pLayer.MinimumScale.ToInt(); layer.MaxScale = pLayer.MaximumScale.ToInt(); #endregion layer.Data = pLayer; if (pLayer is IFeatureLayer mFcLayer) { #region 图层要素是否可选择 layer.Selectable = mFcLayer.Selectable; #endregion #region 图层显示过滤条件 IFeatureLayerDefinition pFLDefinition = pLayer as IFeatureLayerDefinition; if (pFLDefinition != null) { layer.DefinitionExpression = pFLDefinition.DefinitionExpression; //Marshal.ReleaseComObject(pFLDefinition); } #endregion #region 图层样式 Renderer randerer = SymbolConvert.Instance().GetRenderer((pLayer as IGeoFeatureLayer).Renderer); LabelingInfo labelingInfo = null; LabelStyleConvert styleConvert = new LabelStyleConvert(); List labelInfo = styleConvert.EsriLabelToCustomLabels((pLayer as IGeoFeatureLayer).AnnotationProperties); if (labelInfo != null && labelInfo.Count > 0) labelingInfo = labelInfo[0]; if (labelingInfo != null) { AdvancedDrawingInfo adi = new AdvancedDrawingInfo(); adi.DrawingInfo.Renderer = randerer; adi.DrawingInfo.LabelingInfo = labelInfo; layer.Symbol = adi.ToJson(); } //LayerCfg layerCfg = _listCfg.FirstOrDefault(f => f.LayerName == pLayer.Name); //if (layerCfg != null) //{ // layer.Symbol = layerCfg.Symbol; // IFeatureRenderer render = GetSymbol(layerCfg.Symbol); // if (render != null) // (pLayer as IGeoFeatureLayer).Renderer = render; //} Bitmap symbol = new Bitmap(22, 16); IGeoFeatureLayer fcLayer = pLayer as IGeoFeatureLayer; if (fcLayer != null) { ISimpleRenderer render = fcLayer.Renderer as ISimpleRenderer; IUniqueValueRenderer un = null; if (render == null) { un = fcLayer.Renderer as IUniqueValueRenderer; Bitmap groupImg = new Bitmap(Image.FromFile(System.IO.Path.Combine(Application.StartupPath, "images", "DjtbLayer" + ".png")), 22, 16); symbol = groupImg;//图层多级图层显示 } else if (render.Symbol != null) { symbol = PreViewFillSymbol(render.Symbol, 22, 16); } } byte[] bytes = null; if (symbol == null) { symbol = new Bitmap(22, 16); } layer.SymbolImg = symbol; #endregion layer.LayerType = EnumLayerType.FeatureLayer; layer.FcPath = ((pLayer as IFeatureLayer).FeatureClass as FeatureClass).Workspace.PathName; layer.FcName = ((pLayer as IFeatureLayer).FeatureClass as FeatureClass).BrowseName; } else if (pLayer is IRasterLayer) { layer.LayerType = EnumLayerType.RasterLayer; layer.FcPath = (pLayer as IRasterLayer).FilePath; } else if (pLayer is KOTilesLayer) { layer.LayerType = EnumLayerType.KOTilesLayer; layer.FcPath = (pLayer as KOTilesLayer).DBPath; layer.FcName = pLayer.Name; } else if (pLayer is IGroupLayer) { Bitmap groupImg = new Bitmap(Image.FromFile(System.IO.Path.Combine(Application.StartupPath, "images", "grouplayer" + ".png")), 22, 16); layer.LayerType = EnumLayerType.GroupLayer; layer.SymbolImg = groupImg; ILayerGeneralProperties layerGeneralProperties = pLayer as ILayerGeneralProperties; if (string.IsNullOrWhiteSpace(layer.FcName)) layer.FcName = layerGeneralProperties.LayerDescription; } return layer; } else if (pData is TreeListNode) { return pData; } return pData; } public void RemoveLayer(ILayer pLayer) { if (pLayer == null || Layers == null) return; LayerCfg layerInfo2 = Layers.FirstOrDefault(f => f.Data == pLayer); if (layerInfo2 == null) return; LayerCfg infoTemp = Layers.FirstOrDefault(x => x.ID == layerInfo2.PID); if (infoTemp != null) infoTemp.Layers.Remove(layerInfo2); } public void UpdateTree() { if (CurrentLayers == null) return; Layers = (CurrentLayers as LayerCfg).GetAllItem(); trlProject.ParentFieldName = "PID"; trlProject.KeyFieldName = "ID"; trlProject.CheckBoxFieldName = "Visible"; trlProject.ImageIndexFieldName = "ImgIndex"; trlProject.DataSource = Layers; MapsManager.Instance.MapService.getAxMapControl().ActiveView.ContentsChanged(); MapsManager.Instance.MapService.getAxMapControl().Refresh(); RefreshLayerNode(); } /// /// 刷新节点历史展开 /// private void RefreshLayerNode() { foreach (LayerCfg item in Layers.FindAll(x => x.LayerType == EnumLayerType.GroupLayer)) { if (GetNodeByLayerName(item.LayerName) is TreeListNode rfNode) { rfNode.Expanded = item.Expanded; } } } #endregion private IFeatureRenderer GetSymbol(string pStrSymbol) { IFeatureRenderer result = null; if (!string.IsNullOrWhiteSpace(pStrSymbol)) { AdvancedDrawingInfo ad = AdvancedDrawingInfo.FromJson(pStrSymbol); if (ad != null) { if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.SimpleRenderer) { Symbol symbol1 = (ad.DrawingInfo.Renderer as Framework.LayerStyleConvert.XSDClass.SimpleRenderer).Symbol; ISimpleRenderer simpleRander2 = SymbolConvert.Instance().GetSimpleRenderer(symbol1, SymbolTypeEnum.Fill); result = simpleRander2 as IFeatureRenderer; } else if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer) { Renderer rander = ad.DrawingInfo.Renderer; IUniqueValueRenderer uniqueValueRander = SymbolConvert.Instance().GetUniqueValueRenderer(rander, SymbolTypeEnum.Fill); result = uniqueValueRander as IFeatureRenderer; } } } return result; } #region 类事件方法 /// /// 工程树节点拖动前事件方法 /// /// 事件发送者 /// 事件参数 private void trlProject_BeforeDragNode(object sender, DevExpress.XtraTreeList.BeforeDragNodeEventArgs e) { if (e.Node.Level == 0 || e.Node["Data"] == null) e.CanDrag = false; } /// /// 工程树拖放节点经过事件方法 /// /// 事件发送者 /// 事件参数 private void trlProject_DragOver(object sender, DragEventArgs e) { //目标节点 System.Drawing.Point point = trlProject.PointToClient(new System.Drawing.Point(e.X, e.Y)); TreeListNode targetNode = trlProject.CalcHitInfo(point).Node; //禁止拖放到根节点 if (trlProject.IsRootNode(targetNode)) { e.Effect = DragDropEffects.None; } } /// /// 工程树节点放置后事件方法 /// /// 事件发送者 /// 事件参数 private void trlProject_DragDrop(object sender, DragEventArgs e) { TreeList treeList = sender as TreeList; //最上部的拖动节点 List selectedNodes = GetSelectedNodes(true) as List; if (null == selectedNodes || selectedNodes.Count == 0) return; //最上部的拖动图层 TreeListNode dragNode = selectedNodes[0]; ILayer sourceLayer = dragNode["Data"] as ILayer; if (null == sourceLayer) return; //拖动图层的父节点和父图层 TreeListNode sourceParentNode = null; ILayer sourceParentLayer = null; if (null != dragNode.ParentNode) { sourceParentNode = dragNode.ParentNode; sourceParentLayer = sourceParentNode["Data"] as ILayer; } //放置节点 DXDragEventArgs args = e.GetDXDragEventArgs(treeList); TreeListNode dropNode = args.TargetNode; if (null == dropNode) return; //放置图层 ILayer targetLayer = dropNode["Data"] as ILayer; if (null == targetLayer) return; //放置位置 DragInsertPosition insertPosition = args.DragInsertPosition; bool dropAsChilds = insertPosition == DragInsertPosition.AsChild; if (dropAsChilds && !(targetLayer is ICompositeLayer)) { dropAsChilds = false; } //放置节点的父节点和父图层 TreeListNode targetParentNode = null; ILayer targetParentLayer = null; if (dropAsChilds) { targetParentNode = dropNode; targetParentLayer = dropNode["Data"] as ILayer; } else if (null != dropNode.ParentNode) { targetParentNode = dropNode.ParentNode; targetParentLayer = targetParentNode["Data"] as ILayer; } int dragIndex, dropIndex, targetIndex; List movedLayers = new List(); //拖动节点 treeList.BeginUpdate(); for (int i = 0; i < selectedNodes.Count; i++) { dragNode = selectedNodes[i]; sourceLayer = dragNode["Data"] as ILayer; if (dropAsChilds) { targetIndex = dropNode.Nodes.Count; } else if (sourceParentNode != targetParentNode) { if (insertPosition == DragInsertPosition.After || insertPosition == DragInsertPosition.AsChild) { targetIndex = GetNodeIndex(dropNode) + i + 1; } else { targetIndex = GetNodeIndex(dropNode); } } else { dragIndex = GetNodeIndex(dragNode); dropIndex = GetNodeIndex(dropNode); if (insertPosition == DragInsertPosition.After || insertPosition == DragInsertPosition.AsChild) { targetIndex = dragIndex < dropIndex ? dropIndex + i : dropIndex + i + 1; } else { targetIndex = dragIndex < dropIndex ? dropIndex - 1 : dropIndex; } } treeList.MoveNode(dragNode, targetParentNode, true, targetIndex); movedLayers.Add(sourceLayer); } //更新节点可见性 TreeListColumn column = treeList.Columns.ColumnByName("LayerVisible"); if (sourceParentNode != targetParentNode) { UpdateParentVisible(selectedNodes[0]); if (null != sourceParentNode) { if (sourceParentNode.HasChildren) { UpdateParentVisible(sourceParentNode.Nodes[0]); } else if (treeList.GetRowCellValue(sourceParentNode, column) == null) { treeList.SetRowCellValue(sourceParentNode, column, false); } } } treeList.EndUpdate(); targetIndex = GetNodeIndex(selectedNodes[0]); ReorderLayers(sourceParentLayer, targetParentLayer, movedLayers, targetIndex); selectedNodes.Clear(); movedLayers.Clear(); e.Effect = DragDropEffects.None; //CurrentLayers = treeList.DataSource; //Layers = treeList.DataSource as List; UpdateTree(); } /// /// 工程树获取节点状态图片事件方法 /// /// 事件发送者 /// 事件参数 private void trlProject_GetStateImage(object sender, DevExpress.XtraTreeList.GetStateImageEventArgs e) { int imageIndex = this.GetNodeStateImageIndex(e.Node); if (imageIndex != -1) { e.NodeImageIndex = imageIndex; } } /// /// 工程树鼠标弹起事件方法 /// /// 事件发送者 /// 事件参数 private void trlProject_MouseUp(object sender, MouseEventArgs e) { TreeList treeList = sender as TreeList; if (e.Button != MouseButtons.Right) return; System.Drawing.Point point = new System.Drawing.Point(e.X, e.Y); TreeListNode focusedNode = treeList.CalcHitInfo(point).Node; if (null == focusedNode) { treeList.Selection.Clear(); return; } if (!treeList.Selection.Contains(focusedNode)) { try { treeList.Selection.Set(focusedNode); } catch (Exception ex) { LogAPI.Debug(ex); return; } } ILayer layer = focusedNode["Data"] as ILayer; bool isSingleNodeSelected = treeList.Selection.Count == 1; if (layer == null) { MapsManager.Instance.MapService.SetCustomProperty(MapsManager.Instance.MapService.getAxMapControl().Map); SetMenuEnabled(popMapMenu); popMapMenu.ShowPopup(Control.MousePosition);//弹出右键菜单 } else { MapsManager.Instance.MapService.SetCustomProperty(layer); if (layer is IGroupLayer) { ////图层组 SetMenuEnabled(popGroupMenu); popGroupMenu.ShowPopup(Control.MousePosition);//弹出右键菜单 } else { SetMenuEnabled(popLayerMenu); popLayerMenu.ShowPopup(Control.MousePosition);//弹出右键菜单 } } } /// /// 设置弹出菜单最新状态 /// /// public void SetMenuEnabled(PopupMenu menu) { foreach (LinkPersistInfo menuitem in menu.LinksPersistInfo)//循环设置右键菜单启用/禁用状态 { if ((menuitem.Item as BarButtonItem) != null) { var tmpmenu = menuitem.Item as BarButtonItem; var tmpcmd = tmpmenu.Tag; if (tmpcmd == null) return; Type type = tmpcmd.GetType(); //获取类型 try { var propertyInfo = type.GetProperty("Enabled");//获取最新启用状态 //设置菜单启用禁用 tmpmenu.Enabled = (bool)propertyInfo.GetValue(tmpcmd, null); propertyInfo = type.GetProperty("Caption"); if (propertyInfo == null) return; object title = propertyInfo.GetValue(tmpcmd, null); if (title == null) continue; if (string.IsNullOrWhiteSpace(title.ToTrim())) continue; ; tmpmenu.Caption = title.ToTrim(); } catch (Exception exc) { LogAPI.Debug(exc); } } } } /// /// 工程树选择改变事件方法 /// /// 事件发送者 /// 事件参数 private void trlProject_SelectionChanged(object sender, EventArgs e) { TreeList treeList = sender as TreeList; if (treeList.Selection.Count > 1) { TreeListNode focusedNode = treeList.FocusedNode; int parentNodeId, nodeId; if (null != treeList.Selection[0].ParentNode) { parentNodeId = treeList.Selection[0].ParentNode.Id; } else { parentNodeId = -1; } for (int i = 1; i < treeList.Selection.Count; i++) { if (null != treeList.Selection[i].ParentNode) { nodeId = treeList.Selection[i].ParentNode.Id; } else { nodeId = -1; } if (parentNodeId != nodeId) { treeList.Selection.Set(focusedNode); break; } } } //OnSelectedLayersChanged(); } private void trlProject_AfterCheckNode(object sender, NodeEventArgs e) { //List list = (sender as TreeList).DataSource as List; //var layerInfo = list.FirstOrDefault(f => f.ID == e.Node.Id); //if (layerInfo == null) //{ if (e.Node.GetValue("Data") is ILayer) { ILayer layer = e.Node.GetValue("Data") as ILayer; layer.Visible = e.Node.Checked; SaveProjectInfo(layer.Name, e.Node.Checked, out LayerCfg layerInfo); if (layerInfo != null) LayerCfgList = layerInfo.GetAllItem(); UpdateLayer(e.Node, e.Node.Checked); MapsManager.Instance.MapService.getAxMapControl().ActiveView.Refresh(); } //} } private void SaveProjectInfo(string layerName, bool isCheck, out LayerCfg layerInfo) { layerInfo = null; try { ProjectInfo ProInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; if (ProInfo != null && !string.IsNullOrWhiteSpace(ProInfo.TempData)) { byte[] contentArray = Convert.FromBase64String(ProInfo.TempData); string LayerCfg = System.Text.Encoding.Default.GetString(contentArray); layerInfo = KGIS.Framework.Utils.SerializeAPI.DeserializeToObject(LayerCfg); } layerInfo.GetAllItem().Find(a => a.LayerName == layerName).Visible = isCheck; Byte[] bytearr = System.Text.Encoding.Default.GetBytes(SerializeAPI.SerializeToXML(layerInfo)); string strBase64 = Convert.ToBase64String(bytearr); ProInfo.TempData = strBase64; ProInfo.Save(); } catch (Exception ex) { return; } } List LayerCfgList = new List(); private void UpdateLayer(TreeListNode child, bool isCheck) { if (child != null && child.Nodes != null) { foreach (TreeListNode item in child.Nodes) { ILayer layer = item.GetValue("Data") as ILayer; if (layer == null) continue; if (!isCheck) { layer.Visible = false; } else if (!item.Checked) { layer.Visible = false; } else { LayerCfg layerCfg = LayerCfgList.Find(a => a.LayerName == layer.Name); layer.Visible = layerCfg == null ? layer.Visible : GetParentIsChecked(layerCfg); } UpdateLayer(item, isCheck); } } } private bool GetParentIsChecked(LayerCfg layer) { if (LayerCfgList == null || LayerCfgList.Count == 0) return true; LayerCfg parent = LayerCfgList.Find(a => a.Layers.Contains(layer)); if (parent == null) { return true; } else if (!parent.Visible) { return false; } else { return GetParentIsChecked(parent); } } private void RepositoryItemSpinEdit1_EditValueChanged(object sender, System.EventArgs e) { ILayer layer = trlProject.FocusedNode["Data"] as ILayer; ILayerEffects mLayerEffects = layer as ILayerEffects; if (mLayerEffects != null) { mLayerEffects.Transparency = ((short)(sender as SpinEdit).EditValue.ToInt()); MapsManager.Instance.MapService.getAxMapControl().ActiveView.Refresh(); } } /// /// 工程树图层显示/隐藏选择状态改变事件方法 /// /// 事件发送者 /// 事件参数 private void chkLayerVisible_CheckedChanged(object sender, EventArgs e) { if (null == trlProject.FocusedNode) return; CheckEdit chkVisible = sender as CheckEdit; ILayer layer = trlProject.FocusedNode["Data"] as ILayer; trlProject.BeginUnboundLoad(); TreeListColumn column = trlProject.Columns.ColumnByName("LayerVisible"); trlProject.SetRowCellValue(trlProject.FocusedNode, column, chkVisible.Checked); if (trlProject.FocusedNode.ParentNode != null) { UpdateParentVisible(trlProject.FocusedNode); } if (trlProject.FocusedNode.HasChildren) { UpdateChildVisible(trlProject.FocusedNode); } trlProject.EndUnboundLoad(); if (layer != null) { layer.Visible = chkVisible.Checked; } MapsManager.Instance.MapService.getAxMapControl().ActiveView.Refresh(); //this.ActiveView.Refresh(); //ProjectHelper.MakeDirty(); } /// /// 工程树图层可编辑点击事件方法 /// /// 事件发送者 /// 事件参数 private void chkLayerEditable_Click(object sender, EventArgs e) { if (null == trlProject.FocusedNode) return; TreeListColumn column = trlProject.Columns.ColumnByName("LayerEditable"); object obj = trlProject.GetRowCellValue(trlProject.FocusedNode, column); if (obj == null) return; ILayer layer = trlProject.FocusedNode["Data"] as ILayer; if (null == layer || !layer.Valid || !(layer is IFeatureLayer)) return; IFeatureLayer featureLayer = layer as IFeatureLayer; CheckEdit chkLayerEditable = sender as CheckEdit; switch (chkLayerEditable.CheckState) { case CheckState.Checked: chkLayerEditable.CheckState = CheckState.Unchecked; featureLayer.Selectable = false; trlProject.SetRowCellValue(trlProject.FocusedNode, column, false); //更新编辑捕捉环境 //this.OnSystemSnapChanged(); break; case CheckState.Unchecked: chkLayerEditable.CheckState = CheckState.Checked; featureLayer.Selectable = true; trlProject.SetRowCellValue(trlProject.FocusedNode, column, true); //更新编辑捕捉环境 //this.OnSystemSnapChanged(); break; } //ProjectHelper.MakeDirty(); } private TreeListNode mCurrentEditorNode = null; private void chkLayerEditable_DoubleClick(object sender, EventArgs e) { if (null == trlProject.FocusedNode) return; //TreeListColumn column = trlProject.Columns.ColumnByName("LayerEditable"); //object obj = trlProject.GetRowCellValue(trlProject.FocusedNode, column); //if (obj == null) return; List nodes = trlProject.GetNodeList(); TreeListColumn column = trlProject.Columns.ColumnByName("LayerEditable"); ILayer layer = trlProject.FocusedNode["Data"] as ILayer; if (null == layer || !layer.Valid || !(layer is IFeatureLayer)) return; IFeatureLayer featureLayer = layer as IFeatureLayer; if (featureLayer != null) { IEngineEditor tEngineEdit = new EngineEditorClass(); IEngineEditLayers pEditLayer = tEngineEdit as IEngineEditLayers; //if (pEditLayer.IsEditable(featureLayer)) //{ if (tEngineEdit.EditState != esriEngineEditState.esriEngineStateEditing) { tEngineEdit.StartEditing((featureLayer.FeatureClass as FeatureClass).Workspace, MapsManager.Instance.MapService.getAxMapControl().Map); } pEditLayer.SetTargetLayer(featureLayer, 0); if (mCurrentEditorNode != null) { trlProject.SetRowCellValue(mCurrentEditorNode, column, null); } trlProject.FocusedNode.SetValue(column, true); //trlProject.Columns["NodeName"].AppearanceCell.ForeColor = Color.Red; mCurrentEditorNode = trlProject.FocusedNode;// trlProject.SetRowCellValue(trlProject.FocusedNode, "", true); //} //FormatConditionRuleValue ruleForMark = new FormatConditionRuleValue(); //ruleForMark.Condition = FormatCondition.Expression; //ruleForMark.Expression = "[IsEditable] == true"; //ruleForMark.Appearance.BackColor = Color.Red; //trlProject.FormatRules.Add(trlProject.Columns["NodeName"], ruleForMark); } //ProjectHelper.MakeDirty(); } //private void txtLayerName_DoubleClick(object sender, EventArgs e) //{ // ILayer layer = trlProject.FocusedNode["Data"] as ILayer; // if (null == layer || !layer.Valid || !(layer is IFeatureLayer)) return; // IFeatureLayer featureLayer = layer as IFeatureLayer; // if (featureLayer != null) // { // IEngineEditLayers pEditLayer = new EngineEditorClass(); // pEditLayer.SetTargetLayer(featureLayer, 0); // } //} /// /// 工程树图层可选择状态改变事件方法 /// /// 事件发送者 /// 事件参数 private void chkLayerSelectable_CheckedChanged(object sender, EventArgs e) { try { if (null == trlProject.FocusedNode) return; CheckEdit chkSelectable = sender as CheckEdit; ILayer layer = trlProject.FocusedNode.GetValue("Data") as ILayer; trlProject.BeginUnboundLoad(); TreeListColumn column = trlProject.Columns.ColumnByName("LayerSelectable"); trlProject.SetRowCellValue(trlProject.FocusedNode, column, chkSelectable.Checked); if (trlProject.FocusedNode.ParentNode != null) { UpdateParentSelectable(trlProject.FocusedNode); } if (trlProject.FocusedNode.HasChildren) { UpdateChildSelectable(trlProject.FocusedNode); } if (layer is IFeatureLayer) { (layer as IFeatureLayer).Selectable = chkSelectable.Checked; } trlProject.EndUnboundLoad(); MapsManager.Instance.MapService.getAxMapControl().ActiveView.Refresh(); //ProjectHelper.MakeDirty(); } catch (Exception ex) { LogAPI.Debug(ex.Message); } } #endregion /// /// 返回指定节点的索引 /// /// 节点 /// 节点索引 public int GetNodeIndex(TreeListNode node) { if (null == node) return -1; if (null == node.ParentNode) { return trlProject.Nodes.IndexOf(node); } else { return node.ParentNode.Nodes.IndexOf(node); } } /// /// 返回工程树中指定图层编码的节点 /// /// 图层编码 /// 节点 public TreeListNode GetNodeByLayerId(string layerId) { if (string.IsNullOrEmpty(layerId)) return null; TreeListColumn column = trlProject.Columns.ColumnByName("Id"); List nodes = trlProject.GetNodeList(); TreeListNode layerNode = null; foreach (TreeListNode node in nodes) { if (layerId.Equals(trlProject.GetRowCellValue(node, column) as string, StringComparison.OrdinalIgnoreCase)) { layerNode = node; break; } } nodes.Clear(); return layerNode; } /// /// 返回工程树中可编辑图层节点的集合 /// /// 节点集合 public List GetEditableLayerNodes() { List editableNodes = new List(); TreeListColumn column1 = trlProject.Columns.ColumnByName("LayerType"); TreeListColumn column2 = trlProject.Columns.ColumnByName("LayerEditable"); List nodes = trlProject.GetNodeList(); object obj = null; foreach (TreeListNode node in nodes) { obj = trlProject.GetRowCellValue(node, column1); if (null == obj || (int)obj != (int)EnumFeatureLayerType.ShapeFileFeatureLayer) continue; obj = trlProject.GetRowCellValue(node, column2); if (null != obj && !(bool)obj) continue; editableNodes.Add(node); } nodes.Clear(); return editableNodes; } /// /// 返回工程树中正在编辑节点的集合 /// /// 节点 public TreeListNode GetEditingLayerNode() { TreeListNode editingNode = null; TreeListColumn column1 = trlProject.Columns.ColumnByName("LayerType"); TreeListColumn column2 = trlProject.Columns.ColumnByName("LayerEditable"); List nodes = trlProject.GetNodeList(); object obj = null; foreach (TreeListNode node in nodes) { obj = trlProject.GetRowCellValue(node, column1); if (null == obj || (int)obj != (int)EnumFeatureLayerType.ShapeFileFeatureLayer) continue; obj = trlProject.GetRowCellValue(node, column2); if (null != obj) continue; editingNode = node; break; } nodes.Clear(); return editingNode; } /// /// 更新父节点图层显示的选择状态 /// /// 工程树节点 public void UpdateParentVisible(TreeListNode node) { if (null == node || null == node.ParentNode) return; object obj = null; int visibleCount = 0, pendingCount = 0; TreeListColumn column = trlProject.Columns.ColumnByName("LayerVisible"); foreach (TreeListNode n in node.ParentNode.Nodes) { obj = trlProject.GetRowCellValue(n, column); if (null == obj) { pendingCount++; } else if ((bool)obj) { visibleCount++; } } bool visible = false; if (pendingCount > 0) { trlProject.SetRowCellValue(node.ParentNode, column, null); visible = true; } else if (visibleCount == node.ParentNode.Nodes.Count) { trlProject.SetRowCellValue(node.ParentNode, column, true); visible = true; } else if (visibleCount == 0) { trlProject.SetRowCellValue(node.ParentNode, column, false); visible = false; } else { trlProject.SetRowCellValue(node.ParentNode, column, null); visible = true; } ILayer layer = node.ParentNode["Data"] as ILayer; if (null != layer && layer.Visible != visible) { layer.Visible = visible; } if (null != node.ParentNode.ParentNode) { UpdateParentVisible(node.ParentNode); } } /// /// 更新子节点图层显示的选择状态 /// /// 工程树节点 public void UpdateChildVisible(TreeListNode node) { if (null == node || !node.HasChildren) return; TreeListColumn column = trlProject.Columns.ColumnByName("LayerVisible"); object obj = trlProject.GetRowCellValue(node, column); if (null == obj) return; bool visible = (bool)obj; ILayer layer = null; foreach (TreeListNode n in node.Nodes) { trlProject.SetRowCellValue(n, column, visible); layer = n["Data"] as ILayer; if (null != layer && layer.Visible != visible) { layer.Visible = visible; } if (n.HasChildren) { UpdateChildVisible(n); } } } /// /// 更新父节点图层的可选择状态 /// /// 工程树节点 public void UpdateParentSelectable(TreeListNode node) { if (null == node || null == node.ParentNode) return; object obj = null; int visibleCount = 0, pendingCount = 0; TreeListColumn column = trlProject.Columns.ColumnByName("LayerSelectable"); foreach (TreeListNode n in node.ParentNode.Nodes) { obj = trlProject.GetRowCellValue(n, column); if (null == obj) { pendingCount++; } else if ((bool)obj) { visibleCount++; } } if (pendingCount > 0) { trlProject.SetRowCellValue(node.ParentNode, column, null); } else if (visibleCount == node.ParentNode.Nodes.Count) { trlProject.SetRowCellValue(node.ParentNode, column, true); } else if (visibleCount == 0) { trlProject.SetRowCellValue(node.ParentNode, column, false); } else { trlProject.SetRowCellValue(node.ParentNode, column, null); } if (null != node.ParentNode.ParentNode) { this.UpdateParentSelectable(node.ParentNode); } } /// /// 更新子节点图层的可选择状态 /// /// 工程树节点 public void UpdateChildSelectable(TreeListNode node) { if (null == node || !node.HasChildren) return; TreeListColumn column = trlProject.Columns.ColumnByName("LayerSelectable"); object obj = trlProject.GetRowCellValue(node, column); if (null == obj) return; bool selectable = (bool)obj; ILayer layer = null; foreach (TreeListNode n in node.Nodes) { trlProject.SetRowCellValue(n, column, selectable); layer = n["Data"] as ILayer; if (layer is IFeatureLayer) { (layer as IFeatureLayer).Selectable = selectable; } if (n.HasChildren) { UpdateChildSelectable(n); } } } /// /// 显示图层节点 /// /// 图层节点 public void ShowNode(TreeListNode node) { if (null == node) return; this.trlProject.BeginUpdate(); node.Expand(); this.trlProject.Selection.Clear(); this.trlProject.SelectNode(node); this.trlProject.SetFocusedNode(node); this.trlProject.MakeNodeVisible(node); this.trlProject.EndUpdate(); } /// /// 在父节点下移除已删除图层节点 /// /// 父节点 /// 图层集合 public void OnLayersRemoved(TreeListNode parentNode, List layers) { if (null == layers) return; trlProject.BeginUnboundLoad(); TreeListNode node = null; foreach (ILayer layer in layers) { node = GetNodeByLayer(parentNode, layer) as TreeListNode; if (null == node) continue; if (null != node.ParentNode) { node.ParentNode.Nodes.Remove(node); } else { this.trlProject.Nodes.Remove(node); } } //更新图层可见性 TreeListColumn column = this.trlProject.Columns.ColumnByName("LayerVisible"); if (null != parentNode) { TreeListNode updateNode = parentNode; if (parentNode.HasChildren) { updateNode = parentNode.Nodes[0]; } else if (trlProject.GetRowCellValue(updateNode, column) == null) { trlProject.SetRowCellValue(updateNode, column, true); } UpdateParentVisible(updateNode); UpdateChildVisible(updateNode); UpdateParentSelectable(updateNode); UpdateChildSelectable(updateNode); } trlProject.EndUnboundLoad(); //ProjectHelper.MakeDirty(); } /// /// 查找图层在父节点中的位置索引 /// /// 地图对象 /// 图层父节点 /// 图层 /// 位置索引 private int FindLayerNodeIndex(IMap map, TreeListNode parentNode, ILayer layer) { if (null == layer) return -1; int layerIndex = this.GetLayerIndex(map, layer); if (layerIndex == -1) return -1; TreeListNodes childNodes = null; if (null == parentNode) { childNodes = this.trlProject.Nodes; } else { childNodes = parentNode.Nodes; } int k = 0, childLayerIndex = 0, layerNodeIndex = 0; ILayer childLayer = null; foreach (TreeListNode childNode in childNodes) { k++; if (!(childNode.Tag is ILayer)) continue; childLayer = childNode.Tag as ILayer; childLayerIndex = this.GetLayerIndex(map, childLayer); if (childLayerIndex == -1) continue; if (layerIndex > childLayerIndex) layerNodeIndex = k; } return layerNodeIndex; } public int GetLayerIndex(IMap map, ILayer layer) { if (null == map || null == layer) return -1; for (int i = 0; i < map.LayerCount; i++) { if (map.Layer[i] is ICompositeLayer) { ICompositeLayer groupLayer = map.Layer[i] as ICompositeLayer; for (int j = 0; j < groupLayer.Count; j++) { if (groupLayer.Layer[j] == layer) return i + j; } } if (map.get_Layer(i) == layer) return i; } return -1; } /// /// 返回节点状态图片的索引 /// /// 节点 /// 状态图片索引 private int GetNodeStateImageIndex(TreeListNode node) { if (null == node) return -1; ILayer layer = node.Tag as ILayer; if (null == layer) { return 5; } else if (layer is IFeatureLayer) { IFeatureLayer featureLayer = layer as IFeatureLayer; if (!featureLayer.Valid || null == featureLayer.FeatureClass) { return 4; } switch (featureLayer.FeatureClass.ShapeType) { case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint: return 0; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: return 1; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: return 2; } } else if (layer is IRasterLayer) { return 3; } return -1; } /// /// 调整图层集合中图层的顺序 /// /// 源图层的父图层 /// 目标图层的父图层 /// 图层集合 /// 是否作为子图层 /// 图层的放置索引 /// 图层的放置方向 private void ReorderLayers(ILayer sourceParentLayer, ILayer targetParentLayer, List moveLayers, int targetIndex) { if (null == moveLayers || moveLayers.Count == 0) return; IMap map = MapsManager.Instance.MapService.getAxMapControl().Map; IMapLayers2 mapLayers = map as IMapLayers2; IMapAdmin3 mapAdmin = map as IMapAdmin3; LayerCfg layerInfo = null; //LayerCfg cfg = null;//Layers.FirstOrDefault(f => f.Data == sourceParentLayer); //foreach (var item in Layers) //{ // if (item.Data == sourceParentLayer) // { // cfg = item; // break; // } //} //移除图层 for (int i = 0; i < moveLayers.Count; i++) { //LayerCfg MoveLayerCfg = null;//Layers.FirstOrDefault(f => f.Data == sourceParentLayer); //foreach (var item in Layers) //{ // if (item.Data == moveLayers[i]) // { // MoveLayerCfg = item; // break; // } //} if (null == sourceParentLayer) { map.DeleteLayer(moveLayers[i]); } else { //CurrentLayers //if (cfg != null) //{ // if (MoveLayerCfg != null) // cfg.Layers.Remove(MoveLayerCfg); //} (sourceParentLayer as IGroupLayer).Delete(moveLayers[i]); } mapAdmin.FireLayerDeleted(moveLayers[i]); layerInfo = Layers.FirstOrDefault(f => f.LayerName == moveLayers[i].Name); if (layerInfo != null) { LayerCfg parentLayerInfo = Layers.FirstOrDefault(f => f.ID == layerInfo.PID); parentLayerInfo.Layers.Remove(layerInfo); } } LayerCfg ParentLayInfo = null; //增加图层 for (int i = 0; i < moveLayers.Count; i++) { if (null == targetParentLayer) { mapLayers.InsertLayer(moveLayers[i], false, targetIndex + i); ParentLayInfo = _CurrentLayers; } else { mapLayers.InsertLayerInGroup(targetParentLayer as IGroupLayer, moveLayers[i], false, targetIndex + i); ParentLayInfo = Layers.FirstOrDefault(f => f.LayerName == targetParentLayer.Name); } if (ParentLayInfo != null) { ParentLayInfo.Layers.Insert(targetIndex, layerInfo); } mapAdmin.FireLayerAdded(moveLayers[i]); } //ProjectHelper.MakeDirty(); //刷新地图 IActiveView activeView = map as IActiveView; activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection, null, activeView.Extent); } /// /// 折叠指定节点的所有子节点 /// /// 节点 private void CollapseLayerNode(TreeListNode node) { if (null == node || !node.HasChildren) return; foreach (TreeListNode childNode in node.Nodes) { CollapseLayerNode(childNode); } node.Collapse(); } /// /// 匹配要素样式 /// /// 要素图层 /// 字段名称 /// 唯一值集合 /// 单一值渲染器 public void MatchFeatureStyle(IFeatureLayer featureLayer, string fieldName, List uniqueValues, IUniqueValueRenderer uniqueValueRenderer) { if (null == featureLayer || !featureLayer.Valid || string.IsNullOrEmpty(fieldName) || null == uniqueValues || uniqueValues.Count == 0 || null == uniqueValueRenderer) return; IFeatureClass featureClass = featureLayer.FeatureClass; ESRI.ArcGIS.Geometry.esriGeometryType geometryType = featureClass.ShapeType; //设置单值渲染器的属性. uniqueValueRenderer.FieldCount = 1; uniqueValueRenderer.set_Field(0, fieldName); uniqueValueRenderer.DefaultSymbol = GetDefaultFeatureSymbol(geometryType, null); uniqueValueRenderer.DefaultLabel = null;//Constant.Field_NullValue_Label; uniqueValueRenderer.UseDefaultSymbol = false; //设置算术颜色带 bool ok = false; IAlgorithmicColorRamp randomColorRamp = new AlgorithmicColorRampClass(); randomColorRamp.FromColor = GetColor(100, 100, 60); randomColorRamp.ToColor = GetColor(0, 100, 100); randomColorRamp.Size = uniqueValues.Count * 2; randomColorRamp.CreateRamp(out ok); IEnumColors enumColors = randomColorRamp.Colors; enumColors.Reset(); //设置单值渲染器的值和符号 IStyleGalleryItem styleGalleryItem = null; ISymbol symbol = null; foreach (string uniqueValue in uniqueValues) { switch (geometryType) { case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint: styleGalleryItem = this.GetStyleGalleryItem("Marker Symbols", uniqueValue); break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: styleGalleryItem = this.GetStyleGalleryItem("Line Symbols", uniqueValue); break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: styleGalleryItem = this.GetStyleGalleryItem("Fill Symbols", uniqueValue); break; } if (null != styleGalleryItem) { symbol = styleGalleryItem.Item as ISymbol; } else { symbol = GetDefaultFeatureSymbol(geometryType, enumColors.Next()); } uniqueValueRenderer.AddValue(uniqueValue, fieldName, symbol); uniqueValueRenderer.set_Heading(uniqueValue, uniqueValue); uniqueValueRenderer.set_Label(uniqueValue, uniqueValue); uniqueValueRenderer.set_Description(uniqueValue, uniqueValue); uniqueValueRenderer.set_Symbol(uniqueValue, symbol); } ITable table = featureLayer as ITable; int fieldIndex = table.Fields.FindField(fieldName); bool isStringType = table.Fields.get_Field(fieldIndex).Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString; uniqueValueRenderer.set_FieldType(0, isStringType); uniqueValueRenderer.ColorScheme = "自定义"; if (null != enumColors) DisposeArcGISObject(enumColors); if (null != randomColorRamp) DisposeArcGISObject(randomColorRamp); } private IStyleGalleryItem GetStyleGalleryItem(string styleClassName, string styleName) { if (string.IsNullOrEmpty(styleClassName) || string.IsNullOrEmpty(styleName)) return null; IEnumStyleGalleryItem enumStyleGalleryItem = null; IStyleGalleryItem styleGalleryItem = null; try { //enumStyleGalleryItem = this.styleGallery.get_Items(styleClassName, ConfigHelper.GetStyleFile(), null); //enumStyleGalleryItem.Reset(); //while ((styleGalleryItem = enumStyleGalleryItem.Next()) != null) //{ // if (styleGalleryItem.Name.Equals(styleName, StringComparison.OrdinalIgnoreCase)) // { // return styleGalleryItem; // } //} return null; } catch (Exception ex) { Console.WriteLine(String.Format("获取样式类{0}失败:{1}", styleClassName, ex.Message)); return null; } finally { if (null != enumStyleGalleryItem) { DisposeArcGISObject(enumStyleGalleryItem); } } } public void DisposeArcGISObject(object obj) { if (obj == null) return; int refCount = 1; while (refCount > 0) { refCount = System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); } obj = null; } public static IColor GetColor(int red, int green, int blue) { IRgbColor color = new RgbColor(); color.Red = red; color.Green = green; color.Blue = blue; return color as IColor; } public ISymbol GetDefaultFeatureSymbol(ESRI.ArcGIS.Geometry.esriGeometryType shapeType, IColor color) { switch (shapeType) { case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint: ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass(); markerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle; markerSymbol.Size = 7; markerSymbol.Color = color == null ? GetColor(0, 166, 116) : color; markerSymbol.Outline = true; markerSymbol.OutlineSize = 1; markerSymbol.OutlineColor = GetColor(78, 78, 78); return markerSymbol as ISymbol; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Style = ESRI.ArcGIS.Display.esriSimpleLineStyle.esriSLSSolid; lineSymbol.Color = color == null ? GetColor(230, 152, 0) : color; lineSymbol.Width = 1; return lineSymbol as ISymbol; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: ISimpleLineSymbol borderSymbol = new SimpleLineSymbol(); borderSymbol.Style = ESRI.ArcGIS.Display.esriSimpleLineStyle.esriSLSSolid; borderSymbol.Color = GetColor(110, 110, 110); borderSymbol.Width = 0.4; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = ESRI.ArcGIS.Display.esriSimpleFillStyle.esriSFSSolid; simpleFillSymbol.Color = color == null ? GetColor(238, 205, 247) : color; simpleFillSymbol.Outline = borderSymbol; return simpleFillSymbol as ISymbol; } return null; } /// /// 标注要素图层 /// /// 要素图层 /// 标注表达式 /// 标注文字符号 private void LabelFeatureLayer(IFeatureLayer featureLayer, string labelExpression, ITextSymbol labelTextSymbol) { //if (null == featureLayer || !featureLayer.Valid || string.IsNullOrEmpty(labelExpression)) return; //ILabelEngineLayerProperties2 labelEngineLayerProperties = null; //Response response = MapHelper.CreateFeatureLayerLabelProperties(featureLayer, labelExpression, labelTextSymbol, out labelEngineLayerProperties); //if (response.Code == Constant.Success) //{ // IAnnotateLayerProperties annotateLayerProperties = labelEngineLayerProperties as IAnnotateLayerProperties; // IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer; // geoFeatureLayer.AnnotationProperties.Clear(); // geoFeatureLayer.AnnotationProperties.Add(annotateLayerProperties); // geoFeatureLayer.DisplayAnnotation = true; //} } public void InitCatalogContextMenus(IEnumerable itemDatas) { if (itemDatas == null) return; if (_CmdManager == null) _CmdManager = BundleRuntime.Instance.GetFirstOrDefaultService(); if (_MapService == null) { _MapService = BundleRuntime.Instance.GetFirstOrDefaultService(); } if (_LayerPropertyService == null) { _LayerPropertyService = BundleRuntime.Instance.GetFirstOrDefaultService(); } foreach (var item in itemDatas) { BarItem barItem = DealWithCatalogContextMenus(item); switch (item.ContentItemType) { case "Map": popMapMenu.AddItem(barItem); break; case "Group": popGroupMenu.AddItem(barItem); break; case "Layer": popLayerMenu.AddItem(barItem); break; case "WMTSLayer": popLayerMenu.AddItem(barItem); break; default: break; } } }/// /// 将配置列表数据加载成右击菜单项 /// /// /// private BarItem DealWithCatalogContextMenus(ContentMenuItemEntity pMenuItem) { try { BarItem bar = null; if (pMenuItem.Childs != null && pMenuItem.Childs.Count > 0) { bar = new BarSubItem(); bar.Caption = pMenuItem.Name; bar.Glyph = pMenuItem.GetImage(); //创建子项 foreach (var item in pMenuItem.Childs) { BarItem subItem = DealWithCatalogContextMenus(item); (bar as BarSubItem).AddItem(subItem); barManager1.Items.Add(bar); if (ExtendMethd.JudgeIsCouldConversionStringOrHasValue(item.ParentId) == false) { switch (item.ContentItemType) { case "Map": popMapMenu.AddItem(subItem); break; case "Group": popGroupMenu.AddItem(subItem); break; case "Layer": popLayerMenu.AddItem(subItem); break; case "WMTSLayer": popLayerMenu.AddItem(subItem); break; default: break; } } } } else { bar = new BarButtonItem(); bar.Caption = pMenuItem.Name; bar.ItemClick += Bar_ItemClick; bar.Glyph = pMenuItem.GetImage(); if (_CmdManager != null) bar.Tag = _CmdManager.AddCmd(pMenuItem.CommandId, pMenuItem.Bundle, null); if (bar.Tag is BaseMapMenuCommand && _MapService != null) { (bar.Tag as BaseMapMenuCommand).OnCreate(_MapService.getAxMapControl().Object); } else if (bar.Tag is ICommand && _MapService != null) { (bar.Tag as ICommand).OnCreate(_MapService.getAxMapControl().Object); } barManager1.Items.Add(bar); } return bar; } catch (Exception ex) { LogAPI.Debug("执行 将配置列表数据加载成右击菜单项 方法时异常:" + ex + " ; "); return null; } finally { } } private void Bar_ItemClick(object sender, ItemClickEventArgs e) { BarItem item = e.Item as BarItem; if (item == null || item.Tag == null) { return; } try { if (item.Tag is ITool && _MapService != null) { _MapService.SetCurrentTool(item.Tag); } else if (item.Tag is BaseMapMenuCommand) { CommandManagerInvoke.ExeCommand(item.Tag, null); if (item is BarCheckItem) { (item as BarCheckItem).Checked = (item.Tag as BaseMapMenuCommand).Checked; } } else if (item.Tag is ICommand) { (item.Tag as ICommand).OnClick(); if (item is BarCheckItem) { (item as BarCheckItem).Checked = (item.Tag as ICommand).Checked; } } } catch (Exception ex) { LogAPI.Debug(string.Format("执行【{0}】命令异常,异常信息如下:", item.Caption)); LogAPI.Debug(ex); LogAPI.Debug("异常信息结束"); } } public void InitLayerTree(IMap pMap) { try { //InitTreeNode(pMap); } catch (Exception ex) { MessageHelper.Show("初始化图层树时发生异常,异常信息请查看日志文件"); LogAPI.Debug(string.Format("初始化图层树失败:", ex.Message)); LogAPI.Debug(ex); LogAPI.Debug("异常信息结束"); } } private void repositoryItemPictureEdit1_DoubleClick(object sender, EventArgs e) { try { if (null == trlProject.FocusedNode) return; ILayer layer = trlProject.FocusedNode["Data"] as ILayer; if (layer != null) { if (layer is IFeatureLayer && _LayerPropertyService != null) { _LayerPropertyService.SetLayerStyle(layer); Bitmap symbol = new Bitmap(22, 16); IGeoFeatureLayer fcLayer = layer as IGeoFeatureLayer; if (fcLayer != null) { ISimpleRenderer render = fcLayer.Renderer as ISimpleRenderer; IUniqueValueRenderer un = null; if (render == null) { un = fcLayer.Renderer as IUniqueValueRenderer; } else { symbol = PreViewFillSymbol(render.Symbol, 22, 16); } } byte[] bytes = null; if (symbol == null) { symbol = new Bitmap(22, 16); } MemoryStream ms = new MemoryStream(); symbol.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); bytes = ms.GetBuffer(); //byte[] bytes= ms.ToArray(); 这两句都可以,至于区别么,下面有解释 ms.Close(); TreeListColumn column = trlProject.Columns.ColumnByName("colSymbol"); trlProject.SetRowCellValue(trlProject.FocusedNode, column, symbol); MapsManager.Instance.MapService.getAxMapControl().ActiveView.ContentsChanged(); MapsManager.Instance.MapService.getAxMapControl().ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground | esriViewDrawPhase.esriViewForeground | esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGraphicSelection, null, MapsManager.Instance.MapService.getAxMapControl().ActiveView.Extent); MapsManager.Instance.MapService.getAxMapControl().Refresh(); } } } catch (Exception ex) { LogAPI.Debug("设置图层样式界面加载失败:" + ex); MessageHelper.Show("设置图层样式界面加载失败:" + ex); } } private void colLayerName_DoubleClick(object sender, EventArgs e) { } private void btnLayerName_DoubleClick(object sender, EventArgs e) { try { //if (e.Button != MouseButtons.Left) return; //TreeList tree = s as TreeList; //TreeListHitInfo _hitInfo = tree.CalcHitInfo(e.Location); //TreeListNode CurrentNode = _hitInfo.Node; //ILayer layer = trlProject.FocusedNode.GetValue("Data") as ILayer; if (trlProject.FocusedNode != null) { var Data = trlProject.FocusedNode["Data"]; if (Data is IFeatureLayer) { TreeListColumn column = trlProject.Columns.ColumnByName("LayerEditable"); IFeatureLayer featureLayer = Data as IFeatureLayer; //IEngineEditor tEngineEdit = new EngineEditorClass(); IEngineEditLayers pEditLayer = _Edit as IEngineEditLayers; //if (pEditLayer.IsEditable(featureLayer)) IWorkspace ws = (featureLayer.FeatureClass as FeatureClass).Workspace; if (_Edit.EditState != esriEngineEditState.esriEngineStateEditing) { ProjectInfo ProInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; if (ProInfo != null) { _Edit.StartEditing(ws, MapsManager.Instance.MapService.getAxMapControl().Map); } } else if (_Edit.EditWorkspace != ws) { if (_Edit.HasEdits()) { DialogResult r = MessageHelper.ShowYesNoCancelAndTips("当前图层存在编辑为保存,是否保存编辑内容?"); if (r == DialogResult.Cancel) return; _Edit.StopEditing(r == DialogResult.Yes); _Edit.StartEditing(ws, MapsManager.Instance.MapService.getAxMapControl().Map); } else { _Edit.StopEditing(false); _Edit.StartEditing(ws, MapsManager.Instance.MapService.getAxMapControl().Map); } } pEditLayer.SetTargetLayer(featureLayer, 0); if (mCurrentEditorNode != null) { trlProject.SetRowCellValue(mCurrentEditorNode, "IsEdit", false); trlProject.SetRowCellValue(mCurrentEditorNode, "ImgIndex", 0); } trlProject.FocusedNode.SetValue("IsEdit", true); trlProject.FocusedNode.SetValue("ImgIndex", 1); //trlProject.Columns["NodeName"].AppearanceCell.ForeColor = Color.Red; mCurrentEditorNode = trlProject.FocusedNode; } //DataEntity nodeData = tree.GetDataRecordByNode(CurrentNode) as DataEntity; //ResetNode(nodeData); //ClosePopup(); } } catch (Exception ex) { MessageBox.Show(ex.Message); LogAPI.Debug("双击图层开启编辑失败:" + ex.Message); } } private void btnLayerName_Click(object sender, EventArgs e) { if (e is MouseEventArgs) { if ((e as MouseEventArgs).Button == MouseButtons.Right) { MouseEventArgs eArgs = (e as MouseEventArgs); System.Drawing.Point p = (sender as ButtonEdit).PointToScreen((e as MouseEventArgs).Location); System.Drawing.Point p1 = trlProject.PointToClient(p); MouseEventArgs args = new MouseEventArgs(eArgs.Button, eArgs.Clicks, p1.X, p1.Y, eArgs.Delta); trlProject_MouseUp(trlProject, args); } } } } public enum EnumFeatureLayerType : byte { Unkonwn = 0, ShapeFileFeatureLayer = 1, CADFeatureLayer = 2, SurveyFeatureLayer = 3, FileGDBFeatureLayer = 4, PersonalGDBFeatureLayer = 5, EnterpriseGDBFeatureLayer = 6, CADAnnotationFeatureLayer = 7, CoverageFeatureLayer = 8, CoverageAnnotationFeatureLayer = 9, } public class NodeData { public int NodeID { get; set; } public int NodePID { get; set; } public string NodeName { get; set; } public bool IsVisible { get; set; } public bool IsSelectable { get; set; } public bool IsEditable { get; set; } public int NodeType { get; set; } } }