ArcObjects Library Reference  

VegTool_VBNet

About the Server spatial query COM utility Sample

[C#]

VegTool_VBNet.cs


[Visual Basic .NET]

VegTool_VBNet.vb

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
Imports ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools
Imports ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer
Imports ESRI.ArcGIS.ADF.Web.DataSources
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Server
Imports ESRI.ArcGIS.Geometry
Imports VegCOM_VBNet
Imports ESRI.ArcGIS.ADF.ArcGISServer
Imports ESRI.ArcGIS.Geodatabase

Public Class VegTool_VBNet
  Implements 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
    Dim mapctrl As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(args.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)

    ' Get MapFunctionality from the control...
    Dim mapfunc As MapFunctionality = CType(mapctrl.GetFunctionality(mapctrl.MapResourceManagerInstance.ResourceItems.Count - 1), MapFunctionality)
    Dim mapres As MapResourceLocal = CType(mapfunc.MapResource, MapResourceLocal)
    Dim sc As IServerContext = mapres.ServerContextInfo.ServerContext
    Dim map As IMapServer = mapres.MapServer

    Dim mapobj As IMapServerObjects = CType(map, IMapServerObjects)
    Dim fgmap As IMap = mapobj.Map(map.DefaultMapName)
    Dim fl As IFeatureLayer = CType(fgmap.Layer(0), IFeatureLayer)
    Dim fc As IFeatureClass = fl.FeatureClass

    Dim pargs As PointEventArgs = CType(args, PointEventArgs)
    Dim inpt As ESRI.ArcGIS.ADF.Web.Geometry.Point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(pargs.ScreenPoint, mapctrl.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap))
    Dim pt As IPoint = CType(sc.CreateObject("esriGeometry.Point"), IPoint)
    pt.X = inpt.X
    pt.Y = inpt.Y

    Dim tbxvalue As String = CStr(mapctrl.Page.Session("TextBox1Value"))

    Dim distance As Double = 0

    If (Not Double.TryParse(tbxvalue, distance)) Then
      distance = 10000
    End If

    Dim fldName As String = "PRIMARY_"

    Dim vegutils As IVegUtils_VBNet = CType(sc.CreateObject("VegCOM_VBNet.VegUtils_VBNet"), IVegUtils_VBNet)
    Dim vegresults As IVegResults_VBNet = vegutils.sumVegetationType(fc, pt, distance, fldName)

    ' add the graphics to the map
    Dim comGraphics As IGraphicElements = vegresults.ResGraphics
    Dim proxyGraphics() As GraphicElement = CType(ESRI.ArcGIS.ADF.ArcGISServer.Converter.ComObjectToValueObject(comGraphics, sc, GetType(GraphicElement())), GraphicElement())

    Dim rgb As New RgbColor()
    rgb.Red = 155
    rgb.Green = 0
    rgb.Blue = 0
    rgb.AlphaValue = 255

    Dim sls As New SimpleLineSymbol()
    sls.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleLineStyle.esriSLSSolid
    sls.Color = rgb
    sls.Width = 1.2

    For Each pe As ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement In proxyGraphics
      Dim sfs As SimpleFillSymbol = CType(pe.Symbol, SimpleFillSymbol)
      sfs.Outline = sls
    Next pe

    mapfunc.MapDescription.CustomGraphics = proxyGraphics

    Dim cbxvalue As String = CStr(mapctrl.Page.Session("CheckBox1Value"))
    If Boolean.Parse(cbxvalue) Then
      ' display table of summarized areas
      Dim rs As IRecordSet = vegresults.Stats
      Dim value_rs As ESRI.ArcGIS.ADF.ArcGISServer.RecordSet = CType(ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(rs, sc, GetType(ESRI.ArcGIS.ADF.ArcGISServer.RecordSet)), ESRI.ArcGIS.ADF.ArcGISServer.RecordSet)
      Dim rsDatatable As System.Data.DataTable = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToDataTable(value_rs)
      Dim rsDataset As New System.Data.DataSet()
      rsDataset.Tables.Add(rsDatatable)
      mapctrl.Page.Session("VegDataset") = rsDataset

    Else
      mapctrl.Page.Session("VegDataset") = Nothing
    End If

    mapctrl.Refresh()

  End Sub
#End Region

End Class