ArcGIS_Routing_VBNet\App_Code\CustomTools.vb
' Copyright 2010 ESRI ' ' All rights reserved under the copyright laws of the United States ' and applicable international laws, treaties, and conventions. ' ' You may freely redistribute and use this sample code, with or ' without modification, provided you include the original copyright ' notice and use restrictions. ' ' See the use restrictions. ' Imports Microsoft.VisualBasic Imports ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools Imports ESRI.ArcGIS.ADF.Web.UI.WebControls Imports ESRI.ArcGIS.ADF.Web.DataSources Imports System.Web.UI.WebControls Imports System.Web.UI.HtmlControls Imports System.Data Imports System.Drawing Imports System.Collections Imports System.Web Imports ESRI.ArcGIS.ADF.Web.Geometry Imports ESRI.ArcGIS.Server.Web.NetworkAnalyst Imports System Imports ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer Imports ESRI.ArcGIS.ADF.Web Namespace RouteFinder Public Class CustomTools Implements IMapServerCommandAction, IMapServerToolAction Public Sub ServerAction1(ByVal info As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IServerAction.ServerAction Dim mapctrl As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(info.BuddyControls(0), ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) Select Case info.Name Case "FullRoute" Dim fullextent As Envelope = TryCast(mapctrl.Page.Session("PathExtent"), Envelope) If Not fullextent Is Nothing Then mapctrl.Extent = fullextent End If Case "ZoomToStep" Dim stepControl As HtmlInputHidden = CType(mapctrl.Page.FindControl("Step"), HtmlInputHidden) Dim stepNumber As Integer = Convert.ToInt32(stepControl.Value) If stepNumber < 1 Then stepNumber = 1 End If Dim extents As Envelope() = TryCast(mapctrl.Page.Session("DirectionExtents"), Envelope()) If Not extents Is Nothing Then Dim extent As Envelope = extents(stepNumber) mapctrl.Extent = extent End If Case "ReverseDirections" Dim bpi As IBaseRouteFinderPage = CType(mapctrl.Page, IBaseRouteFinderPage) ' Get coords and locations from session Dim toX As Double = Convert.ToDouble(mapctrl.Page.Session("FromX")) Dim toY As Double = Convert.ToDouble(mapctrl.Page.Session("FromY")) Dim fromX As Double = Convert.ToDouble(mapctrl.Page.Session("ToX")) Dim fromY As Double = Convert.ToDouble(mapctrl.Page.Session("ToY")) Dim fromAddress As String = Convert.ToString(mapctrl.Page.Session("ToAddress")) Dim toAddress As String = Convert.ToString(mapctrl.Page.Session("FromAddress")) If fromX = 0.0 AndAlso toX = 0.0 AndAlso fromY = 0.0 AndAlso toY = 0.0 Then Return End If ' Solve the route and display Dim result As NetworkAnalystRouteResult = bpi.SolveRoute(fromX, fromY, toX, toY, fromAddress, toAddress) bpi.DisplayDirections(result, fromAddress, toAddress) mapctrl.Page.Session("FromX") = fromX mapctrl.Page.Session("FromY") = fromY mapctrl.Page.Session("ToX") = toX mapctrl.Page.Session("ToY") = toY mapctrl.Page.Session("FromAddress") = fromAddress mapctrl.Page.Session("ToAddress") = toAddress Case "NewDirections" Dim url As String = "Default.aspx?Reset=true" mapctrl.Page.Response.Redirect(url, True) Case "PrintVersion" Dim mf As MapFunctionality = CType(mapctrl.GetFunctionality(0), MapFunctionality) mapctrl.ImageFormat = ESRI.ArcGIS.ADF.Web.WebImageFormat.PNG8 Dim mi As ESRI.ArcGIS.ADF.Web.MapImage = mf.DrawExtent(mapctrl.Extent) Dim md As MimeData = mi.MimeData mapctrl.Page.Session("mymimedata") = md mapctrl.Page.Response.Write("<script>window.open('" & "PrintPage.aspx', 'PrintWindow', 'dependent=yes ,width=800, height=500, status=no, toolbar=no, menubar=yes, location=no, resizable=yes, scrollbars=yes'); </script>") End Select End Sub Public Sub ServerAction(ByVal args As ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction Throw New System.Exception("The method or operation is not implemented.") End Sub End Class End Namespace