Common_AddGraphics_CSharp\App_Code\GraphicPointTools.cs
// 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. // namespace AddPoint { public class ElementGraphicTool : ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction { #region IMapServerToolAction Members void ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction( ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs toolEventArgs) { // Get a reference to the map control by casting the event aarguments object to a Map ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)toolEventArgs.Control; 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 ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs mapPointEventArgs = (ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs)toolEventArgs; ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint = mapPointEventArgs.MapPoint; // Retrieve the map functionality for the graphics resource ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality graphicsMapFunctionality = adfMap.GetFunctionality("ADFGraphicsResource") as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality; // Make sure the graphics resource was found if (graphicsMapFunctionality == null) { // 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; } // Attempt to retrieve the element graphics layer that will hold the graphic point ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer = null; if (graphicsMapFunctionality.GraphicsDataSet.Tables.Contains("Element Graphics")) elementGraphicsLayer = graphicsMapFunctionality.GraphicsDataSet.Tables["Element Graphics"] as ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer; // Check whether the element graphics layer was found. If not, create it. if (elementGraphicsLayer == null) { // 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. ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc adfToc = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc)Utility.FindControl("Toc1", adfMap.Page); // 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); } // 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 ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol defaultSimpleMarkerSymbol = 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 ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol selectedSimpleMarkerSymbol = 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 ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement 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 (System.Exception exception) { ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult errorCallbackResult = Utility.GetErrorCallback(exception); adfMap.CallbackResults.Add(errorCallbackResult); } } #endregion } public class FeatureGraphicTool : ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction { #region IMapServerToolAction Members void ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction( ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs toolEventArgs) { // Get a reference to the map control by casting the event aarguments object to a Map ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)toolEventArgs.Control; 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 ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs mapPointEventArgs = (ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs)toolEventArgs; ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint = mapPointEventArgs.MapPoint; // Retrieve the map functionality for the graphics resource ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality graphicsMapFunctionality = adfMap.GetFunctionality("ADFGraphicsResource") as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality; // Make sure the graphics resource was found if (graphicsMapFunctionality == null) { // 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; } // Attempt to retrieve the feature graphics layer that will hold the feature point ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer featureGraphicsLayer = null; if (graphicsMapFunctionality.GraphicsDataSet.Tables.Contains("Feature Graphics")) featureGraphicsLayer = graphicsMapFunctionality.GraphicsDataSet.Tables["Feature Graphics"] as ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer; // Check whether the feature graphics layer was found. If not, create it. if (featureGraphicsLayer == null) { // 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 System.Data.DataColumn xDataColumn = new System.Data.DataColumn("X", System.Type.GetType("System.Double")); featureGraphicsLayer.Columns.Add(xDataColumn); // Create a Y column System.Data.DataColumn yDataColumn = new System.Data.DataColumn("Y", System.Type.GetType("System.Double")); featureGraphicsLayer.Columns.Add(yDataColumn); // Create a "CustomDataColumn" column System.Data.DataColumn customDataColumn = 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 ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int> zeroUniqueValue = new ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int>(0); // Create and initialize a SimpleMarkerSymbol to specify the appearance of // graphics with a value of 0 ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol zeroSymbol = 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. ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int> oneUniqueValue = new ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int>(1); // Create and initialize a SimpleMarkerSymbol to specify the appearance of // graphics with a value of 1 ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol oneSymbol = 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 ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol defaultSimpleMarkerSymbol = 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 ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer<int> valueMapRenderer = new ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer<int>(); // 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 ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueCollection<int> valueCollection = 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. ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc adfToc = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc)Utility.FindControl("Toc1", adfMap.Page); // 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. //System.Web.UI.WebControls.CheckBox maptipscheckbox = adfMap.Page.FindControl("maptipsCheckBox") as System.Web.UI.WebControls.CheckBox; string jsEnableCheckbox = string.Format("document.getElementById('{0}').disabled = false", "maptipsCheckbox");//.ClientID); ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult enableCheckboxCallbackResult = 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); } // Add the clicked map point to the feature graphics layer and get a reference to // the row created in the underlying DataTable System.Data.DataRow newDataRow = 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) System.Random randomizer = 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. int randomValue = 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 System.Data.DataColumn selectedColumn = 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 (System.Exception exception) { ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult errorCallbackResult = Utility.GetErrorCallback(exception); adfMap.CallbackResults.Add(errorCallbackResult); } } #endregion } public class FeatureDropDownColor : ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerDropDownBoxAction { #region IServerAction Members void ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IServerAction.ServerAction( ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo toolbarItemInfo) { // 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. ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)toolbarItemInfo.BuddyControls[0]; try { // Get a reference to the color selection Web ADF drop down box ESRI.ArcGIS.ADF.Web.UI.WebControls.DropDownBox adfDropDownBox = (ESRI.ArcGIS.ADF.Web.UI.WebControls.DropDownBox)toolbarItemInfo.Toolbar.ToolbarItems.Find( toolbarItemInfo.Name); // Retrieve the selected color from the drop down box string selectedColor = adfDropDownBox.SelectedValue; // Retrieve the map functionality for the graphics resource ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality graphicsMapFunctionality = adfMap.GetFunctionality("ADFGraphicsResource") as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality; // Make sure the graphics resource was found if (graphicsMapFunctionality == null) { // 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; } // Attempt to retrieve the feature graphics layer for which symbology will be modified ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer featureGraphicsLayer = null; if (graphicsMapFunctionality.GraphicsDataSet.Tables.Contains("Feature Graphics")) featureGraphicsLayer = graphicsMapFunctionality.GraphicsDataSet.Tables["Feature Graphics"] as ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer; // Make sure the feature graphics layer was found if (featureGraphicsLayer == null) { // Initialize a string containing the JavaScript necessary to reset the drop down box's // value to "Red_Blue" string jsResetDropDownList = 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 ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult resetDropDownListCallbackResult = 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; } // Get the ValueMapRenderer and ValueCollection from the feature graphics layer. This is where // the symbol-value pairings are specified ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer<int> currentValueMapRenderer = (ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer<int>)featureGraphicsLayer.Renderer; ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueCollection<int> currentValueCollection = currentValueMapRenderer.Values; // Get the symbol-value pairings for values 0 and 1 from the ValueCollection. Each pairing // is encapsulated in a UniqueValue object. ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int> currentZeroUniqueValue = (ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int>)currentValueCollection[0]; ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int> currentOneUniqueValue = (ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int>)currentValueCollection[1]; // Get the symbol for each of the pairings ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol currentZeroSymbol = (ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol)currentZeroUniqueValue.Symbol; ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol currentOneSymbol = (ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol)currentOneUniqueValue.Symbol; // Check which color combination was selected from the drop down box and reassign the colors // on the SimpleMarkerSymbols accordingly switch (selectedColor) { case "Red_Blue": currentZeroSymbol.Color = System.Drawing.Color.Red; currentOneSymbol.Color = System.Drawing.Color.Blue; break; case "Yellow_Green": currentZeroSymbol.Color = System.Drawing.Color.Yellow; currentOneSymbol.Color = System.Drawing.Color.Green; break; case "Orange_Purple": currentZeroSymbol.Color = System.Drawing.Color.Orange; currentOneSymbol.Color = System.Drawing.Color.Purple; break; default: break; } // 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. ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc adfToc = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc)Utility.FindControl("Toc1", adfMap.Page); // 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 (System.Exception exception) { ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult errorCallbackResult = Utility.GetErrorCallback(exception); adfMap.CallbackResults.Add(errorCallbackResult); } } #endregion } public class FeatureDropDownSymbol : ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerDropDownBoxAction { #region IServerAction Members void ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IServerAction.ServerAction( ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.ToolbarItemInfo toolbarItemInfo) { // 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. ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)toolbarItemInfo.BuddyControls[0]; try { // Get a reference to the color selection Web ADF drop down box ESRI.ArcGIS.ADF.Web.UI.WebControls.DropDownBox adfDropDownBox = (ESRI.ArcGIS.ADF.Web.UI.WebControls.DropDownBox)toolbarItemInfo.Toolbar.ToolbarItems.Find( toolbarItemInfo.Name); // Retrieve the selected shape from the drop down box string selectedShape = adfDropDownBox.SelectedValue; // Retrieve the map functionality for the graphics resource ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality graphicsMapFunctionality = adfMap.GetFunctionality("ADFGraphicsResource") as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality; // Make sure the graphics resource was found if (graphicsMapFunctionality == null) { // 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; } // Attempt to retrieve the feature graphics layer that will hold the feature point ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer featureGraphicsLayer = null; if (graphicsMapFunctionality.GraphicsDataSet.Tables.Contains("Feature Graphics")) featureGraphicsLayer = graphicsMapFunctionality.GraphicsDataSet.Tables["Feature Graphics"] as ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer; // Make sure the feature graphics layer was found if (featureGraphicsLayer == null) { // Initialize a string containing the JavaScript necessary to reset the drop down box's // value to "Red_Blue" string jsResetDropDownList = 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 ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult resetDropDownListCallbackResult = 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; } // Get the ValueMapRenderer and ValueCollection from the feature graphics layer. This is where // the symbol-value pairings are specified ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer<int> currentValueMapRenderer = (ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer<int>)featureGraphicsLayer.Renderer; ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueCollection<int> currentValueCollection = currentValueMapRenderer.Values; // Get the symbol-value pairings for values 0 and 1 from the ValueCollection. Each pairing // is encapsulated in a UniqueValue object. ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int> currentZeroUniqueValue = (ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int>)currentValueCollection[0]; ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int> currentOneUniqueValue = (ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int>)currentValueCollection[1]; // Get the symbol for each of the pairings ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol currentZeroSymbol = (ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol)currentZeroUniqueValue.Symbol; ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol currentOneSymbol = (ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol)currentOneUniqueValue.Symbol; // Check which shape was selected from the drop down box and reassign the shapes of the // SimpleMarkerSymbols accordingly switch (selectedShape) { case "Circle": currentZeroSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Circle; currentOneSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Circle; break; case "Star": currentZeroSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star; currentOneSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star; break; case "Square": currentZeroSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Square; currentOneSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Square; break; default: break; } // 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. ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc adfToc = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Toc)Utility.FindControl("Toc1", adfMap.Page); // 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 (System.Exception exception) { ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult errorCallbackResult = Utility.GetErrorCallback(exception); adfMap.CallbackResults.Add(errorCallbackResult); } } #endregion } }