About the Network Analyst Engine application Sample
[C#]
cmdClearAnalysisLayer.cs
using System.Windows.Forms; using System.Runtime.InteropServices; using ESRI.ArcGIS.ADF.BaseClasses; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.NetworkAnalyst; using ESRI.ArcGIS.Controls; // This command deletes all the network locations and analysis results from the selected NALayer. namespace NAEngine { [Guid("773CCD44-C46A-42eb-A1B2-E00C7B765783")] [ClassInterface(ClassInterfaceType.None)] [ProgId("NAEngine.ClearAnalysisLayer")] public sealed class cmdClearAnalysisLayer : BaseCommand { private IMapControl3 m_mapControl; public cmdClearAnalysisLayer() { base.m_caption = "Clear Analysis Layer"; } public override void OnClick() { IEngineNetworkAnalystEnvironment naEnv = new EngineNetworkAnalystEnvironmentClass(); IEngineNetworkAnalystHelper naHelper = naEnv as IEngineNetworkAnalystHelper; IEngineNAWindow naWindow = naEnv.NAWindow; // Get the NALayer and corresponding NAContext of the layer that // was right-clicked on in the table of contents // m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown INALayer naLayer = (INALayer)m_mapControl.CustomProperty; INAContext naContext = naLayer.Context; // Set the active Analysis layer if (naWindow.ActiveAnalysis != naLayer) naWindow.ActiveAnalysis = naLayer; // Remember what the current category is IEngineNAWindowCategory currentCategory = naWindow.ActiveCategory; // Loop through deleting all the items from all the categories INamedSet naClasses = naContext.NAClasses; for (int i = 0; i < naClasses.Count; i++) { IEngineNAWindowCategory category = naWindow.get_CategoryByNAClassName(naClasses.get_Name(i)); naWindow.ActiveCategory = category; naHelper.DeleteAllNetworkLocations(); } //Reset to the original category naWindow.ActiveCategory = currentCategory; m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, m_mapControl.Extent); } public override void OnCreate(object hook) { m_mapControl = (IMapControl3)hook; } } }
[Visual Basic .NET]
cmdClearAnalysisLayer.vb
Imports System.Windows.Forms Imports System.Runtime.InteropServices Imports ESRI.ArcGIS.ADF.BaseClasses Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.NetworkAnalyst Imports ESRI.ArcGIS.Controls ' This command deletes all the network locations and analysis results from the selected NALayer. Namespace NAEngine <Guid("34CD93E0-8233-4d6f-BE49-FE068EBB226A")> _ <ClassInterface(ClassInterfaceType.None)> _ <ProgId("NAEngine.ClearAnalysisLayer")> _ Public NotInheritable Class ClearAnalysisLayer Inherits BaseCommand Private m_mapControl As IMapControl3 Public Sub New() MyBase.m_caption = "Clear Analysis Layer" End Sub Public Overloads Overrides Sub OnClick() Dim naEnv As IEngineNetworkAnalystEnvironment = New EngineNetworkAnalystEnvironmentClass() Dim naHelper As IEngineNetworkAnalystHelper = TryCast(naEnv, IEngineNetworkAnalystHelper) Dim naWindow As IEngineNAWindow = naEnv.NAWindow ' Get the NALayer and corresponding NAContext of the layer that ' was right-clicked on in the table of contents ' m_MapControl.CustomProperty was set in frmMain.axTOCControl1_OnMouseDown Dim naLayer As INALayer = CType(m_mapControl.CustomProperty, INALayer) Dim naContext As INAContext = naLayer.Context ' Set the active Analysis layer If Not naWindow.ActiveAnalysis Is naLayer Then naWindow.ActiveAnalysis = naLayer End If ' Remember what the current category is Dim currentCategory As IEngineNAWindowCategory = naWindow.ActiveCategory ' Loop through deleting all the items from all the categories Dim naClasses As INamedSet = naContext.NAClasses Dim i As Integer = 0 Do While i < naClasses.Count Dim category As IEngineNAWindowCategory = naWindow.CategoryByNAClassName(naClasses.Name(i)) naWindow.ActiveCategory = category naHelper.DeleteAllNetworkLocations() i += 1 Loop 'Reset to the original category naWindow.ActiveCategory = currentCategory m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, naLayer, m_mapControl.Extent) End Sub Public Overloads Overrides Sub OnCreate(ByVal hook As Object) m_mapControl = CType(hook, IMapControl3) End Sub End Class End Namespace