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

📄 form1.cs

📁 利用CSharp进行二次开发
💻 CS
📖 第 1 页 / 共 2 页
字号:
/*
 Copyright 1995-2005 ESRI

 All rights reserved under the copyright laws of the United States.

 You may freely redistribute and use this sample code, with or without modification.

 Disclaimer: THE SAMPLE CODE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 
 WARRANTIES, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESRI OR 
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 INTERRUPTION) SUSTAINED BY YOU OR A THIRD PARTY, HOWEVER CAUSED AND ON ANY 
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY 
 WAY OUT OF THE USE OF THIS SAMPLE CODE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 SUCH DAMAGE.

 For additional information contact: Environmental Systems Research Institute, Inc.

 Attn: Contracts Dept.

 380 New York Street

 Redlands, California, U.S.A. 92373 

 Email: contracts@esri.com
*/
using System;
using System.Windows.Forms;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.MapControl;
using ESRI.ArcGIS.Utility.COMSupport;

namespace GeoEvents
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	/// 

	public class Form1 : System.Windows.Forms.Form
	{
		public System.Windows.Forms.Button cmdFullExtent;
		public System.Windows.Forms.CheckBox chkTracking;
		public System.Windows.Forms.Label Label1;
		private ESRI.ArcGIS.MapControl.AxMapControl axMapControl1;
		private System.Windows.Forms.Timer timer1;
		private System.ComponentModel.IContainer components;
		private IGeographicCoordinateSystem m_GeographicCoordinateSystem; 
		private IProjectedCoordinateSystem m_ProjectedCoordinateSystem;
		private IGraphicsContainer m_GraphicsContainer;
		private IMapControl2 m_MapControl;
		private ESRI.ArcGIS.LicenseControl.AxLicenseControl axLicenseControl1;  
		private AGENT_IN_FIELD[] agentArray = new AGENT_IN_FIELD[20]; 

		struct AGENT_IN_FIELD
		{
			public bool Located;
			public double Latitude;
			public double Longitude;
			public string CodeNumber;
		}

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <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.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.cmdFullExtent = new System.Windows.Forms.Button();
			this.chkTracking = new System.Windows.Forms.CheckBox();
			this.Label1 = new System.Windows.Forms.Label();
			this.axMapControl1 = new ESRI.ArcGIS.MapControl.AxMapControl();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.axLicenseControl1 = new ESRI.ArcGIS.LicenseControl.AxLicenseControl();
			((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).BeginInit();
			this.SuspendLayout();
			// 
			// cmdFullExtent
			// 
			this.cmdFullExtent.BackColor = System.Drawing.SystemColors.Control;
			this.cmdFullExtent.Cursor = System.Windows.Forms.Cursors.Default;
			this.cmdFullExtent.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cmdFullExtent.ForeColor = System.Drawing.SystemColors.ControlText;
			this.cmdFullExtent.Location = new System.Drawing.Point(560, 416);
			this.cmdFullExtent.Name = "cmdFullExtent";
			this.cmdFullExtent.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cmdFullExtent.Size = new System.Drawing.Size(121, 25);
			this.cmdFullExtent.TabIndex = 4;
			this.cmdFullExtent.Text = "Zoom to Full Extent";
			this.cmdFullExtent.Click += new System.EventHandler(this.cmdFullExtent_Click);
			// 
			// chkTracking
			// 
			this.chkTracking.BackColor = System.Drawing.SystemColors.Control;
			this.chkTracking.Cursor = System.Windows.Forms.Cursors.Default;
			this.chkTracking.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.chkTracking.ForeColor = System.Drawing.SystemColors.ControlText;
			this.chkTracking.Location = new System.Drawing.Point(16, 424);
			this.chkTracking.Name = "chkTracking";
			this.chkTracking.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.chkTracking.Size = new System.Drawing.Size(137, 17);
			this.chkTracking.TabIndex = 3;
			this.chkTracking.Text = "Enable GPS Tracking";
			this.chkTracking.Click += new System.EventHandler(this.chkTracking_Click);
			// 
			// Label1
			// 
			this.Label1.BackColor = System.Drawing.SystemColors.Control;
			this.Label1.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Label1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label1.Location = new System.Drawing.Point(152, 416);
			this.Label1.Name = "Label1";
			this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label1.Size = new System.Drawing.Size(353, 33);
			this.Label1.TabIndex = 5;
			this.Label1.Text = "Use the left hand mouse button to zoom in. Use the other mouse buttons to click o" +
				"n an agent and change the symbology.  ";
			// 
			// axMapControl1
			// 
			this.axMapControl1.Location = new System.Drawing.Point(8, 8);
			this.axMapControl1.Name = "axMapControl1";
			this.axMapControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMapControl1.OcxState")));
			this.axMapControl1.Size = new System.Drawing.Size(664, 400);
			this.axMapControl1.TabIndex = 6;
			this.axMapControl1.OnMouseDown += new ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEventHandler(this.axMapControl1_OnMouseDown);
			// 
			// timer1
			// 
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// axLicenseControl1
			// 
			this.axLicenseControl1.Enabled = true;
			this.axLicenseControl1.Location = new System.Drawing.Point(200, 72);
			this.axLicenseControl1.Name = "axLicenseControl1";
			this.axLicenseControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axLicenseControl1.OcxState")));
			this.axLicenseControl1.Size = new System.Drawing.Size(200, 50);
			this.axLicenseControl1.TabIndex = 7;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(680, 454);
			this.Controls.Add(this.axLicenseControl1);
			this.Controls.Add(this.axMapControl1);
			this.Controls.Add(this.cmdFullExtent);
			this.Controls.Add(this.chkTracking);
			this.Controls.Add(this.Label1);
			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.axMapControl1)).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)
		{

			m_MapControl = (IMapControl2) axMapControl1.GetOcx();

			//Find sample data
			string sFilePath = @"..\..\..\..\..\..\Data\World";

			//Add sample shapefile data
			m_MapControl.AddShapeFile(sFilePath, "world30");
			m_MapControl.AddShapeFile(sFilePath, "dissolveCntry");

			//Symbolize the data
			SymbolizeData(m_MapControl.get_Layer(0), 0.1, GetRGBColor(0, 0, 0), GetRGBColor(0, 128, 0));
			SymbolizeData(m_MapControl.get_Layer(1), 0.1, GetRGBColor(0, 0, 0), GetRGBColor(140, 196, 254));
			//Set up a global Geographic Coordinate System
			MakeCoordinateSystems();

			//Get the MapControl's graphics container and get the IGraphicsContainer interface
			m_GraphicsContainer = m_MapControl.ActiveView.GraphicsContainer;

			//Populate an array with agent id's and locations
			LoadAgentArray();

			//Loop through the array and display each agent location
			for (int i = 0; i <= 19; i++)
			{
				DisplayAgentLocation(agentArray[i]);
			}

			timer1.Interval = 800;
		}

		private void cmdFullExtent_Click(object sender, System.EventArgs e)
		{
			m_MapControl.Extent = m_MapControl.FullExtent;
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			//Distance used in calculating the new point location
			double dMaxDistance = m_MapControl.Extent.Width / 20;

			//Loop through the elements in the GraphicContainer and get the IElement interface
			m_GraphicsContainer.Reset();
			IElement element = m_GraphicsContainer.Next();
			
			Random r = new Random();
			while (element != null)
			{
				//QI for IElementProperties interface from IElement interface
				IElementProperties elementProperties = (IElementProperties) element;
				//If agent has not been located
				if (elementProperties.Name == false.ToString())
				{
					//Get hold of the IPoint interface from the elements geometry
					IPoint point = (IPoint) element.Geometry;
					//Create new random point coordinates based upon current location
					
					point.X = point.X - (dMaxDistance * (r.NextDouble() - 0.5));
					point.Y = point.Y - (dMaxDistance * (r.NextDouble() - 0.5));
					//Set the point onto the GeographicCoordinateSystem - WHERE the point came FROM
					point.Project(m_GeographicCoordinateSystem);
					//Ensure that the point is within the horizon of the coordinate system. Mollweide
					//has a generic rectangular horizon withe the following limits:
					//-179.999988540844, -90.000000000000, 179.999988540844, 90.000000000000
					if (point.X > 179.999988540844)
					{
						point.X = point.X - 359.999977081688;
					}
					else if (point.X < -179.999988540844)
					{
						point.X = point.X + 359.999977081688;

⌨️ 快捷键说明

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