About the Route application using the NAServer extension in ArcGIS Server via a GIS client Sample
[C#]
Route_GISClientClass.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.GISClient;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Location;
using ESRI.ArcGIS.NetworkAnalyst;
using System.Collections.Specialized;
namespace Route_GISClient
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Route_GISServerAPIClass : System.Windows.Forms.Form
{
#region Window Controls Declaration
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtServer;
private System.Windows.Forms.TextBox txtService;
private System.Windows.Forms.PictureBox pictureBox;
private System.Windows.Forms.GroupBox fraINASolverSettings;
private System.Windows.Forms.ComboBox cboUturnPolicy;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.CheckedListBox chklstAccumulateAttributes;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.CheckedListBox chklstRestrictions;
private System.Windows.Forms.ComboBox cboImpedance;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.CheckBox chkIgnoreInvalidLocations;
private System.Windows.Forms.ComboBox cboNALayers;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.CheckBox chkReturnMap;
private System.Windows.Forms.Button cmdSolve;
private System.Windows.Forms.ComboBox cboSnapToleranceUnits;
private System.Windows.Forms.TextBox txtMaxSnapTolerance;
private System.Windows.Forms.TextBox txtSnapTolerance;
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.Label label20;
private System.Windows.Forms.Label label21;
private System.Windows.Forms.Label label22;
private System.Windows.Forms.CheckBox chkPreserveFirst;
private System.Windows.Forms.CheckBox chkBestOrder;
private System.Windows.Forms.ComboBox cboRouteDirectionsLengthUnits;
private System.Windows.Forms.CheckBox chkReturnRoutes;
private System.Windows.Forms.CheckBox chkReturnRouteGeometries;
private System.Windows.Forms.CheckBox chkReturnStops;
private System.Windows.Forms.CheckBox chkReturnDirections;
private System.Windows.Forms.ComboBox cboRouteOutputLines;
private System.Windows.Forms.CheckBox chkUseTimeWindows;
private System.Windows.Forms.CheckBox chkPreserveLast;
private System.Windows.Forms.ComboBox cboRouteDirectionsTimeAttribute;
private System.Windows.Forms.GroupBox fraINARouteSolver;
private System.Windows.Forms.GroupBox fraINAServerRouteParams;
private System.Windows.Forms.TabControl tabCtrlOutput;
private System.Windows.Forms.TabPage tabReturnStopsFeatures;
private System.Windows.Forms.TabPage tabReturnBarrierFeatures;
private System.Windows.Forms.TabPage tabReturnDirections;
private System.Windows.Forms.TabPage tabReturnRouteFeatures;
private System.Windows.Forms.DataGrid dataGridRouteFeatures;
private System.Windows.Forms.DataGrid dataGridStopFeatures;
private System.Windows.Forms.DataGrid dataGridBarrierFeatures;
private System.Windows.Forms.TabPage tabReturnMap;
private System.Windows.Forms.TabPage tabReturnRouteGeometry;
private System.Windows.Forms.TreeView treeViewRouteGeometry;
private System.Windows.Forms.TreeView treeViewDirections;
private System.Windows.Forms.CheckBox checkReturnBarriers;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.CheckBox chkUseHierarchy;
private System.Windows.Forms.ComboBox cboStopsLayers;
private System.Windows.Forms.Button cmdConnect;
private System.Windows.Forms.CheckBox chkUseStartTime;
private System.Windows.Forms.TextBox txtStartTime;
private System.Windows.Forms.GroupBox fraINAServerSolverParams;
private INAServer m_naServer;
private IMapServer m_mapServer;
private ArrayList m_layerIDs;
#endregion
public Route_GISServerAPIClass()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
m_layerIDs = new ArrayList();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txtServer = new System.Windows.Forms.TextBox();
this.txtService = new System.Windows.Forms.TextBox();
this.cmdSolve = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.fraINASolverSettings = new System.Windows.Forms.GroupBox();
this.chkIgnoreInvalidLocations = new System.Windows.Forms.CheckBox();
this.cboUturnPolicy = new System.Windows.Forms.ComboBox();
this.label11 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.chklstAccumulateAttributes = new System.Windows.Forms.CheckedListBox();
this.label5 = new System.Windows.Forms.Label();
this.chklstRestrictions = new System.Windows.Forms.CheckedListBox();
this.cboImpedance = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.chkUseHierarchy = new System.Windows.Forms.CheckBox();
this.fraINAServerSolverParams = new System.Windows.Forms.GroupBox();
this.chkReturnMap = new System.Windows.Forms.CheckBox();
this.cboSnapToleranceUnits = new System.Windows.Forms.ComboBox();
this.cboNALayers = new System.Windows.Forms.ComboBox();
this.label10 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.txtMaxSnapTolerance = new System.Windows.Forms.TextBox();
this.txtSnapTolerance = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.fraINARouteSolver = new System.Windows.Forms.GroupBox();
this.label20 = new System.Windows.Forms.Label();
this.cboRouteOutputLines = new System.Windows.Forms.ComboBox();
this.chkUseTimeWindows = new System.Windows.Forms.CheckBox();
this.chkPreserveLast = new System.Windows.Forms.CheckBox();
this.chkPreserveFirst = new System.Windows.Forms.CheckBox();
this.chkBestOrder = new System.Windows.Forms.CheckBox();
this.chkUseStartTime = new System.Windows.Forms.CheckBox();
this.txtStartTime = new System.Windows.Forms.TextBox();
this.fraINAServerRouteParams = new System.Windows.Forms.GroupBox();
this.cboStopsLayers = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.checkReturnBarriers = new System.Windows.Forms.CheckBox();
this.cboRouteDirectionsTimeAttribute = new System.Windows.Forms.ComboBox();
this.label21 = new System.Windows.Forms.Label();
this.cboRouteDirectionsLengthUnits = new System.Windows.Forms.ComboBox();
this.label22 = new System.Windows.Forms.Label();
this.chkReturnRoutes = new System.Windows.Forms.CheckBox();
this.chkReturnRouteGeometries = new System.Windows.Forms.CheckBox();
this.chkReturnStops = new System.Windows.Forms.CheckBox();
this.chkReturnDirections = new System.Windows.Forms.CheckBox();
this.cmdConnect = new System.Windows.Forms.Button();
this.tabCtrlOutput = new System.Windows.Forms.TabControl();
this.tabReturnMap = new System.Windows.Forms.TabPage();
this.tabReturnRouteFeatures = new System.Windows.Forms.TabPage();
this.dataGridRouteFeatures = new System.Windows.Forms.DataGrid();
this.tabReturnBarrierFeatures = new System.Windows.Forms.TabPage();
this.dataGridBarrierFeatures = new System.Windows.Forms.DataGrid();
this.tabReturnStopsFeatures = new System.Windows.Forms.TabPage();
this.dataGridStopFeatures = new System.Windows.Forms.DataGrid();
this.tabReturnDirections = new System.Windows.Forms.TabPage();
this.treeViewDirections = new System.Windows.Forms.TreeView();
this.tabReturnRouteGeometry = new System.Windows.Forms.TabPage();
this.treeViewRouteGeometry = new System.Windows.Forms.TreeView();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.fraINASolverSettings.SuspendLayout();
this.fraINAServerSolverParams.SuspendLayout();
this.fraINARouteSolver.SuspendLayout();
this.fraINAServerRouteParams.SuspendLayout();
this.tabCtrlOutput.SuspendLayout();
this.tabReturnMap.SuspendLayout();
this.tabReturnRouteFeatures.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridRouteFeatures)).BeginInit();
this.tabReturnBarrierFeatures.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridBarrierFeatures)).BeginInit();
this.tabReturnStopsFeatures.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridStopFeatures)).BeginInit();
this.tabReturnDirections.SuspendLayout();
this.tabReturnRouteGeometry.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 16);
this.label1.TabIndex = 0;
this.label1.Text = "ArcGIS Server";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(120, 16);
this.label2.TabIndex = 1;
this.label2.Text = "Map Server Object";
//
// txtServer
//
this.txtServer.Location = new System.Drawing.Point(128, 16);
this.txtServer.Name = "txtServer";
this.txtServer.Size = new System.Drawing.Size(192, 20);
this.txtServer.TabIndex = 0;
this.txtServer.Text = "<Enter ArcGIS Server Name>";
//
// txtService
//
this.txtService.Location = new System.Drawing.Point(128, 40);
this.txtService.Name = "txtService";
this.txtService.Size = new System.Drawing.Size(192, 20);
this.txtService.TabIndex = 1;
this.txtService.Text = "<Enter ArcGIS Map Server Object>";
//
// cmdSolve
//
this.cmdSolve.Enabled = false;
this.cmdSolve.Location = new System.Drawing.Point(232, 568);
this.cmdSolve.Name = "cmdSolve";
this.cmdSolve.Size = new System.Drawing.Size(200, 32);
this.cmdSolve.TabIndex = 29;
this.cmdSolve.Text = "Find Route";
this.cmdSolve.Click += new System.EventHandler(this.cmdSolve_Click);
//
// pictureBox
//
this.pictureBox.BackColor = System.Drawing.Color.White;
this.pictureBox.Location = new System.Drawing.Point(8, 8);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(448, 456);
this.pictureBox.TabIndex = 20;
this.pictureBox.TabStop = false;
//
// fraINASolverSettings
//
this.fraINASolverSettings.Controls.Add(this.chkIgnoreInvalidLocations);
this.fraINASolverSettings.Controls.Add(this.cboUturnPolicy);
this.fraINASolverSettings.Controls.Add(this.label11);
this.fraINASolverSettings.Controls.Add(this.label7);
this.fraINASolverSettings.Controls.Add(this.chklstAccumulateAttributes);
this.fraINASolverSettings.Controls.Add(this.label5);
this.fraINASolverSettings.Controls.Add(this.chklstRestrictions);
this.fraINASolverSettings.Controls.Add(this.cboImpedance);
this.fraINASolverSettings.Controls.Add(this.label4);
this.fraINASolverSettings.Controls.Add(this.chkUseHierarchy);
this.fraINASolverSettings.Enabled = false;
this.fraINASolverSettings.Location = new System.Drawing.Point(8, 176);
this.fraINASolverSettings.Name = "fraINASolverSettings";
this.fraINASolverSettings.Size = new System.Drawing.Size(424, 192);
this.fraINASolverSettings.TabIndex = 70;
this.fraINASolverSettings.TabStop = false;
this.fraINASolverSettings.Text = "INASolverSettings";
//
// chkIgnoreInvalidLocations
//
this.chkIgnoreInvalidLocations.Location = new System.Drawing.Point(16, 80);
this.chkIgnoreInvalidLocations.Name = "chkIgnoreInvalidLocations";
this.chkIgnoreInvalidLocations.Size = new System.Drawing.Size(144, 21);
this.chkIgnoreInvalidLocations.TabIndex = 10;
this.chkIgnoreInvalidLocations.Text = "Ignore Invalid Locations";
//
// cboUturnPolicy
//
this.cboUturnPolicy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboUturnPolicy.Location = new System.Drawing.Point(128, 48);
this.cboUturnPolicy.Name = "cboUturnPolicy";
this.cboUturnPolicy.Size = new System.Drawing.Size(280, 21);
this.cboUturnPolicy.TabIndex = 9;
//
// label11
//
this.label11.Location = new System.Drawing.Point(16, 56);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(88, 16);
this.label11.TabIndex = 73;
this.label11.Text = "UTurn Policy";
//
// label7
//
this.label7.Location = new System.Drawing.Point(216, 104);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(120, 16);
this.label7.TabIndex = 72;
this.label7.Text = "Accumulate Attributes";
//
// chklstAccumulateAttributes
//
this.chklstAccumulateAttributes.CheckOnClick = true;
this.chklstAccumulateAttributes.Location = new System.Drawing.Point(216, 120);
this.chklstAccumulateAttributes.Name = "chklstAccumulateAttributes";
this.chklstAccumulateAttributes.ScrollAlwaysVisible = true;
this.chklstAccumulateAttributes.Size = new System.Drawing.Size(192, 64);
this.chklstAccumulateAttributes.TabIndex = 13;
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 104);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(72, 16);
this.label5.TabIndex = 70;
this.label5.Text = "Restrictions";
//
// chklstRestrictions
//
this.chklstRestrictions.CheckOnClick = true;
this.chklstRestrictions.Location = new System.Drawing.Point(16, 120);
this.chklstRestrictions.Name = "chklstRestrictions";
this.chklstRestrictions.ScrollAlwaysVisible = true;
this.chklstRestrictions.Size = new System.Drawing.Size(192, 64);
this.chklstRestrictions.TabIndex = 12;
//
// cboImpedance
//
this.cboImpedance.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboImpedance.Location = new System.Drawing.Point(128, 24);
this.cboImpedance.Name = "cboImpedance";
this.cboImpedance.Size = new System.Drawing.Size(280, 21);
this.cboImpedance.TabIndex = 8;
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 24);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(64, 16);
this.label4.TabIndex = 67;
this.label4.Text = "Impedance";
//
// chkUseHierarchy
//
this.chkUseHierarchy.Checked = true;
this.chkUseHierarchy.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkUseHierarchy.Location = new System.Drawing.Point(216, 80);
this.chkUseHierarchy.Name = "chkUseHierarchy";
this.chkUseHierarchy.Size = new System.Drawing.Size(96, 21);
this.chkUseHierarchy.TabIndex = 11;
this.chkUseHierarchy.Text = "Use Hierarchy";
//
// fraINAServerSolverParams
//
this.fraINAServerSolverParams.Controls.Add(this.chkReturnMap);
this.fraINAServerSolverParams.Controls.Add(this.cboSnapToleranceUnits);
this.fraINAServerSolverParams.Controls.Add(this.cboNALayers);
this.fraINAServerSolverParams.Controls.Add(this.label10);
this.fraINAServerSolverParams.Controls.Add(this.label8);
this.fraINAServerSolverParams.Controls.Add(this.txtMaxSnapTolerance);
this.fraINAServerSolverParams.Controls.Add(this.txtSnapTolerance);
this.fraINAServerSolverParams.Controls.Add(this.label9);
this.fraINAServerSolverParams.Enabled = false;
this.fraINAServerSolverParams.Location = new System.Drawing.Point(8, 72);
this.fraINAServerSolverParams.Name = "fraINAServerSolverParams";
this.fraINAServerSolverParams.Size = new System.Drawing.Size(424, 96);
this.fraINAServerSolverParams.TabIndex = 71;
this.fraINAServerSolverParams.TabStop = false;
this.fraINAServerSolverParams.Text = "INAServerSolverParams";
//
// chkReturnMap
//
this.chkReturnMap.Checked = true;
this.chkReturnMap.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkReturnMap.Location = new System.Drawing.Point(8, 72);
this.chkReturnMap.Name = "chkReturnMap";
this.chkReturnMap.Size = new System.Drawing.Size(96, 16);
this.chkReturnMap.TabIndex = 7;
this.chkReturnMap.Text = "Return Map";
//
// cboSnapToleranceUnits
//
this.cboSnapToleranceUnits.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboSnapToleranceUnits.Location = new System.Drawing.Point(240, 48);
this.cboSnapToleranceUnits.Name = "cboSnapToleranceUnits";
this.cboSnapToleranceUnits.Size = new System.Drawing.Size(168, 21);
this.cboSnapToleranceUnits.TabIndex = 6;
//
// cboNALayers
//
this.cboNALayers.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboNALayers.Location = new System.Drawing.Point(128, 24);
this.cboNALayers.Name = "cboNALayers";
this.cboNALayers.Size = new System.Drawing.Size(280, 21);
this.cboNALayers.TabIndex = 3;
this.cboNALayers.SelectedIndexChanged += new System.EventHandler(this.cboNALayers_SelectedIndexChanged);
//
// label10
//
this.label10.Location = new System.Drawing.Point(168, 56);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(16, 16);
this.label10.TabIndex = 72;
this.label10.Text = "to";
//
// label8
//
this.label8.Location = new System.Drawing.Point(8, 24);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(128, 16);
this.label8.TabIndex = 71;
this.label8.Text = "NALayer Name";
//
// txtMaxSnapTolerance
//
this.txtMaxSnapTolerance.Location = new System.Drawing.Point(192, 48);
this.txtMaxSnapTolerance.Name = "txtMaxSnapTolerance";
this.txtMaxSnapTolerance.Size = new System.Drawing.Size(40, 20);
this.txtMaxSnapTolerance.TabIndex = 5;
this.txtMaxSnapTolerance.Text = "50";
//
// txtSnapTolerance
//
this.txtSnapTolerance.Location = new System.Drawing.Point(128, 48);
this.txtSnapTolerance.Name = "txtSnapTolerance";
this.txtSnapTolerance.Size = new System.Drawing.Size(32, 20);
this.txtSnapTolerance.TabIndex = 4;
this.txtSnapTolerance.Text = "2";
//
// label9
//
this.label9.Location = new System.Drawing.Point(8, 48);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(104, 16);
this.label9.TabIndex = 68;
this.label9.Text = "Search Tolerance";
//
// fraINARouteSolver
//
this.fraINARouteSolver.Controls.Add(this.label20);
this.fraINARouteSolver.Controls.Add(this.cboRouteOutputLines);
this.fraINARouteSolver.Controls.Add(this.chkUseTimeWindows);
this.fraINARouteSolver.Controls.Add(this.chkPreserveLast);
this.fraINARouteSolver.Controls.Add(this.chkPreserveFirst);
this.fraINARouteSolver.Controls.Add(this.chkBestOrder);
this.fraINARouteSolver.Controls.Add(this.chkUseStartTime);
this.fraINARouteSolver.Controls.Add(this.txtStartTime);
this.fraINARouteSolver.Enabled = false;
this.fraINARouteSolver.Location = new System.Drawing.Point(232, 376);
this.fraINARouteSolver.Name = "fraINARouteSolver";
this.fraINARouteSolver.Size = new System.Drawing.Size(200, 184);
this.fraINARouteSolver.TabIndex = 76;
this.fraINARouteSolver.TabStop = false;
this.fraINARouteSolver.Text = "INARouteSolver";
//
// label20
//
this.label20.Location = new System.Drawing.Point(8, 136);
this.label20.Name = "label20";
this.label20.Size = new System.Drawing.Size(40, 16);
this.label20.TabIndex = 53;
this.label20.Text = "Shape";
//
// cboRouteOutputLines
//
this.cboRouteOutputLines.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboRouteOutputLines.ItemHeight = 13;
this.cboRouteOutputLines.Location = new System.Drawing.Point(8, 152);
this.cboRouteOutputLines.Name = "cboRouteOutputLines";
this.cboRouteOutputLines.Size = new System.Drawing.Size(184, 21);
this.cboRouteOutputLines.TabIndex = 28;
//
// chkUseTimeWindows
//
this.chkUseTimeWindows.Location = new System.Drawing.Point(8, 80);
this.chkUseTimeWindows.Name = "chkUseTimeWindows";
this.chkUseTimeWindows.Size = new System.Drawing.Size(128, 16);
this.chkUseTimeWindows.TabIndex = 25;
this.chkUseTimeWindows.Text = "Use Time Windows";
//
// chkPreserveLast
//
this.chkPreserveLast.Location = new System.Drawing.Point(24, 56);
this.chkPreserveLast.Name = "chkPreserveLast";
this.chkPreserveLast.Size = new System.Drawing.Size(96, 16);
this.chkPreserveLast.TabIndex = 24;
this.chkPreserveLast.Text = "PreserveLast";
//
// chkPreserveFirst
//
this.chkPreserveFirst.Location = new System.Drawing.Point(24, 40);
this.chkPreserveFirst.Name = "chkPreserveFirst";
this.chkPreserveFirst.Size = new System.Drawing.Size(104, 16);
this.chkPreserveFirst.TabIndex = 23;
this.chkPreserveFirst.Text = "Preserve First";
//
// chkBestOrder
//
this.chkBestOrder.Location = new System.Drawing.Point(8, 24);
this.chkBestOrder.Name = "chkBestOrder";
this.chkBestOrder.Size = new System.Drawing.Size(112, 16);
this.chkBestOrder.TabIndex = 22;
this.chkBestOrder.Text = "Find Best Order";
this.chkBestOrder.CheckedChanged += new System.EventHandler(this.chkBestOrder_CheckedChanged);
//
// chkUseStartTime
//
this.chkUseStartTime.Location = new System.Drawing.Point(8, 96);
this.chkUseStartTime.Name = "chkUseStartTime";
this.chkUseStartTime.Size = new System.Drawing.Size(104, 16);
this.chkUseStartTime.TabIndex = 26;
this.chkUseStartTime.Text = "Use Start Time";
this.chkUseStartTime.CheckedChanged += new System.EventHandler(this.chkUseStartTime_CheckedChanged);
//
// txtStartTime
//
this.txtStartTime.Enabled = false;
this.txtStartTime.Location = new System.Drawing.Point(24, 112);
this.txtStartTime.Name = "txtStartTime";
this.txtStartTime.Size = new System.Drawing.Size(168, 20);
this.txtStartTime.TabIndex = 27;
//
// fraINAServerRouteParams
//
this.fraINAServerRouteParams.Controls.Add(this.cboStopsLayers);
this.fraINAServerRouteParams.Controls.Add(this.label6);
this.fraINAServerRouteParams.Controls.Add(this.checkReturnBarriers);
this.fraINAServerRouteParams.Controls.Add(this.cboRouteDirectionsTimeAttribute);
this.fraINAServerRouteParams.Controls.Add(this.label21);
this.fraINAServerRouteParams.Controls.Add(this.cboRouteDirectionsLengthUnits);
this.fraINAServerRouteParams.Controls.Add(this.label22);
this.fraINAServerRouteParams.Controls.Add(this.chkReturnRoutes);
this.fraINAServerRouteParams.Controls.Add(this.chkReturnRouteGeometries);
this.fraINAServerRouteParams.Controls.Add(this.chkReturnStops);
this.fraINAServerRouteParams.Controls.Add(this.chkReturnDirections);
this.fraINAServerRouteParams.Enabled = false;
this.fraINAServerRouteParams.Location = new System.Drawing.Point(8, 376);
this.fraINAServerRouteParams.Name = "fraINAServerRouteParams";
this.fraINAServerRouteParams.Size = new System.Drawing.Size(216, 224);
this.fraINAServerRouteParams.TabIndex = 75;
this.fraINAServerRouteParams.TabStop = false;
this.fraINAServerRouteParams.Text = "INAServerRouteParams";
//
// cboStopsLayers
//
this.cboStopsLayers.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboStopsLayers.Location = new System.Drawing.Point(80, 24);
this.cboStopsLayers.Name = "cboStopsLayers";
this.cboStopsLayers.Size = new System.Drawing.Size(128, 21);
this.cboStopsLayers.TabIndex = 14;
//
// label6
//
this.label6.Location = new System.Drawing.Point(8, 32);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(64, 16);
this.label6.TabIndex = 81;
this.label6.Text = "Input Stops";
//
// checkReturnBarriers
//
this.checkReturnBarriers.Checked = true;
this.checkReturnBarriers.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkReturnBarriers.Location = new System.Drawing.Point(16, 96);
this.checkReturnBarriers.Name = "checkReturnBarriers";
this.checkReturnBarriers.Size = new System.Drawing.Size(136, 16);
this.checkReturnBarriers.TabIndex = 17;
this.checkReturnBarriers.Text = "Returns Barriers";
//
// cboRouteDirectionsTimeAttribute
//
this.cboRouteDirectionsTimeAttribute.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboRouteDirectionsTimeAttribute.ItemHeight = 13;
this.cboRouteDirectionsTimeAttribute.Location = new System.Drawing.Point(56, 184);
this.cboRouteDirectionsTimeAttribute.Name = "cboRouteDirectionsTimeAttribute";
this.cboRouteDirectionsTimeAttribute.Size = new System.Drawing.Size(152, 21);
this.cboRouteDirectionsTimeAttribute.TabIndex = 21;
//
// label21
//
this.label21.Location = new System.Drawing.Point(8, 192);
this.label21.Name = "label21";
this.label21.Size = new System.Drawing.Size(48, 16);
this.label21.TabIndex = 52;
this.label21.Text = "Dir Time";
//
// cboRouteDirectionsLengthUnits
//
this.cboRouteDirectionsLengthUnits.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboRouteDirectionsLengthUnits.ItemHeight = 13;
this.cboRouteDirectionsLengthUnits.Location = new System.Drawing.Point(56, 160);
this.cboRouteDirectionsLengthUnits.Name = "cboRouteDirectionsLengthUnits";
this.cboRouteDirectionsLengthUnits.Size = new System.Drawing.Size(152, 21);
this.cboRouteDirectionsLengthUnits.TabIndex = 20;
//
// label22
//
this.label22.Location = new System.Drawing.Point(8, 168);
this.label22.Name = "label22";
this.label22.Size = new System.Drawing.Size(56, 16);
this.label22.TabIndex = 50;
this.label22.Text = "Dir Units";
//
// chkReturnRoutes
//
this.chkReturnRoutes.Checked = true;
this.chkReturnRoutes.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkReturnRoutes.Location = new System.Drawing.Point(16, 80);
this.chkReturnRoutes.Name = "chkReturnRoutes";
this.chkReturnRoutes.Size = new System.Drawing.Size(96, 16);
this.chkReturnRoutes.TabIndex = 16;
this.chkReturnRoutes.Text = "Return Routes";
//
// chkReturnRouteGeometries
//
this.chkReturnRouteGeometries.Checked = true;
this.chkReturnRouteGeometries.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkReturnRouteGeometries.Location = new System.Drawing.Point(16, 64);
this.chkReturnRouteGeometries.Name = "chkReturnRouteGeometries";
this.chkReturnRouteGeometries.Size = new System.Drawing.Size(152, 16);
this.chkReturnRouteGeometries.TabIndex = 15;
this.chkReturnRouteGeometries.Text = "Return Route Geometries";
//
// chkReturnStops
//
this.chkReturnStops.Checked = true;
this.chkReturnStops.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkReturnStops.Location = new System.Drawing.Point(16, 112);
this.chkReturnStops.Name = "chkReturnStops";
this.chkReturnStops.Size = new System.Drawing.Size(96, 16);
this.chkReturnStops.TabIndex = 18;
this.chkReturnStops.Text = "Return Stops";
//
// chkReturnDirections
//
this.chkReturnDirections.Checked = true;
this.chkReturnDirections.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkReturnDirections.Location = new System.Drawing.Point(16, 128);
this.chkReturnDirections.Name = "chkReturnDirections";
this.chkReturnDirections.Size = new System.Drawing.Size(160, 16);
this.chkReturnDirections.TabIndex = 19;
this.chkReturnDirections.Text = "Generate Directions";
//
// cmdConnect
//
this.cmdConnect.Location = new System.Drawing.Point(328, 16);
this.cmdConnect.Name = "cmdConnect";
this.cmdConnect.Size = new System.Drawing.Size(96, 40);
this.cmdConnect.TabIndex = 2;
this.cmdConnect.Text = "Connect";
this.cmdConnect.Click += new System.EventHandler(this.cmdConnect_Click);
//
// tabCtrlOutput
//
this.tabCtrlOutput.Controls.Add(this.tabReturnMap);
this.tabCtrlOutput.Controls.Add(this.tabReturnRouteFeatures);
this.tabCtrlOutput.Controls.Add(this.tabReturnBarrierFeatures);
this.tabCtrlOutput.Controls.Add(this.tabReturnStopsFeatures);
this.tabCtrlOutput.Controls.Add(this.tabReturnDirections);
this.tabCtrlOutput.Controls.Add(this.tabReturnRouteGeometry);
this.tabCtrlOutput.Enabled = false;
this.tabCtrlOutput.Location = new System.Drawing.Point(440, 80);
this.tabCtrlOutput.Name = "tabCtrlOutput";
this.tabCtrlOutput.SelectedIndex = 0;
this.tabCtrlOutput.Size = new System.Drawing.Size(472, 496);
this.tabCtrlOutput.TabIndex = 30;
//
// tabReturnMap
//
this.tabReturnMap.Controls.Add(this.pictureBox);
this.tabReturnMap.Location = new System.Drawing.Point(4, 22);
this.tabReturnMap.Name = "tabReturnMap";
this.tabReturnMap.Size = new System.Drawing.Size(464, 470);
this.tabReturnMap.TabIndex = 0;
this.tabReturnMap.Text = "Map";
//
// tabReturnRouteFeatures
//
this.tabReturnRouteFeatures.Controls.Add(this.dataGridRouteFeatures);
this.tabReturnRouteFeatures.Location = new System.Drawing.Point(4, 22);
this.tabReturnRouteFeatures.Name = "tabReturnRouteFeatures";
this.tabReturnRouteFeatures.Size = new System.Drawing.Size(464, 470);
this.tabReturnRouteFeatures.TabIndex = 4;
this.tabReturnRouteFeatures.Text = "Route Features";
//
// dataGridRouteFeatures
//
this.dataGridRouteFeatures.DataMember = "";
this.dataGridRouteFeatures.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGridRouteFeatures.Location = new System.Drawing.Point(8, 8);
this.dataGridRouteFeatures.Name = "dataGridRouteFeatures";
this.dataGridRouteFeatures.Size = new System.Drawing.Size(448, 456);
this.dataGridRouteFeatures.TabIndex = 0;
//
// tabReturnBarrierFeatures
//
this.tabReturnBarrierFeatures.Controls.Add(this.dataGridBarrierFeatures);
this.tabReturnBarrierFeatures.Location = new System.Drawing.Point(4, 22);
this.tabReturnBarrierFeatures.Name = "tabReturnBarrierFeatures";
this.tabReturnBarrierFeatures.Size = new System.Drawing.Size(464, 470);
this.tabReturnBarrierFeatures.TabIndex = 3;
this.tabReturnBarrierFeatures.Text = "Barrier Features";
//
// dataGridBarrierFeatures
//
this.dataGridBarrierFeatures.DataMember = "";
this.dataGridBarrierFeatures.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGridBarrierFeatures.Location = new System.Drawing.Point(8, 8);
this.dataGridBarrierFeatures.Name = "dataGridBarrierFeatures";
this.dataGridBarrierFeatures.Size = new System.Drawing.Size(448, 456);
this.dataGridBarrierFeatures.TabIndex = 0;
//
// tabReturnStopsFeatures
//
this.tabReturnStopsFeatures.Controls.Add(this.dataGridStopFeatures);
this.tabReturnStopsFeatures.Location = new System.Drawing.Point(4, 22);
this.tabReturnStopsFeatures.Name = "tabReturnStopsFeatures";
this.tabReturnStopsFeatures.Size = new System.Drawing.Size(464, 470);
this.tabReturnStopsFeatures.TabIndex = 2;
this.tabReturnStopsFeatures.Text = "Stop Features";
//
// dataGridStopFeatures
//
this.dataGridStopFeatures.DataMember = "";
this.dataGridStopFeatures.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGridStopFeatures.Location = new System.Drawing.Point(8, 8);
this.dataGridStopFeatures.Name = "dataGridStopFeatures";
this.dataGridStopFeatures.Size = new System.Drawing.Size(448, 456);
this.dataGridStopFeatures.TabIndex = 0;
//
// tabReturnDirections
//
this.tabReturnDirections.Controls.Add(this.treeViewDirections);
this.tabReturnDirections.Location = new System.Drawing.Point(4, 22);
this.tabReturnDirections.Name = "tabReturnDirections";
this.tabReturnDirections.Size = new System.Drawing.Size(464, 470);
this.tabReturnDirections.TabIndex = 1;
this.tabReturnDirections.Text = "Directions";
//
// treeViewDirections
//
this.treeViewDirections.Location = new System.Drawing.Point(8, 8);
this.treeViewDirections.Name = "treeViewDirections";
this.treeViewDirections.Size = new System.Drawing.Size(448, 456);
this.treeViewDirections.TabIndex = 69;
//
// tabReturnRouteGeometry
//
this.tabReturnRouteGeometry.Controls.Add(this.treeViewRouteGeometry);
this.tabReturnRouteGeometry.Location = new System.Drawing.Point(4, 22);
this.tabReturnRouteGeometry.Name = "tabReturnRouteGeometry";
this.tabReturnRouteGeometry.Size = new System.Drawing.Size(464, 470);
this.tabReturnRouteGeometry.TabIndex = 5;
this.tabReturnRouteGeometry.Text = "Route Geometry";
//
// treeViewRouteGeometry
//
this.treeViewRouteGeometry.Location = new System.Drawing.Point(8, 8);
this.treeViewRouteGeometry.Name = "treeViewRouteGeometry";
this.treeViewRouteGeometry.Size = new System.Drawing.Size(448, 456);
this.treeViewRouteGeometry.TabIndex = 1;
//
// Route_GISServerAPIClass
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(936, 606);
this.Controls.Add(this.tabCtrlOutput);
this.Controls.Add(this.fraINARouteSolver);
this.Controls.Add(this.fraINAServerRouteParams);
this.Controls.Add(this.fraINAServerSolverParams);
this.Controls.Add(this.fraINASolverSettings);
this.Controls.Add(this.txtService);
this.Controls.Add(this.txtServer);
this.Controls.Add(this.cmdSolve);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.cmdConnect);
this.Name = "Route_GISServerAPIClass";
this.Text = "NAServer - Route GISClient Sample";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.fraINASolverSettings.ResumeLayout(false);
this.fraINAServerSolverParams.ResumeLayout(false);
this.fraINAServerSolverParams.PerformLayout();
this.fraINARouteSolver.ResumeLayout(false);
this.fraINARouteSolver.PerformLayout();
this.fraINAServerRouteParams.ResumeLayout(false);
this.tabCtrlOutput.ResumeLayout(false);
this.tabReturnMap.ResumeLayout(false);
this.tabReturnRouteFeatures.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridRouteFeatures)).EndInit();
this.tabReturnBarrierFeatures.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridBarrierFeatures)).EndInit();
this.tabReturnStopsFeatures.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridStopFeatures)).EndInit();
this.tabReturnDirections.ResumeLayout(false);
this.tabReturnRouteGeometry.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine))
{
if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop))
{
System.Console.WriteLine("This application could not load the correct version of ArcGIS.");
return;
}
}
LicenseInitializer aoLicenseInitializer = new LicenseInitializer();
//ESRI License Initializer generated code.
if (!aoLicenseInitializer.InitializeApplication(
new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeArcView, esriLicenseProductCode.esriLicenseProductCodeArcEditor, esriLicenseProductCode.esriLicenseProductCodeArcInfo },
new esriLicenseExtensionCode[] { }))
{
System.Console.WriteLine(aoLicenseInitializer.LicenseMessage());
System.Console.WriteLine("This application could not initialize with the correct ArcGIS license and will shutdown.");
aoLicenseInitializer.ShutdownApplication();
return;
}
Application.Run(new Route_GISServerAPIClass());
//ESRI License Initializer generated code.
//Do not make any call to ArcObjects after ShutDownApplication()
aoLicenseInitializer.ShutdownApplication();
}
/// <summary>
/// This function
/// - sets the server and solver parameters
/// - populates the stops NALocations
/// - gets and displays the server results (map, directions, etc.)
/// </summary>
private void cmdSolve_Click(object sender, System.EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
try
{
// Get SolverParams
INAServerSolverParams solverParams = m_naServer.GetSolverParameters(cboNALayers.Text) as INAServerSolverParams;
// Set Solver params
SetINASolverSettings(solverParams as INASolverSettings);
SetSolverSpecificInterface(solverParams);
SetServerSolverParams(solverParams as INAServerSolverParams);
// Load Locations
LoadLocations(solverParams);
//Solve the Route
INAServerSolverResults solverResults = null;
solverResults = m_naServer.Solve(solverParams);
//Get NAServer results in the tab controls
OutputResults(solverParams, solverResults);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "An error has occurred");
}
this.Cursor = Cursors.Default;
}
/// <summary>
/// This function
/// - connects to the ArcGIS Server and MapServer
/// - sets all controls for the first route network analysis layer
/// </summary>
private void cmdConnect_Click(object sender, System.EventArgs e)
{
try
{
ConnectToServer();
GetNetworkAnalysisLayers();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "An error has occurred");
}
}
/// <summary>
/// Get MapServer and NAServer Object from the MapServer using GISClient
/// </summary>
private void ConnectToServer()
{
m_naServer = null;
m_mapServer = null;
IPropertySet propertySet = new PropertySet();
propertySet.SetProperty("Machine", txtServer.Text);
IAGSServerConnectionFactory agsServerConnectionFactory = new AGSServerConnectionFactory();
IAGSServerConnection agsServerConnection = agsServerConnectionFactory.Open(propertySet, 0);
IAGSEnumServerObjectName agsEnumServerObjectName = agsServerConnection.ServerObjectNames;
agsEnumServerObjectName.Reset();
IName serverObjectName;
IAGSServerObject agsServerObject = null;
IAGSServerObjectName agsServerObjectName = agsEnumServerObjectName.Next();
while ((agsServerObjectName != null))
{
if (agsServerObjectName.Type.ToUpper() == "NASERVER" &&
agsServerObjectName.Name.ToUpper() == txtService.Text.ToUpper())
{
serverObjectName = agsServerObjectName as IName;
agsServerObject = serverObjectName.Open() as IAGSServerObject;
if (agsServerObject as INAServer != null)
m_naServer = agsServerObject as INAServer;
}
// Search for the MapServer Server Object
if (agsServerObjectName.Type.ToUpper() == "MAPSERVER" &&
agsServerObjectName.Name.ToUpper() == txtService.Text.ToUpper())
{
serverObjectName = agsServerObjectName as IName;
agsServerObject = serverObjectName.Open() as IAGSServerObject;
if (agsServerObject as IMapServer != null)
m_mapServer = agsServerObject as IMapServer;
}
// If we got both of them, exit out
if ((m_naServer != null) && (m_mapServer != null))
return;
agsServerObjectName = agsEnumServerObjectName.Next();
}
throw (new System.Exception("Could not find " + txtService.Text));
}
/// <summary>
/// This function
/// - gets all route network analysis layers
/// - selects the first route network analysis layer
/// - sets all controls for this route network analysis layer
/// </summary>
private void GetNetworkAnalysisLayers()
{
this.Cursor = Cursors.WaitCursor;
try
{
// Enable Frame
fraINAServerSolverParams.Enabled = true;
//Get Route NA layer names
cboNALayers.Items.Clear();
string[] naLayers = m_naServer.GetNALayerNames(ESRI.ArcGIS.NetworkAnalyst.esriNAServerLayerType.esriNAServerRouteLayer);
for (int i = 0; i < naLayers.Length; i++)
{
cboNALayers.Items.Add(naLayers[i]);
}
// Select the first NA Layer name
if (cboNALayers.Items.Count > 0)
cboNALayers.SelectedIndex = 0;
else
MessageBox.Show("There is no Network Analyst layer associated with this MapServer object!", "NAServer - Route Sample", System.Windows.Forms.MessageBoxButtons.OK);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "An error has occurred");
}
this.Cursor = Cursors.Default;
}
/// <summary>
/// This function sets all controls for the selected route network analysis layer
/// </summary>
private void cboNALayers_SelectedIndexChanged(object sender, System.EventArgs e)
{
string naLayerName = cboNALayers.Text;
// Enable Solve Button
cmdSolve.Enabled = (naLayerName.Length == 0);
if (naLayerName.Length == 0)
return;
this.Cursor = Cursors.WaitCursor;
try
{
INAServerSolverParams solverParams = m_naServer.GetSolverParameters(naLayerName);
INAServerNetworkDescription networkDescription = m_naServer.GetNetworkDescription(naLayerName);
// Setup Default Properties
GetINASolverSettings(networkDescription, solverParams as INASolverSettings2);
GetSolverSpecificInterface(solverParams);
GetServerSolverParams(networkDescription, solverParams as INAServerSolverParams);
// Get all Point feature Layers form the ServerContext
GetInputStopsLayers();
// Make frames Enable
MakeFramesEnabled(solverParams);
// Hide Tabs
HideTabs();
cmdSolve.Enabled = true;
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "An error has occurred");
}
this.Cursor = Cursors.Default;
}
/// <summary>
/// Get Default NASolverSettings controls (Cost Attributes, Restrictions Attributes. etc.)
/// </summary>
private void GetINASolverSettings(INAServerNetworkDescription networkDescription, INASolverSettings2 solverSettings)
{
int ImpedanceIndex = 0;
//Get Attributes
cboImpedance.Items.Clear();
chklstAccumulateAttributes.Items.Clear();
chklstRestrictions.Items.Clear();
cboUturnPolicy.SelectedIndex = -1;
INAServerNetworkAttribute[] attributes = networkDescription.NetworkAttributes;
IStringArray accumulateAttributeNames = solverSettings.AccumulateAttributeNames;
IStringArray restrictionAttributeNames = solverSettings.RestrictionAttributeNames;
for (int i = 0; i < attributes.Length; i++)
{
INAServerNetworkAttribute networkAttribute = attributes[i];
string networkAttributeName = networkAttribute.Name;
if (networkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost)
{
chklstAccumulateAttributes.Items.Add(networkAttributeName, IsStringInStringArray(networkAttributeName, accumulateAttributeNames));
int index = cboImpedance.Items.Add(networkAttribute.Name + " (" + networkAttribute.Units.ToString().Substring(7) + ")");
if (networkAttributeName == solverSettings.ImpedanceAttributeName)
ImpedanceIndex = index;
}
if (networkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTRestriction)
{
chklstRestrictions.Items.Add(networkAttribute.Name, IsStringInStringArray(networkAttributeName, restrictionAttributeNames));
}
}
if (cboImpedance.Items.Count > 0)
cboImpedance.SelectedIndex = ImpedanceIndex;
chkUseHierarchy.Checked = solverSettings.UseHierarchy;
chkUseHierarchy.Enabled = solverSettings.HierarchyAttributeName.Length > 0;
chkIgnoreInvalidLocations.Checked = solverSettings.IgnoreInvalidLocations;
cboUturnPolicy.SelectedIndex = System.Convert.ToInt32(solverSettings.RestrictUTurns);
}
private bool IsStringInStringArray(string inputString, IStringArray stringArray)
{
int numInArray = stringArray.Count;
for (int i = 0; i < numInArray; i++)
{
if (inputString.Equals(stringArray.get_Element(i)))
return true;
}
return false;
}
/// <summary>
/// Set Default route solver controls (BestOrder, UseTimeWindows, UseStartTime, etc.)
/// </summary>
private void GetSolverSpecificInterface(INAServerSolverParams solverParams)
{
INARouteSolver2 routeSolver = solverParams as INARouteSolver2;
if (routeSolver != null)
{
chkBestOrder.Checked = routeSolver.FindBestSequence;
chkPreserveFirst.Checked = routeSolver.PreserveFirstStop;
chkPreserveLast.Checked = routeSolver.PreserveLastStop;
if (chkBestOrder.Checked == true)
{
this.chkPreserveFirst.Enabled = true;
this.chkPreserveLast.Enabled = true;
}
else
{
this.chkPreserveFirst.Enabled = false;
this.chkPreserveLast.Enabled = false;
}
chkUseTimeWindows.Checked = routeSolver.UseTimeWindows;
chkUseStartTime.Checked = routeSolver.UseStartTime;
if (chkUseStartTime.Checked)
{
txtStartTime.Enabled = true;
txtStartTime.Text = routeSolver.StartTime.ToString();
}
else
{
txtStartTime.Enabled = false;
txtStartTime.Text = System.DateTime.Now.ToString();
}
cboRouteOutputLines.SelectedIndex = System.Convert.ToInt32(routeSolver.OutputLines);
}
}
/// <summary>
/// Get all point feature layers from the ServerContext
/// Add them in the "Input Stops" drop down list
/// </summary>
private void GetInputStopsLayers()
{
cboStopsLayers.Items.Clear();
m_layerIDs.Clear();
IMapServerInfo serverInfo = m_mapServer.GetServerInfo(m_mapServer.DefaultMapName);
IMapLayerInfos mapLayerInfos = serverInfo.MapLayerInfos;
for (int i = 0; i < mapLayerInfos.Count; i++)
{
IMapLayerInfo mapLayerInfo = mapLayerInfos.get_Element(i);
// Just get point layers that aren't NAClasses
if (
mapLayerInfo.IsFeatureLayer && (
mapLayerInfo.ParentLayerID == -1
|| mapLayerInfos.get_Element(mapLayerInfo.ParentLayerID).Type != "Network Analysis Layer"
)
)
{
IFields fields = mapLayerInfo.Fields;
for (int j = 0; j < fields.FieldCount; j++)
{
IField field = fields.get_Field(j);
if (field.Type == esriFieldType.esriFieldTypeGeometry)
{
IGeometryDef geometryDef = field.GeometryDef;
if (geometryDef.GeometryType == esriGeometryType.esriGeometryPoint)
{
cboStopsLayers.Items.Add(mapLayerInfo.Name);
m_layerIDs.Add(mapLayerInfo.ID);
}
}
}
}
}
// Add <None> at the end in case the user does not want to load Stop Location from a Feature Layer
cboStopsLayers.Items.Add("<None>");
m_layerIDs.Add(-1);
cboStopsLayers.SelectedIndex = 0;
}
/// <summary>
/// Get ServerSolverParams controls (ReturnMap, SnapTolerance, etc.)
/// </summary>
private void GetServerSolverParams(INAServerNetworkDescription networkDescription, INAServerSolverParams solverParams)
{
chkReturnMap.Checked = true;
txtSnapTolerance.Text = solverParams.SnapTolerance.ToString();
txtMaxSnapTolerance.Text = solverParams.MaxSnapTolerance.ToString();
cboSnapToleranceUnits.SelectedIndex = Convert.ToInt32(solverParams.SnapToleranceUnits);
//Set Route Defaults
chkReturnRouteGeometries.Checked = false;
chkReturnRoutes.Checked = true;
chkReturnStops.Checked = true;
chkReturnDirections.Checked = true;
checkReturnBarriers.Checked = true;
//Set Directions Defaults
cboRouteDirectionsTimeAttribute.Items.Clear();
INAServerNetworkAttribute[] attributes = networkDescription.NetworkAttributes;
for (int i = 0; i < attributes.Length; i++)
{
INAServerNetworkAttribute networkAttribute = attributes[i];
if (networkAttribute.UsageType == esriNetworkAttributeUsageType.esriNAUTCost)
{
if (String.Compare(networkAttribute.Units.ToString(), "esriNAUMinutes") == 0)
{
cboRouteDirectionsTimeAttribute.Items.Add(networkAttribute.Name);
}
}
}
// Set the default direction settings
INAServerRouteParams routeParams = solverParams as INAServerRouteParams;
if (routeParams != null)
{
cboRouteDirectionsLengthUnits.Text = routeParams.DirectionsLengthUnits.ToString().Substring(7); ;
//Select the first time attribute
if (cboRouteDirectionsTimeAttribute.Items.Count > 0)
cboRouteDirectionsTimeAttribute.Text = routeParams.DirectionsTimeAttributeName;
}
}
/// <summary>
/// Set general solver settings (Impedance, Restrictions, Accumulates, etc.)
/// </summary>
private void SetINASolverSettings(INASolverSettings solverSettings)
{
solverSettings.ImpedanceAttributeName = ExtractImpedanceName(cboImpedance.Text);
IStringArray restrictionAttributes = solverSettings.RestrictionAttributeNames;
restrictionAttributes.RemoveAll();
for (int i = 0; i < chklstRestrictions.CheckedItems.Count; i++)
restrictionAttributes.Add(chklstRestrictions.Items[chklstRestrictions.CheckedIndices[i]].ToString());
solverSettings.RestrictionAttributeNames = restrictionAttributes;
IStringArray accumulateAttributes = solverSettings.AccumulateAttributeNames;
accumulateAttributes.RemoveAll();
for (int i = 0; i < chklstAccumulateAttributes.CheckedItems.Count; i++)
accumulateAttributes.Add(chklstAccumulateAttributes.Items[chklstAccumulateAttributes.CheckedIndices[i]].ToString());
solverSettings.AccumulateAttributeNames = accumulateAttributes;
solverSettings.RestrictUTurns = (esriNetworkForwardStarBacktrack)cboUturnPolicy.SelectedIndex;
solverSettings.IgnoreInvalidLocations = chkIgnoreInvalidLocations.Checked;
solverSettings.UseHierarchy = chkUseHierarchy.Checked;
}
/// <summary>
/// Set specific solver settings (FindBestSequence, UseTimeWindows, etc.)
/// </summary>
private void SetSolverSpecificInterface(INAServerSolverParams solverParams)
{
INARouteSolver2 routeSolver = solverParams as INARouteSolver2;
if (routeSolver != null)
{
routeSolver.FindBestSequence = chkBestOrder.Checked;
routeSolver.PreserveFirstStop = chkPreserveFirst.Checked;
routeSolver.PreserveLastStop = chkPreserveLast.Checked;
routeSolver.UseTimeWindows = chkUseTimeWindows.Checked;
routeSolver.OutputLines = (esriNAOutputLineType)cboRouteOutputLines.SelectedIndex;
routeSolver.UseStartTime = chkUseStartTime.Checked;
if (routeSolver.UseStartTime == true)
routeSolver.StartTime = System.Convert.ToDateTime(txtStartTime.Text.ToString());
}
}
/// <summary>
/// Set server solver parameters (ReturnMap, SnapTolerance, etc.)
/// </summary>
private void SetServerSolverParams(INAServerSolverParams solverParams)
{
solverParams.ReturnMap = chkReturnMap.Checked;
solverParams.SnapTolerance = Convert.ToDouble(txtSnapTolerance.Text);
solverParams.MaxSnapTolerance = Convert.ToDouble(txtMaxSnapTolerance.Text);
solverParams.SnapToleranceUnits = (esriUnits)cboSnapToleranceUnits.SelectedIndex;
solverParams.ImageDescription.Display.Width = pictureBox.Width;
solverParams.ImageDescription.Display.Height = pictureBox.Height;
// // This code shows how to specify the output spatial reference in order to get the map
// // in a different spatial reference than the Network Dataset
// IESRISpatialReferenceGEN sr = new GeographicCoordinateSystem() as IESRISpatialReferenceGEN;
// int read;
// sr.ImportFromESRISpatialReference("GEOGCS[GCS_North_American_1983,DATUM[D_North_American_1983,SPHEROID[GRS_1980,6378137.0,298.257222101]],PRIMEM[Greenwich,0.0],UNIT[Degree,0.0174532925199433]]", out read);
// solverParams.OutputSpatialReference = sr as ISpatialReference;
INAServerRouteParams routeParams = solverParams as INAServerRouteParams;
if (routeParams != null)
{
routeParams.ReturnRouteGeometries = chkReturnRouteGeometries.Checked;
routeParams.ReturnRoutes = chkReturnRoutes.Checked;
routeParams.ReturnStops = chkReturnStops.Checked;
routeParams.ReturnBarriers = checkReturnBarriers.Checked;
routeParams.ReturnDirections = chkReturnDirections.Checked;
routeParams.DirectionsLengthUnits = GetstringToesriUnits(cboRouteDirectionsLengthUnits.Text); ;
routeParams.DirectionsTimeAttributeName = cboRouteDirectionsTimeAttribute.Text;
}
}
/// <summary>
/// Make frames Enabled
/// </summary>
private void MakeFramesEnabled(INAServerSolverParams solverParams)
{
fraINARouteSolver.Enabled = ((solverParams as INAServerRouteParams) != null);
fraINAServerRouteParams.Enabled = ((solverParams as INAServerRouteParams) != null);
fraINASolverSettings.Enabled = ((solverParams as INAServerRouteParams) != null);
}
/// <summary>
/// Load form
/// </summary>
private void Form1_Load(object sender, System.EventArgs e)
{
cboUturnPolicy.Items.Add("Nowhere");
cboUturnPolicy.Items.Add("Everywhere");
cboUturnPolicy.Items.Add("Only at Dead Ends");
cboSnapToleranceUnits.Items.Add("Unknown Units");
cboSnapToleranceUnits.Items.Add("Inches");
cboSnapToleranceUnits.Items.Add("Points");
cboSnapToleranceUnits.Items.Add("Feet");
cboSnapToleranceUnits.Items.Add("Yards");
cboSnapToleranceUnits.Items.Add("Miles");
cboSnapToleranceUnits.Items.Add("Nautical Miles");
cboSnapToleranceUnits.Items.Add("Millimeters");
cboSnapToleranceUnits.Items.Add("Centimeters");
cboSnapToleranceUnits.Items.Add("Meters");
cboSnapToleranceUnits.Items.Add("Kilometers");
cboSnapToleranceUnits.Items.Add("DecimalDegrees");
cboSnapToleranceUnits.Items.Add("Decimeters");
// Route
cboRouteOutputLines.Items.Add("None");
cboRouteOutputLines.Items.Add("Straight Line");
cboRouteOutputLines.Items.Add("True Shape");
cboRouteOutputLines.Items.Add("True Shape With Ms");
cboRouteDirectionsLengthUnits.Items.Add("Feet");
cboRouteDirectionsLengthUnits.Items.Add("Yards");
cboRouteDirectionsLengthUnits.Items.Add("Miles");
cboRouteDirectionsLengthUnits.Items.Add("Meters");
cboRouteDirectionsLengthUnits.Items.Add("Kilometers");
if (txtServer.Text != "" && txtServer.Text != "<Enter ArcGIS Server Name>"
&& txtService.Text != "" && txtService.Text != "<Enter ArcGIS Map Server Object>")
{
ConnectToServer();
GetNetworkAnalysisLayers();
}
}
/// <summary>
/// This function shows how to populate stop locations using two different options:
/// 1) From Record Set using a Point Feature Class - Uncommented
/// 2) From an Array of PropertySets - Commented out
/// Uncomment the option, you would like to use
/// </summary>
private void LoadLocations(INAServerSolverParams solverParams)
{
INAServerRouteParams routeParams = solverParams as INAServerRouteParams;
// Begin Option 1
IRecordSet recSet = null;
// Get Input Stops Feature Class from the MapServer
// Do not create Stops if <NONE> is selected
if (cboStopsLayers.Text.ToUpper() != "<NONE>")
{
int layerID = (int)m_layerIDs[cboStopsLayers.SelectedIndex];
if (layerID >= 0)
recSet = m_mapServer.QueryFeatureData(m_mapServer.DefaultMapName, layerID, null);
INAServerRecordSet stopsRecSet = new NAServerRecordSet() as INAServerRecordSet;
stopsRecSet.RecordSet = recSet;
routeParams.Stops = stopsRecSet;
}
// End Option 1
// Begin Option 2
/*
IPropertySetArray propSets = new PropertySetArray();
// Set first point
propSets.Add(CreateLocationPropertySet("Stop 1", -122.49024904900, 37.74811940430, null));
// Set second point
propSets.Add(CreateLocationPropertySet("Stop 2", -122.43083365400, 37.75396354490, null));
INAServerPropertySets stopsPropSets = new NAServerPropertySets() as INAServerPropertySets;
stopsPropSets.PropertySets = propSets;
routeParams.Stops = stopsPropSets;
*/
// End Option 2
}
/// <summary>
/// Output Results Messages, Map, Route Geometries, Directions
/// </summary>
private void OutputResults(INAServerSolverParams solverParams, INAServerSolverResults solverResults)
{
string messagesSolverResults = "";
// Output Solve messages
IGPMessages gpMessages = solverResults.SolveMessages;
if (gpMessages != null)
{
for (int i = 0; i < gpMessages.Count; i++)
{
IGPMessage gpMessage = gpMessages.GetMessage(i);
messagesSolverResults += "\n" + gpMessage.Description;
}
}
// Uncomment the following section to output the total impedance of each route in a MessageBox
//INAServerRouteResults routeSolverResults = solverResults as INAServerRouteResults;
//if (routeSolverResults != null)
//{
// for (int i = 0; i < routeSolverResults.TotalImpedances.GetLength(0); i++)
// {
// messagesSolverResults += "\nTotal Impedance for Route[" + (i + 1) + "] = ";
// messagesSolverResults += routeSolverResults.TotalImpedances[i].ToString("f");
// messagesSolverResults += " " + ExtractImpedanceUnits(cboImpedance.Text).ToLower();
// }
//}
// Show a message box displaying both solver messages and total_impedance per route
if (messagesSolverResults.Length > 0)
MessageBox.Show(messagesSolverResults, "NAServer Route Results");
//Output Map
pictureBox.Image = null;
if (solverParams.ReturnMap)
{
IMapImage mapImage = solverResults.MapImage;
if ((mapImage != null) && (mapImage.MimeData != null))
pictureBox.Image = System.Drawing.Image.FromStream(new System.IO.MemoryStream(mapImage.MimeData));
}
pictureBox.Refresh();
if (((solverParams as INAServerRouteParams) != null) && ((solverResults as INAServerRouteResults) != null))
OutputRouteResults(solverParams as INAServerRouteParams, solverResults as INAServerRouteResults);
}
/// <summary>
/// Output Route Results according to the NAServerRouteParams
/// </summary>
private void OutputRouteResults(INAServerRouteParams solverParams, INAServerRouteResults solverResults)
{
// Return Directions if generated
if (solverParams.ReturnDirections)
{
AddTabAndControl(this.tabReturnDirections, this.treeViewDirections);
OutputDirections(solverResults.Directions);
}
else
this.tabCtrlOutput.TabPages.Remove(this.tabReturnDirections);
// Return Route Geometries is generated
if (solverParams.ReturnRouteGeometries)
{
AddTabAndControl(this.tabReturnRouteGeometry, this.treeViewRouteGeometry);
OutputPolylines(solverResults.RouteGeometries);
}
else
this.tabCtrlOutput.TabPages.Remove(this.tabReturnRouteGeometry);
// Return Route Features as RecordSet
if (solverParams.ReturnRoutes)
{
AddTabAndControl(this.tabReturnRouteFeatures, this.dataGridRouteFeatures);
OutputRecSetToDataGrid(solverResults.Routes, dataGridRouteFeatures);
}
else
this.tabCtrlOutput.TabPages.Remove(this.tabReturnRouteFeatures);
// Return Stop Features as RecordSet
if (solverParams.ReturnStops)
{
AddTabAndControl(this.tabReturnStopsFeatures, this.dataGridStopFeatures);
OutputRecSetToDataGrid(solverResults.Stops, dataGridStopFeatures);
}
else
this.tabCtrlOutput.TabPages.Remove(this.tabReturnStopsFeatures);
// Return Barrier Features as RecordSet
if (solverParams.ReturnBarriers)
{
AddTabAndControl(this.tabReturnBarrierFeatures, this.dataGridBarrierFeatures);
OutputRecSetToDataGrid(solverResults.Barriers, dataGridBarrierFeatures);
}
else
this.tabCtrlOutput.TabPages.Remove(this.tabReturnBarrierFeatures);
// Make TabControlOutput enable
tabCtrlOutput.Enabled = true;
}
/// <summary>
/// Output Route Geometries (Polylines) in a TreeView control
/// </summary>
private void OutputPolylines(IPolyline[] polylines)
{
// Suppress repainting the TreeView until all the objects have been created.
treeViewRouteGeometry.BeginUpdate();
// Clear the TreeView each time the method is called.
treeViewRouteGeometry.Nodes.Clear();
for (int i = 0; i < polylines.Length; i++)
{
TreeNode newNode = new TreeNode("Polyline Length for Route [" + (i + 1) + "] = " + polylines[i].Length.ToString());
treeViewRouteGeometry.Nodes.Add(newNode);
IPointCollection pointCollection = polylines[i] as IPointCollection;
for (int j = 0; j < pointCollection.PointCount; j++)
{
IPoint point = pointCollection.get_Point(j);
treeViewRouteGeometry.Nodes[i].Nodes.Add(new TreeNode("Point [" + (j + 1) + "]: " + point.X + "," + point.Y));
}
}
// Check if Route Geometry has been generated
if (polylines.Length == 0)
{
TreeNode newNode = new TreeNode("Route Geometry not generated");
treeViewRouteGeometry.Nodes.Add(newNode);
}
// Begin repainting the TreeView.
treeViewRouteGeometry.ExpandAll();
treeViewRouteGeometry.EndUpdate();
}
/// <summary>
/// Output Directions if a TreeView control
/// </summary>
private void OutputDirections(INAStreetDirections[] serverDirections)
{
// Suppress repainting the TreeView until all the objects have been created.
treeViewDirections.BeginUpdate();
// Clear the TreeView each time the method is called.
treeViewDirections.Nodes.Clear();
for (int i = 0; i < serverDirections.Length; i++)
{
// get Directions from the ith route
INAStreetDirections directions;
directions = serverDirections[i];
// get Summary (Total Distance and Time)
INAStreetDirection direction = directions.Summary;
string totallength = null, totaltime = null;
for (int k = 0; k < direction.StringCount; k++)
{
if (direction.get_StringType(k) == esriDirectionsStringType.esriDSTLength)
totallength = direction.get_String(k);
if (direction.get_StringType(k) == esriDirectionsStringType.esriDSTTime)
totaltime = direction.get_String(k);
}
// Add a Top a Node with the Route number and Total Distance and Total Time
TreeNode newNode = new TreeNode("Directions for Route [" + (i + 1) + "] - Total Distance: " + totallength + " Total Time: " + totaltime);
treeViewDirections.Nodes.Add(newNode);
// Then add a node for each step-by-step directions
for (int directionIndex = 0; directionIndex < directions.DirectionCount; directionIndex++)
{
direction = directions.get_Direction(directionIndex);
for (int stringIndex = 0; stringIndex < direction.StringCount; stringIndex++)
{
if (direction.get_StringType(stringIndex) == esriDirectionsStringType.esriDSTGeneral ||
direction.get_StringType(stringIndex) == esriDirectionsStringType.esriDSTDepart ||
direction.get_StringType(stringIndex) == esriDirectionsStringType.esriDSTArrive)
treeViewDirections.Nodes[i].Nodes.Add(new TreeNode(direction.get_String(stringIndex)));
}
}
}
// Check if Directions have been generated
if (serverDirections.Length == 0)
{
TreeNode newNode = new TreeNode("Directions not generated");
treeViewDirections.Nodes.Add(newNode);
}
// Begin repainting the TreeView.
treeViewDirections.ExpandAll();
treeViewDirections.EndUpdate();
}
/// <summary>
/// Generic function to output RecordSet (Stops, Barriers, or Routes) in a DataGrid Control
/// </summary>
private void OutputRecSetToDataGrid(IRecordSet recSet, System.Windows.Forms.DataGrid outDataGrid)
{
IFields fields = recSet.Fields;
DataSet dataSet = new DataSet("dataSet");
DataTable dataTable = new DataTable("Results");
dataSet.Tables.Add(dataTable);
// Get Field Names
DataColumn dataColumn = null;
for (int f = 0; f < fields.FieldCount; f++)
{
dataColumn = new DataColumn(fields.get_Field(f).Name.ToString());
dataTable.Columns.Add(dataColumn);
}
// Populate DataGrid rows by RecordSet
DataRow newDataRow;
ICursor cur = recSet.get_Cursor(false);
IRow row = cur.NextRow();
if (row != null)
{
while (row != null)
{
newDataRow = dataTable.NewRow();
for (int l = 0; l < row.Fields.FieldCount; l++)
{
newDataRow[l] = row.get_Value(l).ToString();
}
dataTable.Rows.Add(newDataRow);
row = cur.NextRow();
}
}
outDataGrid.SetDataBinding(dataSet, "Results");
outDataGrid.Visible = true;
}
/// <summary>
/// Enable the startTime control
/// </summary>
private void chkUseStartTime_CheckedChanged(object sender, System.EventArgs e)
{
if (chkUseStartTime.Checked == true)
txtStartTime.Enabled = true;
else
txtStartTime.Enabled = false;
}
/// <summary>
/// Enable chkPreserveFirst and chkPreserveFirst controls
/// </summary>
private void chkBestOrder_CheckedChanged(object sender, System.EventArgs e)
{
if (chkBestOrder.Checked == true)
{
this.chkPreserveFirst.Enabled = true;
this.chkPreserveLast.Enabled = true;
}
else
{
this.chkPreserveFirst.Enabled = false;
this.chkPreserveLast.Enabled = false;
}
}
/// <summary>
/// Create a property set for NALocation
/// </summary>
private IPropertySet CreateLocationPropertySet(string name, object X, object Y, ISpatialReference sr)
{
IPropertySet propSet = new PropertySet() as IPropertySet;
propSet.SetProperty("Name", name);
propSet.SetProperty("X", X);
propSet.SetProperty("Y", Y);
propSet.SetProperty("SpatialReference", sr);
return propSet;
}
/// <summary>
/// Helper function to convert a string unit (e.g Miles) to an esriNetworkAnalystUnits (e.g esriNAUMiles)
/// </summary>
private esriNetworkAttributeUnits GetstringToesriUnits(string stresriUnits)
{
switch (stresriUnits.ToLower())
{
case "inches": return esriNetworkAttributeUnits.esriNAUInches;
case "feet": return esriNetworkAttributeUnits.esriNAUFeet;
case "yards": return esriNetworkAttributeUnits.esriNAUYards;
case "miles": return esriNetworkAttributeUnits.esriNAUMiles;
case "nautical miles": return esriNetworkAttributeUnits.esriNAUNauticalMiles;
case "millimeters": return esriNetworkAttributeUnits.esriNAUMillimeters;
case "centimeters": return esriNetworkAttributeUnits.esriNAUCentimeters;
case "meters": return esriNetworkAttributeUnits.esriNAUMeters;
case "kilometers": return esriNetworkAttributeUnits.esriNAUKilometers;
case "decimal degrees": return esriNetworkAttributeUnits.esriNAUDecimalDegrees;
case "decimeters": return esriNetworkAttributeUnits.esriNAUDecimeters;
case "seconds": return esriNetworkAttributeUnits.esriNAUSeconds;
case "minutes": return esriNetworkAttributeUnits.esriNAUMinutes;
case "hours": return esriNetworkAttributeUnits.esriNAUHours;
case "days": return esriNetworkAttributeUnits.esriNAUDays;
case "unknown": return esriNetworkAttributeUnits.esriNAUUnknown;
default: return esriNetworkAttributeUnits.esriNAUUnknown;
}
}
/// <summary>
/// Helper function to extract the impedance name in a string like "impedancename (impedanceunits)"
/// </summary>
private string ExtractImpedanceName(string impedanceUnits)
{
int firstIndex = impedanceUnits.LastIndexOf(" ");
int lastIndex = impedanceUnits.Length;
return impedanceUnits.Remove(firstIndex, (lastIndex - firstIndex));
}
/// <summary>
/// Helper function to extract the impedance unit in a string like "impedancename (impedanceunits)"
/// </summary>
private string ExtractImpedanceUnits(string impedanceUnits)
{
int firstIndex = impedanceUnits.LastIndexOf("(") + 1;
int lastIndex = impedanceUnits.LastIndexOf(")");
return impedanceUnits.Substring(firstIndex, (lastIndex - firstIndex));
}
/// <summary>
/// Hide tabs
/// </summary>
private void HideTabs()
{
// remove tabs initially - There are added when the result is returned.
this.tabCtrlOutput.TabPages.Remove(this.tabReturnDirections);
this.tabCtrlOutput.TabPages.Remove(this.tabReturnStopsFeatures);
this.tabCtrlOutput.TabPages.Remove(this.tabReturnBarrierFeatures);
this.tabCtrlOutput.TabPages.Remove(this.tabReturnRouteGeometry);
this.tabCtrlOutput.TabPages.Remove(this.tabReturnRouteFeatures);
}
/// <summary>
//// Add a tab page and a tab control
/// </summary>
private void AddTabAndControl(TabPage tabPage, System.Windows.Forms.Control controlToAdd)
{
if (!tabCtrlOutput.TabPages.Contains(tabPage))
{
tabCtrlOutput.TabPages.Add(tabPage);
tabPage.Controls.Add(controlToAdd);
}
}
}
}
[Visual Basic .NET]
Route_GISClientClass.vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.OleDb
Imports System.Xml
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.GISClient
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Location
Imports ESRI.ArcGIS.NetworkAnalyst
Imports System.Collections.Specialized
Namespace Route_GISClient
''' <summary>
''' Summary description for Form1.
''' </summary>
Public Class Route_GISServerAPIClass : Inherits System.Windows.Forms.Form
#Region "Window Controls Declaration"
Private label1 As System.Windows.Forms.Label
Private label2 As System.Windows.Forms.Label
Private txtServer As System.Windows.Forms.TextBox
Private txtService As System.Windows.Forms.TextBox
Private pictureBox As System.Windows.Forms.PictureBox
Private fraINASolverSettings As System.Windows.Forms.GroupBox
Private cboUturnPolicy As System.Windows.Forms.ComboBox
Private label11 As System.Windows.Forms.Label
Private label7 As System.Windows.Forms.Label
Private chklstAccumulateAttributes As System.Windows.Forms.CheckedListBox
Private label5 As System.Windows.Forms.Label
Private chklstRestrictions As System.Windows.Forms.CheckedListBox
Private cboImpedance As System.Windows.Forms.ComboBox
Private label4 As System.Windows.Forms.Label
Private chkIgnoreInvalidLocations As System.Windows.Forms.CheckBox
Private WithEvents cboNALayers As System.Windows.Forms.ComboBox
Private label10 As System.Windows.Forms.Label
Private label8 As System.Windows.Forms.Label
Private label9 As System.Windows.Forms.Label
Private chkReturnMap As System.Windows.Forms.CheckBox
Private WithEvents cmdSolve As System.Windows.Forms.Button
Private cboSnapToleranceUnits As System.Windows.Forms.ComboBox
Private txtMaxSnapTolerance As System.Windows.Forms.TextBox
Private txtSnapTolerance As System.Windows.Forms.TextBox
Private components As System.ComponentModel.IContainer = Nothing
Private label20 As System.Windows.Forms.Label
Private label21 As System.Windows.Forms.Label
Private label22 As System.Windows.Forms.Label
Private chkPreserveFirst As System.Windows.Forms.CheckBox
Private WithEvents chkBestOrder As System.Windows.Forms.CheckBox
Private cboRouteDirectionsLengthUnits As System.Windows.Forms.ComboBox
Private chkReturnRoutes As System.Windows.Forms.CheckBox
Private chkReturnRouteGeometries As System.Windows.Forms.CheckBox
Private chkReturnStops As System.Windows.Forms.CheckBox
Private chkReturnDirections As System.Windows.Forms.CheckBox
Private cboRouteOutputLines As System.Windows.Forms.ComboBox
Private chkUseTimeWindows As System.Windows.Forms.CheckBox
Private chkPreserveLast As System.Windows.Forms.CheckBox
Private cboRouteDirectionsTimeAttribute As System.Windows.Forms.ComboBox
Private fraINARouteSolver As System.Windows.Forms.GroupBox
Private fraINAServerRouteParams As System.Windows.Forms.GroupBox
Private tabCtrlOutput As System.Windows.Forms.TabControl
Private tabReturnStopsFeatures As System.Windows.Forms.TabPage
Private tabReturnBarrierFeatures As System.Windows.Forms.TabPage
Private tabReturnDirections As System.Windows.Forms.TabPage
Private tabReturnRouteFeatures As System.Windows.Forms.TabPage
Private dataGridRouteFeatures As System.Windows.Forms.DataGrid
Private dataGridStopFeatures As System.Windows.Forms.DataGrid
Private dataGridBarrierFeatures As System.Windows.Forms.DataGrid
Private tabReturnMap As System.Windows.Forms.TabPage
Private tabReturnRouteGeometry As System.Windows.Forms.TabPage
Private treeViewRouteGeometry As System.Windows.Forms.TreeView
Private treeViewDirections As System.Windows.Forms.TreeView
Private checkReturnBarriers As System.Windows.Forms.CheckBox
Private label6 As System.Windows.Forms.Label
Private chkUseHierarchy As System.Windows.Forms.CheckBox
Private cboStopsLayers As System.Windows.Forms.ComboBox
Private WithEvents cmdConnect As System.Windows.Forms.Button
Private WithEvents chkUseStartTime As System.Windows.Forms.CheckBox
Private txtStartTime As System.Windows.Forms.TextBox
Private fraINAServerSolverParams As System.Windows.Forms.GroupBox
Private m_naServer As INAServer
Private m_mapServer As IMapServer
Private m_layerIDs As ArrayList
#End Region
Public Sub New()
If (Not ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine)) Then
If (Not ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop)) Then
Console.WriteLine("This application could not load the correct version of ArcGIS.")
End If
End If
Dim aoLicenseInitializer As LicenseInitializer = New LicenseInitializer()
'ESRI License Initializer generated code.
If (Not aoLicenseInitializer.InitializeApplication(New ESRI.ArcGIS.esriSystem.esriLicenseProductCode() { _
ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeArcView, _
ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeArcEditor, _
ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeArcInfo}, _
New ESRI.ArcGIS.esriSystem.esriLicenseExtensionCode() {})) Then
Console.WriteLine(aoLicenseInitializer.LicenseMessage())
Console.WriteLine("This application could not initialize with the correct ArcGIS license and will shutdown.")
aoLicenseInitializer.ShutdownApplication()
Return
End If
'
' Required for Windows Form Designer support
'
InitializeComponent()
m_layerIDs = New ArrayList()
End Sub
''' <summary>
''' Clean up any resources being used.
''' </summary>
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not components Is Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
#Region "Windows Form Designer generated code"
''' <summary>
''' Required method for Designer support - do not modify
''' the contents of this method with the code editor.
''' </summary>
Private Sub InitializeComponent()
Me.label1 = New System.Windows.Forms.Label
Me.label2 = New System.Windows.Forms.Label
Me.txtServer = New System.Windows.Forms.TextBox
Me.txtService = New System.Windows.Forms.TextBox
Me.cmdSolve = New System.Windows.Forms.Button
Me.pictureBox = New System.Windows.Forms.PictureBox
Me.fraINASolverSettings = New System.Windows.Forms.GroupBox
Me.chkIgnoreInvalidLocations = New System.Windows.Forms.CheckBox
Me.cboUturnPolicy = New System.Windows.Forms.ComboBox
Me.label11 = New System.Windows.Forms.Label
Me.label7 = New System.Windows.Forms.Label
Me.chklstAccumulateAttributes = New System.Windows.Forms.CheckedListBox
Me.label5 = New System.Windows.Forms.Label
Me.chklstRestrictions = New System.Windows.Forms.CheckedListBox
Me.cboImpedance = New System.Windows.Forms.ComboBox
Me.label4 = New System.Windows.Forms.Label
Me.chkUseHierarchy = New System.Windows.Forms.CheckBox
Me.fraINAServerSolverParams = New System.Windows.Forms.GroupBox
Me.chkReturnMap = New System.Windows.Forms.CheckBox
Me.cboSnapToleranceUnits = New System.Windows.Forms.ComboBox
Me.cboNALayers = New System.Windows.Forms.ComboBox
Me.label10 = New System.Windows.Forms.Label
Me.label8 = New System.Windows.Forms.Label
Me.txtMaxSnapTolerance = New System.Windows.Forms.TextBox
Me.txtSnapTolerance = New System.Windows.Forms.TextBox
Me.label9 = New System.Windows.Forms.Label
Me.fraINARouteSolver = New System.Windows.Forms.GroupBox
Me.label20 = New System.Windows.Forms.Label
Me.cboRouteOutputLines = New System.Windows.Forms.ComboBox
Me.chkUseTimeWindows = New System.Windows.Forms.CheckBox
Me.chkPreserveLast = New System.Windows.Forms.CheckBox
Me.chkPreserveFirst = New System.Windows.Forms.CheckBox
Me.chkBestOrder = New System.Windows.Forms.CheckBox
Me.chkUseStartTime = New System.Windows.Forms.CheckBox
Me.txtStartTime = New System.Windows.Forms.TextBox
Me.fraINAServerRouteParams = New System.Windows.Forms.GroupBox
Me.cboStopsLayers = New System.Windows.Forms.ComboBox
Me.label6 = New System.Windows.Forms.Label
Me.checkReturnBarriers = New System.Windows.Forms.CheckBox
Me.cboRouteDirectionsTimeAttribute = New System.Windows.Forms.ComboBox
Me.label21 = New System.Windows.Forms.Label
Me.cboRouteDirectionsLengthUnits = New System.Windows.Forms.ComboBox
Me.label22 = New System.Windows.Forms.Label
Me.chkReturnRoutes = New System.Windows.Forms.CheckBox
Me.chkReturnRouteGeometries = New System.Windows.Forms.CheckBox
Me.chkReturnStops = New System.Windows.Forms.CheckBox
Me.chkReturnDirections = New System.Windows.Forms.CheckBox
Me.cmdConnect = New System.Windows.Forms.Button
Me.tabCtrlOutput = New System.Windows.Forms.TabControl
Me.tabReturnMap = New System.Windows.Forms.TabPage
Me.tabReturnRouteFeatures = New System.Windows.Forms.TabPage
Me.dataGridRouteFeatures = New System.Windows.Forms.DataGrid
Me.tabReturnBarrierFeatures = New System.Windows.Forms.TabPage
Me.dataGridBarrierFeatures = New System.Windows.Forms.DataGrid
Me.tabReturnStopsFeatures = New System.Windows.Forms.TabPage
Me.dataGridStopFeatures = New System.Windows.Forms.DataGrid
Me.tabReturnDirections = New System.Windows.Forms.TabPage
Me.treeViewDirections = New System.Windows.Forms.TreeView
Me.tabReturnRouteGeometry = New System.Windows.Forms.TabPage
Me.treeViewRouteGeometry = New System.Windows.Forms.TreeView
CType(Me.pictureBox, System.ComponentModel.ISupportInitialize).BeginInit()
Me.fraINASolverSettings.SuspendLayout()
Me.fraINAServerSolverParams.SuspendLayout()
Me.fraINARouteSolver.SuspendLayout()
Me.fraINAServerRouteParams.SuspendLayout()
Me.tabCtrlOutput.SuspendLayout()
Me.tabReturnMap.SuspendLayout()
Me.tabReturnRouteFeatures.SuspendLayout()
CType(Me.dataGridRouteFeatures, System.ComponentModel.ISupportInitialize).BeginInit()
Me.tabReturnBarrierFeatures.SuspendLayout()
CType(Me.dataGridBarrierFeatures, System.ComponentModel.ISupportInitialize).BeginInit()
Me.tabReturnStopsFeatures.SuspendLayout()
CType(Me.dataGridStopFeatures, System.ComponentModel.ISupportInitialize).BeginInit()
Me.tabReturnDirections.SuspendLayout()
Me.tabReturnRouteGeometry.SuspendLayout()
Me.SuspendLayout()
'
'label1
'
Me.label1.Location = New System.Drawing.Point(8, 24)
Me.label1.Name = "label1"
Me.label1.Size = New System.Drawing.Size(120, 16)
Me.label1.TabIndex = 0
Me.label1.Text = "ArcGIS Server"
'
'label2
'
Me.label2.Location = New System.Drawing.Point(8, 48)
Me.label2.Name = "label2"
Me.label2.Size = New System.Drawing.Size(120, 16)
Me.label2.TabIndex = 1
Me.label2.Text = "Map Server Object"
'
'txtServer
'
Me.txtServer.Location = New System.Drawing.Point(128, 16)
Me.txtServer.Name = "txtServer"
Me.txtServer.Size = New System.Drawing.Size(192, 20)
Me.txtServer.TabIndex = 0
Me.txtServer.Text = "<Enter ArcGIS Server Name>"
'
'txtService
'
Me.txtService.Location = New System.Drawing.Point(128, 40)
Me.txtService.Name = "txtService"
Me.txtService.Size = New System.Drawing.Size(192, 20)
Me.txtService.TabIndex = 1
Me.txtService.Text = "<Enter ArcGIS Map Server Object>"
'
'cmdSolve
'
Me.cmdSolve.Enabled = False
Me.cmdSolve.Location = New System.Drawing.Point(232, 568)
Me.cmdSolve.Name = "cmdSolve"
Me.cmdSolve.Size = New System.Drawing.Size(200, 32)
Me.cmdSolve.TabIndex = 29
Me.cmdSolve.Text = "Find Route"
'
'pictureBox
'
Me.pictureBox.BackColor = System.Drawing.Color.White
Me.pictureBox.Location = New System.Drawing.Point(8, 8)
Me.pictureBox.Name = "pictureBox"
Me.pictureBox.Size = New System.Drawing.Size(448, 456)
Me.pictureBox.TabIndex = 20
Me.pictureBox.TabStop = False
'
'fraINASolverSettings
'
Me.fraINASolverSettings.Controls.Add(Me.chkIgnoreInvalidLocations)
Me.fraINASolverSettings.Controls.Add(Me.cboUturnPolicy)
Me.fraINASolverSettings.Controls.Add(Me.label11)
Me.fraINASolverSettings.Controls.Add(Me.label7)
Me.fraINASolverSettings.Controls.Add(Me.chklstAccumulateAttributes)
Me.fraINASolverSettings.Controls.Add(Me.label5)
Me.fraINASolverSettings.Controls.Add(Me.chklstRestrictions)
Me.fraINASolverSettings.Controls.Add(Me.cboImpedance)
Me.fraINASolverSettings.Controls.Add(Me.label4)
Me.fraINASolverSettings.Controls.Add(Me.chkUseHierarchy)
Me.fraINASolverSettings.Enabled = False
Me.fraINASolverSettings.Location = New System.Drawing.Point(8, 176)
Me.fraINASolverSettings.Name = "fraINASolverSettings"
Me.fraINASolverSettings.Size = New System.Drawing.Size(424, 192)
Me.fraINASolverSettings.TabIndex = 70
Me.fraINASolverSettings.TabStop = False
Me.fraINASolverSettings.Text = "INASolverSettings"
'
'chkIgnoreInvalidLocations
'
Me.chkIgnoreInvalidLocations.Location = New System.Drawing.Point(24, 80)
Me.chkIgnoreInvalidLocations.Name = "chkIgnoreInvalidLocations"
Me.chkIgnoreInvalidLocations.Size = New System.Drawing.Size(144, 21)
Me.chkIgnoreInvalidLocations.TabIndex = 10
Me.chkIgnoreInvalidLocations.Text = "Ignore Invalid Locations"
'
'cboUturnPolicy
'
Me.cboUturnPolicy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboUturnPolicy.Location = New System.Drawing.Point(128, 48)
Me.cboUturnPolicy.Name = "cboUturnPolicy"
Me.cboUturnPolicy.Size = New System.Drawing.Size(280, 21)
Me.cboUturnPolicy.TabIndex = 9
'
'label11
'
Me.label11.Location = New System.Drawing.Point(16, 56)
Me.label11.Name = "label11"
Me.label11.Size = New System.Drawing.Size(88, 16)
Me.label11.TabIndex = 73
Me.label11.Text = "Allow U-Turns"
'
'label7
'
Me.label7.Location = New System.Drawing.Point(216, 104)
Me.label7.Name = "label7"
Me.label7.Size = New System.Drawing.Size(120, 16)
Me.label7.TabIndex = 72
Me.label7.Text = "Accumulate Attributes"
'
'chklstAccumulateAttributes
'
Me.chklstAccumulateAttributes.CheckOnClick = True
Me.chklstAccumulateAttributes.Location = New System.Drawing.Point(216, 120)
Me.chklstAccumulateAttributes.Name = "chklstAccumulateAttributes"
Me.chklstAccumulateAttributes.ScrollAlwaysVisible = True
Me.chklstAccumulateAttributes.Size = New System.Drawing.Size(192, 64)
Me.chklstAccumulateAttributes.TabIndex = 13
'
'label5
'
Me.label5.Location = New System.Drawing.Point(16, 104)
Me.label5.Name = "label5"
Me.label5.Size = New System.Drawing.Size(72, 16)
Me.label5.TabIndex = 70
Me.label5.Text = "Restrictions"
'
'chklstRestrictions
'
Me.chklstRestrictions.CheckOnClick = True
Me.chklstRestrictions.Location = New System.Drawing.Point(16, 120)
Me.chklstRestrictions.Name = "chklstRestrictions"
Me.chklstRestrictions.ScrollAlwaysVisible = True
Me.chklstRestrictions.Size = New System.Drawing.Size(192, 64)
Me.chklstRestrictions.TabIndex = 12
'
'cboImpedance
'
Me.cboImpedance.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboImpedance.Location = New System.Drawing.Point(128, 24)
Me.cboImpedance.Name = "cboImpedance"
Me.cboImpedance.Size = New System.Drawing.Size(280, 21)
Me.cboImpedance.TabIndex = 8
'
'label4
'
Me.label4.Location = New System.Drawing.Point(16, 24)
Me.label4.Name = "label4"
Me.label4.Size = New System.Drawing.Size(64, 16)
Me.label4.TabIndex = 67
Me.label4.Text = "Impedance"
'
'chkUseHierarchy
'
Me.chkUseHierarchy.Checked = True
Me.chkUseHierarchy.CheckState = System.Windows.Forms.CheckState.Checked
Me.chkUseHierarchy.Location = New System.Drawing.Point(216, 80)
Me.chkUseHierarchy.Name = "chkUseHierarchy"
Me.chkUseHierarchy.Size = New System.Drawing.Size(96, 21)
Me.chkUseHierarchy.TabIndex = 11
Me.chkUseHierarchy.Text = "Use Hierarchy"
'
'fraINAServerSolverParams
'
Me.fraINAServerSolverParams.Controls.Add(Me.chkReturnMap)
Me.fraINAServerSolverParams.Controls.Add(Me.cboSnapToleranceUnits)
Me.fraINAServerSolverParams.Controls.Add(Me.cboNALayers)
Me.fraINAServerSolverParams.Controls.Add(Me.label10)
Me.fraINAServerSolverParams.Controls.Add(Me.label8)
Me.fraINAServerSolverParams.Controls.Add(Me.txtMaxSnapTolerance)
Me.fraINAServerSolverParams.Controls.Add(Me.txtSnapTolerance)
Me.fraINAServerSolverParams.Controls.Add(Me.label9)
Me.fraINAServerSolverParams.Enabled = False
Me.fraINAServerSolverParams.Location = New System.Drawing.Point(8, 72)
Me.fraINAServerSolverParams.Name = "fraINAServerSolverParams"
Me.fraINAServerSolverParams.Size = New System.Drawing.Size(424, 96)
Me.fraINAServerSolverParams.TabIndex = 71
Me.fraINAServerSolverParams.TabStop = False
Me.fraINAServerSolverParams.Text = "INAServerSolverParams"
'
'chkReturnMap
'
Me.chkReturnMap.Checked = True
Me.chkReturnMap.CheckState = System.Windows.Forms.CheckState.Checked
Me.chkReturnMap.Location = New System.Drawing.Point(8, 72)
Me.chkReturnMap.Name = "chkReturnMap"
Me.chkReturnMap.Size = New System.Drawing.Size(96, 16)
Me.chkReturnMap.TabIndex = 7
Me.chkReturnMap.Text = "Return Map"
'
'cboSnapToleranceUnits
'
Me.cboSnapToleranceUnits.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboSnapToleranceUnits.Location = New System.Drawing.Point(240, 48)
Me.cboSnapToleranceUnits.Name = "cboSnapToleranceUnits"
Me.cboSnapToleranceUnits.Size = New System.Drawing.Size(168, 21)
Me.cboSnapToleranceUnits.TabIndex = 6
'
'cboNALayers
'
Me.cboNALayers.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboNALayers.Location = New System.Drawing.Point(128, 24)
Me.cboNALayers.Name = "cboNALayers"
Me.cboNALayers.Size = New System.Drawing.Size(280, 21)
Me.cboNALayers.TabIndex = 3
'
'label10
'
Me.label10.Location = New System.Drawing.Point(168, 56)
Me.label10.Name = "label10"
Me.label10.Size = New System.Drawing.Size(16, 16)
Me.label10.TabIndex = 72
Me.label10.Text = "to"
'
'label8
'
Me.label8.Location = New System.Drawing.Point(8, 24)
Me.label8.Name = "label8"
Me.label8.Size = New System.Drawing.Size(128, 16)
Me.label8.TabIndex = 71
Me.label8.Text = "NALayer Name"
'
'txtMaxSnapTolerance
'
Me.txtMaxSnapTolerance.Location = New System.Drawing.Point(192, 48)
Me.txtMaxSnapTolerance.Name = "txtMaxSnapTolerance"
Me.txtMaxSnapTolerance.Size = New System.Drawing.Size(40, 20)
Me.txtMaxSnapTolerance.TabIndex = 5
Me.txtMaxSnapTolerance.Text = "50"
'
'txtSnapTolerance
'
Me.txtSnapTolerance.Location = New System.Drawing.Point(128, 48)
Me.txtSnapTolerance.Name = "txtSnapTolerance"
Me.txtSnapTolerance.Size = New System.Drawing.Size(32, 20)
Me.txtSnapTolerance.TabIndex = 4
Me.txtSnapTolerance.Text = "2"
'
'label9
'
Me.label9.Location = New System.Drawing.Point(8, 48)
Me.label9.Name = "label9"
Me.label9.Size = New System.Drawing.Size(104, 16)
Me.label9.TabIndex = 68
Me.label9.Text = "Search Tolerance"
'
'fraINARouteSolver
'
Me.fraINARouteSolver.Controls.Add(Me.label20)
Me.fraINARouteSolver.Controls.Add(Me.cboRouteOutputLines)
Me.fraINARouteSolver.Controls.Add(Me.chkUseTimeWindows)
Me.fraINARouteSolver.Controls.Add(Me.chkPreserveLast)
Me.fraINARouteSolver.Controls.Add(Me.chkPreserveFirst)
Me.fraINARouteSolver.Controls.Add(Me.chkBestOrder)
Me.fraINARouteSolver.Controls.Add(Me.chkUseStartTime)
Me.fraINARouteSolver.Controls.Add(Me.txtStartTime)
Me.fraINARouteSolver.Enabled = False
Me.fraINARouteSolver.Location = New System.Drawing.Point(232, 376)
Me.fraINARouteSolver.Name = "fraINARouteSolver"
Me.fraINARouteSolver.Size = New System.Drawing.Size(200, 184)
Me.fraINARouteSolver.TabIndex = 76
Me.fraINARouteSolver.TabStop = False
Me.fraINARouteSolver.Text = "INARouteSolver"
'
'label20
'
Me.label20.Location = New System.Drawing.Point(8, 136)
Me.label20.Name = "label20"
Me.label20.Size = New System.Drawing.Size(40, 16)
Me.label20.TabIndex = 53
Me.label20.Text = "Shape"
'
'cboRouteOutputLines
'
Me.cboRouteOutputLines.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboRouteOutputLines.ItemHeight = 13
Me.cboRouteOutputLines.Location = New System.Drawing.Point(8, 152)
Me.cboRouteOutputLines.Name = "cboRouteOutputLines"
Me.cboRouteOutputLines.Size = New System.Drawing.Size(184, 21)
Me.cboRouteOutputLines.TabIndex = 28
'
'chkUseTimeWindows
'
Me.chkUseTimeWindows.Location = New System.Drawing.Point(8, 80)
Me.chkUseTimeWindows.Name = "chkUseTimeWindows"
Me.chkUseTimeWindows.Size = New System.Drawing.Size(128, 16)
Me.chkUseTimeWindows.TabIndex = 25
Me.chkUseTimeWindows.Text = "Use Time Windows"
'
'chkPreserveLast
'
Me.chkPreserveLast.Location = New System.Drawing.Point(24, 56)
Me.chkPreserveLast.Name = "chkPreserveLast"
Me.chkPreserveLast.Size = New System.Drawing.Size(96, 16)
Me.chkPreserveLast.TabIndex = 24
Me.chkPreserveLast.Text = "PreserveLast"
'
'chkPreserveFirst
'
Me.chkPreserveFirst.Location = New System.Drawing.Point(24, 40)
Me.chkPreserveFirst.Name = "chkPreserveFirst"
Me.chkPreserveFirst.Size = New System.Drawing.Size(104, 16)
Me.chkPreserveFirst.TabIndex = 23
Me.chkPreserveFirst.Text = "Preserve First"
'
'chkBestOrder
'
Me.chkBestOrder.Location = New System.Drawing.Point(8, 24)
Me.chkBestOrder.Name = "chkBestOrder"
Me.chkBestOrder.Size = New System.Drawing.Size(112, 16)
Me.chkBestOrder.TabIndex = 22
Me.chkBestOrder.Text = "Find Best Order"
'
'chkUseStartTime
'
Me.chkUseStartTime.Location = New System.Drawing.Point(8, 96)
Me.chkUseStartTime.Name = "chkUseStartTime"
Me.chkUseStartTime.Size = New System.Drawing.Size(104, 16)
Me.chkUseStartTime.TabIndex = 26
Me.chkUseStartTime.Text = "Use Start Time"
'
'txtStartTime
'
Me.txtStartTime.Enabled = False
Me.txtStartTime.Location = New System.Drawing.Point(24, 112)
Me.txtStartTime.Name = "txtStartTime"
Me.txtStartTime.Size = New System.Drawing.Size(168, 20)
Me.txtStartTime.TabIndex = 27
'
'fraINAServerRouteParams
'
Me.fraINAServerRouteParams.Controls.Add(Me.cboStopsLayers)
Me.fraINAServerRouteParams.Controls.Add(Me.label6)
Me.fraINAServerRouteParams.Controls.Add(Me.checkReturnBarriers)
Me.fraINAServerRouteParams.Controls.Add(Me.cboRouteDirectionsTimeAttribute)
Me.fraINAServerRouteParams.Controls.Add(Me.label21)
Me.fraINAServerRouteParams.Controls.Add(Me.cboRouteDirectionsLengthUnits)
Me.fraINAServerRouteParams.Controls.Add(Me.label22)
Me.fraINAServerRouteParams.Controls.Add(Me.chkReturnRoutes)
Me.fraINAServerRouteParams.Controls.Add(Me.chkReturnRouteGeometries)
Me.fraINAServerRouteParams.Controls.Add(Me.chkReturnStops)
Me.fraINAServerRouteParams.Controls.Add(Me.chkReturnDirections)
Me.fraINAServerRouteParams.Enabled = False
Me.fraINAServerRouteParams.Location = New System.Drawing.Point(8, 376)
Me.fraINAServerRouteParams.Name = "fraINAServerRouteParams"
Me.fraINAServerRouteParams.Size = New System.Drawing.Size(216, 224)
Me.fraINAServerRouteParams.TabIndex = 75
Me.fraINAServerRouteParams.TabStop = False
Me.fraINAServerRouteParams.Text = "INAServerRouteParams"
'
'cboStopsLayers
'
Me.cboStopsLayers.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboStopsLayers.Location = New System.Drawing.Point(80, 24)
Me.cboStopsLayers.Name = "cboStopsLayers"
Me.cboStopsLayers.Size = New System.Drawing.Size(128, 21)
Me.cboStopsLayers.TabIndex = 14
'
'label6
'
Me.label6.Location = New System.Drawing.Point(8, 32)
Me.label6.Name = "label6"
Me.label6.Size = New System.Drawing.Size(64, 16)
Me.label6.TabIndex = 81
Me.label6.Text = "Input Stops"
'
'checkReturnBarriers
'
Me.checkReturnBarriers.Checked = True
Me.checkReturnBarriers.CheckState = System.Windows.Forms.CheckState.Checked
Me.checkReturnBarriers.Location = New System.Drawing.Point(16, 96)
Me.checkReturnBarriers.Name = "checkReturnBarriers"
Me.checkReturnBarriers.Size = New System.Drawing.Size(136, 16)
Me.checkReturnBarriers.TabIndex = 17
Me.checkReturnBarriers.Text = "Returns Barriers"
'
'cboRouteDirectionsTimeAttribute
'
Me.cboRouteDirectionsTimeAttribute.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboRouteDirectionsTimeAttribute.ItemHeight = 13
Me.cboRouteDirectionsTimeAttribute.Location = New System.Drawing.Point(56, 184)
Me.cboRouteDirectionsTimeAttribute.Name = "cboRouteDirectionsTimeAttribute"
Me.cboRouteDirectionsTimeAttribute.Size = New System.Drawing.Size(152, 21)
Me.cboRouteDirectionsTimeAttribute.TabIndex = 21
'
'label21
'
Me.label21.Location = New System.Drawing.Point(8, 192)
Me.label21.Name = "label21"
Me.label21.Size = New System.Drawing.Size(48, 16)
Me.label21.TabIndex = 52
Me.label21.Text = "Dir Time"
'
'cboRouteDirectionsLengthUnits
'
Me.cboRouteDirectionsLengthUnits.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboRouteDirectionsLengthUnits.ItemHeight = 13
Me.cboRouteDirectionsLengthUnits.Location = New System.Drawing.Point(56, 160)
Me.cboRouteDirectionsLengthUnits.Name = "cboRouteDirectionsLengthUnits"
Me.cboRouteDirectionsLengthUnits.Size = New System.Drawing.Size(152, 21)
Me.cboRouteDirectionsLengthUnits.TabIndex = 20
'
'label22
'
Me.label22.Location = New System.Drawing.Point(8, 168)
Me.label22.Name = "label22"
Me.label22.Size = New System.Drawing.Size(56, 16)
Me.label22.TabIndex = 50
Me.label22.Text = "Dir Units"
'
'chkReturnRoutes
'
Me.chkReturnRoutes.Checked = True
Me.chkReturnRoutes.CheckState = System.Windows.Forms.CheckState.Checked
Me.chkReturnRoutes.Location = New System.Drawing.Point(16, 80)
Me.chkReturnRoutes.Name = "chkReturnRoutes"
Me.chkReturnRoutes.Size = New System.Drawing.Size(96, 16)
Me.chkReturnRoutes.TabIndex = 16
Me.chkReturnRoutes.Text = "Return Routes"
'
'chkReturnRouteGeometries
'
Me.chkReturnRouteGeometries.Checked = True
Me.chkReturnRouteGeometries.CheckState = System.Windows.Forms.CheckState.Checked
Me.chkReturnRouteGeometries.Location = New System.Drawing.Point(16, 64)
Me.chkReturnRouteGeometries.Name = "chkReturnRouteGeometries"
Me.chkReturnRouteGeometries.Size = New System.Drawing.Size(152, 16)
Me.chkReturnRouteGeometries.TabIndex = 15
Me.chkReturnRouteGeometries.Text = "Return Route Geometries"
'
'chkReturnStops
'
Me.chkReturnStops.Checked = True
Me.chkReturnStops.CheckState = System.Windows.Forms.CheckState.Checked
Me.chkReturnStops.Location = New System.Drawing.Point(16, 112)
Me.chkReturnStops.Name = "chkReturnStops"
Me.chkReturnStops.Size = New System.Drawing.Size(96, 16)
Me.chkReturnStops.TabIndex = 18
Me.chkReturnStops.Text = "Return Stops"
'
'chkReturnDirections
'
Me.chkReturnDirections.Checked = True
Me.chkReturnDirections.CheckState = System.Windows.Forms.CheckState.Checked
Me.chkReturnDirections.Location = New System.Drawing.Point(16, 128)
Me.chkReturnDirections.Name = "chkReturnDirections"
Me.chkReturnDirections.Size = New System.Drawing.Size(160, 16)
Me.chkReturnDirections.TabIndex = 19
Me.chkReturnDirections.Text = "Generate Directions"
'
'cmdConnect
'
Me.cmdConnect.Location = New System.Drawing.Point(328, 16)
Me.cmdConnect.Name = "cmdConnect"
Me.cmdConnect.Size = New System.Drawing.Size(96, 40)
Me.cmdConnect.TabIndex = 2
Me.cmdConnect.Text = "Connect"
'
'tabCtrlOutput
'
Me.tabCtrlOutput.Controls.Add(Me.tabReturnMap)
Me.tabCtrlOutput.Controls.Add(Me.tabReturnRouteFeatures)
Me.tabCtrlOutput.Controls.Add(Me.tabReturnBarrierFeatures)
Me.tabCtrlOutput.Controls.Add(Me.tabReturnStopsFeatures)
Me.tabCtrlOutput.Controls.Add(Me.tabReturnDirections)
Me.tabCtrlOutput.Controls.Add(Me.tabReturnRouteGeometry)
Me.tabCtrlOutput.Enabled = False
Me.tabCtrlOutput.Location = New System.Drawing.Point(440, 80)
Me.tabCtrlOutput.Name = "tabCtrlOutput"
Me.tabCtrlOutput.SelectedIndex = 0
Me.tabCtrlOutput.Size = New System.Drawing.Size(472, 496)
Me.tabCtrlOutput.TabIndex = 30
'
'tabReturnMap
'
Me.tabReturnMap.Controls.Add(Me.pictureBox)
Me.tabReturnMap.Location = New System.Drawing.Point(4, 22)
Me.tabReturnMap.Name = "tabReturnMap"
Me.tabReturnMap.Size = New System.Drawing.Size(464, 470)
Me.tabReturnMap.TabIndex = 0
Me.tabReturnMap.Text = "Map"
'
'tabReturnRouteFeatures
'
Me.tabReturnRouteFeatures.Controls.Add(Me.dataGridRouteFeatures)
Me.tabReturnRouteFeatures.Location = New System.Drawing.Point(4, 22)
Me.tabReturnRouteFeatures.Name = "tabReturnRouteFeatures"
Me.tabReturnRouteFeatures.Size = New System.Drawing.Size(464, 470)
Me.tabReturnRouteFeatures.TabIndex = 4
Me.tabReturnRouteFeatures.Text = "Route Features"
'
'dataGridRouteFeatures
'
Me.dataGridRouteFeatures.DataMember = ""
Me.dataGridRouteFeatures.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.dataGridRouteFeatures.Location = New System.Drawing.Point(8, 8)
Me.dataGridRouteFeatures.Name = "dataGridRouteFeatures"
Me.dataGridRouteFeatures.Size = New System.Drawing.Size(448, 456)
Me.dataGridRouteFeatures.TabIndex = 0
'
'tabReturnBarrierFeatures
'
Me.tabReturnBarrierFeatures.Controls.Add(Me.dataGridBarrierFeatures)
Me.tabReturnBarrierFeatures.Location = New System.Drawing.Point(4, 22)
Me.tabReturnBarrierFeatures.Name = "tabReturnBarrierFeatures"
Me.tabReturnBarrierFeatures.Size = New System.Drawing.Size(464, 470)
Me.tabReturnBarrierFeatures.TabIndex = 3
Me.tabReturnBarrierFeatures.Text = "Barrier Features"
'
'dataGridBarrierFeatures
'
Me.dataGridBarrierFeatures.DataMember = ""
Me.dataGridBarrierFeatures.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.dataGridBarrierFeatures.Location = New System.Drawing.Point(8, 8)
Me.dataGridBarrierFeatures.Name = "dataGridBarrierFeatures"
Me.dataGridBarrierFeatures.Size = New System.Drawing.Size(448, 456)
Me.dataGridBarrierFeatures.TabIndex = 0
'
'tabReturnStopsFeatures
'
Me.tabReturnStopsFeatures.Controls.Add(Me.dataGridStopFeatures)
Me.tabReturnStopsFeatures.Location = New System.Drawing.Point(4, 22)
Me.tabReturnStopsFeatures.Name = "tabReturnStopsFeatures"
Me.tabReturnStopsFeatures.Size = New System.Drawing.Size(464, 470)
Me.tabReturnStopsFeatures.TabIndex = 2
Me.tabReturnStopsFeatures.Text = "Stop Features"
'
'dataGridStopFeatures
'
Me.dataGridStopFeatures.DataMember = ""
Me.dataGridStopFeatures.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.dataGridStopFeatures.Location = New System.Drawing.Point(8, 8)
Me.dataGridStopFeatures.Name = "dataGridStopFeatures"
Me.dataGridStopFeatures.Size = New System.Drawing.Size(448, 456)
Me.dataGridStopFeatures.TabIndex = 0
'
'tabReturnDirections
'
Me.tabReturnDirections.Controls.Add(Me.treeViewDirections)
Me.tabReturnDirections.Location = New System.Drawing.Point(4, 22)
Me.tabReturnDirections.Name = "tabReturnDirections"
Me.tabReturnDirections.Size = New System.Drawing.Size(464, 470)
Me.tabReturnDirections.TabIndex = 1
Me.tabReturnDirections.Text = "Directions"
'
'treeViewDirections
'
Me.treeViewDirections.Location = New System.Drawing.Point(8, 8)
Me.treeViewDirections.Name = "treeViewDirections"
Me.treeViewDirections.Size = New System.Drawing.Size(448, 456)
Me.treeViewDirections.TabIndex = 69
'
'tabReturnRouteGeometry
'
Me.tabReturnRouteGeometry.Controls.Add(Me.treeViewRouteGeometry)
Me.tabReturnRouteGeometry.Location = New System.Drawing.Point(4, 22)
Me.tabReturnRouteGeometry.Name = "tabReturnRouteGeometry"
Me.tabReturnRouteGeometry.Size = New System.Drawing.Size(464, 470)
Me.tabReturnRouteGeometry.TabIndex = 5
Me.tabReturnRouteGeometry.Text = "Route Geometry"
'
'treeViewRouteGeometry
'
Me.treeViewRouteGeometry.Location = New System.Drawing.Point(8, 8)
Me.treeViewRouteGeometry.Name = "treeViewRouteGeometry"
Me.treeViewRouteGeometry.Size = New System.Drawing.Size(448, 456)
Me.treeViewRouteGeometry.TabIndex = 1
'
'Route_GISServerAPIClass
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(936, 606)
Me.Controls.Add(Me.tabCtrlOutput)
Me.Controls.Add(Me.fraINARouteSolver)
Me.Controls.Add(Me.fraINAServerRouteParams)
Me.Controls.Add(Me.fraINAServerSolverParams)
Me.Controls.Add(Me.fraINASolverSettings)
Me.Controls.Add(Me.txtService)
Me.Controls.Add(Me.txtServer)
Me.Controls.Add(Me.cmdSolve)
Me.Controls.Add(Me.label2)
Me.Controls.Add(Me.label1)
Me.Controls.Add(Me.cmdConnect)
Me.Name = "Route_GISServerAPIClass"
Me.Text = "NAServer - Route GISClient Sample"
CType(Me.pictureBox, System.ComponentModel.ISupportInitialize).EndInit()
Me.fraINASolverSettings.ResumeLayout(False)
Me.fraINAServerSolverParams.ResumeLayout(False)
Me.fraINAServerSolverParams.PerformLayout()
Me.fraINARouteSolver.ResumeLayout(False)
Me.fraINARouteSolver.PerformLayout()
Me.fraINAServerRouteParams.ResumeLayout(False)
Me.tabCtrlOutput.ResumeLayout(False)
Me.tabReturnMap.ResumeLayout(False)
Me.tabReturnRouteFeatures.ResumeLayout(False)
CType(Me.dataGridRouteFeatures, System.ComponentModel.ISupportInitialize).EndInit()
Me.tabReturnBarrierFeatures.ResumeLayout(False)
CType(Me.dataGridBarrierFeatures, System.ComponentModel.ISupportInitialize).EndInit()
Me.tabReturnStopsFeatures.ResumeLayout(False)
CType(Me.dataGridStopFeatures, System.ComponentModel.ISupportInitialize).EndInit()
Me.tabReturnDirections.ResumeLayout(False)
Me.tabReturnRouteGeometry.ResumeLayout(False)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
''' <summary>
''' The main entry point for the application.
''' </summary>
<STAThread()> _
Shared Sub Main()
Application.Run(New Route_GISServerAPIClass())
End Sub
''' <summary>
''' This function
''' - sets the server and solver parameters
''' - populates the stops NALocations
''' - gets and displays the server results (map, directions, etc.)
''' </summary>
Private Sub cmdSolve_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSolve.Click
Me.Cursor = Cursors.WaitCursor
Try
' Get SolverParams
Dim solverParams As INAServerSolverParams = TryCast(m_naServer.GetSolverParameters(cboNALayers.Text), INAServerSolverParams)
' Set Solver params
SetINASolverSettings(TryCast(solverParams, INASolverSettings))
SetSolverSpecificInterface(solverParams)
SetServerSolverParams(TryCast(solverParams, INAServerSolverParams))
' Load Locations
LoadLocations(solverParams)
'Solve the Route
Dim solverResults As INAServerSolverResults = Nothing
solverResults = m_naServer.Solve(solverParams)
'Get NAServer results in the tab controls
OutputResults(solverParams, solverResults)
Catch exception As Exception
MessageBox.Show(exception.Message, "An error has occurred")
End Try
Me.Cursor = Cursors.Default
End Sub
''' <summary>
''' This function
''' - connects to the ArcGIS Server and MapServer
''' - sets all controls for the first route network analysis layer
''' </summary>
Private Sub cmdConnect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
Try
ConnectToServer()
GetNetworkAnalysisLayers()
Catch exception As Exception
MessageBox.Show(exception.Message, "An error has occurred")
End Try
End Sub
''' <summary>
''' Get MapServer and NAServer Object from the MapServer using GISClient
''' </summary>
Private Sub ConnectToServer()
m_naServer = Nothing
m_mapServer = Nothing
Dim propertySet As IPropertySet = New PropertySet()
propertySet.SetProperty("Machine", txtServer.Text)
Dim agsServerConnectionFactory As IAGSServerConnectionFactory = New AGSServerConnectionFactory()
Dim agsServerConnection As IAGSServerConnection = agsServerConnectionFactory.Open(propertySet, 0)
Dim agsEnumServerObjectName As IAGSEnumServerObjectName = agsServerConnection.ServerObjectNames
agsEnumServerObjectName.Reset()
Dim serverObjectName As IName
Dim agsServerObject As IAGSServerObject = Nothing
Dim agsServerObjectName As IAGSServerObjectName = agsEnumServerObjectName.Next()
Do While (Not agsServerObjectName Is Nothing)
If agsServerObjectName.Type.ToUpper() = "NASERVER" And _
agsServerObjectName.Name.ToUpper() = txtService.Text.ToUpper() Then
serverObjectName = TryCast(agsServerObjectName, IName)
agsServerObject = TryCast(serverObjectName.Open(), IAGSServerObject)
If Not TryCast(agsServerObject, INAServer) Is Nothing Then
m_naServer = TryCast(agsServerObject, INAServer)
End If
End If
' Search for the MapServer Server Object
If agsServerObjectName.Type.ToUpper() = "MAPSERVER" And _
agsServerObjectName.Name.ToUpper() = txtService.Text.ToUpper() Then
serverObjectName = TryCast(agsServerObjectName, IName)
agsServerObject = TryCast(serverObjectName.Open(), IAGSServerObject)
If Not TryCast(agsServerObject, IMapServer) Is Nothing Then
m_mapServer = TryCast(agsServerObject, IMapServer)
End If
End If
' If we got both of them, exit out
If (Not m_naServer Is Nothing) AndAlso (Not m_mapServer Is Nothing) Then
Return
End If
agsServerObjectName = agsEnumServerObjectName.Next()
Loop
Throw (New System.Exception("Could not find " & txtService.Text))
End Sub
''' <summary>
''' This function
''' - gets all route network analysis layers
''' - selects the first route network analysis layer
''' - sets all controls for this route network analysis layer
''' </summary>
Private Sub GetNetworkAnalysisLayers()
Me.Cursor = Cursors.WaitCursor
Try
' Enable Frame
fraINAServerSolverParams.Enabled = True
'Get Route NA layer names
cboNALayers.Items.Clear()
Dim naLayers As String() = m_naServer.GetNALayerNames(ESRI.ArcGIS.NetworkAnalyst.esriNAServerLayerType.esriNAServerRouteLayer)
Dim i As Integer = 0
Do While i < naLayers.Length
cboNALayers.Items.Add(naLayers(i))
i += 1
Loop
' Select the first NA Layer name
If cboNALayers.Items.Count > 0 Then
cboNALayers.SelectedIndex = 0
Else
MessageBox.Show("There is no Network Analyst layer associated with this MapServer object!", "NAServer - Route Sample", System.Windows.Forms.MessageBoxButtons.OK)
End If
Catch exception As Exception
MessageBox.Show(exception.Message, "An error has occurred")
End Try
Me.Cursor = Cursors.Default
End Sub
''' <summary>
''' This function sets all controls for the selected route network analysis layer
''' </summary>
Private Sub cboNALayers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboNALayers.SelectedIndexChanged
Dim naLayerName As String = cboNALayers.Text
' Enable Solve Button
cmdSolve.Enabled = (naLayerName.Length = 0)
If naLayerName.Length = 0 Then
Return
End If
Me.Cursor = Cursors.WaitCursor
Try
Dim solverParams As INAServerSolverParams = m_naServer.GetSolverParameters(naLayerName)
Dim networkDescription As INAServerNetworkDescription = m_naServer.GetNetworkDescription(naLayerName)
' Setup Default Properties
GetINASolverSettings(networkDescription, TryCast(solverParams, INASolverSettings2))
GetSolverSpecificInterface(solverParams)
GetServerSolverParams(networkDescription, TryCast(solverParams, INAServerSolverParams))
' Get all Point feature Layers form the ServerContext
GetInputStopsLayers()
' Make frames Enable
MakeFramesEnabled(solverParams)
' Hide Tabs
HideTabs()
cmdSolve.Enabled = True
Catch exception As Exception
MessageBox.Show(exception.Message, "An error has occurred")
End Try
Me.Cursor = Cursors.Default
End Sub
''' <summary>
''' Get Default NASolverSettings controls (Cost Attributes, Restrictions Attributes. etc.)
''' </summary>
Private Sub GetINASolverSettings(ByVal networkDescription As INAServerNetworkDescription, ByVal solverSettings As INASolverSettings2)
Dim impedanceIndex As Integer = 0
'Get Attributes
cboImpedance.Items.Clear()
chklstAccumulateAttributes.Items.Clear()
chklstRestrictions.Items.Clear()
cboUturnPolicy.SelectedIndex = -1
Dim attributes() As INAServerNetworkAttribute = networkDescription.NetworkAttributes
Dim accumulateAttributeNames As IStringArray = solverSettings.AccumulateAttributeNames
Dim restrictionAttributeNames As IStringArray = solverSettings.RestrictionAttributeNames
For i As Integer = 0 To attributes.Length - 1
Dim networkAttribute As INAServerNetworkAttribute = attributes(i)
Dim networkAttributeName As String = networkAttribute.Name
If networkAttribute.UsageType = esriNetworkAttributeUsageType.esriNAUTCost Then
chklstAccumulateAttributes.Items.Add(networkAttribute.Name, IsStringInStringArray(networkAttributeName, accumulateAttributeNames))
Dim index As Integer = cboImpedance.Items.Add(networkAttribute.Name + " (" + networkAttribute.Units.ToString().Substring(7) + ")")
If networkAttributeName = solverSettings.ImpedanceAttributeName Then
impedanceIndex = index
End If
End If
If networkAttribute.UsageType = esriNetworkAttributeUsageType.esriNAUTRestriction Then
chklstRestrictions.Items.Add(networkAttribute.Name, IsStringInStringArray(networkAttributeName, restrictionAttributeNames))
End If
Next
If cboImpedance.Items.Count > 0 Then
cboImpedance.SelectedIndex = impedanceIndex
End If
chkUseHierarchy.Checked = solverSettings.UseHierarchy
chkUseHierarchy.Enabled = solverSettings.HierarchyAttributeName.Length > 0
chkIgnoreInvalidLocations.Checked = solverSettings.IgnoreInvalidLocations
cboUturnPolicy.SelectedIndex = System.Convert.ToInt32(solverSettings.RestrictUTurns)
End Sub
Private Function IsStringInStringArray(ByVal inputString As String, ByVal stringArray As IStringArray) As Boolean
Dim numInArray As Integer = stringArray.Count
For i As Integer = 0 To numInArray - 1
If inputString.Equals(stringArray.Element(i)) Then
Return True
End If
Next
Return False
End Function
''' <summary>
''' Set Default route solver controls (BestOrder, UseTimeWindows, UseStartTime, etc.)
''' </summary>
Private Sub GetSolverSpecificInterface(ByVal solverParams As INAServerSolverParams)
Dim routeSolver As INARouteSolver2 = TryCast(solverParams, INARouteSolver2)
If Not routeSolver Is Nothing Then
chkBestOrder.Checked = routeSolver.FindBestSequence
chkPreserveFirst.Checked = routeSolver.PreserveFirstStop
chkPreserveLast.Checked = routeSolver.PreserveLastStop
If chkBestOrder.Checked = True Then
Me.chkPreserveFirst.Enabled = True
Me.chkPreserveLast.Enabled = True
Else
Me.chkPreserveFirst.Enabled = False
Me.chkPreserveLast.Enabled = False
End If
chkUseTimeWindows.Checked = routeSolver.UseTimeWindows
chkUseStartTime.Checked = routeSolver.UseStartTime
If chkUseStartTime.Checked Then
txtStartTime.Enabled = True
txtStartTime.Text = routeSolver.StartTime.ToString()
Else
txtStartTime.Enabled = False
txtStartTime.Text = System.DateTime.Now.ToString()
End If
cboRouteOutputLines.SelectedIndex = System.Convert.ToInt32(routeSolver.OutputLines)
End If
End Sub
''' <summary>
''' Get all point feature layers from the ServerContext
''' Add them in the "Input Stops" drop down list
''' </summary>
Private Sub GetInputStopsLayers()
cboStopsLayers.Items.Clear()
m_layerIDs.Clear()
Dim serverInfo As IMapServerInfo = m_mapServer.GetServerInfo(m_mapServer.DefaultMapName)
Dim mapLayerInfos As IMapLayerInfos = serverInfo.MapLayerInfos
Dim i As Integer = 0
Do While i < mapLayerInfos.Count
Dim mapLayerInfo As IMapLayerInfo = mapLayerInfos.Element(i)
' Just get point layers that aren't in composite layers (don't want NAClasses)
If _
mapLayerInfo.IsFeatureLayer AndAlso ( _
mapLayerInfo.ParentLayerID = -1 _
OrElse mapLayerInfos.Element(mapLayerInfo.ParentLayerID).Type <> "Network Analysis Layer" _
) Then
Dim fields As IFields = mapLayerInfo.Fields
Dim j As Integer = 0
Do While j < fields.FieldCount
Dim field As IField = fields.Field(j)
If field.Type = esriFieldType.esriFieldTypeGeometry Then
Dim geometryDef As IGeometryDef = field.GeometryDef
If geometryDef.GeometryType = esriGeometryType.esriGeometryPoint Then
cboStopsLayers.Items.Add(mapLayerInfo.Name)
m_layerIDs.Add(mapLayerInfo.ID)
End If
End If
j += 1
Loop
End If
i += 1
Loop
' Add <None> at the end in case the user does not want to load Stop Location from a Feature Layer
cboStopsLayers.Items.Add("<None>")
m_layerIDs.Add(-1)
cboStopsLayers.SelectedIndex = 0
End Sub
''' <summary>
''' Get ServerSolverParams controls (ReturnMap, SnapTolerance, etc.)
''' </summary>
Private Sub GetServerSolverParams(ByVal networkDescription As INAServerNetworkDescription, ByVal solverParams As INAServerSolverParams)
chkReturnMap.Checked = True
txtSnapTolerance.Text = solverParams.SnapTolerance.ToString()
txtMaxSnapTolerance.Text = solverParams.MaxSnapTolerance.ToString()
cboSnapToleranceUnits.SelectedIndex = Convert.ToInt32(solverParams.SnapToleranceUnits)
'Set Route Defaults
chkReturnRouteGeometries.Checked = False
chkReturnRoutes.Checked = True
chkReturnStops.Checked = True
chkReturnDirections.Checked = True
checkReturnBarriers.Checked = True
'Set Directions Defaults
cboRouteDirectionsTimeAttribute.Items.Clear()
Dim attributes As INAServerNetworkAttribute() = networkDescription.NetworkAttributes
Dim i As Integer = 0
Do While i < attributes.Length
Dim networkAttribute As INAServerNetworkAttribute = attributes(i)
If networkAttribute.UsageType = esriNetworkAttributeUsageType.esriNAUTCost Then
If String.Compare(networkAttribute.Units.ToString(), "esriNAUMinutes") = 0 Then
cboRouteDirectionsTimeAttribute.Items.Add(networkAttribute.Name)
End If
End If
i += 1
Loop
' Set the default direction settings
Dim routeParams As INAServerRouteParams = TryCast(solverParams, INAServerRouteParams)
If Not routeParams Is Nothing Then
cboRouteDirectionsLengthUnits.Text = routeParams.DirectionsLengthUnits.ToString().Substring(7)
'Select the first time attribute
If cboRouteDirectionsTimeAttribute.Items.Count > 0 Then
cboRouteDirectionsTimeAttribute.Text = routeParams.DirectionsTimeAttributeName
End If
End If
End Sub
''' <summary>
''' Set general solver settings (Impedance, Restrictions, Accumulates, etc.)
''' </summary>
Private Sub SetINASolverSettings(ByVal solverSettings As INASolverSettings)
solverSettings.ImpedanceAttributeName = ExtractImpedanceName(cboImpedance.Text)
Dim restrictionAttributes As IStringArray = solverSettings.RestrictionAttributeNames
restrictionAttributes.RemoveAll()
Dim i As Integer = 0
Do While i < chklstRestrictions.CheckedItems.Count
restrictionAttributes.Add(chklstRestrictions.Items(chklstRestrictions.CheckedIndices(i)).ToString())
i += 1
Loop
solverSettings.RestrictionAttributeNames = restrictionAttributes
Dim accumulateAttributes As IStringArray = solverSettings.AccumulateAttributeNames
accumulateAttributes.RemoveAll()
i = 0
Do While i < chklstAccumulateAttributes.CheckedItems.Count
accumulateAttributes.Add(chklstAccumulateAttributes.Items(chklstAccumulateAttributes.CheckedIndices(i)).ToString())
i += 1
Loop
solverSettings.AccumulateAttributeNames = accumulateAttributes
solverSettings.RestrictUTurns = CType(cboUturnPolicy.SelectedIndex, esriNetworkForwardStarBacktrack)
solverSettings.IgnoreInvalidLocations = chkIgnoreInvalidLocations.Checked
solverSettings.UseHierarchy = chkUseHierarchy.Checked
End Sub
''' <summary>
''' Set specific solver settings (FindBestSequence, UseTimeWindows, etc.)
''' </summary>
Private Sub SetSolverSpecificInterface(ByVal solverParams As INAServerSolverParams)
Dim routeSolver As INARouteSolver2 = TryCast(solverParams, INARouteSolver2)
If Not routeSolver Is Nothing Then
routeSolver.FindBestSequence = chkBestOrder.Checked
routeSolver.PreserveFirstStop = chkPreserveFirst.Checked
routeSolver.PreserveLastStop = chkPreserveLast.Checked
routeSolver.UseTimeWindows = chkUseTimeWindows.Checked
routeSolver.OutputLines = CType(cboRouteOutputLines.SelectedIndex, esriNAOutputLineType)
routeSolver.UseStartTime = chkUseStartTime.Checked
If routeSolver.UseStartTime = True Then
routeSolver.StartTime = System.Convert.ToDateTime(txtStartTime.Text.ToString())
End If
End If
End Sub
''' <summary>
''' Set server solver parameters (ReturnMap, SnapTolerance, etc.)
''' </summary>
Private Sub SetServerSolverParams(ByVal solverParams As INAServerSolverParams)
solverParams.ReturnMap = chkReturnMap.Checked
solverParams.SnapTolerance = Convert.ToDouble(txtSnapTolerance.Text)
solverParams.MaxSnapTolerance = Convert.ToDouble(txtMaxSnapTolerance.Text)
solverParams.SnapToleranceUnits = CType(cboSnapToleranceUnits.SelectedIndex, esriUnits)
solverParams.ImageDescription.Display.Width = pictureBox.Width
solverParams.ImageDescription.Display.Height = pictureBox.Height
' // This code shows how to specify the output spatial reference in order to get the map
' // in a different spatial reference than the Network Dataset
' IESRISpatialReferenceGEN sr = new GeographicCoordinateSystem() as IESRISpatialReferenceGEN;
' int read;
' sr.ImportFromESRISpatialReference("GEOGCS[GCS_North_American_1983,DATUM[D_North_American_1983,SPHEROID[GRS_1980,6378137.0,298.257222101]],PRIMEM[Greenwich,0.0],UNIT[Degree,0.0174532925199433]]", out read);
' solverParams.OutputSpatialReference = sr as ISpatialReference;
Dim routeParams As INAServerRouteParams = TryCast(solverParams, INAServerRouteParams)
If Not routeParams Is Nothing Then
routeParams.ReturnRouteGeometries = chkReturnRouteGeometries.Checked
routeParams.ReturnRoutes = chkReturnRoutes.Checked
routeParams.ReturnStops = chkReturnStops.Checked
routeParams.ReturnBarriers = checkReturnBarriers.Checked
routeParams.ReturnDirections = chkReturnDirections.Checked
routeParams.DirectionsLengthUnits = GetstringToesriUnits(cboRouteDirectionsLengthUnits.Text)
routeParams.DirectionsTimeAttributeName = cboRouteDirectionsTimeAttribute.Text
End If
End Sub
''' <summary>
''' Make frames Enabled
''' </summary>
Private Sub MakeFramesEnabled(ByVal solverParams As INAServerSolverParams)
fraINARouteSolver.Enabled = (Not (TryCast(solverParams, INAServerRouteParams)) Is Nothing)
fraINAServerRouteParams.Enabled = (Not (TryCast(solverParams, INAServerRouteParams)) Is Nothing)
fraINASolverSettings.Enabled = (Not (TryCast(solverParams, INAServerRouteParams)) Is Nothing)
End Sub
''' <summary>
''' Load form
''' </summary>
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
cboUturnPolicy.Items.Add("Nowhere")
cboUturnPolicy.Items.Add("Everywhere")
cboUturnPolicy.Items.Add("Only at Dead Ends")
cboSnapToleranceUnits.Items.Add("Unknown Units")
cboSnapToleranceUnits.Items.Add("Inches")
cboSnapToleranceUnits.Items.Add("Points")
cboSnapToleranceUnits.Items.Add("Feet")
cboSnapToleranceUnits.Items.Add("Yards")
cboSnapToleranceUnits.Items.Add("Miles")
cboSnapToleranceUnits.Items.Add("Nautical Miles")
cboSnapToleranceUnits.Items.Add("Millimeters")
cboSnapToleranceUnits.Items.Add("Centimeters")
cboSnapToleranceUnits.Items.Add("Meters")
cboSnapToleranceUnits.Items.Add("Kilometers")
cboSnapToleranceUnits.Items.Add("DecimalDegrees")
cboSnapToleranceUnits.Items.Add("Decimeters")
' Route
cboRouteOutputLines.Items.Add("None")
cboRouteOutputLines.Items.Add("Straight Line")
cboRouteOutputLines.Items.Add("True Shape")
cboRouteOutputLines.Items.Add("True Shape With Ms")
cboRouteDirectionsLengthUnits.Items.Add("Feet")
cboRouteDirectionsLengthUnits.Items.Add("Yards")
cboRouteDirectionsLengthUnits.Items.Add("Miles")
cboRouteDirectionsLengthUnits.Items.Add("Meters")
cboRouteDirectionsLengthUnits.Items.Add("Kilometers")
If txtServer.Text <> "" AndAlso txtServer.Text <> "<Enter ArcGIS Server Name>" AndAlso txtService.Text <> "" AndAlso txtService.Text <> "<Enter ArcGIS Map Server Object>" Then
ConnectToServer()
GetNetworkAnalysisLayers()
End If
End Sub
''' <summary>
''' This function shows how to populate stop locations using two different options:
''' 1) From Record Set using a Point Feature Class - Uncommented
''' 2) From an Array of PropertySets - Commented out
''' Uncomment the option, you would like to use
''' </summary>
Private Sub LoadLocations(ByVal solverParams As INAServerSolverParams)
Dim routeParams As INAServerRouteParams = TryCast(solverParams, INAServerRouteParams)
' Begin Option 1
Dim recSet As IRecordSet = Nothing
' Get Input Stops Feature Class from the MapServer
' Do not create Stops if <NONE> is selected
If cboStopsLayers.Text.ToUpper() <> "<NONE>" Then
Dim layerID As Integer = CInt(m_layerIDs(cboStopsLayers.SelectedIndex))
If layerID >= 0 Then
recSet = m_mapServer.QueryFeatureData(m_mapServer.DefaultMapName, layerID, Nothing)
End If
'Dim stopsRecSet As INAServerRecordSet = New TryCast(NAServerRecordSet(), INAServerRecordSet)
Dim stopsRecSet As INAServerRecordSet = New NAServerRecordSet()
stopsRecSet.RecordSet = recSet
routeParams.Stops = stopsRecSet
End If
' End Option 1
' Begin Option 2
'Dim propSets As IPropertySetArray = New PropertySetArray()
'' Set first point
'propSets.Add(CreateLocationPropertySet("Stop 1", -122.490249049, 37.7481194043, Nothing))
'' Set second point
'propSets.Add(CreateLocationPropertySet("Stop 2", -122.430833654, 37.7539635449, Nothing))
'Dim stopsPropSets As INAServerPropertySets = New NAServerPropertySets()
'stopsPropSets.PropertySets = propSets
'routeParams.Stops = stopsPropSets
' End Option 2
End Sub
''' <summary>
''' Output Results Messages, Map, Route Geometries, Directions
''' </summary>
Private Sub OutputResults(ByVal solverParams As INAServerSolverParams, ByVal solverResults As INAServerSolverResults)
Dim messagesSolverResults As String = ""
' Output Solve messages
Dim gpMessages As IGPMessages = solverResults.SolveMessages
If Not gpMessages Is Nothing Then
Dim i As Integer = 0
Do While i < gpMessages.Count
Dim gpMessage As IGPMessage = gpMessages.GetMessage(i)
messagesSolverResults &= Constants.vbLf + gpMessage.Description
i += 1
Loop
End If
' Uncomment the following section to output the total impedance of each route in a MessageBox
'Dim routeSolverResults As INAServerRouteResults = TryCast(solverResults, INAServerRouteResults)
'If Not routeSolverResults Is Nothing Then
' Dim i As Integer = 0
' Do While i < routeSolverResults.TotalImpedances.GetLength(0)
' messagesSolverResults &= Constants.vbLf & "Total Impedance for Route[" & (i + 1) & "] = "
' messagesSolverResults &= routeSolverResults.TotalImpedances(i).ToString("f")
' messagesSolverResults &= " " & ExtractImpedanceUnits(cboImpedance.Text).ToLower()
' i += 1
' Loop
'End If
' Show a message box displaying both solver messages and total_impedance per route
If messagesSolverResults.Length > 0 Then
MessageBox.Show(messagesSolverResults, "NAServer Route Results")
End If
'Output Map
pictureBox.Image = Nothing
If solverParams.ReturnMap Then
Dim mapImage As IMapImage = solverResults.MapImage
If (Not mapImage Is Nothing) AndAlso (Not mapImage.MimeData Is Nothing) Then
pictureBox.Image = System.Drawing.Image.FromStream(New System.IO.MemoryStream(mapImage.MimeData))
End If
End If
pictureBox.Refresh()
If (Not (TryCast(solverParams, INAServerRouteParams)) Is Nothing) AndAlso (Not (TryCast(solverResults, INAServerRouteResults)) Is Nothing) Then
OutputRouteResults(TryCast(solverParams, INAServerRouteParams), TryCast(solverResults, INAServerRouteResults))
End If
End Sub
''' <summary>
''' Output Route Results according to the NAServerRouteParams
''' </summary>
Private Sub OutputRouteResults(ByVal solverParams As INAServerRouteParams, ByVal solverResults As INAServerRouteResults)
' Return Directions if generated
If solverParams.ReturnDirections Then
AddTabAndControl(Me.tabReturnDirections, Me.treeViewDirections)
OutputDirections(solverResults.Directions)
Else
Me.tabCtrlOutput.TabPages.Remove(Me.tabReturnDirections)
End If
' Return Route Geometries is generated
If solverParams.ReturnRouteGeometries Then
AddTabAndControl(Me.tabReturnRouteGeometry, Me.treeViewRouteGeometry)
OutputPolylines(solverResults.RouteGeometries)
Else
Me.tabCtrlOutput.TabPages.Remove(Me.tabReturnRouteGeometry)
End If
' Return Route Features as RecordSet
If solverParams.ReturnRoutes Then
AddTabAndControl(Me.tabReturnRouteFeatures, Me.dataGridRouteFeatures)
OutputRecSetToDataGrid(solverResults.Routes, dataGridRouteFeatures)
Else
Me.tabCtrlOutput.TabPages.Remove(Me.tabReturnRouteFeatures)
End If
' Return Stop Features as RecordSet
If solverParams.ReturnStops Then
AddTabAndControl(Me.tabReturnStopsFeatures, Me.dataGridStopFeatures)
OutputRecSetToDataGrid(solverResults.Stops, dataGridStopFeatures)
Else
Me.tabCtrlOutput.TabPages.Remove(Me.tabReturnStopsFeatures)
End If
' Return Barrier Features as RecordSet
If solverParams.ReturnBarriers Then
AddTabAndControl(Me.tabReturnBarrierFeatures, Me.dataGridBarrierFeatures)
OutputRecSetToDataGrid(solverResults.Barriers, dataGridBarrierFeatures)
Else
Me.tabCtrlOutput.TabPages.Remove(Me.tabReturnBarrierFeatures)
End If
' Make TabControlOutput enable
tabCtrlOutput.Enabled = True
End Sub
''' <summary>
''' Output Route Geometries (Polylines) in a TreeView control
''' </summary>
Private Sub OutputPolylines(ByVal polylines As IPolyline())
' Suppress repainting the TreeView until all the objects have been created.
treeViewRouteGeometry.BeginUpdate()
' Clear the TreeView each time the method is called.
treeViewRouteGeometry.Nodes.Clear()
Dim i As Integer = 0
Do While i < polylines.Length
Dim newNode As TreeNode = New TreeNode("Polyline Length for Route [" & (i + 1) & "] = " & polylines(i).Length.ToString())
treeViewRouteGeometry.Nodes.Add(newNode)
Dim pointCollection As IPointCollection = TryCast(polylines(i), IPointCollection)
Dim j As Integer = 0
Do While j < pointCollection.PointCount
Dim point As IPoint = pointCollection.Point(j)
treeViewRouteGeometry.Nodes(i).Nodes.Add(New TreeNode("Point [" & (j + 1) & "]: " & point.X & "," & point.Y))
j += 1
Loop
i += 1
Loop
' Check if Route Geometry has been generated
If polylines.Length = 0 Then
Dim newNode As TreeNode = New TreeNode("Route Geometry not generated")
treeViewRouteGeometry.Nodes.Add(newNode)
End If
' Begin repainting the TreeView.
treeViewRouteGeometry.ExpandAll()
treeViewRouteGeometry.EndUpdate()
End Sub
''' <summary>
''' Output Directions if a TreeView control
''' </summary>
Private Sub OutputDirections(ByVal serverDirections As INAStreetDirections())
' Suppress repainting the TreeView until all the objects have been created.
treeViewDirections.BeginUpdate()
' Clear the TreeView each time the method is called.
treeViewDirections.Nodes.Clear()
Dim i As Integer = 0
Do While i < serverDirections.Length
' get Directions from the ith route
Dim directions As INAStreetDirections
directions = serverDirections(i)
' get Summary (Total Distance and Time)
Dim direction As INAStreetDirection = directions.Summary
Dim totallength As String = Nothing, totaltime As String = Nothing
Dim k As Integer = 0
Do While k < direction.StringCount
If direction.StringType(k) = esriDirectionsStringType.esriDSTLength Then
totallength = direction.String(k)
End If
If direction.StringType(k) = esriDirectionsStringType.esriDSTTime Then
totaltime = direction.String(k)
End If
k += 1
Loop
' Add a Top a Node with the Route number and Total Distance and Total Time
Dim newNode As TreeNode = New TreeNode("Directions for Route [" & (i + 1) & "] - Total Distance: " & totallength & " Total Time: " & totaltime)
treeViewDirections.Nodes.Add(newNode)
' Then add a node for each step-by-step directions
Dim directionIndex As Integer = 0
Do While directionIndex < directions.DirectionCount
direction = directions.Direction(directionIndex)
Dim stringIndex As Integer = 0
Do While stringIndex < direction.StringCount
If direction.StringType(stringIndex) = esriDirectionsStringType.esriDSTGeneral OrElse direction.StringType(stringIndex) = esriDirectionsStringType.esriDSTDepart OrElse direction.StringType(stringIndex) = esriDirectionsStringType.esriDSTArrive Then
treeViewDirections.Nodes(i).Nodes.Add(New TreeNode(direction.String(stringIndex)))
End If
stringIndex += 1
Loop
directionIndex += 1
Loop
i += 1
Loop
' Check if Directions have been generated
If serverDirections.Length = 0 Then
Dim newNode As TreeNode = New TreeNode("Directions not generated")
treeViewDirections.Nodes.Add(newNode)
End If
' Begin repainting the TreeView.
treeViewDirections.ExpandAll()
treeViewDirections.EndUpdate()
End Sub
''' <summary>
''' Generic function to output RecordSet (Stops, Barriers, or Routes) in a DataGrid Control
''' </summary>
Private Sub OutputRecSetToDataGrid(ByVal recSet As IRecordSet, ByVal outDataGrid As System.Windows.Forms.DataGrid)
Dim fields As IFields = recSet.Fields
Dim dataSet As DataSet = New DataSet("dataSet")
Dim dataTable As DataTable = New DataTable("Results")
dataSet.Tables.Add(dataTable)
' Get Field Names
Dim dataColumn As DataColumn = Nothing
Dim f As Integer = 0
Do While f < fields.FieldCount
dataColumn = New DataColumn(fields.Field(f).Name.ToString())
dataTable.Columns.Add(dataColumn)
f += 1
Loop
' Populate DataGrid rows by RecordSet
Dim newDataRow As DataRow
Dim cur As ICursor = recSet.Cursor(False)
Dim row As IRow = cur.NextRow()
If Not row Is Nothing Then
Do While Not row Is Nothing
newDataRow = dataTable.NewRow()
Dim l As Integer = 0
Do While l < row.Fields.FieldCount
newDataRow(l) = row.Value(l).ToString()
l += 1
Loop
dataTable.Rows.Add(newDataRow)
row = cur.NextRow()
Loop
End If
outDataGrid.SetDataBinding(dataSet, "Results")
outDataGrid.Visible = True
End Sub
''' <summary>
''' Enable the startTime control
''' </summary>
Private Sub chkUseStartTime_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkUseStartTime.CheckedChanged
If chkUseStartTime.Checked = True Then
txtStartTime.Enabled = True
Else
txtStartTime.Enabled = False
End If
End Sub
''' <summary>
''' Enable chkPreserveFirst and chkPreserveFirst controls
''' </summary>
Private Sub chkBestOrder_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkBestOrder.CheckedChanged
If chkBestOrder.Checked = True Then
Me.chkPreserveFirst.Enabled = True
Me.chkPreserveLast.Enabled = True
Else
Me.chkPreserveFirst.Enabled = False
Me.chkPreserveLast.Enabled = False
End If
End Sub
''' <summary>
''' Create a property set for NALocation
''' </summary>
Private Function CreateLocationPropertySet(ByVal name As String, ByVal X As Object, ByVal Y As Object, ByVal sr As ISpatialReference) As IPropertySet
Dim propSet As IPropertySet = New PropertySet()
propSet.SetProperty("Name", name)
propSet.SetProperty("X", X)
propSet.SetProperty("Y", Y)
propSet.SetProperty("SpatialReference", sr)
Return propSet
End Function
''' <summary>
''' Helper function to convert a string unit (e.g Miles) to an esriNetworkAnalystUnits (e.g esriNAUMiles)
''' </summary>
Private Function GetstringToesriUnits(ByVal stresriUnits As String) As esriNetworkAttributeUnits
Select Case stresriUnits.ToLower()
Case "inches"
Return esriNetworkAttributeUnits.esriNAUInches
Case "feet"
Return esriNetworkAttributeUnits.esriNAUFeet
Case "yards"
Return esriNetworkAttributeUnits.esriNAUYards
Case "miles"
Return esriNetworkAttributeUnits.esriNAUMiles
Case "nautical miles"
Return esriNetworkAttributeUnits.esriNAUNauticalMiles
Case "millimeters"
Return esriNetworkAttributeUnits.esriNAUMillimeters
Case "centimeters"
Return esriNetworkAttributeUnits.esriNAUCentimeters
Case "meters"
Return esriNetworkAttributeUnits.esriNAUMeters
Case "kilometers"
Return esriNetworkAttributeUnits.esriNAUKilometers
Case "decimal degrees"
Return esriNetworkAttributeUnits.esriNAUDecimalDegrees
Case "decimeters"
Return esriNetworkAttributeUnits.esriNAUDecimeters
Case "seconds"
Return esriNetworkAttributeUnits.esriNAUSeconds
Case "minutes"
Return esriNetworkAttributeUnits.esriNAUMinutes
Case "hours"
Return esriNetworkAttributeUnits.esriNAUHours
Case "days"
Return esriNetworkAttributeUnits.esriNAUDays
Case "unknown"
Return esriNetworkAttributeUnits.esriNAUUnknown
Case Else
Return esriNetworkAttributeUnits.esriNAUUnknown
End Select
End Function
''' <summary>
''' Helper function to extract the impedance name in a string like "impedancename (impedanceunits)"
''' </summary>
Private Function ExtractImpedanceName(ByVal impedanceUnits As String) As String
Dim firstIndex As Integer = impedanceUnits.LastIndexOf(" ")
Dim lastIndex As Integer = impedanceUnits.Length
Return impedanceUnits.Remove(firstIndex, (lastIndex - firstIndex))
End Function
''' <summary>
''' Helper function to extract the impedance unit in a string like "impedancename (impedanceunits)"
''' </summary>
Private Function ExtractImpedanceUnits(ByVal impedanceUnits As String) As String
Dim firstIndex As Integer = impedanceUnits.LastIndexOf("(") + 1
Dim lastIndex As Integer = impedanceUnits.LastIndexOf(")")
Return impedanceUnits.Substring(firstIndex, (lastIndex - firstIndex))
End Function
''' <summary>
''' Hide tabs
''' </summary>
Private Sub HideTabs()
' remove tabs initially - There are added when the result is returned.
Me.tabCtrlOutput.TabPages.Remove(Me.tabReturnDirections)
Me.tabCtrlOutput.TabPages.Remove(Me.tabReturnStopsFeatures)
Me.tabCtrlOutput.TabPages.Remove(Me.tabReturnBarrierFeatures)
Me.tabCtrlOutput.TabPages.Remove(Me.tabReturnRouteGeometry)
Me.tabCtrlOutput.TabPages.Remove(Me.tabReturnRouteFeatures)
End Sub
''' <summary>
'// Add a tab page and a tab control
''' </summary>
Private Sub AddTabAndControl(ByVal tabPage As TabPage, ByVal controlToAdd As System.Windows.Forms.Control)
If (Not tabCtrlOutput.TabPages.Contains(tabPage)) Then
tabCtrlOutput.TabPages.Add(tabPage)
tabPage.Controls.Add(controlToAdd)
End If
End Sub
End Class
End Namespace