Common Custom renderers
Common_CustomRenderers_VBNet\App_Code\LineColorRenderer.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
Namespace ESRI.ADF.Samples.Renderers
  ''' <summary>
  ''' Renders linear graphic features with color and thickness determined by designated attributes
  ''' </summary>
  <System.Serializable> _
  Public Class LineColorRenderer
    Inherits ESRI.ADF.Samples.Renderers.RendererBase
    #Region "Public Properties"

    Private lineColorColumn_Renamed As String = "Color"

    ''' <summary>
    ''' Name of the column that will determine a feature's color
    ''' </summary>
    Public Property LineColorColumn() As String
      Get
        Return lineColorColumn_Renamed
      End Get
      Set
        lineColorColumn_Renamed = Value
      End Set
    End Property

    Private lineThicknessColumn_Renamed As String = "Width"

    ''' <summary>
    ''' Name of the column that will determine the feature's line thickness
    ''' </summary>
    Public Property LineThicknessColumn() As String
      Get
        Return lineThicknessColumn_Renamed
      End Get
      Set
        lineThicknessColumn_Renamed = Value
      End Set
    End Property

    #End Region

    #Region "IRenderer Members"

    ''' <summary>
    ''' Main part of the IRenderer interface, within which a feature encapsulating the specified DataRow is to be 
    ''' rendered on the specified graphics surface. The geometry instance has already been transformed to screen 
    ''' coordinate, so we don't have to worry about that here.
    ''' </summary>
    ''' <param name="row">row containing the feature's data</param>
    ''' <param name="graphics">GDI+ surface on which to render the feature</param>
    ''' <param name="geometryColumn">column containing the feature's geometry</param>
    Public Overrides Sub Render(ByVal row As System.Data.DataRow, ByVal graphics As System.Drawing.Graphics, ByVal geometryColumn As System.Data.DataColumn)
      ' Validate method input
      If row Is Nothing OrElse graphics Is Nothing OrElse geometryColumn Is Nothing Then
        Return
      End If

      ' Validate input geometry
      Dim adfGeometry As ESRI.ArcGIS.ADF.Web.Geometry.Geometry = TryCast(row(geometryColumn), ESRI.ArcGIS.ADF.Web.Geometry.Geometry)
      If adfGeometry Is Nothing Then
        Return
      End If

      ' Initialize line color and thickness
      Dim lineColor As System.Drawing.Color = System.Drawing.Color.Black
      Dim lineWidth As Single = 1

      ' Get the feature's line thickness and color as specified by its attributes
      If row.Table.Columns.Contains(Me.LineThicknessColumn) Then
        Single.TryParse(row(Me.LineThicknessColumn).ToString(), lineWidth)
      End If

      If row.Table.Columns.Contains(Me.LineColorColumn) AndAlso TypeOf row(Me.LineColorColumn) Is System.Drawing.Color Then
        lineColor = CType(row(LineColorColumn), System.Drawing.Color)
      End If

      ' Draw the feature
      If TypeOf adfGeometry Is ESRI.ArcGIS.ADF.Web.Geometry.Polygon Then
        Utility.DrawPolygon(graphics, TryCast(adfGeometry, ESRI.ArcGIS.ADF.Web.Geometry.Polygon), lineColor, lineWidth)
      ElseIf TypeOf adfGeometry Is ESRI.ArcGIS.ADF.Web.Geometry.Polyline Then
        Utility.DrawPolyline(graphics, TryCast(adfGeometry, ESRI.ArcGIS.ADF.Web.Geometry.Polyline), lineColor, lineWidth)
      End If
    End Sub

    #End Region
  End Class
End Namespace