Exemplo n.º 1
0
        public bool ShowModal(IEngineNetworkAnalystEnvironment naEnv)
        {
            m_okClicked = false;

            // Zoom to result after solve or not
            chkZoomToResultAfterSolve.Checked = naEnv.ZoomToResultAfterSolve;

            // Set the radio button based on the value in ShowAnalysisMessagesAfterSolve.
            // This is a bit property where multiple values are possible.
            // Simplify it for the user so assume message types build on each other.
            //  For example, if you want info, you probably want warnings and errors too
            //   No Messages = 0
            //   Errors = esriEngineNAMessageTypeError
            //   Errors and warnings = esriEngineNAMessageTypeError & esriEngineNAMessageTypeWarning
            //   All = esriEngineNAMessageTypeError & esriEngineNAMessageTypeWarning & esriEngineNAMessageTypeInformative
            if ((esriEngineNAMessageType)(naEnv.ShowAnalysisMessagesAfterSolve & (int)esriEngineNAMessageType.esriEngineNAMessageTypeInformative) == esriEngineNAMessageType.esriEngineNAMessageTypeInformative)
            {
                rdoAllMessages.Checked = true;
            }
            else if ((esriEngineNAMessageType)(naEnv.ShowAnalysisMessagesAfterSolve & (int)esriEngineNAMessageType.esriEngineNAMessageTypeWarning) == esriEngineNAMessageType.esriEngineNAMessageTypeWarning)
            {
                rdoErrorsAndWarnings.Checked = true;
            }
            else if ((esriEngineNAMessageType)(naEnv.ShowAnalysisMessagesAfterSolve & (int)esriEngineNAMessageType.esriEngineNAMessageTypeError) == esriEngineNAMessageType.esriEngineNAMessageTypeError)
            {
                rdoErrors.Checked = true;
            }
            else
            {
                rdoNoMessages.Checked = true;
            }

            this.ShowDialog();
            if (m_okClicked)
            {
                // Set ZoomToResultAfterSolve
                naEnv.ZoomToResultAfterSolve = chkZoomToResultAfterSolve.Checked;

                // Set ShowAnalysisMessagesAfterSolve
                // Use simplified version so higher severity errors also show lower severity "info" and "warnings"
                if (rdoAllMessages.Checked)
                {
                    naEnv.ShowAnalysisMessagesAfterSolve = (int)esriEngineNAMessageType.esriEngineNAMessageTypeInformative + (int)esriEngineNAMessageType.esriEngineNAMessageTypeWarning + (int)esriEngineNAMessageType.esriEngineNAMessageTypeError;
                }
                else if (rdoErrorsAndWarnings.Checked)
                {
                    naEnv.ShowAnalysisMessagesAfterSolve = (int)esriEngineNAMessageType.esriEngineNAMessageTypeWarning + (int)esriEngineNAMessageType.esriEngineNAMessageTypeError;
                }
                else if (rdoErrors.Checked)
                {
                    naEnv.ShowAnalysisMessagesAfterSolve = (int)esriEngineNAMessageType.esriEngineNAMessageTypeError;
                }
                else
                {
                    naEnv.ShowAnalysisMessagesAfterSolve = 0;
                }
            }

            return(m_okClicked);
        }
Exemplo n.º 2
0
        public override void OnCreate(object hook)
        {
            m_mapControl = (IMapControl3)hook;

            // Get the Network Analyst Env
            m_naEnv = new EngineNetworkAnalystEnvironmentClass();
        }
Exemplo n.º 3
0
        public override void OnCreate(object hook)
        {
            IHookHelper hookhelper = new HookHelperClass();

            if (hook != null)
            {
                hookhelper.Hook = hook;

                m_mapControl = (IMapControl3)hookhelper.Hook;

                // Get the Network Analyst Env
                m_naEnv = new EngineNetworkAnalystEnvironmentClass();
            }
            // TODO:  Add other initialization code
        }
Exemplo n.º 4
0
        public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv)
        {
            // Initialize variables
            m_okClicked        = false;
            m_listDisplayTable = new System.Collections.ArrayList();

            var activeCategory = naEnv.NAWindow.ActiveCategory as IEngineNAWindowCategory2;

            if (activeCategory == null)
            {
                return(false);
            }

            IDataLayer dataLayer = activeCategory.DataLayer;

            if (dataLayer == null)
            {
                return(false);
            }

            // Set up the title of this dialog
            String dataLayerName = GetDataLayerName(dataLayer);

            if (dataLayerName.Length == 0)
            {
                return(false);
            }

            this.Text = "Load Items into " + dataLayerName;

            // Make sure the combo box lists only the appropriate possible input data layers
            PopulateInputDataComboBox(mapControl, dataLayer);

            //Select the first display table from the list
            if (cboInputData.Items.Count > 0)
            {
                cboInputData.SelectedIndex = 0;
            }

            // Show the window
            this.ShowDialog();

            // If we selected a layer and clicked OK, load the locations
            if (m_okClicked && (cboInputData.SelectedIndex >= 0))
            {
                try
                {
                    // Get a cursor on the source display table (either though the selection set or table)
                    // Use IDisplayTable because it accounts for joins, querydefs, etc.
                    // IDisplayTable is implemented by FeatureLayers and StandaloneTables.
                    //
                    IDisplayTable displayTable = m_listDisplayTable[cboInputData.SelectedIndex] as IDisplayTable;
                    ICursor       cursor;
                    if (chkUseSelection.Checked)
                    {
                        ISelectionSet selSet;
                        selSet = displayTable.DisplaySelectionSet;
                        selSet.Search(null, false, out cursor);
                    }
                    else
                    {
                        cursor = displayTable.SearchDisplayTable(null, false);
                    }

                    // Get the NAContext from the active analysis layer
                    INAContext naContext = naEnv.NAWindow.ActiveAnalysis.Context;

                    // Get the dataset for the active NAClass
                    IDataset naDataset = activeCategory.NAClass as IDataset;

                    // Setup NAClassLoader and Load Locations
                    INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2;
                    naClassLoader.Initialize(naContext, naDataset.Name, cursor);

                    // Avoid loading network locations onto non-traversable portions of elements
                    INALocator3 locator = naContext.Locator as INALocator3;
                    locator.ExcludeRestrictedElements = true;
                    locator.CacheRestrictedElements(naContext);

                    int rowsIn      = 0;
                    int rowsLocated = 0;
                    naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated);

                    // Let the user know if some of the rows failed to locate
                    if (rowsIn != rowsLocated)
                    {
                        MessageBox.Show("Out of " + rowsIn + " + rows, " + rowsLocated + " rows were located",
                                        "Loading locations", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Loading locations failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                return(true);
            }

            return(false);
        }
		public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv)
		{
			// Initialize variables
			m_okClicked = false;
			m_listDisplayTable = new System.Collections.ArrayList();

			var activeCategory = naEnv.NAWindow.ActiveCategory as IEngineNAWindowCategory2;
			if (activeCategory == null)
				return false;

			IDataLayer dataLayer = activeCategory.DataLayer;
			if (dataLayer == null)
				return false;

			// Set up the title of this dialog
			String dataLayerName = GetDataLayerName(dataLayer);
			if (dataLayerName.Length == 0)
				return false;

			this.Text = "Load Items into " + dataLayerName;

			// Make sure the combo box lists only the appropriate possible input data layers
			PopulateInputDataComboBox(mapControl, dataLayer);

			//Select the first display table from the list
			if (cboInputData.Items.Count > 0)
				cboInputData.SelectedIndex = 0;

			// Show the window
			this.ShowDialog();

			// If we selected a layer and clicked OK, load the locations
			if (m_okClicked && (cboInputData.SelectedIndex >= 0))
			{
				try
				{
					// Get a cursor on the source display table (either though the selection set or table)
					// Use IDisplayTable because it accounts for joins, querydefs, etc.
					// IDisplayTable is implemented by FeatureLayers and StandaloneTables.
					//
					IDisplayTable displayTable = m_listDisplayTable[cboInputData.SelectedIndex] as IDisplayTable;
					ICursor cursor;
					if (chkUseSelection.Checked)
					{
						ISelectionSet selSet;
						selSet = displayTable.DisplaySelectionSet;
						selSet.Search(null, false, out cursor);
					}
					else
						cursor = displayTable.SearchDisplayTable(null, false);

					// Get the NAContext from the active analysis layer
					INAContext naContext = naEnv.NAWindow.ActiveAnalysis.Context;

					// Get the dataset for the active NAClass  
					IDataset naDataset = activeCategory.NAClass as IDataset;

					// Setup NAClassLoader and Load Locations
					INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2;
					naClassLoader.Initialize(naContext, naDataset.Name, cursor);

					// Avoid loading network locations onto non-traversable portions of elements
					INALocator3 locator = naContext.Locator as INALocator3;
					locator.ExcludeRestrictedElements = true;
					locator.CacheRestrictedElements(naContext);

					int rowsIn = 0;
					int rowsLocated = 0;
					naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated);

					// Let the user know if some of the rows failed to locate
					if (rowsIn != rowsLocated)
						MessageBox.Show("Out of " + rowsIn + " + rows, " + rowsLocated + " rows were located", 
										"Loading locations", MessageBoxButtons.OK, MessageBoxIcon.Information);
				}
				catch (Exception e)
				{
					MessageBox.Show(e.Message, "Loading locations failure", MessageBoxButtons.OK, MessageBoxIcon.Error );					
				}

				return true;
			}

			return false;
		}
Exemplo n.º 6
0
        public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv)
        {
            // Initialize variables
            m_okClicked        = false;
            m_listDisplayTable = new System.Collections.ArrayList();

            // Get the NALayer and NAContext
            INALayer   naLayer   = naEnv.NAWindow.ActiveAnalysis;
            INAContext naContext = naLayer.Context;

            //Get the active category
            IEngineNAWindowCategory2 activeCategory = naEnv.NAWindow.ActiveCategory as IEngineNAWindowCategory2;

            if (activeCategory == null)
            {
                return(false);
            }

            INAClass   naClass    = activeCategory.NAClass;
            IDataset   naDataset  = naClass as IDataset;
            IDataLayer pDataLayer = activeCategory.DataLayer;

            ILayer           pLayer           = pDataLayer as ILayer;
            IFeatureLayer    pFeatureLayer    = pDataLayer as IFeatureLayer;
            IStandaloneTable pStandaloneTable = pDataLayer as IStandaloneTable;

            esriGeometryType targetGeoType = esriGeometryType.esriGeometryNull;

            String dataLayerName = "";

            if (pFeatureLayer != null)
            {
                if (pLayer.Valid)
                {
                    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                    if (pFeatureClass != null)
                    {
                        targetGeoType = pFeatureClass.ShapeType;
                        dataLayerName = pLayer.Name;
                    }
                }
            }
            else if (pStandaloneTable != null)
            {
                dataLayerName = pStandaloneTable.Name;
            }

            if (dataLayerName.Length == 0)
            {
                return(false);
            }

            this.Text = "Load Items into " + dataLayerName;

            // Loop through all the sourcedisplayTables having targetGeoType to the combo box and the
            // list of displayTables

            IEnumLayer    sourceLayers       = null;
            ILayer        sourceLayer        = null;
            IDisplayTable sourceDisplayTable = null;
            UID           searchInterfaceUID = new UID();

            if (targetGeoType != esriGeometryType.esriGeometryNull)
            {
                searchInterfaceUID.Value = typeof(IFeatureLayer).GUID.ToString("B");
                sourceLayers             = mapControl.Map.get_Layers(searchInterfaceUID, true);

                sourceLayer = sourceLayers.Next();
                while (sourceLayer != null)
                {
                    IFeatureLayer sourceFeatureLayer = sourceLayer as IFeatureLayer;
                    sourceDisplayTable = sourceLayer as IDisplayTable;

                    if ((sourceFeatureLayer != null) && (sourceDisplayTable != null))
                    {
                        IFeatureClass    sourceFeatureClass = sourceFeatureLayer.FeatureClass;
                        esriGeometryType sourceGeoType      = sourceFeatureClass.ShapeType;
                        if ((sourceGeoType == targetGeoType) ||
                            (targetGeoType == esriGeometryType.esriGeometryPoint && sourceGeoType == esriGeometryType.esriGeometryMultipoint))
                        {
                            // Add the layer name to the combobox and the layer to the list
                            cboInputData.Items.Add(sourceLayer.Name);
                            m_listDisplayTable.Add(sourceDisplayTable);
                        }
                    }

                    sourceLayer = sourceLayers.Next();
                }
            }
            else //if (targetGeoType == esriGeometryType.esriGeometryNull)
            {
                IStandaloneTableCollection sourceStandaloneTables = mapControl.Map as IStandaloneTableCollection;
                IStandaloneTable           sourceStandaloneTable  = null;
                sourceDisplayTable = null;

                int count = 0;
                if (sourceStandaloneTables != null)
                {
                    count = sourceStandaloneTables.StandaloneTableCount;
                }

                for (int i = 0; i < count; ++i)
                {
                    sourceStandaloneTable = sourceStandaloneTables.get_StandaloneTable(i);
                    sourceDisplayTable    = sourceStandaloneTable as IDisplayTable;

                    if ((sourceStandaloneTable != null) && (sourceDisplayTable != null))
                    {
                        // Add the table name to the combobox and the layer to the list
                        cboInputData.Items.Add(sourceStandaloneTable.Name);
                        m_listDisplayTable.Add(sourceDisplayTable);
                    }
                }

                searchInterfaceUID.Value = typeof(INALayer).GUID.ToString("B");
                sourceLayers             = mapControl.Map.get_Layers(searchInterfaceUID, true);

                sourceLayer = sourceLayers.Next();
                while (sourceLayer != null)
                {
                    INALayer sourceNALayer = sourceLayer as INALayer;
                    if (sourceNALayer != null)
                    {
                        sourceStandaloneTables = sourceNALayer as IStandaloneTableCollection;
                        sourceStandaloneTable  = null;
                        sourceDisplayTable     = null;

                        count = 0;
                        if (sourceStandaloneTables != null)
                        {
                            count = sourceStandaloneTables.StandaloneTableCount;
                        }

                        for (int i = 0; i < count; ++i)
                        {
                            sourceStandaloneTable = sourceStandaloneTables.get_StandaloneTable(i);
                            sourceDisplayTable    = sourceStandaloneTable as IDisplayTable;

                            if ((sourceStandaloneTable != null) && (sourceDisplayTable != null))
                            {
                                // Add the table name to the combobox and the layer to the list
                                cboInputData.Items.Add(sourceStandaloneTable.Name);
                                m_listDisplayTable.Add(sourceDisplayTable);
                            }
                        }
                    }

                    sourceLayer = sourceLayers.Next();
                }
            }

            //Select the first display table from the list
            if (cboInputData.Items.Count > 0)
            {
                cboInputData.SelectedIndex = 0;
            }

            // Show the window
            this.ShowDialog();

            // If we selected a layer and clicked OK, load the locations
            if (m_okClicked && (cboInputData.SelectedIndex >= 0))
            {
                // Get a cursor on the source display table (either though the selection set or table)
                // Use IDisplayTable because it accounts for joins, querydefs, etc.
                // IDisplayTable is implemented by FeatureLayers and StandaloneTables.
                //
                IDisplayTable displayTable = m_listDisplayTable[cboInputData.SelectedIndex] as IDisplayTable;
                ICursor       cursor;
                if (chkUseSelection.Checked)
                {
                    ISelectionSet selSet;
                    selSet = displayTable.DisplaySelectionSet;
                    selSet.Search(null, false, out cursor);
                }
                else
                {
                    cursor = displayTable.SearchDisplayTable(null, false);
                }

                // Setup NAClassLoader and Load Locations
                INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2;
                naClassLoader.Initialize(naContext, naDataset.Name, cursor);

                // Avoid loading network locations onto non-traversable portions of elements
                INALocator3 locator = naContext.Locator as INALocator3;
                locator.ExcludeRestrictedElements = true;
                locator.CacheRestrictedElements(naContext);

                int rowsIn      = 0;
                int rowsLocated = 0;
                naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated);

                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            this.SetStyle(ControlStyles.EnableNotifyMessage, true);
            //Set label editing to manual
            axTOCControl1.LabelEdit = esriTOCControlEdit.esriTOCControlManual;
            //identifyCommand.Identify idCommand=new identifyCommand.Identify();
            //idCommand.setStatsBar(statusBar1);
            string strMxdFileName = Application.StartupPath + @"\..\..\..\Data\Network\data.mxd";
            if (axMapControl1.CheckMxFile(strMxdFileName) == true)
            {
                axMapControl1.LoadMxFile(strMxdFileName, null, null);
                axMapControl2.LoadMxFile(strMxdFileName, null, null);
                if (CheckNetWorkExtension(Application.StartupPath + @"\..\..\..\Data\Network\Network") == true)
                {
                    toolBarButtonOpen.Enabled = true;
                    toolBarButtonSolve.Enabled = false;
                    EnableNetworkMenu(false);
                }
                else
                {
                    toolBarButtonOpen.Enabled = false;
                    toolBarButtonSolve.Enabled = false;
                    EnableNetworkMenu(false);
                }
            }
            else
            {
                MessageBox.Show("��ѡ����ĵ���ͼ�ļ�������,������ָ��!", "������ʾ");
            }
            // Initialize naEnv variables
            m_naEnv = new EngineNetworkAnalystEnvironmentClass();
            m_naEnv.ZoomToResultAfterSolve = false;
            m_naEnv.ShowAnalysisMessagesAfterSolve = (int)(esriEngineNAMessageType.esriEngineNAMessageTypeInformative | esriEngineNAMessageType.esriEngineNAMessageTypeWarning);
            //m_naWindow = m_naEnv.NAWindow;

            //overviewControl1.SetBuddyMapControl(axMapControl1);
            axTOCControl1.SetBuddyControl(axMapControl1);
            IElement element = m_AOI as IElement;
            axMapControl2.Extent = axMapControl2.FullExtent;
            element.Geometry = axMapControl1.Extent.Envelope;
            m_AOI.SpatialReference = axMapControl1.SpatialReference;
            axMapControl2.SpatialReference = axMapControl1.SpatialReference;
            UpdateUI();

            this.WindowState = FormWindowState.Normal;
        }
Exemplo n.º 8
0
        public override void OnCreate(object hook)
        {
            m_mapControl = (IMapControl3) hook;

            // Get the Network Analyst Env
            m_naEnv = new EngineNetworkAnalystEnvironmentClass();
        }
Exemplo n.º 9
0
        public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv)
        {
            // Initialize variables
            m_okClicked = false;
            m_lstLayers = new System.Collections.ArrayList();
            this.Text = "Load Locations into " + naEnv.NAWindow.ActiveCategory.Layer.Name;

            // Loop through all the layers, adding the point feature layers to the combo box and array
            IEnumLayer layers = mapControl.Map.get_Layers(null, true);
            ILayer layer;
            layer = layers.Next();
            while (layer != null)
            {
                IFeatureLayer fLayer = layer as IFeatureLayer;
                IDisplayTable displayTable = layer as IDisplayTable;

                if ((fLayer != null) && (displayTable != null))
                {
                    IFeatureClass fClass = fLayer.FeatureClass;
                    if (fClass.ShapeType == esriGeometryType.esriGeometryPoint)
                    {
                        // Add the layer name to the combobox and the layer to the list
                        cboPointLayers.Items.Add(layer.Name);
                        m_lstLayers.Add(layer);
                    }
                }
                layer = layers.Next();
            }
            //Select the first point feature layer from the list
            if (cboPointLayers.Items.Count > 0)
                cboPointLayers.SelectedIndex = 0;

            // Show the window
            this.ShowDialog();

            // If we selected a layer and clicked OK, load the locations
            if (m_okClicked && (cboPointLayers.SelectedIndex >= 0))
            {
                // Get the NALayer and NAContext
                INALayer naLayer = naEnv.NAWindow.ActiveAnalysis;
                INAContext naContext = naLayer.Context;

                //Get the active category
                IEngineNAWindowCategory activeCategory = naEnv.NAWindow.ActiveCategory;
                INAClass naClass = activeCategory.NAClass;
                IDataset naDataset = naClass as IDataset;

                // Get a cursor to the input features (either though the selection set or table)
                // Use IDisplayTable because it accounts for joins, querydefs, etc.
                IDisplayTable displayTable = m_lstLayers[cboPointLayers.SelectedIndex] as IDisplayTable;
                ICursor cursor;
                if (chkUseSelectedFeatures.Checked)
                {
                    ISelectionSet selSet;
                    selSet = displayTable.DisplaySelectionSet;
                    selSet.Search(null, false, out cursor);
                }
                else
                {
                    cursor = displayTable.SearchDisplayTable(null, false);
                }

                // Setup NAClassLoader and Load Locations
                INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2;
                naClassLoader.Initialize(naContext, naDataset.Name, cursor);
                int rowsIn = 0;
                int rowsLocated = 0;
                naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated);

                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 10
0
        private void frmMain_Load(object sender, System.EventArgs e)
        {
            // Add commands to the NALayer context menu
            m_menuLayer = new ToolbarMenuClass();

            int nItem = -1;

            m_menuLayer.AddItem(new cmdLoadLocations(), -1, ++nItem, false, esriCommandStyles.esriCommandStyleTextOnly);
            m_menuLayer.AddItem(new cmdRemoveLayer(), -1, ++nItem, false, esriCommandStyles.esriCommandStyleTextOnly);
            m_menuLayer.AddItem(new cmdClearAnalysisLayer(), -1, ++nItem, true, esriCommandStyles.esriCommandStyleTextOnly);
            m_menuLayer.AddItem(new cmdNALayerProperties(), -1, ++nItem, true, esriCommandStyles.esriCommandStyleTextOnly);

            // Since this ToolbarMenu is a standalone popup menu use the SetHook method to
            //  specify the object that will be sent as a "hook" to the menu commands in their OnCreate methods.
            m_menuLayer.SetHook(axMapControl1);

            // Add command for ArcGIS Network Analyst extension env properties to end of "Network Analyst" dropdown menu
            nItem = -1;
            for (int i = 0; i < axToolbarControl1.Count; ++i)
            {
                IToolbarItem item = axToolbarControl1.GetItem(i);
                IToolbarMenu mnu  = item.Menu;

                if (mnu == null)
                {
                    continue;
                }

                IMenuDef mnudef = mnu.GetMenuDef();
                string   name   = mnudef.Name;

                // Find the ArcGIS Network Analyst extension solver menu drop down and note the index
                if (name == "ControlToolsNetworkAnalyst_SolverMenu")
                {
                    nItem = i;
                    //break;
                }
            }

            if (nItem >= 0)
            {
                // Using the index found above, get the solver menu drop down and add the Properties command to the end of it.
                IToolbarItem item = axToolbarControl1.GetItem(nItem);
                IToolbarMenu mnu  = item.Menu;
                if (mnu != null)
                {
                    mnu.AddItem(new cmdNAProperties(), -1, mnu.Count, true, esriCommandStyles.esriCommandStyleTextOnly);
                }

                // Since this ToolbarMenu is an item on the ToolbarControl the Hook is shared and initialized by the ToolbarControl.
                //  Therefore, SetHook is not called here, like it is for the menu above.
            }

            // Initialize naEnv variables
            m_naEnv = CommonFunctions.GetTheEngineNetworkAnalystEnvironment();
            if (m_naEnv == null)
            {
                MessageBox.Show("Error: EngineNetworkAnalystEnvironment is not properly configured");
                return;
            }

            m_naEnv.ZoomToResultAfterSolve         = false;
            m_naEnv.ShowAnalysisMessagesAfterSolve = (int)(esriEngineNAMessageType.esriEngineNAMessageTypeInformative |
                                                           esriEngineNAMessageType.esriEngineNAMessageTypeWarning);

            // Set up the buddy control and initialize the NA extension, so we can get to NAWindow to listen to window events.
            // This is necessary, as the various controls are not yet set up. They need to be in order to get the NAWindow's events.
            axToolbarControl1.SetBuddyControl(axMapControl1);
            IExtension ext = m_naEnv as IExtension;
            object     obj = axToolbarControl1.Object;

            ext.Startup(ref obj);

            // m_naWindow is set after Startup of the Network Analyst extension
            m_naWindow = m_naEnv.NAWindow;
            if (m_naWindow == null)
            {
                MessageBox.Show("Error: Unexpected null NAWindow");
                return;
            }

            m_onContextMenu = new IEngineNAWindowEventsEx_OnContextMenuEventHandler(OnContextMenu);
            ((IEngineNAWindowEventsEx_Event)m_naWindow).OnContextMenu += m_onContextMenu;

            m_OnNetworkLayersChanged = new IEngineNetworkAnalystEnvironmentEvents_OnNetworkLayersChangedEventHandler(OnNetworkLayersChanged);
            ((IEngineNetworkAnalystEnvironmentEvents_Event)m_naEnv).OnNetworkLayersChanged += m_OnNetworkLayersChanged;

            m_OnCurrentNetworkLayerChanged = new IEngineNetworkAnalystEnvironmentEvents_OnCurrentNetworkLayerChangedEventHandler(OnCurrentNetworkLayerChanged);
            ((IEngineNetworkAnalystEnvironmentEvents_Event)m_naEnv).OnCurrentNetworkLayerChanged += m_OnCurrentNetworkLayerChanged;
        }
Exemplo n.º 11
0
        private void frmMain_Load(object sender, System.EventArgs e)
        {
            // Add commands to the NALayer context menu
            // 向Nalayer上下文菜单添加命令
            m_menuLayer = new ToolbarMenuClass();

            int nItem = -1;

            m_menuLayer.AddItem(new cmdLoadLocations(), -1, ++nItem, false, esriCommandStyles.esriCommandStyleTextOnly);
            m_menuLayer.AddItem(new cmdRemoveLayer(), -1, ++nItem, false, esriCommandStyles.esriCommandStyleTextOnly);
            m_menuLayer.AddItem(new cmdClearAnalysisLayer(), -1, ++nItem, true, esriCommandStyles.esriCommandStyleTextOnly);
            m_menuLayer.AddItem(new cmdNALayerProperties(), -1, ++nItem, true, esriCommandStyles.esriCommandStyleTextOnly);
            m_menuLayer.SetHook(axMapControl1);

            // Add command for Network Analyst env properties to end of "Network Analyst" dropdown menu
            // 将网络分析env属性的命令添加到“网络分析师”下拉菜单的末尾
            nItem = -1;
            for (int i = 0; i < axToolbarControl1.Count; ++i)
            {
                IToolbarItem item = axToolbarControl1.GetItem(i);
                IToolbarMenu mnu  = item.Menu;

                if (mnu == null)
                {
                    continue;
                }

                IMenuDef mnudef = mnu.GetMenuDef();
                string   name   = mnudef.Name;
                if (name == "ControlToolsNetworkAnalyst_SolverMenu")
                {
                    nItem = i;
                    break;
                }
            }

            if (nItem >= 0)
            {
                IToolbarItem item = axToolbarControl1.GetItem(nItem);
                IToolbarMenu mnu  = item.Menu;
                if (mnu != null)
                {
                    mnu.AddItem(new cmdNAProperties(), -1, mnu.Count, true, esriCommandStyles.esriCommandStyleTextOnly);
                }
            }

            // Initialize naEnv variables
            // 初始化naEnv变量
            m_naEnv = new EngineNetworkAnalystEnvironmentClass();
            m_naEnv.ZoomToResultAfterSolve         = false;
            m_naEnv.ShowAnalysisMessagesAfterSolve = (int)(esriEngineNAMessageType.esriEngineNAMessageTypeInformative | esriEngineNAMessageType.esriEngineNAMessageTypeWarning);

            // Explicitly setup buddy control and initialize NA extension
            // so we can get to NAWindow to listen to window events
            // This is necessary the various controls are not yet setup and they
            // need to be in order to get the NAWindow's events.
            // 显式设置伙伴控件并初始化na扩展,以便我们可以访问na window来侦听窗口事件。
            // 这是必需的,各种控件尚未设置,它们需要用于获取nawindow的事件。
            axToolbarControl1.SetBuddyControl(axMapControl1);
            IExtension ext = m_naEnv as IExtension;
            object     obj = axToolbarControl1.Object;

            ext.Startup(ref obj);
            m_naWindow      = m_naEnv.NAWindow;
            m_onContextMenu = new IEngineNAWindowEventsEx_OnContextMenuEventHandler(OnContextMenu);
            ((IEngineNAWindowEventsEx_Event)m_naWindow).OnContextMenu += m_onContextMenu;
        }
Exemplo n.º 12
0
        public bool ShowModal(IMapControl3 mapControl, IEngineNetworkAnalystEnvironment naEnv)
        {
            // Initialize variables
            m_okClicked = false;
            m_lstLayers = new System.Collections.ArrayList();
            this.Text   = "Load Locations into " + naEnv.NAWindow.ActiveCategory.Layer.Name;

            // Loop through all the layers, adding the point feature layers to the combo box and array
            IEnumLayer layers = mapControl.Map.get_Layers(null, true);
            ILayer     layer;

            layer = layers.Next();
            while (layer != null)
            {
                IFeatureLayer fLayer       = layer as IFeatureLayer;
                IDisplayTable displayTable = layer as IDisplayTable;

                if ((fLayer != null) && (displayTable != null))
                {
                    IFeatureClass fClass = fLayer.FeatureClass;
                    if (fClass.ShapeType == esriGeometryType.esriGeometryPoint)
                    {
                        // Add the layer name to the combobox and the layer to the list
                        cboPointLayers.Items.Add(layer.Name);
                        m_lstLayers.Add(layer);
                    }
                }
                layer = layers.Next();
            }
            //Select the first point feature layer from the list
            if (cboPointLayers.Items.Count > 0)
            {
                cboPointLayers.SelectedIndex = 0;
            }

            // Show the window
            this.ShowDialog();

            // If we selected a layer and clicked OK, load the locations
            if (m_okClicked && (cboPointLayers.SelectedIndex >= 0))
            {
                // Get the NALayer and NAContext
                INALayer   naLayer   = naEnv.NAWindow.ActiveAnalysis;
                INAContext naContext = naLayer.Context;

                //Get the active category
                IEngineNAWindowCategory activeCategory = naEnv.NAWindow.ActiveCategory;
                INAClass naClass   = activeCategory.NAClass;
                IDataset naDataset = naClass as IDataset;

                // Get a cursor to the input features (either though the selection set or table)
                // Use IDisplayTable because it accounts for joins, querydefs, etc.
                IDisplayTable displayTable = m_lstLayers[cboPointLayers.SelectedIndex] as IDisplayTable;
                ICursor       cursor;
                if (chkUseSelectedFeatures.Checked)
                {
                    ISelectionSet selSet;
                    selSet = displayTable.DisplaySelectionSet;
                    selSet.Search(null, false, out cursor);
                }
                else
                {
                    cursor = displayTable.SearchDisplayTable(null, false);
                }

                // Setup NAClassLoader and Load Locations
                INAClassLoader2 naClassLoader = new NAClassLoader() as INAClassLoader2;
                naClassLoader.Initialize(naContext, naDataset.Name, cursor);
                int rowsIn      = 0;
                int rowsLocated = 0;
                naClassLoader.Load(cursor, null, ref rowsIn, ref rowsLocated);

                return(true);
            }
            else
            {
                return(false);
            }
        }
		private void frmMain_Load(object sender, System.EventArgs e)
		{
			// Add commands to the NALayer context menu
			m_menuLayer = new ToolbarMenuClass();

			int nItem = -1;
			m_menuLayer.AddItem(new cmdLoadLocations(), -1, ++nItem, false, esriCommandStyles.esriCommandStyleTextOnly);
			m_menuLayer.AddItem(new cmdRemoveLayer(), -1, ++nItem, false, esriCommandStyles.esriCommandStyleTextOnly);
			m_menuLayer.AddItem(new cmdClearAnalysisLayer(), -1, ++nItem, true, esriCommandStyles.esriCommandStyleTextOnly);
			m_menuLayer.AddItem(new cmdNALayerProperties(), -1, ++nItem, true, esriCommandStyles.esriCommandStyleTextOnly);

			// Since this ToolbarMenu is a standalone popup menu use the SetHook method to
			//  specify the object that will be sent as a "hook" to the menu commands in their OnCreate methods.
			m_menuLayer.SetHook(axMapControl1);

			// Add command for ArcGIS Network Analyst extension env properties to end of "Network Analyst" dropdown menu
			nItem = -1;
			for (int i = 0; i < axToolbarControl1.Count; ++i)
			{
				IToolbarItem item = axToolbarControl1.GetItem(i);
				IToolbarMenu mnu = item.Menu;

				if (mnu == null) continue;

				IMenuDef mnudef = mnu.GetMenuDef();
				string name = mnudef.Name;

				// Find the ArcGIS Network Analyst extension solver menu drop down and note the index
				if (name == "ControlToolsNetworkAnalyst_SolverMenu")
				{
					nItem = i;
					//break;
				}
			}

			if (nItem >= 0)
			{
				// Using the index found above, get the solver menu drop down and add the Properties command to the end of it.
				IToolbarItem item = axToolbarControl1.GetItem(nItem);
				IToolbarMenu mnu = item.Menu;
				if (mnu != null)
					mnu.AddItem(new cmdNAProperties(), -1, mnu.Count, true, esriCommandStyles.esriCommandStyleTextOnly);

				// Since this ToolbarMenu is an item on the ToolbarControl the Hook is shared and initialized by the ToolbarControl.
				//  Therefore, SetHook is not called here, like it is for the menu above.
			}

			// Initialize naEnv variables
			m_naEnv = CommonFunctions.GetTheEngineNetworkAnalystEnvironment();
			if (m_naEnv == null)
			{
				MessageBox.Show("Error: EngineNetworkAnalystEnvironment is not properly configured");
				return;
			}

			m_naEnv.ZoomToResultAfterSolve = false;
			m_naEnv.ShowAnalysisMessagesAfterSolve = (int)(esriEngineNAMessageType.esriEngineNAMessageTypeInformative | 
														   esriEngineNAMessageType.esriEngineNAMessageTypeWarning);

			// Set up the buddy control and initialize the NA extension, so we can get to NAWindow to listen to window events.
			// This is necessary, as the various controls are not yet set up. They need to be in order to get the NAWindow's events.
			axToolbarControl1.SetBuddyControl(axMapControl1);
			IExtension ext = m_naEnv as IExtension;
			object obj = axToolbarControl1.Object;
			
			ext.Startup(ref obj);
			
			// m_naWindow is set after Startup of the Network Analyst extension
			m_naWindow = m_naEnv.NAWindow;
			if (m_naWindow == null)
			{
				MessageBox.Show("Error: Unexpected null NAWindow");
				return;
			}

			m_onContextMenu = new IEngineNAWindowEventsEx_OnContextMenuEventHandler(OnContextMenu);
			((IEngineNAWindowEventsEx_Event)m_naWindow).OnContextMenu += m_onContextMenu;

            m_OnNetworkLayersChanged = new IEngineNetworkAnalystEnvironmentEvents_OnNetworkLayersChangedEventHandler(OnNetworkLayersChanged);
            ((IEngineNetworkAnalystEnvironmentEvents_Event)m_naEnv).OnNetworkLayersChanged += m_OnNetworkLayersChanged;

            m_OnCurrentNetworkLayerChanged = new IEngineNetworkAnalystEnvironmentEvents_OnCurrentNetworkLayerChangedEventHandler(OnCurrentNetworkLayerChanged);
            ((IEngineNetworkAnalystEnvironmentEvents_Event)m_naEnv).OnCurrentNetworkLayerChanged += m_OnCurrentNetworkLayerChanged;
		}