www.pudn.com > C sharp和MapObjects实现.rar > CEnvironment.cs


using System; 
using System.Drawing; 
 
namespace MainSystem 
{ 
	///  
	///  
	///  
	public struct LayerInfo 
	{ 
		public string szName; 
		public string szLayerName; 
		public string szFileName; 
		public string szTableName; 
		public string szFieldName; 
		public string szType; 
		public string szSubType;									//中类 
		public string szSubType2;									//小类 
		public string szSubType3; 
		public bool bCanControl; 
		public bool bVisible;										//可显示状态,只能通过图层控制来改变 
		public bool bSelected;										 
		public bool bCanSelected;									//可选择 
		public bool bBackground; 
		public bool bLable; 
		public double dScale; 
		public double dShowScale; 
		public int	nCharacterIndex; 
		public string szFontName; 
		public int  nFontSize; 
		public int	nSymSize; 
		public uint	nSymColor; 
 
		public MapObjects2.MapLayer	layer; 
		public MapObjects2.Recordset	rsSel; 
	}; 
 
	public class MLine 
	{ 
		public int nPointNumber; 
		public MPoint[] pPoint; 
 
		public MLine() 
		{ 
		} 
	};	 
 
	public class CloestPath 
	{ 
		public MPoint pt1 = null; 
		public MPoint pt2 = null; 
	}; 
 
	public class MPoint 
	{ 
		public double x; 
		public double y; 
 
		public MPoint() 
		{ 
		} 
	}; 
 
	public class Buses 
	{ 
		public int		nNum; 
		public MPoint[] pts; 
 
		public Buses() 
		{ 
			pts = new MPoint[200];  
		} 
	} 
 
	enum MapOpr {MO_NULL=0,MO_ZOOMIN,MO_ZOOMOUT,MO_ZOOMFULL,MO_PAN,MO_POINTSEL,MO_RECTSEL,MO_CIRCLESEL,MO_POLYGONSEL,MO_INFO,MO_LINEMEAS,MO_POLYMEAS,MO_SEACHBYDIST,MO_CLOSEST}; 
	enum MapDisp {MO_ALL = 0,MO_SCHOOL = 1, MO_TOUR,MO_HOSPITAL,MO_SHOP,MO_HOTEL,MO_GAS,MO_BANK,MO_MOVIE,MO_RESTAURANT,MO_WS,MO_POST,MO_LIBRAY,MO_STATION} 
 
	public struct MapInfo 
	{ 
		public string szName; 
		public string szMetaTable; 
		public string szIndexTable; 
		public string szType; 
 
		public MapObjects2.Rectangle rect; 
	}; 
 
	public struct IndexInfo 
	{ 
		public string szName; 
		public double dX; 
		public double dY; 
		public MapObjects2.Rectangle m_extent; 
 
	}; 
 
	public class CEnvironment 
	{ 
		//常量 
		public const string BUSLINE_LAYERNAME = "公交线路"; 
		public const string BUSSTATION_LAYERNAME = "公交车站"; 
		public const uint	SYMBOL_COLOR_NONE = 9999; 
 
		public string				m_szDBName = ""; 
		public string				m_szSDBPath = ""; 
		public string				m_AppPath = ""; 
		public string				m_szHelpPath = ""; 
 
		public MapObjects2.DataConnection m_db = null; 
 
		public int					m_nCurrMapIndex = -1; 
		public int					m_nMapNum = -1; 
		public MapInfo[]			m_mapInfos = null; 
 
		public int					m_nLayerNum = -1; 
		public LayerInfo[]			m_layerInfos = null; 
 
		public int					m_nIndexNum = -1; 
		public IndexInfo[]			m_indexInfos = null; 
 
		public MapObjects2.Symbol m_selSymbol = null; 
		public string				m_szfntStation = ""; 
		public char					m_chStation = 'a'; 
		public int					m_nfntStation = 10; 
 
		//		public string				m_szFontName = "";  
 
		public System.Data.DataSet	m_dataSet = null;  
 
		public long					m_x,m_y; 
 
		public  int					m_MapOpr; 
		public	CloestPath			m_cloestPath = null; 
 
		public double				m_dDistance;		//最短距离查询 
		public object				m_selectedFeature = null; 
		public MapObjects2.Symbol m_selectedSymbol = null; 
		public short				m_selectedSymbolSize; 
		public double				m_selectedScale; 
		public MLine[]				m_drawLine = null; 
		public Buses				m_buses = null; 
		public string				m_szBusFilter = ""; 
 
		public	bool				m_bPathInit = false; 
		public CPath				m_path; 
 
		public string				m_szPlaceName = ""; 
 
		public MapObjects2.Rectangle m_shapeRect; 
 
		public MapObjects2.MapLayer m_layerRoad = null; 
 
		public CEnvironment() 
		{ 
			m_MapOpr = (int)MapOpr.MO_NULL; 
  
			m_selSymbol = new MapObjects2.Symbol();   
		 
			m_selSymbol.SymbolType = MapObjects2.SymbolTypeConstants.moPointSymbol;   
			m_selSymbol.Color = 0xff;   
 
			m_path = new CPath(); 
			m_bPathInit = false; 
 
			m_cloestPath = new CloestPath();  
		} 
 
		public int GetMapIndex(string szMapName) 
		{ 
			int nIndex = -1; 
 
			for (int i = 0; i < m_nMapNum; i ++) 
			{ 
				if (szMapName.Equals(m_mapInfos[i].szName)) 
				{ 
					nIndex = i; 
					break; 
				} 
			} 
 
			return nIndex; 
		} 
 
		public int GetLayerIndexByName(string szName) 
		{ 
			int nIndex = -1; 
 
			for (int i = 0; i < m_nLayerNum; i ++) 
			{ 
				if (szName.Equals(this.m_layerInfos[i].szName)) 
				{ 
					nIndex = i; 
					break; 
				} 
			} 
 
			return nIndex; 
		 
		} 
 
		///  
		/// 根据地名得到地名所在的图层名 
		///  
		/// string 地名名称 
		/// string 索引表名称 
		/// 图层名称 
		public string GetLayerName(string szName,string szTblName) 
		{ 
			string szTableName = ""; 
 
			string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + 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 " + szTblName + " Where 名称 ='"+szName+"'"; 
 
			myDataAdapter = new System.Data.OleDb.OleDbDataAdapter(szSQL,myConnection); 
			myDataAdapter.Fill(dataSet,"地名索引"); 
 
			System.Data.DataTable indexTbl = dataSet.Tables["地名索引"]; 
			 
			System.Data.DataRow[] rowsType = indexTbl.Select(); 
 
			if (0 == rowsType.Length) 
				return ""; 
 
			szTableName = rowsType[0]["图层名"].ToString();  
			 
			return szTableName;		 
		} 
 
		public string GetFieldName(string szName) 
		{ 
			string szTable = GetTableName(szName,"地名索引"); 
 
			string szFieldName = "单位名称"; 
 
			string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + 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 "+ this.m_mapInfos[this.m_nCurrMapIndex].szMetaTable +  " Where 属性表名 ='"+szTable+"'"; 
 
			myDataAdapter = new System.Data.OleDb.OleDbDataAdapter(szSQL,myConnection); 
			myDataAdapter.Fill(dataSet,"索引"); 
 
			System.Data.DataTable indexTbl = dataSet.Tables["索引"]; 
			 
			System.Data.DataRow[] rowsType = indexTbl.Select(); 
 
			if (0 == rowsType.Length) 
				return szFieldName; 
 
			szFieldName = rowsType[0]["字段名"].ToString();  
			 
			return szFieldName; 
 
		} 
 
		public string GetTableName(string szName, string szTbleName) 
		{ 
			string szTableName = ""; 
 
			string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + 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 " + szTbleName + " Where 名称 ='"+szName+"'"; 
 
			myDataAdapter = new System.Data.OleDb.OleDbDataAdapter(szSQL,myConnection); 
			myDataAdapter.Fill(dataSet,"地名索引"); 
 
			System.Data.DataTable indexTbl = dataSet.Tables["地名索引"]; 
			 
			System.Data.DataRow[] rowsType = indexTbl.Select(); 
 
			if (0 == rowsType.Length) 
				return szTableName; 
 
			szTableName = rowsType[0]["属性表名"].ToString();  
			 
			return szTableName; 
		} 
 
		public void ExecuteSpatial(AxMapObjects2.AxMap map,object shape,MapObjects2.SearchMethodConstants sMode,bool bMPoint) 
		{ 
			for (int i = 0; i < this.m_nLayerNum; i ++) 
			{ 
				if (bMPoint) 
				{ 
					double dScale = CalcScale(map); 
					if (dScale > 8000) 
					{ 
						dScale = dScale/10000; 
						dScale = dScale / 5000; 
					} 
					else 
					{ 
						dScale = dScale/10000; 
						dScale = dScale / 2500; 
					} 
 
					if (m_layerInfos[i].layer.Visible && m_layerInfos[i].bCanSelected)   
						m_layerInfos[i].rsSel = m_layerInfos[i].layer.SearchByDistance(shape, dScale,""); 
					else 
						m_layerInfos[i].rsSel = null; 
				} 
				else 
				{ 
					if (m_layerInfos[i].layer.Visible && m_layerInfos[i].bCanSelected)   
						m_layerInfos[i].rsSel = m_layerInfos[i].layer.SearchShape(shape, sMode,""); 
					else 
						m_layerInfos[i].rsSel = null; 
				} 
			} 
		} 
 
		public void ClearSelRsts() 
		{ 
			for (int i = 0; i < this.m_nLayerNum; i ++) 
			{ 
		 
				m_layerInfos[i].rsSel = null; 
			} 
		} 
 
		public void DrawRecordset(AxMapObjects2.AxMap map) 
		{ 
 
			for (int i = 0; i < this.m_nLayerNum; i ++) 
			{ 
				if (m_layerInfos[i].layer.Visible) 
				{ 
					 
					if (m_layerInfos[i].rsSel != null) 
					{ 
						MapObjects2.Symbol sym = new MapObjects2.Symbol();  
						sym.SymbolType = m_layerInfos[i].layer.Symbol.SymbolType;  
						sym.Style = m_layerInfos[i].layer.Symbol.Style; 
						sym.Size = m_layerInfos[i].layer.Symbol.Size; 
						sym.Color = 0xff; 
 
						if (m_layerInfos[i].nCharacterIndex >= 0 && m_layerInfos[i].layer.shapeType == MapObjects2.ShapeTypeConstants.moShapeTypePoint ) 
						{ 
							//							sym = m_layerInfos[i].layer.Symbol;  
							//							sym.Color = 0xff; 
 
							sym.SymbolType = MapObjects2.SymbolTypeConstants.moPointSymbol; 
							sym.Font.Name  = m_layerInfos[i].szFontName; 
							sym.Style = 4; 
							sym.Size = m_layerInfos[i].layer.Symbol.Size; 
							sym.CharacterIndex = (short)m_layerInfos[i].nCharacterIndex; 
						} 
 
						m_layerInfos[i].rsSel.MoveFirst(); 
	 
						while  (!m_layerInfos[i].rsSel.EOF) 
						{ 
							map.DrawShape(m_layerInfos[i].rsSel.Fields.Item("Shape").Value,sym); 
							m_layerInfos[i].rsSel.MoveNext();  
						}	 
					} 
				} 
 
			} 
 
		} 
 
		public void DrawSelectedShape(AxMapObjects2.AxMap map, frmMain frm) 
		{ 
			MapObjects2.Symbol sym = new MapObjects2.Symbol();  
			sym.Color = 0xff; 
 
			if (this.m_selectedSymbol == null) 
				map.DrawShape(m_selectedFeature,sym ); 
			else 
			{ 
				double dScale = this.CalcScale(map); 
 
				//				if (m_selectedScale > dScale) 
			{ 
				m_selectedSymbol.Size = frm.ReCalcFontSize(m_selectedSymbolSize,dScale); 
				map.DrawShape(m_selectedFeature,m_selectedSymbol ); 
			} 
			} 
 
		} 
		 
 
		///////////////////////////////////////////////////////////////////  
		/// 功能:判断图层是否可见 
		/// 参数: 
		/// 返回值: 
		/// /////////////////////////////////////////////////////////////// 
		public bool GetLayerVisible(int disp) 
		{ 
			bool bVisible = true; 
			int  nType = 2; 
			string szSubType = ""; 
 
			switch ((MapDisp)disp) 
			{ 
				case MapDisp.MO_ALL: 
					nType = 1; 
					break; 
				case MapDisp.MO_HOSPITAL: 
					szSubType = "医院"; 
					break; 
				case MapDisp.MO_SCHOOL: 
					szSubType = "教育"; 
					break; 
				case MapDisp.MO_SHOP: 
					szSubType = "零售"; 
					break; 
				case MapDisp.MO_TOUR: 
					szSubType = "旅游"; 
					break; 
				case MapDisp.MO_GAS: 
					break; 
				case MapDisp.MO_HOTEL:  
					szSubType = "住宿"; 
					break; 
				case MapDisp.MO_LIBRAY: 
					szSubType = "图书馆"; 
					nType = 3; 
					break; 
				case MapDisp.MO_MOVIE: 
					szSubType = "影剧院、音乐厅"; 
					nType = 3; 
					break; 
				case MapDisp.MO_POST: 
					szSubType = "邮政"; 
					break; 
				case MapDisp.MO_RESTAURANT: 
					szSubType = "餐饮"; 
					break; 
				case MapDisp.MO_WS: 
					szSubType = "dddd"; 
					break; 
				case MapDisp.MO_STATION: 
					szSubType = "站点"; 
					nType = 4; 
					break; 
			} 
 
			int nCount = 0; 
 
			for (int i = 0; i < this.m_nLayerNum; i ++) 
			{ 
				if (m_layerInfos[i].bCanControl)  
				{ 
					switch (nType) 
					{ 
						case 1: 
							nCount ++; 
							if (!m_layerInfos[i].bVisible) 
							{ 
								return false; 
							} 
 
							break; 
						case 2: 
							if (szSubType == m_layerInfos[i].szSubType) 
							{ 
								nCount ++; 
								if (!m_layerInfos[i].bVisible) 
								{ 
									return false; 
								} 
							} 
							break; 
						case 3: 
							if (szSubType == m_layerInfos[i].szSubType2) 
							{ 
								nCount ++; 
								if (!m_layerInfos[i].bVisible) 
								{ 
									return false; 
								} 
							} 
							break; 
						case 4: 
							if (szSubType == m_layerInfos[i].szSubType3) 
							{ 
								nCount ++; 
								if (!m_layerInfos[i].bVisible) 
								{ 
									return false; 
								} 
							} 
							break; 
					} 
				} 
			}		 
 
			if (0 == nCount) 
				bVisible = false; 
 
			return bVisible; 
		} 
 
		///////////////////////////////////////////////////////////////////  
		/// 功能:设置图层是否可见 
		/// 参数: 
		/// 返回值: 
		/// /////////////////////////////////////////////////////////////// 
		public void SetLayerVisible(int disp, bool bVisible, double dScale) 
		{ 
			int  nType = 2; 
			string szSubType = ""; 
 
			switch ((MapDisp)disp) 
			{ 
				case MapDisp.MO_ALL: 
					nType = 1; 
					break; 
				case MapDisp.MO_HOSPITAL: 
					szSubType = "医院"; 
					break; 
				case MapDisp.MO_SCHOOL: 
					szSubType = "教育"; 
					break; 
				case MapDisp.MO_SHOP: 
					szSubType = "零售"; 
					break; 
				case MapDisp.MO_TOUR: 
					szSubType = "旅游"; 
					break; 
				case MapDisp.MO_GAS: 
					break; 
				case MapDisp.MO_HOTEL:  
					szSubType = "住宿"; 
					break; 
				case MapDisp.MO_LIBRAY: 
					szSubType = "图书馆"; 
					nType = 3; 
					break; 
				case MapDisp.MO_MOVIE: 
					szSubType = "影剧院、音乐厅"; 
					nType = 3; 
					break; 
				case MapDisp.MO_POST: 
					szSubType = "邮政"; 
					break; 
				case MapDisp.MO_RESTAURANT: 
					szSubType = "餐饮"; 
					break; 
				case MapDisp.MO_WS: 
					szSubType = "厕所"; 
					break; 
				case MapDisp.MO_STATION: 
					szSubType = "站点"; 
					nType = 4; 
					break; 
			} 
 
			for (int i = 0; i < this.m_nLayerNum; i ++) 
			{ 
				if (m_layerInfos[i].bCanControl)  
				{ 
					switch (nType) 
					{ 
						case 1: 
							if (!bVisible) 
							{ 
								m_layerInfos[i].bVisible = bVisible; 
								m_layerInfos[i].layer.Visible =  m_layerInfos[i].bVisible; 
							} 
							else 
							{ 
								m_layerInfos[i].bVisible = bVisible; 
 
								if (m_layerInfos[i].dScale > dScale) 
									m_layerInfos[i].layer.Visible =  m_layerInfos[i].bVisible; 
							} 
							break; 
						case 2: 
							if (szSubType == m_layerInfos[i].szSubType) 
							{ 
								if (!bVisible) 
								{ 
									m_layerInfos[i].bVisible = bVisible; 
									m_layerInfos[i].layer.Visible =  m_layerInfos[i].bVisible; 
								} 
								else 
								{ 
									m_layerInfos[i].bVisible = bVisible; 
 
									if (m_layerInfos[i].dScale > dScale) 
										m_layerInfos[i].layer.Visible =  m_layerInfos[i].bVisible; 
								} 
							} 
							break; 
						case 3: 
							if (szSubType == m_layerInfos[i].szSubType2) 
							{ 
								if (!bVisible) 
								{ 
									m_layerInfos[i].bVisible = bVisible; 
									m_layerInfos[i].layer.Visible =  m_layerInfos[i].bVisible; 
								} 
								else 
								{ 
									m_layerInfos[i].bVisible = bVisible; 
 
									if (m_layerInfos[i].dScale > dScale) 
										m_layerInfos[i].layer.Visible =  m_layerInfos[i].bVisible; 
								} 
							} 
							break; 
						case 4: 
							if (szSubType == m_layerInfos[i].szSubType3) 
							{ 
								if (!bVisible) 
								{ 
									m_layerInfos[i].bVisible = bVisible; 
									m_layerInfos[i].layer.Visible =  m_layerInfos[i].bVisible; 
								} 
								else 
								{ 
									m_layerInfos[i].bVisible = bVisible; 
 
									if (m_layerInfos[i].dScale > dScale) 
										m_layerInfos[i].layer.Visible =  m_layerInfos[i].bVisible; 
								} 
							} 
							break; 
					} 
				} 
			} 
		} 
 
		private void SubGussFs(ref double X,ref double Y,double B,double L,int nCenterLongi) 
		{ 
			//高斯投影分带 
			int nzonenum; 
			if(nCenterLongi==0) 
			{ 
				nzonenum = (int)L/6+1; 
				nCenterLongi = nzonenum*6-3; 
			} 
			else 
				nzonenum = (int)nCenterLongi/6+1; 
 
			//以弧度为单位的经纬度数值 
			double rB = B/180*3.1415926; 
			double rL = (L-nCenterLongi)/180*3.1415926;		//同时计算了中央经线 
			//1980坐标系参数 
			const double a = 6378245.00;		//长轴 
			const double b = 6356863.50;		//短轴 
			//			const double alpha = 0.0033523299;	//扁率 
			double sqre1 = (a*a-b*b)/(a*a);		//第一偏心率平方 
			//			double sqre2 = (a*a-b*b)/(b*b);		//第二偏心率平方 
			//B:纬度 
			//L:精度 
			//子午圈曲率半径 
			double sinb = Math.Sin(rB); 
			double cosb = Math.Cos(rB); 
			double M = a*(1-sqre1)/(1-sqre1*sinb*sinb)/Math.Sqrt(1-sqre1*sinb*sinb); 
			//卯酉圈曲率半径 
			double N = a/Math.Sqrt(1-sqre1*sinb*sinb); 
			double sqrita = N/M-1; 
			 
			//该纬度点到赤道的子午线弧长 
			double s = a*(1-sqre1)*(1.00505117739*rB-0.00506237764/2*Math.Sin(2*rB)+ 
				0.0000106245/4*Math.Sin(4*rB)-0.00000002081/6*Math.Sin(6*rB)); 
 
			double tanb = Math.Tan(rB); 
			X = s+rL*rL*N/2*sinb*cosb+rL*rL*rL*rL*N/24*sinb*cosb*cosb*cosb*(5-tanb*tanb+9*sqrita*sqrita+4*sqrita); 
			Y = rL*N*cosb+rL*rL*rL*N/6*cosb*cosb*cosb*(1-tanb*tanb+sqrita)+ 
				rL*rL*rL*rL*rL*N/120*cosb*cosb*cosb*cosb*cosb*(5-18*tanb*tanb+tanb*tanb*tanb*tanb); 
			Y = Y+500000+nzonenum*1.0e+6; 
		} 
 
		private void SubGussFs(double X,double Y,double L0,ref double B,ref double L) 
		{    
			double p=57.29577951472; 
			const double a=6.378245000e+06; 
			const double e2=0.00669342162297; 
			const double e12=0.00673852541468; 
			const double c0=0.157046064172e-06; 
			const double c1=0.005051773759; 
			const double c2=0.000029837302; 
			const double c3=0.000000238189; 
 
			double bf0=c0*X; 
			double bf0c=Math.Cos(bf0); 
			double bf0s=Math.Sin(bf0); 
			double bf=bf0+bf0c*(c1*bf0s-c2*Math.Pow(bf0s,3)+c3*Math.Pow(bf0s,5)); 
			double bt=Math.Tan(bf); 
			double bc=Math.Cos(bf); 
			double bs=Math.Sin(bf); 
			double bi=e12*Math.Pow(bc,2); 
			double v2=1.0e+0+bi; 
			double bn=a/Math.Sqrt(1.0-e2*Math.Pow(bs,2)); 
			double yn=Y/bn; 
 
			/*calculate lantitude b */ 
 
			double b1=-v2*bt*Math.Pow(yn,2)/2.0; 
			double b2=-(5.0+3.0*Math.Pow(bt,2)+bi-9.0*bi*Math.Pow(bt,2))*b1*Math.Pow(yn,2)/12.0; 
			double b3=(61.0+90.0*Math.Pow(bt,2)+45.0*Math.Pow(bt,4))*b1*Math.Pow(yn,4)/360.0; 
			B = bf+b1+b2+b3; 
			B = B * p; 
 
			/* calculate the longitude l */ 
 
			double l1=yn/bc; 
			double l2=-(1.0+2.0*Math.Pow(bt,2)+bi)*l1*Math.Pow(yn,2)/6.0; 
			double l3=(5.0+28.0*Math.Pow(bt,2)+24.0*Math.Pow(bt,4)+6.0*bi 
				+8.0*bi*Math.Pow(bt,2))*l1*Math.Pow(yn,4)/120.0; 
			L=l1+l2+l3; 
			L=L * p; 
 
			L=L + L0; 
			if(L > 360.0) 
				L=L - 360.0; 
		} 
 
		private void CalGuassToLB(double dX, double dY, ref double dLongitude, ref double dLatitude)  
		{ 
			// TODO: Add your dispatch handler code here 
			double L0; 
			int nZoonNum; 
						 
			nZoonNum = (int)(dY/(1.0E+6)); 
			L0 = nZoonNum * 6-3; 
			 
			dY = dY - nZoonNum*1.0E+6; 
			SubGussFs(dX,dY-500000,L0,ref dLatitude,ref dLongitude); 
			dLongitude = dLongitude + nZoonNum*6 - 3 ; 
		} 
 
		private void CalGuassFromLB(double dLongitude, double dLatitude, ref double dX, ref double dY, long nCenterL)  
		{ 
			// TODO: Add your dispatch handler code here 
			int CenterL = (int)nCenterL; 
 
			SubGussFs(ref dX,ref dY,dLatitude,dLongitude,CenterL); 
 
			nCenterL = (long)CenterL; 
		} 
 
		private double CalcLenght(MPoint[] pt,int nSize) 
		{ 
			double dLength = 0; 
			double x1=0,x2=0,y1=0,y2=0; 
			int nCenterL = ((int)(pt[0].x)/6+1)*6-3;  
 
			for(int i=0;i= this.CalcLenght(pts, 2)) 
							{ 
								if (bClosest) 
								{ 
									//查找最近 
									string szTemp = rs.Fields.Item("名称").Value.ToString(); 
 
									if (szTemp == "") 
										continue; 
 
									if (((dMinDist < 0) || (dMinDist > dDist)) && (!this.m_szPlaceName.Equals(szTemp))) 
									{ 
										dMinDist = dDist; 
										szPlaceName = szTemp; 
									} 
								} 
								else 
								{ 
									listBox.Items.Add(rs.Fields.Item("名称").Value.ToString());  
							 
								} 
							} 
 
							rs.MoveNext();  
						} 
 
						if (bClosest && (szPlaceName != "") && (!this.m_szPlaceName.Equals(szPlaceName)) ) 
							listBox.Items.Add(szPlaceName);  
 
					} 
				} 
				else 
				{ 
					this.m_layerInfos[i].rsSel = null; 
				} 
			} 
 
			return listBox.Items.Count;   
 
		} 
 
		public bool IsImage(string szName) 
		{ 
			string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + 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 多媒体索引 Where 名称 ='"+szName+"'"; 
 
			myDataAdapter = new System.Data.OleDb.OleDbDataAdapter(szSQL,myConnection); 
			myDataAdapter.Fill(dataSet,"多媒体索引"); 
 
			System.Data.DataTable indexTbl = dataSet.Tables["多媒体索引"]; 
			 
			System.Data.DataRow[] rowsType = indexTbl.Select(); 
 
			if (0 == rowsType.Length) 
				return false; 
	 
			return true;		 
		} 
 
		public MLine  CreateLine(MapObjects2.Line moline) 
		{ 
			 
			MLine line = new MLine(); 
			MapObjects2.Points pts = (MapObjects2.Points)moline.Parts.Item(0); 
			 
			line.nPointNumber = pts.Count; 
			line.pPoint = new MPoint[line.nPointNumber];  
 
			for (int i = 0; i < line.nPointNumber; i++) 
			{ 
				MapObjects2.Point pt = (MapObjects2.Point)pts.Item(i);  
				line.pPoint[i] = new MPoint();  
				line.pPoint[i].x = pt.X; 
				line.pPoint[i].y = pt.Y; 
			} 
 
 
			return line; 
 
			 
		} 
 
 
		public MapObjects2.Point GetPoint(string szName) 
		{ 
			MapObjects2.Point pt = null; 
 
			string szLayer = GetLayerName(szName,"地名索引");    
			string szTable = GetTableName(szName,"地名索引"); 
			 
			if ("" == szTable) 
			{ 
				return null; 
			} 
			int nIndex =  GetLayerIndexByName(szTable);  
 
			if (nIndex < 0) 
				return null; 
 
			//			if (!m_layerInfos[nIndex].layer.Visible) 
			//			{ 
			//				return null; 
			//			} 
			// 
			MapObjects2.Recordset rs; 
			rs = m_layerInfos[nIndex].layer.SearchExpression("名称 like '" + szName + "'"); 
			 
			if (rs != null) 
			{ 
				rs.MoveFirst(); 
  
				if (!rs.EOF)  
				{ 
 
					switch (m_layerInfos[nIndex].layer.shapeType) 
					{ 
						case MapObjects2.ShapeTypeConstants.moShapeTypePoint: 
						{ 
							pt = (MapObjects2.Point)rs.Fields.Item("shape").Value; 
						} 
							break; 
						case MapObjects2.ShapeTypeConstants.moShapeTypeLine: 
						{ 
							MapObjects2.Line line; 
							line = (MapObjects2.Line)(rs.Fields.Item("shape").Value); 
							pt = line.Extent.Center;   
						} 
							break; 
						case MapObjects2.ShapeTypeConstants.moShapeTypePolygon: 
						{ 
							MapObjects2.Polygon  poly; 
							poly = (MapObjects2.Polygon)(rs.Fields.Item("shape").Value); 
							pt = poly.Extent.Center;   
						} 
							break; 
					}  
					 
 
				} 
			} 
		 
			return pt; 
		} 
 
		public MapObjects2.Line GetLine(string szName) 
		{ 
			MapObjects2.Line line = null; 
 
			string szLayer = GetLayerName(szName,"地名索引");    
			string szTable = GetTableName(szName,"地名索引"); 
			 
			if ("" == szTable) 
			{ 
				return null; 
			} 
			int nIndex =  GetLayerIndexByName(szTable);  
 
			if (nIndex < 0) 
				return null; 
 
			//			if (!m_layerInfos[nIndex].layer.Visible) 
			//			{ 
			//				return null; 
			//			} 
 
			MapObjects2.Recordset rs; 
			rs = m_layerInfos[nIndex].layer.SearchExpression("名称 like '" + szName + "'"); 
			 
			if (rs != null) 
			{ 
				rs.MoveFirst(); 
  
				if (!rs.EOF)  
				{ 
 
					switch (m_layerInfos[nIndex].layer.shapeType) 
					{ 
						case MapObjects2.ShapeTypeConstants.moShapeTypePoint: 
							return line; 
						case MapObjects2.ShapeTypeConstants.moShapeTypeLine: 
							line = (MapObjects2.Line)(rs.Fields.Item("shape").Value); 
							break; 
						case MapObjects2.ShapeTypeConstants.moShapeTypePolygon: 
							return line; 
						default: 
							break; 
					}  
					 
				} 
			} 
		 
			return line; 
		}	 
 
		public MPoint FromMapPoint(AxMapObjects2.AxMap map, double x,double y) 
		{ 
			MPoint pt = new MPoint(); 
			double dW = System.Math.Abs( map.Extent.Right - map.Extent.Left); 
			double dH = System.Math.Abs(map.Extent.Top-map.Extent.Bottom)  ; 
			 
			double dRatio = 1.0; 
			double dOrgX=0; 
			double dOrgY=0; 
 
			if(map.Width/dW>map.Height/dH)		//横向居中 
			{ 
				dRatio = map.Height /dH; 
				dOrgX = (map.Width-dW*dRatio)/2; 
			} 
			else if(map.Width/dW 0 车站顺序,否则失败 
		/// //////////////////////////////////////////////////////////////////////////////////////////// 
		public int GetStationOrder(string szLineName, string szStationName) 
		{ 
 
			string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + 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 公交车站路线 " +  " Where 线路名 ='"+szLineName+"' And 站名 ='"+szStationName+" '"; 
 
			myDataAdapter = new System.Data.OleDb.OleDbDataAdapter(szSQL,myConnection); 
			myDataAdapter.Fill(dataSet,"索引"); 
 
			System.Data.DataTable indexTbl = dataSet.Tables["索引"]; 
			 
			System.Data.DataRow[] rowsType = indexTbl.Select(); 
 
			if (0 == rowsType.Length) 
				return -1; 
 
			return (int)rowsType[0]["顺序"];		 
		} 
	} 
}