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.
		
		
		
		
		
			
		
			
				
					
					
						
							246 lines
						
					
					
						
							7.7 KiB
						
					
					
				
			
		
		
	
	
							246 lines
						
					
					
						
							7.7 KiB
						
					
					
				using ESRI.ArcGIS.Carto; | 
						|
using ESRI.ArcGIS.Controls; | 
						|
using ESRI.ArcGIS.esriSystem; | 
						|
using ESRI.ArcGIS.Geometry; | 
						|
using KGIS.Framework.Maps; | 
						|
using KGIS.Framework.Platform; | 
						|
using KGIS.Framework.Utils; | 
						|
using Kingo.Plugin.MapView.Interface; | 
						|
using System; | 
						|
using System.Collections.Generic; | 
						|
using System.Linq; | 
						|
using System.Text; | 
						|
using System.Threading.Tasks; | 
						|
 | 
						|
namespace Kingo.Plugin.MapView.Commands | 
						|
{ | 
						|
    public class BaseSnapCommand2 : ICheckBarItem | 
						|
    { | 
						|
        private IHookHelper m_hookHelper; | 
						|
        private EngineEditorClass m_editor = new EngineEditorClass(); | 
						|
        private ISnappingEnvironment snapEnv = null; | 
						|
        private bool IsChecked = false; | 
						|
        List<IFeatureLayer> layers = new List<IFeatureLayer>(); | 
						|
        public virtual esriSnappingType SnappingType { get { return esriSnappingType.esriSnappingTypeNone; } } | 
						|
 | 
						|
        public bool Checked | 
						|
        { | 
						|
            get | 
						|
            { | 
						|
                IsChecked = (snapEnv.SnappingType & SnappingType) == SnappingType; | 
						|
                return IsChecked; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        public virtual void OnCreate(object hook) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                if (hook == null) | 
						|
                { | 
						|
                    return; | 
						|
                } | 
						|
                if (m_hookHelper == null) | 
						|
                { | 
						|
                    m_hookHelper = new HookHelper(); | 
						|
                    m_hookHelper.Hook = hook; | 
						|
                } | 
						|
 | 
						|
                if (m_hookHelper.ActiveView == null) | 
						|
                { | 
						|
                    m_hookHelper = null; | 
						|
                    return; | 
						|
                } | 
						|
                layers = null; | 
						|
                IHookHelper2 hookHelper2 = m_hookHelper as IHookHelper2; | 
						|
                if (hookHelper2 != null) | 
						|
                { | 
						|
                    IExtensionManager extensionManager = hookHelper2.ExtensionManager; | 
						|
 | 
						|
                    if (extensionManager != null) | 
						|
                    { | 
						|
                        IExtension extension = extensionManager.FindExtension(new UIDClass | 
						|
                        { | 
						|
                            Value = "{E07B4C52-C894-4558-B8D4-D4050018D1DA}"//捕捉 | 
						|
                        }); | 
						|
                        if (extension != null) | 
						|
                        { | 
						|
                            this.snapEnv = (extension as ISnappingEnvironment); | 
						|
                            this.snapEnv.SnappingType = esriSnappingType.esriSnappingTypeEndpoint ^ esriSnappingType.esriSnappingTypeEdge ^ esriSnappingType.esriSnappingTypeVertex; | 
						|
                        } | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                LogAPI.Debug("加载 BaseSnap 类时失败,异常原因: " + ex + " ; "); | 
						|
                m_hookHelper = null; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private IMapService _MapService; | 
						|
 | 
						|
        public virtual void OnClick() | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                this.IsChecked = !this.IsChecked; | 
						|
                if (this.IsChecked) | 
						|
                { | 
						|
                    if (snapEnv != null) | 
						|
                    { | 
						|
                        if ((snapEnv.SnappingType & SnappingType) != SnappingType) | 
						|
                        { | 
						|
                            snapEnv.SnappingType = snapEnv.SnappingType | SnappingType; | 
						|
                        } | 
						|
                    } | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    if (snapEnv != null && (snapEnv.SnappingType & SnappingType) == SnappingType) | 
						|
                    { | 
						|
                        if ((snapEnv.SnappingType ^ SnappingType) == esriSnappingType.esriSnappingTypeNone) | 
						|
                        { | 
						|
                            snapEnv.SnappingType = esriSnappingType.esriSnappingTypeNone; | 
						|
                        } | 
						|
                        else | 
						|
                        { | 
						|
                            if (snapEnv != null && (snapEnv.SnappingType & SnappingType) == SnappingType) | 
						|
                            { | 
						|
                                snapEnv.SnappingType = snapEnv.SnappingType ^ SnappingType; | 
						|
                            } | 
						|
                        } | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                LogAPI.Debug(ex); | 
						|
            } | 
						|
            finally | 
						|
            { | 
						|
 | 
						|
            } | 
						|
        } | 
						|
 | 
						|
 | 
						|
        public int Bitmap | 
						|
        { | 
						|
            get { return 0; } | 
						|
        } | 
						|
 | 
						|
        public string Caption | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
 | 
						|
        public string Category | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
 | 
						|
        public bool Enabled | 
						|
        { | 
						|
            get { return m_editor.EditState == esriEngineEditState.esriEngineStateEditing; } | 
						|
        } | 
						|
 | 
						|
        public int HelpContextID | 
						|
        { | 
						|
            get { return 0; } | 
						|
        } | 
						|
 | 
						|
        public string HelpFile | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
 | 
						|
        public string Message | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
 | 
						|
        public string Name | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
 | 
						|
        public virtual string Tooltip | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
        #region 获取所有可见图层 | 
						|
        ///// <summary> | 
						|
        ///// 获取当前地图中可见的矢量图层 | 
						|
        ///// </summary> | 
						|
        ///// <param name="pMap"></param> | 
						|
        ///// <returns></returns> | 
						|
        //private List<IFeatureLayer> GetVisibleLayer(IMap pMap) | 
						|
        //{ | 
						|
        //    List<IFeatureLayer> result = new List<IFeatureLayer>(); | 
						|
        //    if (pMap == null) | 
						|
        //        return result; | 
						|
        //    try | 
						|
        //    { | 
						|
        //        for (int i = 0; i < pMap.LayerCount; i++) | 
						|
        //        { | 
						|
        //            ILayer layer = pMap.get_Layer(i); | 
						|
        //            if (layer is IFeatureLayer) | 
						|
        //            { | 
						|
        //                if ((layer as IFeatureLayer).Visible) | 
						|
        //                { | 
						|
        //                    result.Add(layer as IFeatureLayer); | 
						|
        //                } | 
						|
        //            } | 
						|
        //            else if (layer is ICompositeLayer) | 
						|
        //            { | 
						|
        //                if ((layer as IGroupLayer).Visible) | 
						|
        //                { | 
						|
        //                    result.AddRange(GetVisibleLayerByGroupLayer(layer as ICompositeLayer)); | 
						|
        //                } | 
						|
        //            } | 
						|
        //        } | 
						|
        //    } | 
						|
        //    catch (Exception ex) | 
						|
        //    { | 
						|
        //        LogAPI.Debug("获取当前地图中可见的矢量图层时失败,异常原因:" + ex + " ; "); | 
						|
        //    } | 
						|
        //    return result; | 
						|
        //} | 
						|
 | 
						|
        //private List<IFeatureLayer> GetVisibleLayerByGroupLayer(ICompositeLayer pGroupLayer) | 
						|
        //{ | 
						|
        //    List<IFeatureLayer> result = new List<IFeatureLayer>(); | 
						|
        //    if (pGroupLayer != null && pGroupLayer.Count > 0) | 
						|
        //    { | 
						|
        //        for (int i = 0; i < pGroupLayer.Count; i++) | 
						|
        //        { | 
						|
        //            ILayer layer = pGroupLayer.get_Layer(i); | 
						|
        //            if (layer is IAnnotationLayer) | 
						|
        //            { | 
						|
 | 
						|
        //            } | 
						|
        //            else if (layer is IGroupLayer) | 
						|
        //            { | 
						|
        //                if ((layer as IGroupLayer).Visible) | 
						|
        //                { | 
						|
        //                    result.AddRange(GetVisibleLayerByGroupLayer(layer as ICompositeLayer)); | 
						|
        //                } | 
						|
        //            } | 
						|
        //            else | 
						|
        //            { | 
						|
        //                if (layer is IFeatureLayer) | 
						|
        //                { | 
						|
        //                    if ((layer as IFeatureLayer).Visible) | 
						|
        //                    { | 
						|
        //                        result.Add((IFeatureLayer)layer); | 
						|
        //                    } | 
						|
        //                } | 
						|
        //            } | 
						|
        //        } | 
						|
        //    } | 
						|
        //    return result; | 
						|
        //} | 
						|
        #endregion | 
						|
 | 
						|
    } | 
						|
}
 | 
						|
 |