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

📄 form1.cs

📁 利用CSharp进行二次开发
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.axMapControl1.TabIndex = 10;
			this.axMapControl1.OnMouseDown += new ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEventHandler(this.axMapControl1_OnMouseDown);
			this.axMapControl1.OnAfterDraw += new ESRI.ArcGIS.MapControl.IMapControlEvents2_OnAfterDrawEventHandler(this.axMapControl1_OnAfterDraw);
			// 
			// axLicenseControl1
			// 
			this.axLicenseControl1.Enabled = true;
			this.axLicenseControl1.Location = new System.Drawing.Point(88, 24);
			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 = 11;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(432, 310);
			this.Controls.Add(this.axLicenseControl1);
			this.Controls.Add(this.axMapControl1);
			this.Controls.Add(this.cmdReset);
			this.Controls.Add(this.cmdFullExtent);
			this.Controls.Add(this.Label3);
			this.Controls.Add(this.Label2);
			this.Controls.Add(this.Text1);
			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)
		{
			//Find sample data by navigating two folders up
			string sFilePath = @"..\..\..\..\..\..\Data\World";

			//Add sample 'country' shapefile data
			axMapControl1.AddShapeFile(sFilePath, "Country");

			//Grab hold of the IgeoFeaturelayer interface on the layer
			//in the map control in order to symbolize the data
			IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer) axMapControl1.get_Layer(0);

			//Create a simple renderer and grab hold of ISimpleRenderer interface
			ISimpleRenderer simpleRenderer = new  SimpleRendererClass();
			//Create a fill symbol and grab hold of the ISimpleFillSymbol interface
			ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); 
			//Create a line symbol and grab hold of the ISimpleLineSymbol interface
			ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();

			//Assign line symbol and fill symbol properties
			lineSymbol.Width = 0.1;
			lineSymbol.Color = GetRGBColor(255, 0, 0); //Red
			fillSymbol.Outline = lineSymbol;
			fillSymbol.Color = GetRGBColor(0, 0, 255); //Blue

			//Set the symbol property of the renderer
			simpleRenderer.Symbol = (ISymbol) fillSymbol;

			//Set the renderer property of the geo feature layer
			geoFeatureLayer.Renderer = (IFeatureRenderer) simpleRenderer;
		}

		private void cmdFullExtent_Click(object sender, System.EventArgs e)
		{
			//Assign map controls extent property to the full extent of all the layers
			axMapControl1.Extent = axMapControl1.FullExtent;
		}

		private void cmdReset_Click(object sender, System.EventArgs e)
		{
			//Get rid of the line and points collection
			m_Polyline = null;
			m_PointCollection = null;
			//Refresh the foreground thereby removing any text annotation
			axMapControl1.CtlRefresh(esriViewDrawPhase.esriViewForeground, Type.Missing, Type.Missing);
		}

		private IRgbColor GetRGBColor(int red,int green, int blue) 
		{
			//Create rgb color and grab hold of the IRGBColor interface
			IRgbColor rGB = new RgbColorClass(); 
			//Set rgb color properties
			rGB.Red = red;
			rGB.Green = green;
			rGB.Blue = blue;
			rGB.UseWindowsDithering = true;
			return rGB;
		}

		private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			//Release COM objects 
			ESRI.ArcGIS.Utility.COMSupport.AOUninitialize.Shutdown();
		}

		private void axMapControl1_OnAfterDraw(object sender, ESRI.ArcGIS.MapControl.IMapControlEvents2_OnAfterDrawEvent e)
		{
			//If foreground refreshed
			if (e.viewDrawPhase == (int) esriViewDrawPhase.esriViewForeground)
			{
				//If a line object for splining text exists
				if (m_Polyline != null) 
				{
					//Ensure there's at least two points in the line
					if (m_PointCollection.PointCount > 1)
					{
						//Create a line symbol and grab hold of the ILineSymbol interface
						ILineSymbol lineSymbol = new SimpleLineSymbolClass();
						//Set line symbol properties
						lineSymbol.Color = GetRGBColor(0, 0, 0);
						lineSymbol.Width = 2;

						//Create a text symbol and grab hold of the ITextSymbol interface
						ITextSymbol textSymbol = new TextSymbolClass();
						//Create a system drawing font symbol with the specpfied properties
						System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16, FontStyle.Bold);

						//Set the text symbol font by getting the IFontDisp interface
						textSymbol.Font =  (stdole.IFontDisp) OLE.GetIFontDispFromFont(drawFont);
						textSymbol.Color = GetRGBColor(0, 0, 0);

						//Create a text path and grab hold of the ITextPath interface
						ITextPath textPath = new BezierTextPathClass();  //to spline the text
						//Grab hold of the ISimpleTextSymbol interface through the ITextSymbol interface
						ISimpleTextSymbol simpleTextSymbol = (ISimpleTextSymbol) textSymbol;
						//Set the text path of the simple text symbol
						simpleTextSymbol.TextPath = textPath;

						//Draw the line object and spline the user text around the line
						object oLineSymbol = lineSymbol;
						object oTextSymbol = textSymbol;
						axMapControl1.DrawShape(m_Polyline, ref oLineSymbol);
						axMapControl1.DrawText(m_Polyline, Text1.Text, ref oTextSymbol);
					}
				}
			}
		}

		private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvent e)
		{
			//If left hand mouse button
			if (e.button == 1) 
			{
				//Create a point and grab hold of the IPoint inteface
				IPoint point = new PointClass();
				//Set point properties
				point.X = e.mapX;
				point.Y = e.mapY;

				//If this is the first point of a new line
				if (m_Polyline == null)
				{
					//Create the forms private polyline member and grab hold of the IPolyline interface
					m_Polyline = new PolylineClass();
				}

				//QI for the IPointsCollection interface using the IPolyline interface
				object o = Type.Missing;
				//object o1 = m_PointCollection.PointCount-1;
				m_PointCollection = (IPointCollection) m_Polyline;
				m_PointCollection.AddPoint(point, ref o, ref o);

				//Refresh the foreground thereby removing any text annotation
				axMapControl1.CtlRefresh(esriViewDrawPhase.esriViewForeground, Type.Missing,Type.Missing);
			}
			else
			{
				//If right or middle mouse button zoom to user defined rectangle
				//Create an envelope and grab hold of the IEnvelope interface
				IEnvelope envelope = axMapControl1.TrackRectangle();
				//If user dragged a rectangle
				if (envelope != null)
				{
					//Set map controls extent property
					axMapControl1.Extent = envelope;
				}
			}
		}
	}
}

⌨️ 快捷键说明

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