ADF Tutorials
ADFTutorials_VBNet\AccessArcGISServer\App_Code\PointBufferTool.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
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
Imports ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools
Imports ESRI.ArcGIS.ADF.Web.UI.WebControls
Imports ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer
Imports ESRI.ArcGIS.Server
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Display

''' <summary>
''' Summary description for PointBufferTool
''' </summary>
Public Class PointBufferTool
  Implements IMapServerToolAction
  Public Sub ServerAction(ByVal args As ToolEventArgs) Implements IMapServerToolAction.ServerAction
    Dim mapctrl As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map
    mapctrl = CType(args.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)

    Dim mpea As MapPointEventArgs = CType(args, MapPointEventArgs)

    Dim mf As ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality
    mf = CType(mapctrl.GetFunctionality("MapResourceItem0"), ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)

    Dim mapDescription As ESRI.ArcGIS.ADF.ArcGISServer.MapDescription = mf.MapDescription

    Dim ags_map_point As ESRI.ArcGIS.ADF.ArcGISServer.PointN
    ags_map_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPoint(mpea.MapPoint)

    Dim rgb As ESRI.ArcGIS.ADF.ArcGISServer.RgbColor
    rgb = New ESRI.ArcGIS.ADF.ArcGISServer.RgbColor()
    rgb.Red = 0
    rgb.Green = 255
    rgb.Blue = 0
    rgb.AlphaValue = 255

    Dim sms As ESRI.ArcGIS.ADF.ArcGISServer.SimpleMarkerSymbol
    sms = New ESRI.ArcGIS.ADF.ArcGISServer.SimpleMarkerSymbol()
    sms.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleMarkerStyle.esriSMSDiamond
    sms.Color = rgb
    sms.Size = 20.0

    Dim marker As ESRI.ArcGIS.ADF.ArcGISServer.MarkerElement
    marker = New ESRI.ArcGIS.ADF.ArcGISServer.MarkerElement()
    marker.Symbol = sms
    marker.Point = ags_map_point

    Dim mrl As ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal
    mrl = CType(mf.MapResource, ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)
    Dim serverContext As ESRI.ArcGIS.Server.IServerContext = mrl.ServerContextInfo.ServerContext

    Dim ipnt As ESRI.ArcGIS.Geometry.IPoint
    ipnt = CType(ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ValueObjectToComObject(ags_map_point, serverContext), ESRI.ArcGIS.Geometry.IPoint)
    Dim topop As ESRI.ArcGIS.Geometry.ITopologicalOperator = CType(ipnt, ESRI.ArcGIS.Geometry.ITopologicalOperator)
    Dim bufferdistance As Double = mapctrl.Extent.Width / 6
    Dim bufferpolygon As ESRI.ArcGIS.Geometry.IPolygon = CType(topop.Buffer(bufferdistance), ESRI.ArcGIS.Geometry.IPolygon)

    Dim buffer_polyn As ESRI.ArcGIS.ADF.ArcGISServer.PolygonN
    buffer_polyn = CType(ESRI.ArcGIS.ADF.ArcGISServer.Converter.ComObjectToValueObject (bufferpolygon, serverContext, GetType(ESRI.ArcGIS.ADF.ArcGISServer.PolygonN)), ESRI.ArcGIS.ADF.ArcGISServer.PolygonN)

    Dim rgb1 As ESRI.ArcGIS.ADF.ArcGISServer.RgbColor
    rgb1 = New ESRI.ArcGIS.ADF.ArcGISServer.RgbColor()
    rgb1.Red = 255
        rgb1.Green = 0
    rgb1.Blue = 0
        rgb1.AlphaValue = 0

    Dim sfs1 As ESRI.ArcGIS.ADF.ArcGISServer.SimpleFillSymbol
    sfs1 = New ESRI.ArcGIS.ADF.ArcGISServer.SimpleFillSymbol()
    sfs1.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleFillStyle.esriSFSForwardDiagonal
    sfs1.Color = rgb1

    Dim polyelement1 As ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement
    polyelement1 = New ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement()
    polyelement1.Symbol = sfs1
    polyelement1.Polygon = buffer_polyn

    Dim ges As ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement()
    ges = New ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement(1){}
    ges(0) = marker
    ges(1) = polyelement1
    mapDescription.CustomGraphics = ges

    mapctrl.RefreshResource(mf.Resource.Name)
  End Sub
End Class