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.
		
		
		
		
		
			
		
			
				
					
					
						
							498 lines
						
					
					
						
							19 KiB
						
					
					
				
			
		
		
	
	
							498 lines
						
					
					
						
							19 KiB
						
					
					
				using ESRI.ArcGIS.Carto; | 
						|
using ESRI.ArcGIS.Controls; | 
						|
using ESRI.ArcGIS.Display; | 
						|
using ESRI.ArcGIS.Geodatabase; | 
						|
using KGIS.Framework.Utils; | 
						|
using Kingo.Plugin.EngineEditor.Common; | 
						|
using KGIS.Framework.Utils.Helper; | 
						|
using System; | 
						|
using System.Collections.Generic; | 
						|
using System.Drawing; | 
						|
using System.Runtime.InteropServices; | 
						|
using System.Windows; | 
						|
using System.Windows.Controls; | 
						|
using System.Windows.Forms; | 
						|
using System.Windows.Input; | 
						|
using System.Windows.Interop; | 
						|
using System.Windows.Media; | 
						|
using System.Windows.Media.Imaging; | 
						|
 | 
						|
namespace Kingo.Plugin.EngineEditor.Views | 
						|
{ | 
						|
    public delegate void FeatureSelectEventHandler(); | 
						|
 | 
						|
    /// <summary> | 
						|
    /// FrmFeatureSelected.xaml 的交互逻辑 | 
						|
    /// </summary> | 
						|
    public partial class FrmFeatureSelected : Window | 
						|
    { | 
						|
        public int OID; | 
						|
        EngineEditorClass m_editor = null; | 
						|
        ISelectionSet pSelectionSet = null; | 
						|
        //List<int> listSelectObjectID; | 
						|
        List<Bitmap> listSelectBitmap; | 
						|
        ImageList imageListSmall = new ImageList();//产生图像对象 | 
						|
        private IHookHelper M_hookHelper = new HookHelper(); | 
						|
        ILayer layer = null; | 
						|
        IFeatureLayer pFeatureLayer = null; | 
						|
        public bool bReturn = false; | 
						|
        public event FeatureSelectEventHandler featureHandler; | 
						|
        IGeoFeatureLayer GeoFeatureLayer; | 
						|
        IQueryFilter queryFilter = null; | 
						|
        IFeatureCursor pFeatureCursor = null; | 
						|
        IDictionary<int, string> pOid_DLBM = new Dictionary<int, string>(); | 
						|
        IFeature pFeature = null; | 
						|
        BitmapScaleHelper pBitmapHelper = new BitmapScaleHelper(); | 
						|
        public FrmFeatureSelected() | 
						|
        { | 
						|
            InitializeComponent(); | 
						|
            bReturn = true; | 
						|
            if (m_editor == null) | 
						|
            { | 
						|
                m_editor = new EngineEditorClass(); | 
						|
            } | 
						|
            Init(); | 
						|
        } | 
						|
 | 
						|
        /// <summary> | 
						|
        /// Edit Tool 左键 "数据切换" | 
						|
        /// </summary> | 
						|
        /// <param name="m_hookHelper"></param> | 
						|
        /// <param name="item"></param> | 
						|
        public FrmFeatureSelected(IHookHelper m_hookHelper, List<int> item) | 
						|
        { | 
						|
            InitializeComponent(); | 
						|
            try | 
						|
            { | 
						|
                Init(); | 
						|
                bReturn = true; | 
						|
                Bitmap bitmap = null; | 
						|
                int[] selected = new int[1]; | 
						|
                if (m_editor == null) | 
						|
                { | 
						|
                    m_editor = new EngineEditorClass(); | 
						|
                } | 
						|
                this.Title = m_editor.TargetLayer.Name; | 
						|
                //取消当前列名 | 
						|
                //this.nameFine.Header = Title; | 
						|
                M_hookHelper = m_hookHelper; | 
						|
                //this.listView1.View = item; | 
						|
                string where = null; | 
						|
                for (int i = 0; i < item.Count; i++) | 
						|
                { | 
						|
                    //this.listView1.Items.Add(item[i]); | 
						|
                    where += " OBJECTID=" + item[i] + " or"; | 
						|
                } | 
						|
                layer = m_editor.TargetLayer; | 
						|
                pFeatureLayer = layer as IFeatureLayer; | 
						|
                pSelectionSet = (pFeatureLayer as IFeatureSelection).SelectionSet; | 
						|
                IEnumIDs enumIDs = pSelectionSet.IDs; | 
						|
                enumIDs.Reset(); | 
						|
                int objectid = enumIDs.Next(); | 
						|
                if (objectid > 0) | 
						|
                { | 
						|
                    where = where.Substring(0, where.Length - 2); | 
						|
                    queryFilter.WhereClause = where; | 
						|
 | 
						|
                    GeoFeatureLayer = layer as IGeoFeatureLayer; | 
						|
                    pFeatureCursor = pFeatureLayer.Search(queryFilter, true); | 
						|
                    if (!GetDLBMByOid(item.ToArray())) | 
						|
                    { | 
						|
                        LogAPI.Debug("要素转换器打开异常:GetDLBMByOid方法获取地类图斑失败"); | 
						|
                        return; | 
						|
                    } | 
						|
                    IDictionary<string, ISymbol> pDic = GetSymbol(GeoFeatureLayer, pFeatureCursor); | 
						|
                    #region 注释 | 
						|
                    //方法1 缺点,存在相同的图斑报错,原因pDic是主键,不存相同图斑 | 
						|
                    //foreach (KeyValuePair<string, ISymbol> item1 in pDic) | 
						|
                    //{ | 
						|
                    //    bitmap = PreViewFillSymbol(item1.Value, 30, 30); | 
						|
                    //    selected[0] = 4; | 
						|
                    //    bitmap = PhotoScreenShot(bitmap, 3, 3, selected)[0]; | 
						|
                    //    imageListSmall.Images.Add(bitmap); | 
						|
                    //} | 
						|
                    //for (int i = 0; i < item.Count; i++) | 
						|
                    //{ | 
						|
                    //    this.listView1.Items.Add(new FeatureConversion(item[i], (Bitmap)imageListSmall.Images[imageListSmall.Images.Count - i - 1])); | 
						|
                    //    if (item[i].ToString() == objectid.ToString()) | 
						|
                    //    { | 
						|
                    //        this.listView1.SelectedIndex = i; | 
						|
                    //    } | 
						|
                    //} | 
						|
                    //  | 
						|
                    #endregion | 
						|
 | 
						|
                    //方法2 | 
						|
                    foreach (KeyValuePair<int, string> pair in pOid_DLBM) | 
						|
                    { | 
						|
                        if (bitmap != null) | 
						|
                        { | 
						|
                            bitmap.Dispose(); | 
						|
                            bitmap = null; | 
						|
                        } | 
						|
                        if (!string.IsNullOrWhiteSpace(pair.Value) && pDic.ContainsKey(pair.Value)) | 
						|
                        { | 
						|
                            bitmap = pBitmapHelper.PreViewFillSymbol(pDic[pair.Value], 30, 30); | 
						|
                            selected[0] = 4; | 
						|
                            bitmap = pBitmapHelper.PhotoScreenShot(bitmap, 3, 3, selected)[0]; | 
						|
                        } | 
						|
                        if (bitmap == null) | 
						|
                        { | 
						|
                            bitmap = new Bitmap(10, 10); | 
						|
                        } | 
						|
                        this.listView1.Items.Add(new FeatureConversion(pair.Key, bitmap)); | 
						|
                        if (pair.Key == objectid) | 
						|
                        { | 
						|
                            this.listView1.SelectedIndex = this.listView1.Items.Count - 1; | 
						|
                        } | 
						|
 | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                LogAPI.Debug("要素转换器打开异常:" + ex); | 
						|
            } | 
						|
            finally | 
						|
            { | 
						|
                if (pFeature != null) | 
						|
                { | 
						|
                    Marshal.ReleaseComObject(pFeature); | 
						|
                } | 
						|
                if (pFeatureCursor != null) | 
						|
                { | 
						|
                    Marshal.ReleaseComObject(pFeatureCursor); | 
						|
                } | 
						|
                GC.Collect(); | 
						|
            } | 
						|
        } | 
						|
        public FrmFeatureSelected(IHookHelper m_hookHelper, Dictionary<string, List<int>> keyValuePairs) | 
						|
        { | 
						|
            InitializeComponent(); | 
						|
            try | 
						|
            { | 
						|
                Init(); | 
						|
                bReturn = true; | 
						|
                Bitmap bitmap = null; | 
						|
                if (m_editor == null) | 
						|
                    m_editor = new EngineEditorClass(); | 
						|
                M_hookHelper = m_hookHelper; | 
						|
                this.listView1.Items.Clear(); | 
						|
                foreach (var item in keyValuePairs) | 
						|
                { | 
						|
                    foreach (var itemOIDs in item.Value) | 
						|
                    { | 
						|
                        if (bitmap == null) | 
						|
                            bitmap = new Bitmap(9, 9); | 
						|
                        this.listView1.Items.Add(new FeatureConversion(item.Key, itemOIDs, bitmap)); | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                LogAPI.Debug("要素转换器打开异常:" + ex); | 
						|
            } | 
						|
            finally | 
						|
            { | 
						|
                if (pFeature != null) | 
						|
                { | 
						|
                    Marshal.ReleaseComObject(pFeature); | 
						|
                } | 
						|
                if (pFeatureCursor != null) | 
						|
                { | 
						|
                    Marshal.ReleaseComObject(pFeatureCursor); | 
						|
                } | 
						|
                GC.Collect(); | 
						|
            } | 
						|
        } | 
						|
        private IDictionary<string, ISymbol> GetSymbol(IGeoFeatureLayer pGeoFeatureLayer, IFeatureCursor pFeatureCursor) | 
						|
        { | 
						|
            IDictionary<string, ISymbol> pDic = new Dictionary<string, ISymbol>(); | 
						|
            LabelAPI.GetSymbolInfos(pGeoFeatureLayer.Renderer, pFeatureCursor, pDic); | 
						|
 | 
						|
            return pDic; | 
						|
        } | 
						|
        private void Init() | 
						|
        { | 
						|
            //是否展示“识别列表” | 
						|
            this.staPanel.Visibility = Visibility.Collapsed; | 
						|
            this.featureHandler += new FeatureSelectEventHandler(SelectChange); | 
						|
            if (listSelectBitmap == null) | 
						|
            { | 
						|
                listSelectBitmap = new List<Bitmap>(); | 
						|
            } | 
						|
            if (queryFilter == null) | 
						|
            { | 
						|
                queryFilter = new QueryFilterClass(); | 
						|
            } | 
						|
        } | 
						|
        private void listView1_SelectionChanged(object sender, SelectionChangedEventArgs e) | 
						|
        { | 
						|
            //SelectChange(); | 
						|
            if (featureHandler != null) | 
						|
            { | 
						|
                featureHandler(); | 
						|
            } | 
						|
        } | 
						|
        /// <summary> | 
						|
        /// 根据OID获得DLBM | 
						|
        /// </summary> | 
						|
        /// <param name="item">oid数组</param> | 
						|
        /// <returns></returns> | 
						|
        public bool GetDLBMByOid(int[] item) | 
						|
        { | 
						|
            pOid_DLBM.Clear(); | 
						|
            string DLBM = null; | 
						|
            if (pFeatureLayer == null) | 
						|
            { | 
						|
                return false; | 
						|
            } | 
						|
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; | 
						|
            for (int i = 0; i < item.Length; i++) | 
						|
            { | 
						|
                pFeature = pFeatureClass.GetFeature(item[i]); | 
						|
                for (int j = 0; j < pFeature.Fields.FieldCount; j++) | 
						|
                { | 
						|
                    IField field = pFeature.Fields.get_Field(j); | 
						|
                    if (field.Name.ToUpper() != "DLBM" || field.AliasName != "地类编码") | 
						|
                        continue; | 
						|
                    if (pFeature.get_Value(j) is DBNull || pFeature.get_Value(j) == null) | 
						|
                    { | 
						|
                        DLBM = null; | 
						|
                    } | 
						|
                    else | 
						|
                    { | 
						|
                        DLBM = pFeature.get_Value(j).ToString().Trim(); | 
						|
                    } | 
						|
                } | 
						|
                pOid_DLBM.Add(item[i], DLBM); | 
						|
            } | 
						|
            return true; | 
						|
        } | 
						|
        public void SelectChange(bool IsTest) | 
						|
        { | 
						|
            //先清除地图上所有选中要素,但目标图用来选中查询的图层选中图形不清除 | 
						|
            ESRI.ArcGIS.Geometry.IGeometry gg = (m_editor as IEngineEditSketch).Geometry; | 
						|
            this.M_hookHelper.FocusMap.ClearSelection(); | 
						|
            //获取用户选择的OBJECTID | 
						|
            FeatureConversion conversion = listView1.SelectedItem as FeatureConversion; | 
						|
            OID = conversion.OBJECTID; | 
						|
            //OID = listView1.SelectedItem; | 
						|
            pSelectionSet = (pFeatureLayer as IFeatureSelection).SelectionSet; | 
						|
 | 
						|
            IFeatureClass pFeatureclass = pFeatureLayer.FeatureClass; | 
						|
            IQueryFilter pQuery = new QueryFilterClass(); | 
						|
            pQuery.WhereClause = "OBJECTID=" + OID + ""; | 
						|
            IFeatureCursor cursor = pFeatureclass.Search(pQuery, true); | 
						|
            IFeature pFeature = cursor.NextFeature(); | 
						|
            if (pFeature != null) | 
						|
            { | 
						|
                (M_hookHelper.Hook as IMapControlDefault).Map.SelectFeature((pFeatureLayer as ILayer), pFeature); | 
						|
                //KGIS.Common.Utility.CommonAPI.MoveToCenterBySelectFeature(M_hookHelper.Hook as IMapControlDefault, (pFeatureLayer as ILayer), pFeature); | 
						|
            } | 
						|
            this.M_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, M_hookHelper.ActiveView.Extent); | 
						|
            //------------------------------------- | 
						|
            #region  | 
						|
            //if (listSelectObjectID == null) | 
						|
            //{ | 
						|
            //    listSelectObjectID = new List<int>(); | 
						|
            //} | 
						|
            //清除选集 | 
						|
            //pSelectionSet.RemoveList(pSelectionSet.Count, ref listSelectObjectID.ToArray()[0]); | 
						|
            //listSelectObjectID.Clear(); | 
						|
            //listSelectObjectID.Add(OID); | 
						|
            //先清除地图上所有选中要素,但目标图用来选中查询的图层选中图形不清除 | 
						|
            //pSelectionSet.AddList(listSelectObjectID.Count, ref listSelectObjectID.ToArray()[0]); | 
						|
            //M_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, M_hookHelper.ActiveView.Extent); | 
						|
            //this.M_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, M_hookHelper.ActiveView.Extent); | 
						|
            //IFeatureClass pFeatureclass = pFeatureLayer.FeatureClass; | 
						|
            //IQueryFilter pQuery = new QueryFilterClass(); | 
						|
            //pQuery.WhereClause = "OBJECTID=" + OID + ""; | 
						|
            //IFeatureCursor cursor = pFeatureclass.Search(pQuery, true); | 
						|
            //IFeature pFeature = cursor.NextFeature(); | 
						|
            //if (pFeature != null) | 
						|
            //{ | 
						|
            //    (m_editor as IEngineEditSketch).Geometry = pFeature.Shape; | 
						|
            //} | 
						|
 | 
						|
 | 
						|
            //IFeatureSelection pFeatureSele = M_hookHelper.ActiveView.FocusMap.FeatureSelection as IFeatureSelection; | 
						|
            //if (pFeatureSele != null) | 
						|
            //{ | 
						|
            //    pFeatureSele.Add(); | 
						|
            //} | 
						|
            //IEnumFeature pEnumFeature1 = (M_hookHelper.ActiveView.FocusMap.FeatureSelection) as IEnumFeature; | 
						|
            //IEnumFeature pEnumFeature = (pSelectionSet as IFeatureSelection) as IEnumFeature; | 
						|
            //IFeature pFeature = pEnumFeature1.Next(); | 
						|
            //if(pFeature!=null) | 
						|
            //{ | 
						|
            //    (m_editor as IEngineEditSketch).Geometry = pFeature.ShapeCopy; | 
						|
            //} | 
						|
            #endregion | 
						|
        } | 
						|
        public void SelectChange() | 
						|
        { | 
						|
            //先清除地图上所有选中要素,但目标图用来选中查询的图层选中图形不清除 | 
						|
            ESRI.ArcGIS.Geometry.IGeometry gg = (m_editor as IEngineEditSketch).Geometry; | 
						|
            this.M_hookHelper.FocusMap.ClearSelection(); | 
						|
            //获取用户选择的OBJECTID | 
						|
            FeatureConversion conversion = listView1.SelectedItem as FeatureConversion; | 
						|
            OID = conversion.OBJECTID; | 
						|
            pFeatureLayer = KGIS.Framework.Maps.MapsManager.Instance.MapService.GetFeatureLayerByName(conversion.LayerNameByOID); | 
						|
            IQueryFilter pQuery = new QueryFilterClass | 
						|
            { | 
						|
                WhereClause = "OBJECTID=" + OID + "" | 
						|
            }; | 
						|
            IFeatureCursor cursor = pFeatureLayer.FeatureClass.Search(pQuery, true); | 
						|
            IFeature pFeature = cursor.NextFeature(); | 
						|
            if (pFeature != null) | 
						|
            { | 
						|
                (M_hookHelper.Hook as IMapControlDefault).Map.SelectFeature((pFeatureLayer as ILayer), pFeature); | 
						|
            } | 
						|
            this.M_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, M_hookHelper.ActiveView.Extent); | 
						|
        } | 
						|
        private void form_closed(object sender, EventArgs e) | 
						|
        { | 
						|
            //this.DialogResult = true; | 
						|
            GC.Collect(); | 
						|
            this.Close(); | 
						|
            bReturn = false; | 
						|
        } | 
						|
 | 
						|
        private void listView1_MouseDown(object sender, MouseButtonEventArgs e) | 
						|
        { | 
						|
            if (e.LeftButton == MouseButtonState.Pressed) | 
						|
            { | 
						|
                if (featureHandler != null) | 
						|
                { | 
						|
                    featureHandler(); | 
						|
                } | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private void Button_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) | 
						|
        { | 
						|
            int currentOid = listView1.SelectedIndex; | 
						|
            if (currentOid > -1 && currentOid < listView1.Items.Count - 1) | 
						|
            { | 
						|
                ++currentOid; | 
						|
            } | 
						|
            else if (currentOid == listView1.Items.Count - 1) | 
						|
            { | 
						|
                currentOid = 0; | 
						|
            } | 
						|
            listView1.SelectedIndex = currentOid; | 
						|
        } | 
						|
 | 
						|
        private void Btnlist_Click(object sender, RoutedEventArgs e) | 
						|
        { | 
						|
            if (this.staPanel.Visibility == Visibility.Visible) | 
						|
            { | 
						|
                this.staPanel.Visibility = Visibility.Collapsed; | 
						|
            } | 
						|
            else if (this.staPanel.Visibility == Visibility.Collapsed) | 
						|
            { | 
						|
                this.staPanel.Visibility = Visibility.Visible; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        public bool? ShowInMainForm(bool isModel = false) | 
						|
        { | 
						|
            this.ShowInTaskbar = false; | 
						|
            if (System.Windows.Application.Current != null) | 
						|
            { | 
						|
                this.Owner = System.Windows.Application.Current.MainWindow; | 
						|
            } | 
						|
            else | 
						|
            { | 
						|
                WindowInteropHelper helper = new WindowInteropHelper(this); | 
						|
                helper.Owner = ExtensionShowWindow.MainWinForm.Handle; | 
						|
                System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(this); | 
						|
            } | 
						|
            if (isModel) | 
						|
            { | 
						|
                return this.ShowDialog(); | 
						|
            } | 
						|
            else | 
						|
            { | 
						|
 | 
						|
                this.Show(); | 
						|
                return true; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
    } | 
						|
 | 
						|
    public class FeatureConversion | 
						|
    { | 
						|
        private ImageSource img { get; set; } | 
						|
        private int objectid { get; set; } | 
						|
        private string layerNameByOID { get; set; } | 
						|
        public ImageSource IMG | 
						|
        { | 
						|
            get | 
						|
            { | 
						|
                return img; | 
						|
            } | 
						|
        } | 
						|
        public int OBJECTID | 
						|
        { | 
						|
            get | 
						|
            { | 
						|
                return objectid; | 
						|
            } | 
						|
        } | 
						|
        /// <summary> | 
						|
        /// 对应的图层名字 | 
						|
        /// </summary> | 
						|
        public string LayerNameByOID | 
						|
        { | 
						|
            get | 
						|
            { | 
						|
                return layerNameByOID; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        [System.Runtime.InteropServices.DllImport("gdi32.dll")] | 
						|
        public static extern bool DeleteObject(IntPtr hObject); | 
						|
 | 
						|
        public static ImageSource ChangeBitmapToImageSource(Bitmap bitmap) | 
						|
        { | 
						|
            IntPtr hBitmap = bitmap.GetHbitmap(); | 
						|
            ImageSource wpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( | 
						|
                hBitmap, | 
						|
                IntPtr.Zero, | 
						|
                Int32Rect.Empty, | 
						|
                BitmapSizeOptions.FromEmptyOptions()); | 
						|
 | 
						|
            if (!DeleteObject(hBitmap)) | 
						|
            { | 
						|
                if (hBitmap != null) | 
						|
                { | 
						|
                    Marshal.FreeCoTaskMem(hBitmap); | 
						|
                } | 
						|
                else | 
						|
                    throw new System.ComponentModel.Win32Exception(); | 
						|
            } | 
						|
 | 
						|
            return wpfBitmap; | 
						|
        } | 
						|
        public FeatureConversion(int oid, Bitmap img) | 
						|
        { | 
						|
            this.objectid = oid; | 
						|
            this.img = ChangeBitmapToImageSource(img); | 
						|
        } | 
						|
        public FeatureConversion(string layerNamebyOID, int oid, Bitmap img) | 
						|
        { | 
						|
            this.layerNameByOID = layerNamebyOID; | 
						|
            this.objectid = oid; | 
						|
            this.img = ChangeBitmapToImageSource(img); | 
						|
        } | 
						|
        public FeatureConversion(int oid, ImageSource img) | 
						|
        { | 
						|
            this.img = img; | 
						|
            this.objectid = oid; | 
						|
        } | 
						|
    } | 
						|
 | 
						|
}
 | 
						|
 |