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

📄 form1.cs

📁 利用CSharp进行二次开发
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.axLicenseControl1.TabIndex = 27;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(552, 478);
			this.Controls.Add(this.axLicenseControl1);
			this.Controls.Add(this.TrackBar1);
			this.Controls.Add(this.chkSpin);
			this.Controls.Add(this.optTools1);
			this.Controls.Add(this.optTools0);
			this.Controls.Add(this.cmdLoadDocument);
			this.Controls.Add(this.cmdZoomOut);
			this.Controls.Add(this.cmdZoomIn);
			this.Controls.Add(this.cmdFullExtent);
			this.Controls.Add(this.Label1);
			this.Controls.Add(this.lblNavigate);
			this.Controls.Add(this.lblZoom);
			this.Controls.Add(this.lblLoad);
			this.Controls.Add(this.axGlobeControl1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
			this.Load += new System.EventHandler(this.Form1_Load);
			((System.ComponentModel.ISupportInitialize)(this.axGlobeControl1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.TrackBar1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//Initialize the application
			if (CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeEngine) != esriLicenseStatus.esriLicenseCheckedOut)
			{
				if (CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcView) != esriLicenseStatus.esriLicenseCheckedOut)
				{
					if (CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcEditor) != esriLicenseStatus.esriLicenseCheckedOut)
					{
						if (CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcInfo) != esriLicenseStatus.esriLicenseCheckedOut)
						{
							System.Windows.Forms.MessageBox.Show("The initialization failed. This application cannot run!");
							this.Close();
						}
					}
				}
			}

			//Initialize member variables
			m_ActiveView = axGlobeControl1.GlobeDisplay.ActiveViewer;
			m_Camera = m_ActiveView.Camera;
		}

		private void cmdLoadDocument_Click(object sender, System.EventArgs e)
		{
			//Open a file dialog for selecting map documents
			openFileDialog1.Title = "Globe Documents";
			openFileDialog1.DefaultExt = ".3dd";
			openFileDialog1.Filter = "Globe Document(*.3dd)|*.3dd";
			openFileDialog1.ShowDialog();

			//Check a file is selected and that it's a valid Globe document
			//before attempting to load it
			if (openFileDialog1.FileName != "")
			{
				if (axGlobeControl1.Check3dFile(openFileDialog1.FileName) == true)
				{
					axGlobeControl1.Load3dFile(openFileDialog1.FileName);
				}
				else
				{
					MessageBox.Show("Cannot load " + openFileDialog1.FileName);
				}
			}
		}

		private void cmdFullExtent_Click(object sender, System.EventArgs e)
		{
			IGlobeCamera camera = (IGlobeCamera) m_Camera;

			//Make sure that the camera is using global coordinates
			camera.OrientationMode = esriGlobeCameraOrientationMode.esriGlobeCameraOrientationGlobal;

			//Point the camera at 0,0 in lat,long - this is the default target
			IPoint target = new PointClass();
			target.PutCoords(0.0, 0.0);
			target.Z = 0.0;
			m_Camera.Target = target;

			//Reset the camera to its default values
			m_Camera.Azimuth = 140;
			m_Camera.Inclination = 45;
			m_Camera.ViewingDistance = 4.0;
			m_Camera.ViewFieldAngle = 30.0;
			m_Camera.RollAngle = 0.0;
			m_Camera.RecalcUp();
			m_ActiveView.Redraw(false);
		}

		private void cmdZoomIn_Click(object sender, System.EventArgs e)
		{
			//Reset the camera field of view angle to 0.9 of its previous value
			double vfa = m_Camera.ViewFieldAngle;
			m_Camera.ViewFieldAngle = vfa * 0.9;
			m_ActiveView.Redraw(false);
		}

		private void cmdZoomOut_Click(object sender, System.EventArgs e)
		{
			//Reset the camera field of view angle to 1.1 times its previous value
			double vfa = m_Camera.ViewFieldAngle;
			m_Camera.ViewFieldAngle = vfa * 1.1;
			m_ActiveView.Redraw(false);
		}

		private void CalculateMoveFactors(double dist)
		{
			bool bIsAtCenter;
			int indexGlobe;

			//See if the camera is pointing at the center of the globe.
			IGlobeViewer globeViewer = (IGlobeViewer) m_ActiveView;
			globeViewer.GetIsTargetAtCenter(out bIsAtCenter, out indexGlobe);

			//If the camera is pointing at the center of the globe then the zoom speed
			//depends on how far away it is, otherwise the zoom factor is fixed. As the
			//camera approaches the globe surface (where dist = 1) the zoom speed slows
			//down. The other factors were worked out by trial and error.
			if (bIsAtCenter == true)
			{
				m_dZoom = cMinZoom + (cMaxZoom - cMinZoom) * (dist - 1.0) / 3.0;
			}
			else
			{
				m_dZoom = 1.1;
			}
		}

		private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			//Release COM objects, check in extension and shutdown
			ESRI.ArcGIS.Utility.COMSupport.AOUninitialize.Shutdown();
			m_AoInitialize.CheckInExtension(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
			m_AoInitialize.Shutdown();
		}

		private void axGlobeControl1_OnMouseDown(object sender, ESRI.ArcGIS.GlobeControl.IGlobeControlEvents_OnMouseDownEvent e)
		{
			//Mouse down should initiate a zoom only if the Zoom check box is checked
			if (m_bZooming == false)
			{
				return;
			}

			if (e.button == 1)
			{
				m_bMouseDown = true;
				m_pMousePos.X = e.x;
				m_pMousePos.Y = e.y;
			}
		}

		private void axGlobeControl1_OnMouseUp(object sender, ESRI.ArcGIS.GlobeControl.IGlobeControlEvents_OnMouseUpEvent e)
		{
			//Cancel the zoom operation
			m_bMouseDown = false;
			//Navigate can cancel spin - make sure it starts again
			if (m_dSpinSpeed > 0)
			{
				axGlobeControl1.GlobeViewer.StartSpinning(esriGlobeSpinDirection.esriCounterClockwise);
			}
		}

		private void axGlobeControl1_OnMouseMove(object sender, ESRI.ArcGIS.GlobeControl.IGlobeControlEvents_OnMouseMoveEvent e)
		{
			if (m_bMouseDown == false)
			{
				return;
			}

			//If we're in a zoom operation then
			//Get the difference in mouse position between this and the last one
			double dx = e.x - m_pMousePos.X;
			double dy = e.y - m_pMousePos.Y;
			if ((dx == 0) & (dy == 0)) 
			{
				return;					   
			}

			//Work out how far the observer is currently from the globe and use this
			//distance to determine how far to move
			IPoint observer = m_Camera.Observer;
			double zObs;
			double xObs; 
			double yObs;
			double dist; 
			observer.QueryCoords(out xObs, out yObs);
			zObs = observer.Z;
			dist = System.Math.Sqrt(xObs * xObs + yObs * yObs + zObs * zObs);
			CalculateMoveFactors(dist);

			//Zoom out and in as the mouse moves up and down the screen respectively
			if ((dy < 0) & (dist < cDistanceZoomLimit)) 
			{
				m_Camera.Zoom(m_dZoom);
			}
			else if (dy > 0) 
			{
				m_Camera.Zoom((1 / m_dZoom));
			}

			m_pMousePos.X = e.x;
			m_pMousePos.Y = e.y;
			m_ActiveView.Redraw(false);
		}

		private void chkSpin_Click(object sender, System.EventArgs e)
		{
			if (chkSpin.CheckState == CheckState.Checked)
            {
				axGlobeControl1.GlobeViewer.StartSpinning(esriGlobeSpinDirection.esriCounterClockwise);
				axGlobeControl1.GlobeViewer.SpinSpeed = 3;
				TrackBar1.Enabled = true;
				m_dSpinSpeed = 3;
			}
			else
			{
				axGlobeControl1.GlobeViewer.StopSpinning();
				TrackBar1.Enabled = false;
				m_dSpinSpeed = 0;
			}
		}

		private void TrackBar1_Scroll(object sender, System.EventArgs e)
		{
			//The globe should increase its spin speed with every increment greater than
			//5 and decrease it for every increment less.
			int sliderPos = (TrackBar1.Value - 5);
			if (sliderPos == 0)
			{
				m_dSpinSpeed = 3;
			}
			else if (sliderPos > 0) 
			{
				m_dSpinSpeed = 3 * (sliderPos + 1);
			}
			else
			{
				m_dSpinSpeed = 3 / (1 - sliderPos);
			}

			axGlobeControl1.GlobeViewer.SpinSpeed = m_dSpinSpeed;
		}

		private void MixedControls_Click(object sender, System.EventArgs e)
		{
			RadioButton b = (RadioButton) sender;
			//Set current tool
			switch (b.Name)
			{
				case "optTools0":
					m_bZooming = false;
					axGlobeControl1.Navigate = true;
					axGlobeControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
					break;
				case "optTools1":
					m_bZooming = true;
					axGlobeControl1.Navigate = false;
					axGlobeControl1.MousePointer = esriControlsMousePointer.esriPointerZoom;
					break;
			}
		}

		private esriLicenseStatus CheckOutLicenses(esriLicenseProductCode productCode) 
		{
			esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
			
			m_AoInitialize = new AoInitializeClass();
			if (m_AoInitialize == null) return licenseStatus;

			//Determine if the product is available
			licenseStatus = m_AoInitialize.IsProductCodeAvailable(productCode);
			if (licenseStatus == esriLicenseStatus.esriLicenseAvailable)
			{
				//Determine if the extension is available
				licenseStatus = m_AoInitialize.IsExtensionCodeAvailable(productCode, esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
				if (licenseStatus == esriLicenseStatus.esriLicenseAvailable)
				{
					//Initialize the license
					licenseStatus = m_AoInitialize.Initialize(productCode);
					if (licenseStatus == esriLicenseStatus.esriLicenseCheckedOut) 
					{
						//Check out the extension
						licenseStatus = m_AoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
					}
				}
			}
			return licenseStatus;
		}

	}
}

⌨️ 快捷键说明

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