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

📄 addstop.cs

📁 AE+vb来实现的最短路径的实现功能!gis
💻 CS
字号:
using System;

using System.Runtime.InteropServices;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Utility.BaseClasses;
using ESRI.ArcGIS.Utility.CATIDs;
using ESRI.ArcGIS.ControlCommands;

using ESRI.ArcGIS.ToolbarControl;
using ESRI.ArcGIS.MapControl;
using ESRI.ArcGIS.SceneControl;
using ESRI.ArcGIS.Analyst3D;

//Ismael Chivite
//ESRI Redlands
//March 2005
namespace EvacuationRoutesTools
{
	[ClassInterface(ClassInterfaceType.None)]
    [Guid("e4097c0d-9763-4f57-bf40-6b1876883b5f")]

	public class AddStop:  BaseTool
	{
		private IHookHelper m_pHookHelper = new HookHelperClass();
		private ISceneHookHelper m_pSceneHookHelper = new SceneHookHelperClass();
		private bool m_is2D = true;

		private bool m_Enabled = true;
		private string m_sAgentType = "Agent";

		#region "Component Category Registration"
		[ComRegisterFunction()]
		static void Reg(string regKey)
		{
				MxCommands.Register(regKey);
				ControlsCommands.Register(regKey);
		}

		[ComUnregisterFunction()]
		static void Unreg(string regKey)
		{
				MxCommands.Unregister(regKey);
				ControlsCommands.Unregister(regKey);
		}
		#endregion 

		public AddStop()
		{
			base.m_category = "Network_3D";
			base.m_caption = "Adds an agent (Type Agent)";
			base.m_message = "Adds a location by clicking on the map/globe";
			base.m_toolTip = "Add a location by clicking on the map/globe";
			base.m_name = "AddStop";
			try
			{
				string [] res = GetType().Assembly.GetManifestResourceNames();
				if(res.GetLength(0)>0)
				{
					base.m_bitmap = new System.Drawing.Bitmap(GetType().Assembly.GetManifestResourceStream("EvacuationRoutesTools.AddStop.bmp"));
				}
			}
			catch(Exception exx)
			{
				//System.Windows.Forms.MessageBox.Show(exx.Message);
			}
		}
	
		public override void OnCreate(object hook)
		{
			if (hook!=null)
			{
				if (hook is IToolbarControl)
				{
					IToolbarControl pToolBarControl = hook as IToolbarControl;
					if (pToolBarControl.Buddy is MapControl)
					{
						m_is2D = true;
						m_pHookHelper.Hook = hook; //This is a toolbar if the app is an ArcEngine app.
					}
					else
					{
						m_is2D = false;
						m_pSceneHookHelper.Hook = hook ;
					}
				}
				else
				{
					m_Enabled = false;
				}
			}
		}
	
	
		public override void OnMouseDown(int Button, int Shift, int X, int Y)
		{
			
			if (m_is2D==false)
			{
				MouseDown3D(Button,Shift,X,Y);
			}
			else
			{
				MouseDown2D(Button,Shift,X,Y);
			}
		}
	
		public override bool Enabled
		{
			get
			{
				return m_Enabled;
			}
		}
		private void MouseDown3D(int Button,int Shift,int X,int Y)
		{
			try
			{
				
				IToolbarControl pToolBar = m_pSceneHookHelper.Hook as IToolbarControl;
				ISceneGraph pSceneGraph = m_pSceneHookHelper.SceneGraph;

				IPoint pPoint = null;
				object pOwner = null;
				object ppObject = null;
				pSceneGraph.Locate(pSceneGraph.ActiveViewer,X,Y,ESRI.ArcGIS.Analyst3D.esriScenePickMode.esriScenePickGeography,false,out pPoint,out pOwner,out ppObject);

				//Get the active floor and NALayer
				ISceneControl pSceneControl = pToolBar.Buddy as ISceneControl;
				AppProperties.AppProperties pAppProps =  pSceneControl.CustomProperty as AppProperties.AppProperties;
				string sActiveFloor = pAppProps.ActiveFloor;
				ESRI.ArcGIS.NetworkAnalyst.INALayer pNALayer = pAppProps.NetworkLayer;

				//Adds a new NAObject to the NALayer (2D)
				string sStopsName = "";
				switch(pNALayer.Context.Solver.Name)
				{
					case "Route Solver":
						sStopsName = "Stops";
						break;
					case "Closest Facility Solver":
						sStopsName = "Incidents";
						break;
					case "Service Area Solver":
						sStopsName = "Facilities";
						break;
				}
				IPoint pPoint2D = new PointClass();
				pPoint2D.PutCoords(pPoint.X,pPoint.Y);
				bool added = APL.NetworkUtils.AddNetWorkLocation(pNALayer,sStopsName,pPoint2D,sActiveFloor,m_sAgentType,15);

				//Adds a new 3D representation of the NAObject (3D)
				if (added)
				{
					double dHeight = pAppProps.FloorsHeight;
					IPoint pPoint3D = ((ESRI.ArcGIS.esriSystem.IClone)pPoint).Clone() as IPoint;;
					((IZAware)pPoint3D).ZAware = true;
					pPoint3D.Z = dHeight;

					IFeatureClass pFC = pAppProps.Marker3DLayer.FeatureClass;
					IFeature p3DF = pFC.CreateFeature();

					int idxType = pFC.Fields.FindField("Type");
					if (idxType>0) p3DF.set_Value(idxType,"Stop");
					int idxFloor = pFC.Fields.FindField("Floor");
					if (idxFloor>0) p3DF.set_Value(idxFloor,sActiveFloor);

					p3DF.Shape = pPoint3D;
					p3DF.Store();
					//Refresh 3D
					pSceneGraph.Invalidate(pAppProps.Marker3DLayer,true,false);
					pSceneGraph.RefreshViewers();
				}
			}
			catch(Exception exx)
			{
				System.Windows.Forms.MessageBox.Show("Add Stop tool: " + exx.Message);
			}

		}
		private void MouseDown2D(int Button,int Shift,int X,int Y)
		{
			try
			{
				
				IToolbarControl pToolBar = m_pHookHelper.Hook as IToolbarControl;
				IPoint pPoint = m_pHookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X,Y);

				//Get the active floor and NALayer
				IMapControl3 pMapControl = pToolBar.Buddy as IMapControl3;
				AppProperties.AppProperties pAppProps =  pMapControl.CustomProperty as AppProperties.AppProperties;

				string sActiveFloor = pAppProps.ActiveFloor;
				ESRI.ArcGIS.NetworkAnalyst.INALayer pNALayer = pAppProps.NetworkLayer;

				//Adds a new NAObject to the NALayer (2D)
				string sStopsName = "";
				switch(pNALayer.Context.Solver.Name)
				{
					case "Route Solver":
						sStopsName = "Stops";
						break;
					case "Closest Facility Solver":
						sStopsName = "Incidents";
						break;
					case "Service Area Solver":
						sStopsName = "Facilities";
						break;
				}
				IPoint pPoint2D = new PointClass();
				pPoint2D.PutCoords(pPoint.X,pPoint.Y);
				bool added = APL.NetworkUtils.AddNetWorkLocation(pNALayer,sStopsName,pPoint2D,sActiveFloor,m_sAgentType,15);


				//Adds a new 3D representation of the NAObject (3D)
				if (added)
				{
					double dHeight = pAppProps.FloorsHeight;
					IPoint pPoint3D = m_pHookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X,Y);
					((IZAware)pPoint3D).ZAware = true;
					pPoint3D.Z = dHeight;

					IFeatureClass pFC = pAppProps.Marker3DLayer.FeatureClass;
					IFeature p3DF = pFC.CreateFeature();
					int idxType = pFC.Fields.FindField("Type");
					int idxFloor = pFC.Fields.FindField("Floor");
					if (idxType>0) p3DF.set_Value(idxType,"Stop");
					if (idxFloor>0) p3DF.set_Value(idxFloor,sActiveFloor);
					p3DF.Shape = pPoint3D;
					p3DF.Store();

					//Refresh 2D
					//m_pHookHelper.ActiveView.Refresh();
					ITopologicalOperator pTopOp = pPoint3D as ITopologicalOperator;
					
					m_pHookHelper.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography,null,pTopOp.Buffer(5).Envelope);
					//Refresh 3D
					ISceneGraph pSceneGraph = pAppProps.SceneGraph;
					pSceneGraph.Invalidate(pAppProps.Marker3DLayer,true,false);
					pSceneGraph.RefreshViewers();
				}
			}
			catch(Exception exx)
			{
				System.Windows.Forms.MessageBox.Show("Add Stop tool: " + exx.Message);
			}

		}
	}
}

⌨️ 快捷键说明

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