Common_AddGraphics_VBNet\App_Code\GraphicPointTools.vb
' Copyright 2011 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 AddPoint Public Class ElementGraphicTool 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 a reference to the map control by casting the event aarguments object to a Map Dim adfMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(toolEventArgs.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) Try ' Get a reference to the point clicked on the map as a Web ADF point object by ' (1) casting the event arguments to a MapPointEventArgs object and (2) accessing ' the MapPoint property on MapPointEventArgs Dim mapPointEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs = CType(toolEventArgs, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs) Dim adfPoint As ESRI.ArcGIS.ADF.Web.Geometry.Point = mapPointEventArgs.MapPoint ' Retrieve the map functionality for the graphics resource Dim graphicsMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality = TryCast(adfMap.GetFunctionality("ADFGraphicsResource"), ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality) ' Make sure the graphics resource was found If graphicsMapFunctionality Is Nothing Then ' If the graphics resource was not found, use the ProcessError utility function ' to notify the user. This function creates a Web ADF callback result that ' specifies displaying a JavaScript alert with the passed-in text. We copy ' this callback result to the Map Control's callback results collection, because ' Web ADF Tools and Commands (and the classes that inherit from them) process ' callback results from the map after execution. adfMap.CallbackResults.CopyFrom (Utility.CreateErrorCallback("ADF graphics functionality not found")) Return End If ' Attempt to retrieve the element graphics layer that will hold the graphic point Dim elementGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer = Nothing If graphicsMapFunctionality.GraphicsDataSet.Tables.Contains("Element Graphics") Then elementGraphicsLayer = TryCast(graphicsMapFunctionality.GraphicsDataSet.Tables("Element Graphics"), ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer) End If ' Check whether the element graphics layer was found. If not, create it. If elementGraphicsLayer Is Nothing Then ' Create a new instance of ElementGraphicsLayer and assign it to our ' ElementGraphicsLayer object variable. elementGraphicsLayer = New ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer() ' Name the layer via the inherited System.Data.DataTable.TableName property elementGraphicsLayer.TableName = "Element Graphics" ' Add the layer to the graphics resource's tables collection. Note that the ' resource's GraphicsDataSet property inherits from System.Data.DataSet, so we ' add the table the same way as we would if this were a "regular" DataSet object graphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer) ' Get a reference to the Toc control on the same page as the map. Note this code ' assumes that a Toc control named "Toc1" exists and will throw an exception if ' one does not. Dim adfToc As ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc = CType(Utility.FindControl("Toc1", adfMap.Page), ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc) ' Refreshing the Toc control will add the new graphics layer to the Toc via ' the MapResourceManager --> Map --> Toc buddy relationship adfToc.Refresh() ' Copy the callback results from the Toc (which has callback results because of the ' above call to Refresh) to the Map because Web ADF Tools and Commands only process ' the callback results of the Map. adfMap.CallbackResults.CopyFrom(adfToc.CallbackResults) End If ' Uncomment to make the tool remove the previous point when adding a new one 'elementGraphicsLayer.Clear(); ' Initialize a simple marker symbol that will be used specify the default symbology ' of the graphics in the element graphics layer Dim defaultSimpleMarkerSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol = New ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol() defaultSimpleMarkerSymbol.Color = System.Drawing.Color.Black defaultSimpleMarkerSymbol.Width = 20 defaultSimpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Triangle ' Initialize a simple marker symbol that will be used to specify the appearance of ' selected graphics in the element graphics layer Dim selectedSimpleMarkerSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol = New ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol() selectedSimpleMarkerSymbol.Color = System.Drawing.Color.Yellow selectedSimpleMarkerSymbol.Width = 12 ' Create a graphic element located at the point clicked on the map, and with the symbology ' specified by the renderers initialized above Dim graphicElement As ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement = New ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(adfPoint, defaultSimpleMarkerSymbol, selectedSimpleMarkerSymbol) ' Add the element to the graphics layer elementGraphicsLayer.Add(graphicElement) ' Refresh the graphics resource so the new graphics element is displayed adfMap.RefreshResource(graphicsMapFunctionality.Resource.Name) Catch exception As System.Exception Dim errorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = Utility.GetErrorCallback(exception) adfMap.CallbackResults.Add(errorCallbackResult) End Try End Sub #End Region End Class Public Class FeatureGraphicTool 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 a reference to the map control by casting the event aarguments object to a Map Dim adfMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(toolEventArgs.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) Try ' Get a reference to the point clicked on the map as a Web ADF point object by ' (1) casting the event arguments to a MapPointEventArgs object and (2) accessing ' the MapPoint property on MapPointEventArgs Dim mapPointEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs = CType(toolEventArgs, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs) Dim adfPoint As ESRI.ArcGIS.ADF.Web.Geometry.Point = mapPointEventArgs.MapPoint ' Retrieve the map functionality for the graphics resource Dim graphicsMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality = TryCast(adfMap.GetFunctionality("ADFGraphicsResource"), ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality) ' Make sure the graphics resource was found If graphicsMapFunctionality Is Nothing Then ' If the graphics resource was not found, use the ProcessError utility function ' to notify the user. This function creates a Web ADF callback result that ' specifies displaying a JavaScript alert with the passed-in text. We copy ' this callback result to the Map Control's callback results collection, because ' Web ADF Tools and Commands (and the classes that inherit from them) process ' callback results from the map after execution. adfMap.CallbackResults.CopyFrom (Utility.CreateErrorCallback("ADF graphics functionality not found")) Return End If ' Attempt to retrieve the feature graphics layer that will hold the feature point Dim featureGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer = Nothing If graphicsMapFunctionality.GraphicsDataSet.Tables.Contains("Feature Graphics") Then featureGraphicsLayer = TryCast(graphicsMapFunctionality.GraphicsDataSet.Tables("Feature Graphics"), ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer) End If ' Check whether the feature graphics layer was found. If not, create it. If featureGraphicsLayer Is Nothing Then ' Create a new instance of ElementGraphicsLayer and assign it to our ' ElementGraphicsLayer object variable. featureGraphicsLayer = New ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer() ' Name the layer via the inherited System.Data.DataTable.TableName property featureGraphicsLayer.TableName = "Feature Graphics" ' Add the layer to the graphics resource's tables collection. Note that the ' resource's GraphicsDataSet property inherits from System.Data.DataSet, so we ' add the table the same way as we would if this were a "regular" DataSet object graphicsMapFunctionality.GraphicsDataSet.Tables.Add(featureGraphicsLayer) ' Configure and add columns to the feature graphics layer. Since the ' FeatureGraphicsLayer type inherits from System.Data.DataTable, we instantiate ' and initialize the columns in the same way as System.Data.DataColumns, and ' add them to the FeatureGraphicsLayer in the same way as we would with a ' DataTable. ' Create an X column Dim xDataColumn As System.Data.DataColumn = New System.Data.DataColumn("X", System.Type.GetType("System.Double")) featureGraphicsLayer.Columns.Add(xDataColumn) ' Create a Y column Dim yDataColumn As System.Data.DataColumn = New System.Data.DataColumn("Y", System.Type.GetType("System.Double")) featureGraphicsLayer.Columns.Add(yDataColumn) ' Create a "CustomDataColumn" column Dim customDataColumn As System.Data.DataColumn = New System.Data.DataColumn("CustomDataColumn", System.Type.GetType("System.Int32")) featureGraphicsLayer.Columns.Add(customDataColumn) ' Define the symbology for the feature graphics layer. In this case, we ' demonstrate creation of unique value symbology - a different symbol for ' different values of a given field. To do this, we need to not only define ' marker symbols (we use SimpleMarkerSymbols here), but we also need to ' define objects that specify which symbol to use for which values. To ' associate particular symbols with particular values, we use the Web ADF ' UniqueValue object. Then to associate symbol-value pairings with a ' feature graphics layer, including which field to take values from for ' symbolization, we use a Web ADF ValueMapRenderer object. ' Instantiate a UniqueValue object and initialize it to be associated with ' an integer value of 0. This is done by specifying int as the type in the ' angle brackets, and 0 as the parameter to the constructor Dim zeroUniqueValue As ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer) = New ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer)(0) ' Create and initialize a SimpleMarkerSymbol to specify the appearance of ' graphics with a value of 0 Dim zeroSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol = New ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol() zeroSymbol.Color = System.Drawing.Color.Red zeroSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Circle zeroSymbol.Width = 12 ' Associate the SimpleMarkerSymbol initialized above with the UniqueValue object zeroUniqueValue.Symbol = zeroSymbol ' The SymbolLabel will be shown in the table of contents zeroUniqueValue.SymbolLabel = "0" ' Instantiate another UniqueValue object, this time initializing it to be ' associated with an integer value of 1. Dim oneUniqueValue As ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer) = New ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer)(1) ' Create and initialize a SimpleMarkerSymbol to specify the appearance of ' graphics with a value of 1 Dim oneSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol = New ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol() oneSymbol.Color = System.Drawing.Color.Blue oneSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Circle oneSymbol.Width = 12 ' Associate this new SimpleMarkerSymbol with the UniqueValue object associated ' with an integer value of 1 oneUniqueValue.Symbol = oneSymbol ' The SymbolLabel will be shown in the table of contents oneUniqueValue.SymbolLabel = "1" ' Create and initialize a SimpleMarkerSymbol to specify default symbology for the ' feature graphics layer - this will be used in the event the value being used for ' symbolization was not specified by a value-symbol pairing Dim defaultSimpleMarkerSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol = New ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol() defaultSimpleMarkerSymbol.Color = System.Drawing.Color.DarkGoldenrod defaultSimpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Cross defaultSimpleMarkerSymbol.Width = 12 ' Instantiate a ValueMapRenderer to use in associating the symbol-value pairings ' with a feature graphics layer and specifying which column to symbolize Dim valueMapRenderer As ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer(Of Integer) = New ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer(Of Integer)() ' Specify which column to draw values from for symbolization valueMapRenderer.ValueColumnName = "CustomDataColumn" ' Initialize the default label and symbol. This will be used if the value ' being symbolized does not have an explicit symbology specification. valueMapRenderer.DefaultLabel = "Default Value" valueMapRenderer.DefaultSymbol = defaultSimpleMarkerSymbol ' Get a reference to the collection of values with explicit symbol-value pairings ' in the ValueMapRenderer Dim valueCollection As ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueCollection(Of Integer) = valueMapRenderer.Values ' Add the symbol-value pairings specified above and encapsulated in UniqueValue ' objects to the ValueMapRenderer valueCollection.Add(zeroUniqueValue) valueCollection.Add(oneUniqueValue) ' Associate the default and selected symbology of the feature graphics layer ' with the symbol-value definitions contained in the ValueMapRenderer featureGraphicsLayer.Renderer = valueMapRenderer featureGraphicsLayer.SelectedRenderer = valueMapRenderer ' Get a reference to the Toc control on the same page as the map. Note this code ' assumes the existence of a Toc control named "Toc1" and will throw an exception if ' there is no such control. Dim adfToc As ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc = CType(Utility.FindControl("Toc1", adfMap.Page), ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc) ' Refreshing the Toc control will add the new graphics layer to the Toc via ' the MapResourceManager --> Map --> Toc buddy relationship adfToc.Refresh() ' Copy the callback results from the Toc (which has callback results because of the ' above call to Refresh) to the Map because Web ADF Tools and Commands only process ' the callback results of the Map. adfMap.CallbackResults.CopyFrom(adfToc.CallbackResults) ' Create a callback result containing the JavaScript needed to enable the "Enable ' Map Tips on Feature Points" checkbox. The checkbox can now be enabled because ' the code triggered by checking the checkbox assumes the existence of the feature ' graphics layer that was just created. Dim jsEnableCheckbox As String = String.Format("document.getElementById('{0}').disabled = false", "maptipsCheckBox") Dim enableCheckboxCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript(jsEnableCheckbox) ' Add the checkbox enabling callback result to the map so the JavaScript is executed adfMap.CallbackResults.Add(enableCheckboxCallbackResult) End If ' Add the clicked map point to the feature graphics layer and get a reference to ' the row created in the underlying DataTable Dim newDataRow As System.Data.DataRow = featureGraphicsLayer.Add(adfPoint) ' Populate the CustomDataColumn field with a random number between 0 and 2 (inclusive). ' We use these values to demonstrate the feature graphics layer's defined symbol-value ' pairings (for 0 and 1) as well as the default symbology (for 2) Dim randomizer As System.Random = New System.Random() ' Note the parameters passed to Next are actually 0 and 3 because the lower bound is ' inclusive, but the upper bound is exclusive. Dim randomValue As Integer = randomizer.Next(0, 3) newDataRow("CustomDataColumn") = randomValue ' Populate the X and Y fields with the location of the clicked map point. The first format ' parameter specifies to only include two decimal places. newDataRow("X") = String.Format("{0:#.##}", adfPoint.X) newDataRow("Y") = String.Format("{0:#.##}", adfPoint.Y) ' Set the new feature graphic to be selected by setting the field storing the corresponding ' boolean to true Dim selectedColumn As System.Data.DataColumn = featureGraphicsLayer.IsSelectedColumn newDataRow(selectedColumn) = True ' Refresh the graphics resource so the new feature graphic is displayed on the map adfMap.RefreshResource(graphicsMapFunctionality.Resource.Name) Catch exception As System.Exception Dim errorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = Utility.GetErrorCallback(exception) adfMap.CallbackResults.Add(errorCallbackResult) End Try End Sub #End Region End Class Public Class FeatureDropDownColor Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerDropDownBoxAction #Region "IServerAction Members" Private Sub ServerAction(ByVal toolbarItemInfo As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IServerAction.ServerAction ' Get a reference to the Map control via the BuddyControls array of the passed-in ' ToolbarItemInfo. Note this code assumes the desired map is at the first index ' of the array. Dim adfMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(toolbarItemInfo.BuddyControls(0), ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) Try ' Get a reference to the color selection Web ADF drop down box Dim adfDropDownBox As ESRI.ArcGIS.ADF.Web.UI.WebControls.DropDownBox = CType(toolbarItemInfo.Toolbar.ToolbarItems.Find(toolbarItemInfo.Name), ESRI.ArcGIS.ADF.Web.UI.WebControls.DropDownBox) ' Retrieve the selected color from the drop down box Dim selectedColor As String = adfDropDownBox.SelectedValue ' Retrieve the map functionality for the graphics resource Dim graphicsMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality = TryCast(adfMap.GetFunctionality("ADFGraphicsResource"), ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality) ' Make sure the graphics resource was found If graphicsMapFunctionality Is Nothing Then ' If the graphics resource was not found, use the ProcessError utility function ' to notify the user. This function creates a Web ADF callback result that ' specifies displaying a JavaScript alert with the passed-in text. We copy ' this callback result to the Map Control's callback results collection, because ' Web ADF Tools and Commands (and the classes that inherit from them) process ' callback results from the map after execution. adfMap.CallbackResults.CopyFrom (Utility.CreateErrorCallback("ADF graphics functionality not found")) Return End If ' Attempt to retrieve the feature graphics layer for which symbology will be modified Dim featureGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer = Nothing If graphicsMapFunctionality.GraphicsDataSet.Tables.Contains("Feature Graphics") Then featureGraphicsLayer = TryCast(graphicsMapFunctionality.GraphicsDataSet.Tables("Feature Graphics"), ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer) End If ' Make sure the feature graphics layer was found If featureGraphicsLayer Is Nothing Then ' Initialize a string containing the JavaScript necessary to reset the drop down box's ' value to "Red_Blue" Dim jsResetDropDownList As String = String.Format("document.getElementById('{0}{1}{2}').value = 'Red_Blue'", toolbarItemInfo.Toolbar.ClientID, adfDropDownBox.Name, adfDropDownBox.Type) ' Create a new ADF callback result containing the JavaScript Dim resetDropDownListCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript(jsResetDropDownList) ' Add the JavaScript callback result to the map so it is executed adfMap.CallbackResults.Add(resetDropDownListCallbackResult) ' Use the ProcessError utility method to add a callback to the map that will inform ' the user of the error adfMap.CallbackResults.CopyFrom (Utility.CreateErrorCallback("ADF feature graphics layer not found")) Return End If ' Get the ValueMapRenderer and ValueCollection from the feature graphics layer. This is where ' the symbol-value pairings are specified Dim currentValueMapRenderer As ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer(Of Integer) = CType(featureGraphicsLayer.Renderer, ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer(Of Integer)) Dim currentValueCollection As ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueCollection(Of Integer) = currentValueMapRenderer.Values ' Get the symbol-value pairings for values 0 and 1 from the ValueCollection. Each pairing ' is encapsulated in a UniqueValue object. Dim currentZeroUniqueValue As ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer) = CType(currentValueCollection(0), ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer)) Dim currentOneUniqueValue As ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer) = CType(currentValueCollection(1), ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer)) ' Get the symbol for each of the pairings Dim currentZeroSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol = CType(currentZeroUniqueValue.Symbol, ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol) Dim currentOneSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol = CType(currentOneUniqueValue.Symbol, ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol) ' Check which color combination was selected from the drop down box and reassign the colors ' on the SimpleMarkerSymbols accordingly Select Case selectedColor Case "Red_Blue" currentZeroSymbol.Color = System.Drawing.Color.Red currentOneSymbol.Color = System.Drawing.Color.Blue Case "Yellow_Green" currentZeroSymbol.Color = System.Drawing.Color.Yellow currentOneSymbol.Color = System.Drawing.Color.Green Case "Orange_Purple" currentZeroSymbol.Color = System.Drawing.Color.Orange currentOneSymbol.Color = System.Drawing.Color.Purple Case Else End Select ' Get a reference to the Toc control on the same page as the map. Note this code ' assumes the existence of a Toc control named "Toc1" and will throw an exception if ' there is no such control. Dim adfToc As ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc = CType(Utility.FindControl("Toc1", adfMap.Page), ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc) ' Refreshing the Toc control will add the new graphics layer to the Toc via ' the MapResourceManager --> Map --> Toc buddy relationship adfToc.Refresh() ' The Toc has callback results because of (a) the change in feature graphic symbology, ' and (b) the above call to Refresh. To update the Toc to reflect the new symbology of ' the feature graphics layer, we must copy these callback results to the Map because ' Web ADF DropDownBoxes only process the callback results of the Map. adfMap.CallbackResults.CopyFrom(adfToc.CallbackResults) ' Refresh the graphics resource so the feature graphic modifications are displayed adfMap.RefreshResource(graphicsMapFunctionality.Resource.Name) Catch exception As System.Exception Dim errorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = Utility.GetErrorCallback(exception) adfMap.CallbackResults.Add(errorCallbackResult) End Try End Sub #End Region End Class Public Class FeatureDropDownSymbol Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerDropDownBoxAction #Region "IServerAction Members" Private Sub ServerAction(ByVal toolbarItemInfo As ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo) Implements ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IServerAction.ServerAction ' Get a reference to the Map control via the BuddyControls array of the passed-in ' ToolbarItemInfo. Note this code assumes the desired map is at the first index ' of the array. Dim adfMap As ESRI.ArcGIS.ADF.Web.UI.WebControls.Map = CType(toolbarItemInfo.BuddyControls(0), ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) Try ' Get a reference to the color selection Web ADF drop down box Dim adfDropDownBox As ESRI.ArcGIS.ADF.Web.UI.WebControls.DropDownBox = CType(toolbarItemInfo.Toolbar.ToolbarItems.Find(toolbarItemInfo.Name), ESRI.ArcGIS.ADF.Web.UI.WebControls.DropDownBox) ' Retrieve the selected shape from the drop down box Dim selectedShape As String = adfDropDownBox.SelectedValue ' Retrieve the map functionality for the graphics resource Dim graphicsMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality = TryCast(adfMap.GetFunctionality("ADFGraphicsResource"), ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality) ' Make sure the graphics resource was found If graphicsMapFunctionality Is Nothing Then ' If the graphics resource was not found, use the ProcessError utility function ' to notify the user. This function creates a Web ADF callback result that ' specifies displaying a JavaScript alert with the passed-in text. We copy ' this callback result to the Map Control's callback results collection, because ' Web ADF Tools and Commands (and the classes that inherit from them) process ' callback results from the map after execution. adfMap.CallbackResults.CopyFrom (Utility.CreateErrorCallback("ADF graphics functionality not found")) Return End If ' Attempt to retrieve the feature graphics layer that will hold the feature point Dim featureGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer = Nothing If graphicsMapFunctionality.GraphicsDataSet.Tables.Contains("Feature Graphics") Then featureGraphicsLayer = TryCast(graphicsMapFunctionality.GraphicsDataSet.Tables("Feature Graphics"), ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer) End If ' Make sure the feature graphics layer was found If featureGraphicsLayer Is Nothing Then ' Initialize a string containing the JavaScript necessary to reset the drop down box's ' value to "Red_Blue" Dim jsResetDropDownList As String = String.Format("document.getElementById('{0}{1}{2}').value = 'Circle'", toolbarItemInfo.Toolbar.ClientID, adfDropDownBox.Name, adfDropDownBox.Type) ' Create a new ADF callback result containing the JavaScript Dim resetDropDownListCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript(jsResetDropDownList) ' Add the JavaScript callback result to the map so it is executed adfMap.CallbackResults.Add(resetDropDownListCallbackResult) ' Use the ProcessError utility method to add a callback to the map that will inform ' the user of the error adfMap.CallbackResults.CopyFrom (Utility.CreateErrorCallback("ADF feature graphics layer not found")) Return End If ' Get the ValueMapRenderer and ValueCollection from the feature graphics layer. This is where ' the symbol-value pairings are specified Dim currentValueMapRenderer As ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer(Of Integer) = CType(featureGraphicsLayer.Renderer, ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer(Of Integer)) Dim currentValueCollection As ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueCollection(Of Integer) = currentValueMapRenderer.Values ' Get the symbol-value pairings for values 0 and 1 from the ValueCollection. Each pairing ' is encapsulated in a UniqueValue object. Dim currentZeroUniqueValue As ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer) = CType(currentValueCollection(0), ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer)) Dim currentOneUniqueValue As ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer) = CType(currentValueCollection(1), ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue(Of Integer)) ' Get the symbol for each of the pairings Dim currentZeroSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol = CType(currentZeroUniqueValue.Symbol, ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol) Dim currentOneSymbol As ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol = CType(currentOneUniqueValue.Symbol, ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol) ' Check which shape was selected from the drop down box and reassign the shapes of the ' SimpleMarkerSymbols accordingly Select Case selectedShape Case "Circle" currentZeroSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Circle currentOneSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Circle Case "Star" currentZeroSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star currentOneSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star Case "Square" currentZeroSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Square currentOneSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Square Case Else End Select ' Get a reference to the Toc control on the same page as the map. Note this code ' assumes the existence of a Toc control named "Toc1" and will throw an exception if ' there is no such control. Dim adfToc As ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc = CType(Utility.FindControl("Toc1", adfMap.Page), ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc) ' Refreshing the Toc control will add the new graphics layer to the Toc via ' the MapResourceManager --> Map --> Toc buddy relationship adfToc.Refresh() ' The Toc has callback results because of (a) the change in feature graphic symbology, ' and (b) the above call to Refresh. To update the Toc to reflect the new symbology of ' the feature graphics layer, we must copy these callback results to the Map because ' Web ADF DropDownBoxes only process the callback results of the Map. adfMap.CallbackResults.CopyFrom(adfToc.CallbackResults) ' Refresh the graphics resource so the feature graphic modifications are displayed adfMap.RefreshResource(graphicsMapFunctionality.Resource.Name) Catch exception As System.Exception Dim errorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = Utility.GetErrorCallback(exception) adfMap.CallbackResults.Add(errorCallbackResult) End Try End Sub #End Region End Class End Namespace