Common Add graphics
Common_AddGraphics_VBNet\Default.aspx.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.Collections.Generic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Partial Public Class [Default]
    Inherits System.Web.UI.Page
#Region "Instance Variable Declarations"
    Private _CallbackResultCollection As New ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection()
#End Region

#Region "ASP.NET Page Event Handlers"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        AddHandler maptipsCheckBox.CheckedChanged, AddressOf maptipsCheckBox_CheckedChanged

        'PS: The disabled attribute is added on load. The real problem comes when you have a checkbox like this: <asp:checkbox enabled="false" />. This gets rendered out like this:
        '<span disabled='disabled'><input type='checkbox' disabled='disabled'></span>
        'In our javascript, when we enable the input, we're not enabling the surrounding span. As it happens, in FireFox, this doesn't seem to be an issue (the checkbox will be enabled as you would expect). In IE6, however, the checkbox will be disabled because the surrounding span is disabled.
        'To get around this, you can do the following instead of saying myCheckBox.Enabled = false in your code-behind:
        'myCheckBox.InputAttributes.Add("disabled", "disabled");

        '(NB: this pertains to ASP.Net 2.0, it may work differently in 1.x)

        maptipsCheckBox.InputAttributes.Add("disabled", "disabled")
        ScriptManager1.RegisterAsyncPostBackControl(maptipsCheckBox)

        If (Not ScriptManager1.IsInAsyncPostBack) Then
            ' Set the Session variable indicating whether or not the MapTips have been initialized.  Used
            ' because, once the MapTips have been initialized, they only need to be displayed or hidden.
            Session("MapTipsInitialized") = False
        End If
        Dim requestParameters As System.Collections.Specialized.NameValueCollection = Page.Request.Params
        Dim requestString As String = Nothing

        Dim controlID As String = requestParameters("__EVENTTARGET")

        ' Check whether the __EVENTTARGET parameter is null or empty and whether it contains the
        ' Toolbar control's ID
        If (Not String.IsNullOrEmpty(controlID)) AndAlso controlID.Contains(Toolbar2.ID) Then
            requestString = requestParameters("__EVENTARGUMENT")
            If requestString.Contains("AddLabels") Then
                ' Call the method to create and add new labels
                AddGraphicLabels("ServerResource", "Cities", "AREANAME", "Element Graphics - Labels", "ADFGraphicsResource")

                ' Copy callback results from both the Map and the Toc.  The map will contain
                ' callback results in the event labels were added, while the Toc will have
                ' callback results if the graphics resource or graphics layer containing the
                ' labels was created and added to the map
                _CallbackResultCollection.CopyFrom(Map1.CallbackResults)
                _CallbackResultCollection.CopyFrom(Toc1.CallbackResults)
                ScriptManager1.RegisterDataItem(Page, _CallbackResultCollection.ToString(), False)
            End If
        End If
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Make sure the page is not in a postback (i.e. is in initial page load)
        ' before calling method to add graphics to the map.
        If (Not ScriptManager1.IsInAsyncPostBack) Then
            AddGraphicData()
        End If
    End Sub
#End Region

#Region "Instance Methods"

    ' Method that creates and adds two rectangles to the map - one as an element graphic and one as
    ' a feature graphic
    Protected Sub AddGraphicData()
        Try
            ' Retrieve the map functionality for the graphics resource
            Dim graphicsMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality = TryCast(Map1.GetFunctionality("ADFGraphicsResource"), ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)

            ' Check whether the graphics resource was found.  If not, create it.
            If graphicsMapFunctionality Is Nothing Then
                Dim commonMapResource As ESRI.ArcGIS.ADF.Web.DataSources.IMapResource = CreateGraphicsResource("ADFGraphicsResource")
                graphicsMapFunctionality = CType(Map1.GetFunctionality(commonMapResource), ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)

                ' Refresh the Toc so it displays the graphics resource
                Toc1.Refresh()
            End If

            ' Create and name a new ElementGraphicsLayer
            Dim elementGraphicsLayer As New ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer()
            elementGraphicsLayer.TableName = "Element Graphics - Extent Rectangle"

            ' Get a reference to the graphics resource's graphics dataset
            Dim graphicsDataSet As ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsDataSet = graphicsMapFunctionality.GraphicsDataSet

            ' Add the newly created element graphics layer to the graphics dataset
            graphicsDataSet.Tables.Add(elementGraphicsLayer)

            ' Create a Web ADF polygon and specify its geometry as a rectangle
            Dim adfElementPolygon As New ESRI.ArcGIS.ADF.Web.Geometry.Polygon()
            adfElementPolygon.Rings.Add(New ESRI.ArcGIS.ADF.Web.Geometry.Ring(New ESRI.ArcGIS.ADF.Web.Geometry.Envelope(-100, 20, -80, 40)))

            ' Create a fill symbol with a diagonal fill and red boundary
            Dim adfSimpleFillSymbol As New ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol()
            adfSimpleFillSymbol.Transparency = 0
            adfSimpleFillSymbol.FillType = ESRI.ArcGIS.ADF.Web.Display.Symbol.PolygonFillType.FDiagonal
            adfSimpleFillSymbol.BoundaryColor = System.Drawing.Color.Red

            ' Create a graphic element composed of the rectangle and fill symbols created above
            Dim adfGraphicElement As New ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(adfElementPolygon, adfSimpleFillSymbol)

            ' Create another fill symbol.  This one is transparent with no boundary.
            Dim adfSelectedSimpleFillSymbol As New ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol()
            adfSelectedSimpleFillSymbol.Color = System.Drawing.Color.Transparent
            adfSelectedSimpleFillSymbol.BoundaryWidth = 0

            ' Set the graphic element's selected symbol to the transparent fill symbol.
            ' The element will be displayed with this fill when selected.
            adfGraphicElement.SelectedSymbol = adfSelectedSimpleFillSymbol

            ' Add the graphic element to the element graphics layer, and get a reference
            ' to the row of the data table that represents the element.
            Dim dataRow As System.Data.DataRow = elementGraphicsLayer.Add(adfGraphicElement)
            ' Make sure the element is not selected.  Do this by setting the data column
            ' storing whether or not the element is selected to false.
            dataRow(elementGraphicsLayer.IsSelectedColumn) = False

            ' Create and name a new FeatureGraphicsLayer
            Dim featureGraphicsLayer As New ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer()
            featureGraphicsLayer.TableName = "Feature Graphics - Extent Rectangle"

            ' Add the feature graphics layer to the graphics resource's graphics dataset
            graphicsDataSet.Tables.Add(featureGraphicsLayer)

            ' Create another Web ADF polygon and specify its geometry as a different rectangle
            Dim adfFeaturePolygon As New ESRI.ArcGIS.ADF.Web.Geometry.Polygon()
            adfFeaturePolygon.Rings.Add(New ESRI.ArcGIS.ADF.Web.Geometry.Ring(New ESRI.ArcGIS.ADF.Web.Geometry.Envelope(-70, 20, -50, 40)))

            ' Add the polygon to the feature graphics layer
            featureGraphicsLayer.Add(adfFeaturePolygon)

            ' Create a Web ADF simple renderer and specify its symbol as the simple fill
            ' symbol created above
            Dim adfSimpleRenderer As New ESRI.ArcGIS.ADF.Web.Display.Renderer.SimpleRenderer()
            adfSimpleRenderer.Symbol = adfSimpleFillSymbol

            ' Symbolize the polygon contained in the feature graphics layer by assigning the
            ' simpler renderer to the feature graphics layer.  Note that this is a different
            ' pattern than assigning symbology for element graphics layers.  For feature graphics
            ' layers, symbology is specified at the layer level.  For element graphics layers,
            ' symbology is specified element by element.
            featureGraphicsLayer.Renderer = adfSimpleRenderer
        Catch exception As System.Exception
            Dim jsErrorAlert As String = String.Format("<script>{0}</script>", Utility.GetJavaScriptErrorString(exception))
            Response.Write(jsErrorAlert)
        End Try
    End Sub

    ' Method that creates and adds labels to the map for the current map extent, with parameters
    ' defined as follows:
    ' sourceResourceName - the name of the map resource containing the layer to generate labels from
    ' sourceLayerName - the name of the layer to generate labels from
    ' sourceFieldName - the name of the field from which the labels will take their values
    ' graphicsLayerName - the name of the graphics layer that will contain the labels
    ' graphicsResourceName - the name of the resource containing the label graphics layer
    Protected Sub AddGraphicLabels(ByVal sourceResourceName As String, ByVal sourceLayerName As String, ByVal sourceFieldName As String, ByVal graphicsLayerName As String, ByVal graphicsResourceName As String)
        Try
            ' Retrieve the map functionality for the graphics resource
            Dim graphicsMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality = TryCast(Map1.GetFunctionality(graphicsResourceName), ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)

            ' Check whether the graphics resource was found.  If not, create it.
            If graphicsMapFunctionality Is Nothing Then
                Dim commonMapResource As ESRI.ArcGIS.ADF.Web.DataSources.IMapResource = CreateGraphicsResource(graphicsResourceName)
                graphicsMapFunctionality = CType(Map1.GetFunctionality(commonMapResource), ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality)

                ' Refresh the Toc so it displays the graphics resource
                Toc1.Refresh()
            End If

            ' Check whether the graphics layer holding the labels already exists in the graphics resource
            If graphicsMapFunctionality.GraphicsDataSet.Tables.Contains(graphicsLayerName) Then
                ' Remove the labels graphics layer from the resource.  We will re-create, re-populate, 
                ' and re-add the layer based on the current map extent
                graphicsMapFunctionality.GraphicsDataSet.Tables.Remove(graphicsLayerName)
            End If

            ' Create and name an element graphics layer to contain the labels
            Dim elementGraphicsLayer As New ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer()
            elementGraphicsLayer.TableName = graphicsLayerName

            ' Add the element layer to the graphics dataset of the graphics resource
            graphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer)

            ' Refresh the Toc so it displays the new graphics layer
            Toc1.Refresh()

            ' Get a reference to the common API map functionality object for the map resource
            ' with the passed-in name.  Note this code assumes such a resource exists.
            Dim commonMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality = CType(Map1.GetFunctionality(sourceResourceName), ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)

            ' Get the underlying GIS resource from the map functionality
            Dim gisResource As ESRI.ArcGIS.ADF.Web.DataSources.IGISResource = commonMapFunctionality.Resource

            ' Use the GIS resource to create a query functionality object to query the 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)

            ' Declare string arrays to store layer IDs and names
            Dim layerIDs() As String
            Dim layerNames() As String
            ' Get the queryable layers contained in the "ServerResource" map resource via the 
            ' query functionality object created by this resource.  Store the output in 
            ' the layer ID and name arrays.
            queryFunctionality.GetQueryableLayers(Nothing, layerIDs, layerNames)

            ' Set the name of the layer to query and that will be used to generate labels
            Dim queryLayerName As String = sourceLayerName

            ' Declare a variable to hold the ID of the query layer
            Dim queryLayerID As String = Nothing
            ' Iterate through the layer names array to find the ID of the query layer
            For index As Integer = 0 To layerNames.Length - 1
                ' Check to see whether the layer name at the current index of the array matches
                ' the name of the query layer.  If so, retrieve the ID at the same index from 
                ' the layer ID array and assign it to the query layer ID variable
                If layerNames(index) = queryLayerName Then
                    queryLayerID = layerIDs(index)
                    Exit For
                End If
            Next index

            ' Define name of the field to use when labeling
            Dim labelFieldName As String = sourceFieldName

            ' Instantiate a Web ADF spatial filter to use in executing the query
            Dim adfSpatialFilter As New ESRI.ArcGIS.ADF.Web.SpatialFilter()

            ' Define the fields to include in the query.  This is done by (1) specifying a
            ' delimited string variable containing the list of fields, (2) creating a 
            ' StringCollection object from the field list and the delimiter, and (3) passing
            ' the StringCollection into the SubFields property of the Web ADF spatial filter.
            ' Note that, since the query results will be used to populate the label graphics
            ' layer, the fields we specify here will ultimately be the ones included in the layer.
            Dim fieldList As String = labelFieldName
            Dim stringCollection As New ESRI.ArcGIS.ADF.StringCollection(fieldList, ","c)
            adfSpatialFilter.SubFields = stringCollection

            ' Specify the spatial filter's parameters.  Here we limit the area of the query to
            ' the map extent, specify that feature geometries are to be returned with the
            ' query results, and limit the number of results returned to be no more than 20.
            adfSpatialFilter.Geometry = Map1.Extent
            adfSpatialFilter.ReturnADFGeometries = True
            adfSpatialFilter.MaxRecords = 100

            ' Execute the query and pass the result to a DataTable object
            Dim resultDataTable As System.Data.DataTable = queryFunctionality.Query(graphicsMapFunctionality.Name, queryLayerID, adfSpatialFilter)

            ' Declare a variable to hold the column index of the column in the results DataTable
            ' that stores feature geometries
            Dim geometryColumnIndex As Integer = -1
            ' Iterate through the columns of the results table 
            For index As Integer = 0 To resultDataTable.Columns.Count - 1
                ' Check whether the type of data stored in the column at the current index
                ' is Web ADF geometry.  If so, store the current index as the geometry
                ' column index and exit the loop.
                If resultDataTable.Columns(index).DataType Is GetType(ESRI.ArcGIS.ADF.Web.Geometry.Geometry) Then
                    geometryColumnIndex = index
                    Exit For
                End If
            Next index

            ' Iterate through each row of the results table, create a label for the feature
            ' the row represents, and add the label to the element graphics layer
            For Each dataRow As System.Data.DataRow In resultDataTable.Rows
                ' Get a reference to the Web ADF geometry stored in the geometry column
                ' of the current row
                Dim adfGeometry As ESRI.ArcGIS.ADF.Web.Geometry.Geometry = CType(dataRow(geometryColumnIndex), ESRI.ArcGIS.ADF.Web.Geometry.Geometry)

                ' Get the center point of the geometry
                Dim adfCenterPoint As ESRI.ArcGIS.ADF.Web.Geometry.Point = ESRI.ArcGIS.ADF.Web.Geometry.Polygon.GetCenterPoint(adfGeometry)

                ' Instantiate and initialize a FontInfo object.  This will specify the font
                ' of the labels
                Dim fontInfo As New ESRI.ArcGIS.ADF.Web.FontInfo()
                fontInfo.Name = "Arial"
                fontInfo.Color = System.Drawing.Color.Blue
                fontInfo.Size = 8

                ' Instantiate a Web ADF text marker symbol
                Dim adfTextMarkerSymbol As New ESRI.ArcGIS.ADF.Web.Display.Symbol.TextMarkerSymbol()
                ' Specify the font of the text marker symbol by passing it the FontInfo object
                adfTextMarkerSymbol.Font = fontInfo
                ' Specify the text of the text marker symbol as the value stored in the label
                ' field of the current row
                adfTextMarkerSymbol.Text = CStr(dataRow(labelFieldName))

                ' Create a graphic element with the center point and text marker symbol and add
                ' it to the element graphics layer storing the labels
                Dim graphicElement As New ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(adfCenterPoint, adfTextMarkerSymbol)
                elementGraphicsLayer.Add(graphicElement)
            Next dataRow

            ' Refresh the graphics resource so any new labels added are displayed
            Map1.RefreshResource(graphicsResourceName)
        Catch exception As System.Exception
            Dim errorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = Utility.GetErrorCallback(exception)
            Map1.CallbackResults.Add(errorCallbackResult)
        End Try
    End Sub

    ' Method that toggles map tips on or off via server-side code.  Parameters are defined as follows:
    ' showMapTips - whether to show or hide map tips
    ' mapTips - the Web ADF MapTips control to interact with
    ' resourceName - the name of the map resource containing the layer on which to show map tips
    ' layerName - the name of the layer on which to show map tips
    ' mapResourceManager - the MapResourceManager control containing the resource indicated by resourceName
    Protected Sub ToggleMapTipsServer(ByVal showMapTips As Boolean, ByVal resourceName As String, ByVal layerName As String)
        Try
            ' Get the Session variable indicating whether or not the MapTips have been initialized.
            ' If they haven't been, initialize and display them.  If they have been, simply show or 
            ' hide them, depending on the value of showMapTips.
            Dim mapTipsInitialized As Boolean = CBool(Session("MapTipsInitialized"))
            ' Check whether to display or hide map tips
            If (Not mapTipsInitialized) Then

                ' Variable to hold the layer ID of the layer with the passed-in layer name
                Dim layerID As String = Nothing

                ' Retrieve a reference to the Common Data Source API MapFunctionality object
                ' corresponding to the passed-in resource name
                Dim commonMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality = Map1.GetFunctionality(resourceName)

                ' declare and populate arrays to hold the layer names and IDs in the current resource
                Dim layerNames() As String
                Dim layerIDs() As String

                commonMapFunctionality.GetLayers(layerIDs, layerNames)

                ' Iterate through the layer names array until the passed-in layer name is found.
                ' Then retrieve the layer ID at the same index from the layerIDs array and store
                ' this for later use.
                For i As Integer = 0 To layerNames.Length - 1
                    If layerNames(i).ToLower() = layerName.ToLower() Then
                        layerID = layerIDs(i)
                        ' The layer ID has been found, so exit the loop
                        Exit For
                    End If
                Next i

                ' Make sure a layer ID was found
                If layerID Is Nothing Then
                    Return
                End If

                ' Get the LayerDefinition object for the layer on which map tips will be shown.
                ' LayerFormat, which stores the renderer (symbology), visible fields, aliases, 
                ' display field, and attribute display format, can be accessed via this object.
                Dim layerFormat As ESRI.ArcGIS.ADF.Web.UI.WebControls.LayerFormat = ESRI.ArcGIS.ADF.Web.UI.WebControls.LayerFormat.FromMapResourceManager(MapResourceManager1, resourceName, layerID)

                ' Initialize the MapTips control.  At a minimum, the Layer, Map, and LayerFormat properties
                ' must be set.  As shown here, the layer must be specified by MapResourceManager ID, resource
                ' name, and layer name, in the format <MapResourceManager ID>::<resource name>::<layer name>.
                ' This is required because layer name and resource name alone do not necessarily uniquely
                ' specify a layer.  Two layers with the same name belonging to resources of the same name
                ' can exist in the same application if they belong to different MapResourceManagers.
                MapTips1.Layer = String.Format("{0}::{1}::{2}", MapResourceManager1.ID, resourceName, layerName)
                ' Pass in the ID of the map on which map tips will be shown.
                MapTips1.Map = Map1.ID
                ' Enable MapTips to be shown even if layer on which they are based is not visible.
                MapTips1.ShowOnlyWhenLayerIsVisible = False
                ' Use the LayerFormat from the LayerDefinition object initialized above to specify the
                ' format of the map tips.
                MapTips1.LayerFormat = layerFormat

                ' Remove the GRAPHICS_ID and IS_SELECTED fields from the map tips.  These are system
                ' fields that are present by default in the LayerFormats of feature graphics layers.

                ' Declare and initialize variables to store the number of fields in the layer format
                ' and the current field index.
                Dim fieldCount As Integer = MapTips1.LayerFormat.Fields.Count
                Dim index As Integer = 0

                ' Iterate through the fields of the MapTips control's LayerFormat
                For i As Integer = 0 To fieldCount - 1
                    ' Check whether the field at the current index is the GRAPHICS_ID or
                    ' IS_SELECTED field and remove it from the LayerFormat if so.  Note that,
                    ' in this case, we do not increment index.  This is because we have just
                    ' removed the field stored at index, therefore the same index will actually
                    ' refer to a different field on the next loop iteration.
                    If (MapTips1.LayerFormat.Fields(index).Name = "GRAPHICS_ID") OrElse (MapTips1.LayerFormat.Fields(index).Name = "IS_SELECTED") Then
                        MapTips1.LayerFormat.Fields.Remove(MapTips1.LayerFormat.Fields(index))
                    Else
                        ' The field at the current index is not one of those being sought, so
                        ' increment index to move on to the next field.
                        index += 1
                    End If
                Next i

                MapTips1.LayerFormat.UseDefaultTitleAndContents = False
                ' Refresh the MapTips control to commit the changes made to its properties
                MapTips1.RefreshMapTips()

                Session("MapTipsInitialized") = True
            Else
                ' MapTips are already initialized, so just toggle the Visible property
                If showMapTips Then
                    MapTips1.Visible = True
                Else
                    MapTips1.Visible = False
                End If
            End If

            ' Refresh the resource on which the map tips will be shown so that the map tips
            ' are displayed or hidden.
            Map1.RefreshResource(resourceName)

            ' ADF JavaScript to change active tool in toolbar and map control on client
            Dim jsToolbarItemDeactivate As String = String.Format("" & ControlChars.CrLf & "                                var toolbar = Toolbars['{0}'];" & ControlChars.CrLf & "                                var currentToolField = $get(toolbar.currentToolField);" & ControlChars.CrLf & "                                currentToolField.value = '';" & ControlChars.CrLf & "                                toolbar.selectTool();" & ControlChars.CrLf & "                                toolbar.refreshGroup();" & ControlChars.CrLf & "                                $find('{1}').set_mouseMode(ESRI.ADF.UI.MouseMode.Pan);", Toolbar1.ClientID, Map1.ClientID)

            Dim deactivateToolbarItemsCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript(jsToolbarItemDeactivate)

            Map1.CallbackResults.Add(deactivateToolbarItemsCallbackResult)

        Catch exception As System.Exception
            Dim errorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = Utility.GetErrorCallback(exception)
            Map1.CallbackResults.Add(errorCallbackResult)
        End Try
    End Sub

    ' Function that creates a graphics resource in MapResourceManager1 with the passed-in resourceName.
    ' The created resource is returned as a Common Data Source API MapResource object.
    Protected Function CreateGraphicsResource(ByVal resourceName As String) As ESRI.ArcGIS.ADF.Web.DataSources.IMapResource
        ' Instantiate and configure a GISResourceItemDefinition to store the definition of the 
        ' graphics resource
        Dim gisResourceItemDefinition As New ESRI.ArcGIS.ADF.Web.UI.WebControls.GISResourceItemDefinition()
        gisResourceItemDefinition.ResourceDefinition = "GraphicsResource"
        gisResourceItemDefinition.DataSourceDefinition = "In Memory"
        gisResourceItemDefinition.DataSourceType = "GraphicsLayer"


        ' Instantiate and configure a DisplaySettings object to store the display settings
        ' of the graphics resource
        Dim displaySettings As New ESRI.ArcGIS.ADF.Web.DisplaySettings()
        displaySettings.Transparency = 0.0F
        displaySettings.Visible = True

        ' Instantiate a map resource item
        Dim mapResourceItem As New ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem()
        ' Configure the map resource item with the passed-in resource name, the GIS resource
        ' item definition, and the display settings
        mapResourceItem.Name = resourceName
        mapResourceItem.Definition = gisResourceItemDefinition
        mapResourceItem.DisplaySettings = displaySettings

        ' Add the map resource item to the map resource manager, and place it above any
        ' other resource items
        MapResourceManager1.ResourceItems.Insert(0, mapResourceItem)

        ' Create and return the graphics resource as an IMapResource object
        Return MapResourceManager1.CreateResource(mapResourceItem)
    End Function

#End Region

#Region "ASP.NET Web Control Events"

    Private Sub maptipsCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        Try
            Dim isChecked As Boolean = maptipsCheckBox.Checked

            ToggleMapTipsServer(isChecked, "ADFGraphicsResource", "Feature Graphics")

            If isChecked AndAlso (MapTips1.LayerFormat IsNot Nothing) Then
                ' Adjust the appearance of the map tips.  The Title property determines what shows
                ' on mouseover and in the map tip's header when the map tip is clicked.  The Contents 
                ' property determines what shows in the body of the map tip when clicked.  Field names 
                ' in curly braces will be substituted with actual field values at run time.  As shown,
                ' HTML can be used to customize the appearance of either the Title or the Contents.
                MapTips1.LayerFormat.Title = "<div style='font-family:Arial; font-weight:bold'>" & "Location: ({X}, {Y})</div>"
                MapTips1.LayerFormat.Contents = "<div style='font-family:Arial; font-size: 9pt; " & "font-weight:bold; color:Red;'>Custom Data Column Value: {CustomDataColumn}</div>"

                ' Refresh the resource on which the map tips will be shown so that the updated
                ' title and contents formatting is applied.
                Map1.RefreshResource(MapTips1.ResourceName)
            End If

            ' Copy callback results from both the MapTips control and the Map
            _CallbackResultCollection.CopyFrom(MapTips1.CallbackResults)
            _CallbackResultCollection.CopyFrom(Map1.CallbackResults)
            ScriptManager1.RegisterDataItem(Page, _CallbackResultCollection.ToString(), False)
        Catch exception As System.Exception
            Dim errorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = Utility.GetErrorCallback(exception)
            _CallbackResultCollection.Add(errorCallbackResult)
        End Try
    End Sub

#End Region
End Class