⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frminfo.cs

📁 公布ilrbuivbiu复合带搜ifd回复地鸥鸟个能否地偶女男的
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace MainSystem
{
	public struct ItemInfo
	{
		public string szName;
		public string szType;
		public string szSubType;
		public string szTable;
		public string szFieldName;
		public MapObjects2.Recordset rst;
		public MapObjects2.MapLayer layer;
	};

	/// <summary>
	/// Summary description for frmInfo.
	/// </summary>
	public class frmInfo : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label _label_layer;
		private System.Windows.Forms.ListBox _listBox1;
		private System.Windows.Forms.Label _label1;
		private System.Windows.Forms.ComboBox _comboBox1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private frmMain _frmMain;
		private ItemInfo[] _itmInfos;
		private int _nIdx;

		public frmInfo(frmMain mainForm)
		{
			_frmMain = mainForm;
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;

			InitializeComponent();
		}

		
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this._label_layer = new System.Windows.Forms.Label();
			this._listBox1 = new System.Windows.Forms.ListBox();
			this._label1 = new System.Windows.Forms.Label();
			this._comboBox1 = new System.Windows.Forms.ComboBox();
			this.SuspendLayout();
			// 
			// _label_layer
			// 
			this._label_layer.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this._label_layer.Location = new System.Drawing.Point(8, 244);
			this._label_layer.Name = "_label_layer";
			this._label_layer.Size = new System.Drawing.Size(152, 24);
			this._label_layer.TabIndex = 9;
			this._label_layer.Text = "图层名:";
			// 
			// _listBox1
			// 
			this._listBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this._listBox1.ItemHeight = 12;
			this._listBox1.Location = new System.Drawing.Point(8, 52);
			this._listBox1.Name = "_listBox1";
			this._listBox1.SelectionMode = System.Windows.Forms.SelectionMode.None;
			this._listBox1.Size = new System.Drawing.Size(152, 184);
			this._listBox1.TabIndex = 8;
			// 
			// _label1
			// 
			this._label1.Location = new System.Drawing.Point(8, 4);
			this._label1.Name = "_label1";
			this._label1.Size = new System.Drawing.Size(144, 16);
			this._label1.TabIndex = 7;
			// 
			// _comboBox1
			// 
			this._comboBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this._comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this._comboBox1.Location = new System.Drawing.Point(8, 20);
			this._comboBox1.Name = "_comboBox1";
			this._comboBox1.Size = new System.Drawing.Size(152, 20);
			this._comboBox1.TabIndex = 6;
			this._comboBox1.SelectionChangeCommitted += new System.EventHandler(this._comboBox1_SelectionChangeCommitted);
			// 
			// frmInfo
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(168, 273);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this._label_layer,
																		  this._listBox1,
																		  this._label1,
																		  this._comboBox1});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
			this.Name = "frmInfo";
			this.Text = "地物详细信息";
			this.Load += new System.EventHandler(this.frmInfo_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmInfo_Load(object sender, System.EventArgs e)
		{
			_label_layer.Text = "图层名:没有";
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////
		//功能:确定指定位置的地物
		//参数:[in]long x	鼠标位置的X值(像素坐标)
		//		[in]long y	鼠标位置的Y值(像素坐标)
		//返回值:void
		/// /////////////////////////////////////////////////////////////////////////////////////////////////
		public void Identify(long x , long y)
		{
			CEnvironment			env = _frmMain._environment;
			
			env.ClearSelRsts();

			int						nFeatCount = 0;					//选中地物的数目
			MapObjects2.Point		pt;								//鼠标的位置(地图坐标)

			pt = _frmMain._map.ToMapPoint(x,y);

			_nIdx = -1;

			//初始化控件
			_comboBox1.Items.Clear();
			_listBox1.Items.Clear();
  
			_itmInfos = new ItemInfo[env.m_nLayerNum]; 

			//动态计算查询距离
			double dScale = env.CalcScale(_frmMain._map);			//地图比例尺

			if (dScale > 8000)
			{
				dScale = dScale/10000;
				dScale = dScale / 5000;
			}
			else
			{
				dScale = dScale/10000;
				dScale = dScale / 2500;
			}

			//首先,查询点地物,其次,查询线地物,最后查询面状地物
			//查询的图层只要是可见的
			MapObjects2.ShapeTypeConstants[] aShapeType = new MapObjects2.ShapeTypeConstants[3];
			aShapeType[0] = MapObjects2.ShapeTypeConstants.moShapeTypePoint;
			aShapeType[1] = MapObjects2.ShapeTypeConstants.moShapeTypeLine;
			aShapeType[2] = MapObjects2.ShapeTypeConstants.moShapeTypePolygon;

			for (int j = 0; j < 3; j ++)
			{
				for (int i = 0; i < env.m_nLayerNum; i ++)
				{		
					if (env.m_layerInfos[i].layer.shapeType !=aShapeType[j])
						continue;

					_itmInfos[i].szName = "";

					//图层可见并且可选择,才能够identify
					if (env.m_layerInfos[i].layer.Visible && env.m_layerInfos[i].bCanSelected)
					{
						_itmInfos[i].rst = env.m_layerInfos[i].layer.SearchByDistance(pt,dScale,"");
					}
					else
					{
						//图层不可显示,则跳到下一个
						_itmInfos[i].rst = null;

						continue;
					}

					_itmInfos[i].szTable =env.m_layerInfos[i].szTableName;
					_itmInfos[i].layer  =env.m_layerInfos[i].layer ;	
					_itmInfos[i].szType =env.m_layerInfos[i].szType; 
					_itmInfos[i].szSubType =env.m_layerInfos[i].szSubType; 
					_itmInfos[i].szFieldName = env.m_layerInfos[i].szFieldName;  
				
					if (_itmInfos[i].rst != null)
					{
						if (!_itmInfos[i].rst.EOF)
						{
							if (_itmInfos[i].rst.Fields._Item("名称").Value != System.DBNull.Value)
							{
								_itmInfos[i].szName = _itmInfos[i].rst.Fields._Item("名称").Value.ToString();

							}
							else
							{
								_itmInfos[i].rst = null;

								continue;
							}
	
							if (_itmInfos[i].szName != "")
							{
								_comboBox1.Items.Add(_itmInfos[i].szName); 
								nFeatCount ++;
							}
						}
					}
				}
			}

			if (nFeatCount > 0)
			{
				this._label1.Text = "总共找到"+nFeatCount.ToString()+"个地名";
				this._comboBox1.SelectedIndex = 0; 

				_nIdx = 0;

				LoadListBox(GetIndex(_comboBox1.Items[0].ToString()));
			}
			else
			{
				this._label1.Text = "没有找到任何地名";
				_label_layer.Text = "类型:没有"; 
				env.m_selectedSymbol = null;
				env.m_selectedFeature = null;
			}
		}

		/// /////////////////////////////////////////////////////////////////////////////////////////
		/// 功能:显示地名的详细信息
		/// 参数:
		/// 返回值:
		/// ///////////////////////////////////////////////////////////////////////////////////////
		private void LoadListBox(int nIndex)
		{
			if ("" == _itmInfos[nIndex].szName)
				return;

			_listBox1.Items.Clear();


			_label_layer.Text = "类型:"+_itmInfos[nIndex].szSubType; 
  
			if (_itmInfos[nIndex].szTable == "")
			{
				_listBox1.Items.Add("没有详细信息");  

				goto FLASH;
			}
			else
			{
				string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _frmMain._environment.m_szDBName + 
					";Persist Security Info=False";		
				System.Data.OleDb.OleDbConnection  myConnection = new System.Data.OleDb.OleDbConnection(strConnectionString);   
				myConnection.Open();
				System.Data.DataSet dataSet = new System.Data.DataSet("临时库");
				System.Data.OleDb.OleDbDataAdapter myDataAdapter;

				string szSQL;
				szSQL = "Select * From [" + _itmInfos[nIndex].szTable + "] Where "+_itmInfos[nIndex].szFieldName +" ='"+_itmInfos[nIndex].szName+"'";

				myDataAdapter = new System.Data.OleDb.OleDbDataAdapter(szSQL,myConnection);
				
				try
				{
					myDataAdapter.Fill(dataSet,"地名");
				}
				catch
				{
					goto FLASH;
				}

				System.Data.DataTable indexTbl = dataSet.Tables["地名"];
			
				System.Data.DataRow[] rowsType = indexTbl.Select();

				if (0 == rowsType.Length)
				{
					_listBox1.Items.Add("没有详细信息");  

					goto FLASH;
				}

				for (int i = 0; i < indexTbl.Columns.Count; i ++)
				{	
					string szValue = indexTbl.Columns[i].ColumnName + ":" + rowsType[0][i].ToString(); 
					_listBox1.Items.Add(szValue); 
				}

			}
			FLASH:
				_frmMain._map.FlashShape(_itmInfos[nIndex].rst.Fields.Item("Shape").Value ,4);

			//设置选中地物的符号
			if (_frmMain._environment.m_layerInfos[nIndex].nCharacterIndex >= 0 && _frmMain._environment.m_layerInfos[nIndex].layer.shapeType == MapObjects2.ShapeTypeConstants.moShapeTypePoint )
			{
				_frmMain._environment.m_selectedSymbol = new MapObjects2.Symbol();
 
				_frmMain._environment.m_selectedSymbol.SymbolType = MapObjects2.SymbolTypeConstants.moPointSymbol;
				_frmMain._environment.m_selectedSymbol.Font.Name  = _frmMain._environment.m_layerInfos[nIndex].szFontName;
				_frmMain._environment.m_selectedSymbol.Style = 4;
				_frmMain._environment.m_selectedSymbol.Size = (short)_frmMain._environment.m_layerInfos[nIndex].layer.Symbol.Size;
				_frmMain._environment.m_selectedSymbol.CharacterIndex = (short)_frmMain._environment.m_layerInfos[nIndex].nCharacterIndex;
				_frmMain._environment.m_selectedSymbol.Color = 0xff;

				_frmMain._environment.m_selectedSymbolSize = (short)_frmMain._environment.m_layerInfos[nIndex].nSymSize;
			}
			else
			{
				if (_frmMain._environment.m_layerInfos[nIndex].layer.shapeType == MapObjects2.ShapeTypeConstants.moShapeTypePoint )
				{
					_frmMain._environment.m_selectedSymbol = new MapObjects2.Symbol();

					_frmMain._environment.m_selectedSymbol.SymbolType = _frmMain._environment.m_layerInfos[nIndex].layer.Symbol.SymbolType;
					_frmMain._environment.m_selectedSymbol.Style  = _frmMain._environment.m_layerInfos[nIndex].layer.Symbol.Style;
					_frmMain._environment.m_selectedSymbol.Size = _frmMain._environment.m_layerInfos[nIndex].layer.Symbol.Size;
					_frmMain._environment.m_selectedSymbol.Color = 0xff;

					_frmMain._environment.m_selectedSymbolSize = (short)_frmMain._environment.m_layerInfos[nIndex].nSymSize;
				}
				else
					_frmMain._environment.m_selectedSymbol = null;
			}

			_frmMain._environment.m_selectedFeature =_itmInfos[nIndex].rst.Fields.Item("Shape").Value;
			_frmMain._map.Extent = _frmMain._map.Extent; 
		}

		private int GetIndex(string szName)
		{
			int nIndex = -1;

			for (int i = 0; i < _frmMain._environment.m_nLayerNum; i ++)
			{
				if (_itmInfos[i].szName.Equals(szName))
				{
					nIndex = i;
					break;
				}
			}

			return nIndex;
		}

		private void _comboBox1_SelectionChangeCommitted(object sender, System.EventArgs e)
		{
			if (_nIdx != _comboBox1.SelectedIndex)
				_nIdx = _comboBox1.SelectedIndex;
			else
			{
				_frmMain._map.FlashShape(_itmInfos[GetIndex(_comboBox1.Items[_nIdx].ToString())].rst.Fields.Item("Shape").Value ,4);
				return;
			}

			LoadListBox(GetIndex(_comboBox1.Items[_nIdx].ToString()));
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -