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

📄 form1.cs

📁 AE+vb来实现的最短路径的实现功能!gis
💻 CS
📖 第 1 页 / 共 5 页
字号:
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			// 
			// splitter2
			// 
			this.splitter2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.splitter2.Location = new System.Drawing.Point(0, 592);
			this.splitter2.Name = "splitter2";
			this.splitter2.Size = new System.Drawing.Size(1028, 3);
			this.splitter2.TabIndex = 9;
			this.splitter2.TabStop = false;
			// 
			// panel4
			// 
			this.panel4.Controls.Add(this.tabControl1);
			this.panel4.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panel4.Location = new System.Drawing.Point(0, 0);
			this.panel4.Name = "panel4";
			this.panel4.Size = new System.Drawing.Size(1028, 592);
			this.panel4.TabIndex = 10;
			// 
			// timer1
			// 
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(1028, 753);
			this.Controls.Add(this.panel4);
			this.Controls.Add(this.splitter2);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.statusBar1);
			this.Controls.Add(this.axLicenseControl1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Form1";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = " Evacuation Routes Demo            (Applications Prototype Lab  ArcGIS 9.1)";
			this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
			this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
			this.Load += new System.EventHandler(this.Form1_Load);
			this.tabControl1.ResumeLayout(false);
			this.tabPage1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.Toolbar2D)).EndInit();
			this.panel6.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.Map2D)).EndInit();
			this.panel5.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.TOC2D)).EndInit();
			this.tabPage2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.ToolBar3D)).EndInit();
			this.panel3.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.Map3D)).EndInit();
			this.panel2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.TOC3D)).EndInit();
			this.groupBox2.ResumeLayout(false);
			this.groupBoxAreaOfReach.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.SliderAreaOfReach)).EndInit();
			this.groupClosestFacility.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.SliderSeconds)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.HelpPanel)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.StatusPanel)).EndInit();
			this.panel1.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.panel4.ResumeLayout(false);
			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)
		{
			Splash pSplash = new Splash();
			pSplash.Show();

			pSplash.SetStatus("Searching map documents");

			string sExecutingAssembly = System.Reflection.Assembly.GetExecutingAssembly().Location;
			string sExecutionFolder = System.IO.Path.GetDirectoryName(sExecutingAssembly);

			if (System.IO.Directory.Exists(@"C:\Demos\EvacuationRoutes\"))
			{
				sExecutionFolder = @"C:\Demos\EvacuationRoutes";
			}
			sExecutionFolder = sExecutionFolder + System.IO.Path.DirectorySeparatorChar.ToString();

			if (!System.IO.File.Exists(sExecutionFolder  + m_sxd))
			{
				MessageBox.Show( sExecutionFolder  + m_sxd + " does not exist. Application will not work");
				return;
			}
			if (!System.IO.File.Exists(sExecutionFolder  + m_mxd))
			{
				MessageBox.Show( sExecutionFolder  + m_mxd + " does not exist. Application will not work");
				return;
			}
				
			//Load documents
			pSplash.SetStatus("Loading 3D view...");
			this.Map3D.LoadSxFile(sExecutionFolder  + m_sxd);
			pSplash.SetStatus("Loading 2D view...");
			this.Map2D.LoadMxFile(sExecutionFolder + m_mxd,null,null);
			pSplash.SetStatus("Configuring Application...");
			
			//Configure Animation Layer and Closest Facility
			m_AgentAnimation2DLayer = ESRIControlUtils.GetLayerFromMap(this.Map2D,m_sAgentMotionLayer2D)as IFeatureLayerDefinition;
			m_AgentAnimation3DLayer = ESRIControlUtils.GetLayerFromMap(this.Map3D,m_sAgentMotionLayer3D)as IFeatureLayerDefinition;
			INALayer pNAClosestFac = ESRIControlUtils.GetLayerFromMap(this.Map2D,m_sClosestFacilityLayer) as INALayer;

			INAContext pNAContext = pNAClosestFac.Context;
			IFeatureClass pFC = pNAContext.NAClasses.get_ItemByName("Incidents") as IFeatureClass;
			MiscUtils.AddField(pFC,"Type",esriFieldType.esriFieldTypeString);
			pFC = pNAContext.NAClasses.get_ItemByName("Barriers") as IFeatureClass;
			MiscUtils.AddField(pFC,"Origin",esriFieldType.esriFieldTypeString);
			((IFeatureLayerDefinition)pNAClosestFac.get_LayerByNAClassName("Barriers")).DefinitionExpression = "Origin <> 'FromPolygonBarrier'";

			MiscUtils.SwitchToInMemoryFC(m_AgentAnimation2DLayer as IFeatureLayer,pNAClosestFac);
			MiscUtils.ConnectoToFC(m_AgentAnimation3DLayer as IFeatureLayer,((IFeatureLayer)m_AgentAnimation2DLayer).FeatureClass);


			//Build Collection Floors-Height

			m_FloorNames = m_sFloorNames.Split(',');
			string[]  s = m_sFloorHeights.Split(',');
			m_FloorHeights = new double[s.Length];
			for (int i = 0;i<s.Length;i++)
			{
				m_FloorHeights[i]=Convert.ToDouble(s[i]);
			}

			//Pass the AppProperty class to the map
			ILayer pRouteLayer = ESRIControlUtils.GetLayerFromMap(this.Map2D,m_sRouteLayer);
			if (pRouteLayer==null )
			{
				MessageBox.Show(m_sRouteLayer + "  Network layer has not been found in the map control (2D).");
				return;
			}
			INALayer pNARouteLayer = pRouteLayer as INALayer;
			pNAContext = pNARouteLayer.Context;
			pFC = pNAContext.NAClasses.get_ItemByName("Barriers") as IFeatureClass;
			MiscUtils.AddField(pFC,"Origin",esriFieldType.esriFieldTypeString);
			((IFeatureLayerDefinition)pNARouteLayer.get_LayerByNAClassName("Barriers")).DefinitionExpression = "Origin <> 'FromPolygonBarrier'";

			ILayer pStops3DLayer = ESRIControlUtils.GetLayerFromMap(this.Map3D,m_sStops3D);
			if (pStops3DLayer==null )
			{
				MessageBox.Show(pStops3DLayer + "  feature layer has not been found in the scene control.");
				return;
			}
			MiscUtils.SwitchToInMemoryFC(pStops3DLayer as IFeatureLayer,pRouteLayer as INALayer);

			m_pAppProperties.ActiveFloor = this.LstFloors.Text;
			m_pAppProperties.FloorsHeight = MiscUtils.GetFloorHeight(m_FloorNames,m_FloorHeights,this.LstFloors.Text);
			m_pAppProperties.NetworkLayer = pRouteLayer as INALayer;
			m_pAppProperties.Marker3DLayer = pStops3DLayer as IFeatureLayer;
			m_pAppProperties.SceneGraph = this.Map3D.SceneGraph;
			
			this.Map2D.CustomProperty = m_pAppProperties;
			this.Map3D.CustomProperty = m_pAppProperties;


			//Configure Routes2D Active and Routes2D No Active
			ICompositeLayer pRoute2DGroupLayer = ESRIControlUtils.GetLayerFromMap(this.Map2D,m_s2DRouteGroup)as ICompositeLayer;
			if (pRoute2DGroupLayer==null )
			{
				MessageBox.Show(m_s2DRouteGroup + "  GROUP layer has not been found.");
				return;
			}
			m_pRoute2DActiveLayer = ESRIControlUtils.GetLayerFromCompositeLayer(pRoute2DGroupLayer,m_s2DRouteActive);
			m_Route2DNoActiveLayer = ESRIControlUtils.GetLayerFromCompositeLayer(pRoute2DGroupLayer,m_s2DRouteNoActive);
			if (m_pRoute2DActiveLayer==null || m_Route2DNoActiveLayer == null )
			{
				MessageBox.Show("Either " + m_s2DRouteActive + " or " + m_s2DRouteNoActive + " could have not been found within the " + m_s2DRouteGroup + " GROUP layer.");
				return;
			}
			MiscUtils.SwitchToInMemoryFC(m_pRoute2DActiveLayer as IFeatureLayer,pRouteLayer as INALayer);
			MiscUtils.ConnectoToFC(m_Route2DNoActiveLayer as IFeatureLayer,((IFeatureLayer)m_pRoute2DActiveLayer).FeatureClass);


			//Configure Route3D
			IFeatureLayer pFLRoute3D = ESRIControlUtils.GetLayerFromMap(this.Map3D,m_sRoute3D) as IFeatureLayer;	
			MiscUtils.SwitchToInMemoryFC(pFLRoute3D,pRouteLayer as INALayer);
			
			//Configure Polygon Barriers
			IFeatureLayer pFLPolygonBarriers2D = ESRIControlUtils.GetLayerFromMap(this.Map2D,m_sPolygonBarriers2D)as IFeatureLayer;
			IFeatureLayer pFLPolygonBarriers3D = ESRIControlUtils.GetLayerFromMap(this.Map3D,m_sPolygonBarriers3D)as IFeatureLayer;
			MiscUtils.SwitchToInMemoryFC(pFLPolygonBarriers2D,pRouteLayer as INALayer);
			MiscUtils.ConnectoToFC( pFLPolygonBarriers3D, pFLPolygonBarriers2D.FeatureClass);
			
			//Configure Serive Area Layers
			INALayer pServiceAreaLayer = ESRIControlUtils.GetLayerFromMap(this.Map2D,m_sServiceAreaLayer)as INALayer;
			IFeatureLayer pFLServiceArea2D = ESRIControlUtils.GetLayerFromMap(this.Map2D,m_sServiceArea2D)as IFeatureLayer;
			IFeatureLayer pFLServiceArea3D = ESRIControlUtils.GetLayerFromMap(this.Map3D,m_sServiceArea3D)as IFeatureLayer;

			pNAContext = pServiceAreaLayer.Context;
			pFC = pNAContext.NAClasses.get_ItemByName("Barriers") as IFeatureClass;
			MiscUtils.AddField(pFC,"Origin",esriFieldType.esriFieldTypeString);
			((IFeatureLayerDefinition)pServiceAreaLayer.get_LayerByNAClassName("Barriers")).DefinitionExpression = "Origin <> 'FromPolygonBarrier'";

			MiscUtils.SwitchToInMemoryFC(pFLServiceArea2D,pServiceAreaLayer);
			MiscUtils.ConnectoToFC( pFLServiceArea3D, pFLServiceArea2D.FeatureClass);
			

			//Fill ActiveFloor list.
			//Make first floor visible (will refresh because lstFloors_OnChange will be triggered)

			this.LstFloors.BeginUpdate();
			this.LstFloors.Items.Clear();
			int iTotalFloors = m_FloorNames.Length;
			for (int n = 0;n<iTotalFloors;n++)
			{
				this.LstFloors.Items.Add(m_FloorNames[n]);
			}
			this.LstFloors.Text = m_FloorNames[iTotalFloors-1];
			this.LstFloors.EndUpdate();

			//Fill impedance and restrictions list
			INetworkDataset pNDS = ((INALayer)pRouteLayer).Context.NetworkDataset;
			int iTotalAttrs = pNDS.AttributeCount;
			for (int a = 0; a<iTotalAttrs;a++)
			{
				INetworkAttribute pNAttr = pNDS.get_Attribute(a);
				if (pNAttr.UsageType == esriNetworkAttributeUsageType.esriNAUTCost)
				{
					this.LstImpendances.Items.Add(pNAttr.Name);
				}
				if (pNAttr.UsageType == esriNetworkAttributeUsageType.esriNAUTRestriction)
				{
					this.ChkRestrictions.Items.Add(pNAttr.Name);
				}
				this.LstImpendances.SelectedIndex = 0;
			}
			this.LstSolvers.Text = "Route Solver";

			pSplash.Hide();
			pSplash = null;
		}

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

		private void LstFloors_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string sSelectedFloor = this.LstFloors.Text;
			//Control layer visibility and symbology in 2D
			ICompositeLayer pFloorsLayer = ESRIControlUtils.GetLayerFromMap(this.Map2D,m_sFloorsGroupLayer)as ICompositeLayer;

			int iTotalFloors = m_FloorNames.Length;
			for (int i = 0;i<iTotalFloors;i++)
			{
				ILayer pFloorLayer2D = ESRIControlUtils.GetLayerFromCompositeLayer(pFloorsLayer,m_FloorNames[i]);
				pFloorLayer2D.Visible = (sSelectedFloor==pFloorLayer2D.Name);
			}

			//Filter 2DRoutes by floor
			ICompositeLayer pRoute2DGroupLayer = ESRIControlUtils.GetLayerFromMap(this.Map2D,m_s2DRouteGroup)as ICompositeLayer;
			IFeatureLayerDefinition p2DRouteActiveDef = ESRIControlUtils.GetLayerFromCompositeLayer(pRoute2DGroupLayer,m_s2DRouteActive) as IFeatureLayerDefinition;
			IFeatureLayerDefinition p2DRouteNoActiveDef = ESRIControlUtils.GetLayerFromCompositeLayer(pRoute2DGroupLayer,m_s2DRouteNoActive) as IFeatureLayerDefinition;

			p2DRouteActiveDef.DefinitionExpression = "Floor = '" + this.LstFloors.Text + "'"; //TODO: Use SQLSyntax
			p2DRouteNoActiveDef.DefinitionExpression = "Floor <> '" + this.LstFloors.Text + "'"; //TODO: Use SQLSyntax

			//Filter ServiceArea by floor
			IFeatureLayerDefinition pSA2DLayer = ESRIControlUtils.GetLayerFromMap(this.Map2D,m_sServiceArea2D) as IFeatureLayerDefinition;
			pSA2DLayer.DefinitionExpression = "Floor = '" + this.LstFloors.Text + "'"; //TODO: Use SQLSyntax
			
			//Filter Polygon Barriers by floor
			IFeatureLayerDefinition pPolygonBarriers2DFL = ESRIControlUtils.GetLayerFromMap(this.Map2D,m_sPolygonBarriers2D) as IFeatureLayerDefinition;
			pPolygonBarriers2DFL.DefinitionExpression = "Floor = '" + this.LstFloors.Text + "'"; //TODO: Use SQLSyntax
			
			//Control Layer visibility in 3D
			double dCurrentHeight = MiscUtils.GetFloorHeight(m_FloorNames,m_FloorHeights,sSelectedFloor);
			IFeatureLayerDefinition pSA3DLayer = ESRIControlUtils.GetLayerFromMap(this.Map3D,m_sServiceArea3D) as IFeatureLayerDefinition;
			IFeatureLayerDefinition pPolygonBarrier3DLayer = ESRIControlUtils.GetLayerFromMap(this.Map3D,m_sPolygonBarriers3D) as IFeatureLayerDefinition;
			IFeatureLayerDefinition pStops3D = ESRIControlUtils.GetLayerFromMap(this.Map3D,m_sStops3D) as IFeatureLayerDefinition;
			string sFilter = "";
			for (int i = 0;i<iTotalFloors;i++)
			{
				ILayer pFloorLayer3D = ESRIControlUtils.GetLayerFromMap(this.Map3D,m_FloorNames[i]);
				pFloorLayer3D.Visible = (dCurrentHeight >= MiscUtils.GetFloorHeight(m_FloorNames,m_FloorHeights,pFloorLayer3D.Name));
				if(pFloorLayer3D.Visible) sFilter = sFilter +  "Floor = '" + pFloorLayer3D.Name + "' OR ";
			}
			sFilter = sFilter.Substring(0,sFilter.Length - 4);
			pSA3DLayer.DefinitionExpression = sFilter;
			pPolygonBarrier3DLayer.DefinitionExpression = sFilter;
			pStops3D.DefinitionExpression = sFilter;

			//Set the 'map' active floor
			m_pAppProperties.ActiveFloor = this.LstFloors.Text;
			m_pAppProperties.FloorsHeight = MiscUtils.GetFloorHeight(m_FloorNames,m_FloorHeights,this.LstFloors.Text);
			m_pAppProperties.PolygonBarrier3DLayer = pPolygonBarrier3DLayer as IFeatureLayer;
			
			this.Map2D.CustomProperty = m_pAppProperties;

			//if (this.tabControl1.SelectedIndex == 0)

⌨️ 快捷键说明

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