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

📄 form1.cs

📁 很好的带有编辑功能、量算功能。可在地图上进行距离、面积、角度测量
💻 CS
📖 第 1 页 / 共 5 页
字号:
			// 
			// m_DeleteArea
			// 
			this.m_DeleteArea.Index = 2;
			this.m_DeleteArea.Text = "面";
			this.m_DeleteArea.Click += new System.EventHandler(this.m_Delete_Area_Click);
			// 
			// toolBarButton23
			// 
			this.toolBarButton23.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// toolBarVertex
			// 
			this.toolBarVertex.DropDownMenu = this.m_Vertex;
			this.toolBarVertex.ImageIndex = 16;
			this.toolBarVertex.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			// 
			// m_Vertex
			// 
			this.m_Vertex.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.menuItem1,
																					 this.menuItem2});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.Text = "线";
			this.menuItem1.Click += new System.EventHandler(this.m_Edit_Vertex_Line_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.Text = "面";
			this.menuItem2.Click += new System.EventHandler(this.m_Edit_Vertex_Area_Click);
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.axTOC1);
			this.panel1.Controls.Add(this.splitter2);
			this.panel1.Controls.Add(this.panel2);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
			this.panel1.Location = new System.Drawing.Point(0, 28);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(192, 439);
			this.panel1.TabIndex = 2;
			// 
			// axTOC1
			// 
			this.axTOC1.ContainingControl = this;
			this.axTOC1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.axTOC1.Location = new System.Drawing.Point(0, 0);
			this.axTOC1.Name = "axTOC1";
			this.axTOC1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axTOC1.OcxState")));
			this.axTOC1.Size = new System.Drawing.Size(192, 252);
			this.axTOC1.TabIndex = 2;
			// 
			// splitter2
			// 
			this.splitter2.Cursor = System.Windows.Forms.Cursors.HSplit;
			this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.splitter2.Location = new System.Drawing.Point(0, 252);
			this.splitter2.Name = "splitter2";
			this.splitter2.Size = new System.Drawing.Size(192, 3);
			this.splitter2.TabIndex = 1;
			this.splitter2.TabStop = false;
			// 
			// panel2
			// 
			this.panel2.Controls.Add(this.mapHawk);
			this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.panel2.Location = new System.Drawing.Point(0, 255);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(192, 184);
			this.panel2.TabIndex = 0;
			// 
			// mapHawk
			// 
			this.mapHawk.ContainingControl = this;
			this.mapHawk.Dock = System.Windows.Forms.DockStyle.Fill;
			this.mapHawk.Location = new System.Drawing.Point(0, 0);
			this.mapHawk.Name = "mapHawk";
			this.mapHawk.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("mapHawk.OcxState")));
			this.mapHawk.Size = new System.Drawing.Size(192, 184);
			this.mapHawk.TabIndex = 0;
			// 
			// splitter1
			// 
			this.splitter1.Location = new System.Drawing.Point(192, 28);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(3, 439);
			this.splitter1.TabIndex = 3;
			this.splitter1.TabStop = false;
			// 
			// tabControl1
			// 
			this.tabControl1.Alignment = System.Windows.Forms.TabAlignment.Bottom;
			this.tabControl1.Controls.Add(this.tabMap);
			this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.tabControl1.ItemSize = new System.Drawing.Size(25, 17);
			this.tabControl1.Location = new System.Drawing.Point(195, 28);
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(517, 439);
			this.tabControl1.TabIndex = 4;
			// 
			// tabMap
			// 
			this.tabMap.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.tabMap.Controls.Add(this.axMap1);
			this.tabMap.Location = new System.Drawing.Point(4, 4);
			this.tabMap.Name = "tabMap";
			this.tabMap.Size = new System.Drawing.Size(509, 414);
			this.tabMap.TabIndex = 0;
			this.tabMap.Text = "地图";
			// 
			// axMap1
			// 
			this.axMap1.ContainingControl = this;
			this.axMap1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.axMap1.Location = new System.Drawing.Point(0, 0);
			this.axMap1.Name = "axMap1";
			this.axMap1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMap1.OcxState")));
			this.axMap1.Size = new System.Drawing.Size(505, 410);
			this.axMap1.TabIndex = 0;
			this.axMap1.OnMouseDown += new ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEventHandler(this.axMap1_OnMouseDown);
			this.axMap1.OnMouseMove += new ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseMoveEventHandler(this.axMap1_OnMouseMove);
			this.axMap1.OnSelectionChanged += new System.EventHandler(this.axMap1_OnSelectionChanged);
			this.axMap1.OnMouseUp += new ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseUpEventHandler(this.axMap1_OnMouseUp);
			this.axMap1.OnDoubleClick += new ESRI.ArcGIS.MapControl.IMapControlEvents2_OnDoubleClickEventHandler(this.axMap1_OnDoubleClick);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(712, 489);
			this.Controls.Add(this.tabControl1);
			this.Controls.Add(this.splitter1);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.toolBar1);
			this.Controls.Add(this.statusBar1);
			this.Menu = this.m_Main;
			this.Name = "Form1";
			this.Text = "Form1";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
			this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
			this.Load += new System.EventHandler(this.Form1_Load);
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.statusBarPanel4)).EndInit();
			this.panel1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.axTOC1)).EndInit();
			this.panel2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.mapHawk)).EndInit();
			this.tabControl1.ResumeLayout(false);
			this.tabMap.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.axMap1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			#region 初始化AO许可对象			
			if (m_AoInitialize == null)
			{
				System.Windows.Forms.MessageBox.Show("Unable to initialize. This application cannot run!");
				this.Close();
			}
			//Determine if the product is available
			esriLicenseStatus licenseStatus = (esriLicenseStatus) m_AoInitialize.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine);
			if (licenseStatus == esriLicenseStatus.esriLicenseAvailable)
			{
				licenseStatus = (esriLicenseStatus) m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
				if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
				{
					System.Windows.Forms.MessageBox.Show("The initialization failed. This application cannot run!");
					this.Close();
				}
			}
			else	
			{				
				System.Windows.Forms.MessageBox.Show("The ArcGIS Engine product is unavailable. This application cannot run!");
				this.Close();
			}
			#endregion			
			
			string strPath;

			try
			{   
//				IMapDocument pMxd;
//				pMxd = new MapDocumentClass();				
//				pMxd.New("Noname43651.mxd");  
//				 
//				axMap1.Map = pMxd.get_Map(0) ;
//				pMxd.SetActiveView(axMap1.ActiveView);  
//				axLayout1.PageLayout = pMxd.PageLayout; 
			
				//向主地图添加图层
				strPath = Application.StartupPath + @"\USA\";  
				axMap1.AddShapeFile(strPath,"STATES");     
				axMap1.AddShapeFile(strPath,"USHIGH");
				axMap1.AddShapeFile(strPath,"CAPITALS");

				#region //设置USHIGH图层显示风格
				ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
				ISimpleRenderer renderer = new SimpleRendererClass(); 

				lineSymbol.Color = GetRGBColor(255,100,100) ;
				lineSymbol.Width =1.2;
				renderer.Symbol =(ISymbol) lineSymbol;

				IGeoFeatureLayer layer=(IGeoFeatureLayer) axMap1.get_Layer(1);
				layer.Renderer =(IFeatureRenderer) renderer;
				#endregion

				#region //设置Captials图层显示风格
				ISimpleMarkerSymbol markSymbol = new SimpleMarkerSymbolClass();
				renderer = new SimpleRendererClass(); 

				markSymbol.Color =GetRGBColor(50,50,50);
				markSymbol.Size =3.5;
				renderer.Symbol =(ISymbol) markSymbol;

				layer=(IGeoFeatureLayer) axMap1.get_Layer(0);
				layer.Renderer =(IFeatureRenderer) renderer;
				#endregion
					
				#region //连接SDE数据库,如果成功就向鹰眼中添加行政区划图层,不成功则添加STATES图层
//				IPropertySet pConn =new PropertySetClass() ;

////				string[] Names = new string[5] {"Server","Instance","User","Password","Version"};
////				string[] Values =new string[5] {"yangsg","esri_sde","sde","sde","DEFAULT"};
////				pConn..SetProperties((object) Names,(object) Values);

//				pConn.SetProperty("Server","yangsg"); 
//				pConn.SetProperty("Instance","esri_sde");
//				pConn.SetProperty("User","sde");
//				pConn.SetProperty("Password","sde");
//				pConn.SetProperty("Version","DEFAULT"); 
//
//				IWorkspaceFactory pWKSF = new  SdeWorkspaceFactoryClass() ;
//				IFeatureWorkspace pWorkspace =(IFeatureWorkspace) pWKSF.Open(pConn,0); 
//				
//				IFeatureClass pFeatureClass = pWorkspace.OpenFeatureClass("sde.行政区划");
//				if (pFeatureClass == null) 
//				{
//					MessageBox.Show("不能添加SDE图层"); 
//					mapHawk.AddShapeFile(strPath,"STATES"); 
//				}
//				else
//				{
//					IFeatureLayer pLayer = new FeatureLayerClass() ;
//					pLayer.FeatureClass = pFeatureClass;
//					pLayer.Name ="sde.行政区划";
//					
//					//向鹰眼地图中添加图层
//					mapHawk.AddLayer((ILayer) pLayer, 0);
//				}    
				#endregion 

				//将TOC与主地图绑定
				axTOC1.SetBuddyControl(axMap1);
	
				//定义坐标系接口
				ISpatialReferenceFactory pSpaRefFactory;
				ISpatialReference pSpaRef;

				//读取坐标系参数文件
				pSpaRefFactory = new SpatialReferenceEnvironmentClass();
                strPath =  strPath + @"USALambert.prj" ;
				pSpaRef = pSpaRefFactory.CreateESRISpatialReferenceFromPRJFile(strPath) ;
				
				//设置主地图投影参数
//				axMap1.SpatialReference =  pSpaRef ;
//				axMap1.ActiveView.Refresh(); 
				
				pMap = axMap1.Map ;
				pForm = new AttributeList();
				pForm.Owner = this;

				pTool = new SurveyTools();
				pTool.Map = axMap1.Map ;

				pEditor = new AoEditor();
				pEditor.Map = axMap1.Map ;
		
			}
			catch( System.Exception err)
			{
				MessageBox.Show(this,err.Message.ToString() );
			}

		}


		private void Form1_SizeChanged(object sender, System.EventArgs e)
		{
			if ( this.Width >1000 ) statusBarPanel4.Width = this.Width - 610;
		}

		private void m_File_Exit_Click(object sender, System.EventArgs e)  //退出
		{
			Application.Exit(); 
		}

		private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			ESRI.ArcGIS.Utility.COMSupport.AOUninitialize.Shutdown();
			m_AoInitialize.Shutdown();
			if (pForm !=null )
			{   
				pForm.Close() ;
				pForm = null;
			}
		}

		private void m_View_Select_Click(object sender, System.EventArgs e)  //选取
		{
			ICommand pCommand ;

			pCommand = new ControlsSelectFeaturesToolClass();
			pCommand.OnCreate(axMap1.Object );
			axMap1.CurrentTool =(ITool) pCommand;

			iMapAction = 1;
			statusBarPanel1.Text ="选择";
		}

		private void m_View_ZoomIn_Click(object sender, System.EventArgs e)  //放大
		{
			ICommand pCommand ;

			pCommand = new ControlsMapZoomInToolClass(); 
			pCommand.OnCreate(axMap1.Object );
			axMap1.CurrentTool =(ITool) pCommand;

			iMapAction = 2;
			statusBarPanel1.Text ="放大";
		}

		private void m_View_ZoomOut_Click(object sender, System.EventArgs e)  //缩小
		{
			ICommand pCommand ;

			pCommand = new ControlsMapZoomOutToolClass() ;
			pCommand.OnCreate(axMap1.Object );
			axMap1.CurrentTool =(ITool) pCommand;

			iMapAction = 3;
			statusBarPanel1.Text ="缩小";
		}
		
		private void m_View_EntireView_Click(object sender, System.EventArgs e)  //全图
		{
			ICommand pCommand ;

			pCommand = new ControlsMapFullExtentCommandClass() ;
			pCommand.OnCreate(axMap1.Object );
			pCommand.OnClick(); 			
		}

		private void m_File_Print_Click(object sender, System.EventArgs e)
		{			
			
			IExport pExport = new ExportJPEGClass();
			pExport.ExportFileName = @"C:\ExportTest1.jpg";

			pExport.Resolution = 96;

			IActiveView pActiveView = axMap1.ActiveView; 
			tagRECT exportRECT = pActiveView.ExportFrame;

			IEnvelope pPixelBoundsEnv = new EnvelopeClass();

⌨️ 快捷键说明

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