ArcGIS Buffer geoprocessing
ArcGIS_Buffer_Geoprocessing_VBNet\App_Code\PointTool.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 System
Public Class PointTool
    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 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)

    Try
      ' Get the point drawn by the user
      Dim mapPointEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs = TryCast(toolEventArgs, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs)
      Dim adfPoint As ESRI.ArcGIS.ADF.Web.Geometry.Point = mapPointEventArgs.MapPoint

      ' Get the name of the graphics resource from session that will contain the 
      ' user-placed point
      Dim graphicsResourceName As String = CStr(adfMap.Page.Session("graphicsResourceName"))

      ' Get the graphics map functionality for the resource
      Dim graphicsMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality = TryCast(adfMap.GetFunctionality(graphicsResourceName), ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)

      ' Get the name of the graphics layer to which we will add the user-placed point from
      ' from session, then use this name to retrieve the graphics layer from the graphics
      ' map functionality.
      Dim pointGraphicsLayerName As String = CStr(adfMap.Page.Session("pointGraphicsLayerName"))
      Dim elementGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer = TryCast(graphicsMapFunctionality.GraphicsDataSet.Tables(pointGraphicsLayerName), ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)

      ' If the graphics layer was not found, create it
      If elementGraphicsLayer Is Nothing Then
        elementGraphicsLayer = New ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer()
        elementGraphicsLayer.TableName = pointGraphicsLayerName
        graphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer)
      End If

      ' Uncomment to allow only one point to be drawn on the map at a time
      'elementGraphicsLayer.Clear();

      ' Create the symbology for the point
      Dim adfSimpleMarkerSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol = New ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol()
            adfSimpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Triangle
            adfSimpleMarkerSymbol.Color = System.Drawing.Color.Aqua
            adfSimpleMarkerSymbol.Width = 12

      ' Create a graphic element based on the point and the symbology
      Dim graphicElement As ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement = New ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(adfPoint, adfSimpleMarkerSymbol)

      ' Add the element to the graphics layer
      elementGraphicsLayer.Add(graphicElement)

      ' Refresh the graphics resource so the newly added graphic is displayed
      adfMap.RefreshResource(graphicsResourceName)
    Catch exception As System.Exception
      Dim errorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = Utility.CreateErrorCallbackResult(exception)
      adfMap.CallbackResults.Add(errorCallbackResult)
    End Try
  End Sub

  #End Region
End Class