ArcGIS_SimpleEdit_VBNet\ArcGIS_SimpleEdit_WebAppVBNet\App_Code\IdentifyTool.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 Imports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Public Class IdentifyTool Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction #Region "IMapServerToolAction Members" Private Sub ServerAction(ByVal toolEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction ' Get reference to the map control Dim adfMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(toolEventArgs.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) Try ' Cast tool event arguments to map point event arguments, which allows ' easy access to the map point clicked by the user Dim mapPointEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs = CType(toolEventArgs, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs) ' Get the map point from the map point event arguments Dim adfPoint As ESRI.ArcGIS.ADF.Web.Geometry.Point = mapPointEventArgs.MapPoint Dim mapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality = adfMap.GetFunctionality("ServerResource") ' Retrieve the resource for the current map functionality object Dim gisResource As ESRI.ArcGIS.ADF.Web.DataSources.IGISResource = mapFunctionality.Resource ' Check whether the current resource supports querying Dim supportsQuery As Boolean = gisResource.SupportsFunctionality(GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)) If supportsQuery Then ' Create a query functionality object from the current resource Dim queryFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality = CType(gisResource.CreateFunctionality(GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), Nothing), ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality) ' Get the names and ids of the queryable layers in the current resource Dim layerIDs As String() = Nothing Dim layerNames As String() = Nothing queryFunctionality.GetQueryableLayers(Nothing, layerIDs, layerNames) ' Set the layer name on which you want to identify Dim activeLayerName As String = "ServiceCalls" ' Iterate through the layer names until a match is found for ' activeLayerName. Include a call to ToUpper() or ToLower() in the comparison ' to eliminate case sensitivity. Dim activeLayerID As String = Nothing Dim index As Integer = 0 Do While index < layerNames.Length If layerNames(index).ToUpper() = activeLayerName.ToUpper() Then ' Get the layer id of the match found from the layer id array activeLayerID = layerIDs(index) Exit Do End If index += 1 Loop ' Initialize a variable to store tolerance. This will be used as the tolerance ' around the point clicked by the user Dim pixelTolerance As Integer = 3 ' Execute the identify operation Dim resultDataTableArray As System.Data.DataTable() = queryFunctionality.Identify(mapFunctionality.Name, adfPoint, pixelTolerance, ESRI.ArcGIS.ADF.Web.IdentifyOption.AllLayers, New String() { activeLayerID }) ' Exit the loop if no results were found If resultDataTableArray Is Nothing Then Return End If ' Display results in a GridView Utility.DisplayOrHideSelectionTable(adfMap, CType(resultDataTableArray(0), ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer), True) End If Catch exception As System.Exception Dim errorAlertCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = Utility.CreateErrorCallbackResult(exception) adfMap.CallbackResults.Add(errorAlertCallbackResult) End Try End Sub #End Region End Class