Common_CustomTasks_VBNet\FindNearTask_VBNet\Tools.vb
' Copyright 2011 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 System Namespace FindNearTask_VBNet Public Class SearchAreaByPoint Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction, ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup #Region "IMapServerToolAction Members" Public Sub ServerAction(ByVal args As ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction 'Toolbar.Cell.Row.Table.Task Dim task As ESRI.ArcGIS.ADF.Web.UI.WebControls.FloatingPanelTask = TryCast(toolbarItemInfo.Toolbar.Parent.Parent.Parent.Parent, ESRI.ArcGIS.ADF.Web.UI.WebControls.FloatingPanelTask) If task Is Nothing Then Return End If Dim cTask As FindNearTask = TryCast(task, FindNearTask) Dim map As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = TryCast(args.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) If map Is Nothing Then Return End If ' #Region "Create geometry" Dim pargs As ESRI.ArcGIS.ADF.Web.UI.WebControls.PointEventArgs = TryCast(args, ESRI.ArcGIS.ADF.Web.UI.WebControls.PointEventArgs) Dim point As ESRI.ArcGIS.ADF.Web.Geometry.Point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(pargs.ScreenPoint, map.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap)) Dim inputGeometries As ESRI.ArcGIS.ADF.Web.Geometry.Geometry() = New ESRI.ArcGIS.ADF.Web.Geometry.Geometry(0){} inputGeometries(0) = TryCast(point, ESRI.ArcGIS.ADF.Web.Geometry.Geometry) cTask.TaskInput.SetUserInputGeometries(inputGeometries) ' #End Region cTask.UpdateInputGraphicsLayers() Dim hideActivityIndicatorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript("hideUpdateAreaIndicator();") map.CallbackResults.Add(hideActivityIndicatorCallbackResult) End Sub #End Region #Region "IToolbarItemSetup Members" Private toolbarItemInfo As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo Public Sub Initialize(ByVal info As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup.Initialize toolbarItemInfo = info End Sub Public Sub Unload(ByVal info As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup.Unload End Sub #End Region End Class Public Class SearchAreaByTaskResult Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction #Region "IMapServerToolAction Members" Public Sub ServerAction(ByVal args As ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction End Sub #End Region End Class Public Class AddSearchPolyline Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction, ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup #Region "IMapServerToolAction Members" Public Sub ServerAction(ByVal args As ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction ' Get a reference to the containing FindNearTask Dim findNearTask As FindNearTask_VBNet.FindNearTask = TryCast(Utility.GetContainer(toolbarItemInfo.Toolbar, GetType(FindNearTask_VBNet.FindNearTask)), FindNearTask_VBNet.FindNearTask) Dim mapPolylineEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPolylineEventArgs = TryCast(args, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPolylineEventArgs) Dim inputGeometries As ESRI.ArcGIS.ADF.Web.Geometry.Geometry() = New ESRI.ArcGIS.ADF.Web.Geometry.Geometry(0){} inputGeometries(0) = TryCast(mapPolylineEventArgs.MapPolyline, ESRI.ArcGIS.ADF.Web.Geometry.Geometry) findNearTask.TaskInput.SetUserInputGeometries(inputGeometries) findNearTask.UpdateInputGraphicsLayers() ' Get a reference to the map control on which the tool was executed Dim adfMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(args.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) Dim hideActivityIndicatorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript("hideUpdateAreaIndicator();") adfMap.CallbackResults.Add(hideActivityIndicatorCallbackResult) End Sub #End Region #Region "IToolbarItemSetup Members" Private toolbarItemInfo As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo Public Sub Initialize(ByVal info As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup.Initialize toolbarItemInfo = info End Sub Public Sub Unload(ByVal info As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup.Unload End Sub #End Region End Class Public Class Utility Public Shared Function GetContainer(ByVal control As System.Web.UI.Control, ByVal typeOfContainer As System.Type) As System.Web.UI.Control Dim containerControl As System.Web.UI.Control = Nothing If Not control.Parent Is Nothing Then If typeOfContainer.IsAssignableFrom(control.Parent.GetType()) Then containerControl = control.Parent Else containerControl = GetContainer(control.Parent, typeOfContainer) End If End If Return containerControl End Function End Class Public Class AddSearchPolygon Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction, ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup #Region "IMapServerToolAction Members" Public Sub ServerAction(ByVal args As ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction ' Get a reference to the containing FindNearTask Dim findNearTask As FindNearTask_VBNet.FindNearTask = TryCast(Utility.GetContainer(toolbarItemInfo.Toolbar, GetType(FindNearTask_VBNet.FindNearTask)), FindNearTask_VBNet.FindNearTask) Dim mapPolygonEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPolygonEventArgs = TryCast(args, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPolygonEventArgs) Dim inputGeometries As ESRI.ArcGIS.ADF.Web.Geometry.Geometry() = New ESRI.ArcGIS.ADF.Web.Geometry.Geometry(0){} inputGeometries(0) = TryCast(mapPolygonEventArgs.MapPolygon, ESRI.ArcGIS.ADF.Web.Geometry.Geometry) findNearTask.TaskInput.SetUserInputGeometries(inputGeometries) findNearTask.UpdateInputGraphicsLayers() ' Get a reference to the map control on which the tool was executed Dim adfMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(args.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) Dim hideActivityIndicatorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript("hideUpdateAreaIndicator();") adfMap.CallbackResults.Add(hideActivityIndicatorCallbackResult) End Sub #End Region #Region "IToolbarItemSetup Members" Private toolbarItemInfo As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo Public Sub Initialize(ByVal info As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup.Initialize toolbarItemInfo = info End Sub Public Sub Unload(ByVal info As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup.Unload End Sub #End Region End Class Public Class SearchAreaBySelection Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction, ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup #Region "IMapServerToolAction Members" Public Sub ServerAction(ByVal toolEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction ' Get a reference to the containing FindNearTask Dim findNearTask As FindNearTask_VBNet.FindNearTask = TryCast(Utility.GetContainer(toolbarItemInfo.Toolbar, GetType(FindNearTask_VBNet.FindNearTask)), FindNearTask_VBNet.FindNearTask) ' Get a reference to the map control on which the tool was executed Dim adfMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(toolEventArgs.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) ' Get the map extent of the rectangle drawn on the map Dim mapRectangleEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapRectangleEventArgs = CType(toolEventArgs, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapRectangleEventArgs) Dim adfEnvelope As ESRI.ArcGIS.ADF.Web.Geometry.Envelope = mapRectangleEventArgs.MapExtent ' Get the user-specified tool parameters specified via the page's interface Dim selectionInput As String = Nothing If adfMap.Page.IsCallback Then ' Since the page is using the callback framework, the tool parameters have been packaged ' along with the callback parameters. This is done via custom javascript. Dim callbackArguments As String = adfMap.Page.Request.Params("__CALLBACKPARAM") Dim callbackArgsCollection As System.Collections.Specialized.NameValueCollection = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackUtility.ParseStringIntoNameValueCollection(callbackArguments) selectionInput = callbackArgsCollection("SelectionLayer") Else ' Since the page is using the PartialPostback framework, and the controls receiving user ' input are ASP.NET server controls, the tool parameters are automatically passed in ' the page's request parameters. selectionInput = adfMap.Page.Request.Params("SelectionLayer") End If Dim selectionInputArray As String() = selectionInput.Split(","c) ' Get the name of the resource on which to perform the selection Dim resourceName As String = selectionInputArray(0) ' Get a reference to the resource Dim commonMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality = adfMap.GetFunctionality(resourceName) Dim gisResource As ESRI.ArcGIS.ADF.Web.DataSources.IGISResource = commonMapFunctionality.Resource ' Create a query functionality to use in querying the resource Dim commonQueryFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality = CType(gisResource.CreateFunctionality(GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), Nothing), ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality) Dim selectionLayerID As String = selectionInputArray(1) ' Set-up a spatial filter to use in querying the resource Dim adfSpatialFilter As ESRI.ArcGIS.ADF.Web.SpatialFilter = New ESRI.ArcGIS.ADF.Web.SpatialFilter() adfSpatialFilter.ReturnADFGeometries = True adfSpatialFilter.MaxRecords = 100 adfSpatialFilter.Geometry = adfEnvelope ' Query the selection layer with the user-drawn rectangle Dim resultsDataTable As System.Data.DataTable = commonQueryFunctionality.Query(commonMapFunctionality.Name, selectionLayerID, adfSpatialFilter) ' Convert the results data table to a graphics layer Dim resultsGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer = ESRI.ArcGIS.ADF.Web.Converter.ToGraphicsLayer(resultsDataTable) Dim inputGeometries As ESRI.ArcGIS.ADF.Web.Geometry.Geometry() = New ESRI.ArcGIS.ADF.Web.Geometry.Geometry(resultsGraphicsLayer.Rows.Count - 1){} Dim i As Integer = 0 Do While i < resultsGraphicsLayer.Rows.Count inputGeometries(i) = resultsGraphicsLayer.GeometryFromRow(resultsGraphicsLayer.Rows(i)) i += 1 Loop findNearTask.TaskInput.SetUserInputGeometries(inputGeometries) findNearTask.UpdateInputGraphicsLayers() Dim hideActivityIndicatorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript("hideUpdateAreaIndicator();") adfMap.CallbackResults.Add(hideActivityIndicatorCallbackResult) ' Select each result so that its node is checked in the TaskResults control 'foreach (System.Data.DataRow dataRow in resultsGraphicsLayer.Rows) ' dataRow[resultsGraphicsLayer.IsSelectedColumn] = true; ' Render the results on the client to enable callouts and highlighting 'resultsGraphicsLayer.RenderOnClient = true; '// Create a DataSet and add the results to it 'string resultsDataSetName = string.Format("Selected Features - {0}", ' resultsGraphicsLayer.TableName); 'System.Data.DataSet resultsDataSet = new System.Data.DataSet(resultsDataSetName); 'resultsDataSet.Tables.Add(resultsGraphicsLayer); '// Retrieve the TaskResults control from session and add the results to it 'ESRI.ArcGIS.ADF.Web.UI.WebControls.TaskResults taskResults = ' (ESRI.ArcGIS.ADF.Web.UI.WebControls.TaskResults)adfMap.Page.Session["TaskResultsControl"]; 'taskResults.DisplayResults(null, null, null, resultsDataSet); '// Copy the TaskResults' callback results to the Map so the results show up 'adfMap.CallbackResults.CopyFrom(taskResults.CallbackResults); Return End Sub #End Region #Region "IToolbarItemSetup Members" Private toolbarItemInfo As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo Public Sub Initialize(ByVal info As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup.Initialize toolbarItemInfo = info End Sub Public Sub Unload(ByVal info As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IToolbarItemSetup.Unload End Sub #End Region End Class Public Class ClearInput Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerCommandAction #Region "IMapServerCommandAction Members" Private Sub ServerAction(ByVal toolbarItemInfo As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IServerAction.ServerAction ' Get a reference to the containing FindNearTask Dim findNearTask As FindNearTask_VBNet.FindNearTask = TryCast(Utility.GetContainer(toolbarItemInfo.Toolbar, GetType(FindNearTask_VBNet.FindNearTask)), FindNearTask_VBNet.FindNearTask) findNearTask.ClearTaskInput() End Sub #End Region End Class End Namespace