Common_MapTips_CSharp\App_Code\MapTipsLayerMenu.cs
// 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. // public class MapTipsLayerMenu : 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 the Web ADF Map ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap = toolbarItemInfo.BuddyControls[0] as ESRI.ArcGIS.ADF.Web.UI.WebControls.Map; // Get the DropDownBox containing the layer names ESRI.ArcGIS.ADF.Web.UI.WebControls.DropDownBox dropDownBox = toolbarItemInfo.Toolbar.ToolbarItems.Find("DropDownBox0") as ESRI.ArcGIS.ADF.Web.UI.WebControls.DropDownBox; // Get the MapTips control that will be used to show MapTips on the selected layer ESRI.ArcGIS.ADF.Web.UI.WebControls.MapTips mapTips = ESRI.ArcGIS.ADF.Web.UI.WebControls.Utility.FindControl("MapTips1", adfMap.Page) as ESRI.ArcGIS.ADF.Web.UI.WebControls.MapTips; // Get the selected layer name string layerName = dropDownBox.SelectedItem.Text; if (layerName == "- Select MapTips Layer -") return; // Get the ID of the selected layer and the name of the resource item containing that layer string[] resourceNameAndLayerID = dropDownBox.SelectedItem.Value.Split(':'); // Update the MapTips Layer property mapTips.Layer = string.Format("{0}::{1}::{2}", adfMap.MapResourceManager, resourceNameAndLayerID[0], layerName); // Retrieve the layer format of the selected layer and apply it to the MapTips control ESRI.ArcGIS.ADF.Web.UI.WebControls.LayerFormat layerFormat = ESRI.ArcGIS.ADF.Web.UI.WebControls.LayerFormat.FromMapResourceManager(adfMap.MapResourceManagerInstance, resourceNameAndLayerID[0], resourceNameAndLayerID[1]); #region Only necessary for 9.3 final ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem mapResourceItem = adfMap.MapResourceManagerInstance.ResourceItems.Find(mapTips.ResourceName); System.Collections.Generic.Dictionary<string, ESRI.ArcGIS.ADF.Web.UI.WebControls.LayerFormat> layerFormatDictionary = new System.Collections.Generic.Dictionary<string, ESRI.ArcGIS.ADF.Web.UI.WebControls.LayerFormat>(); // Iterate through the resource's layer definitions and add each one's ID and LayerFormat to the // dictionary foreach (ESRI.ArcGIS.ADF.Web.UI.WebControls.LayerDefinition layerDefinition in mapResourceItem.LayerDefinitions) layerFormatDictionary.Add(layerDefinition.ID, layerDefinition.LayerFormat); // Set the resource's layer definitions to null to force full re-initialization mapResourceItem.LayerDefinitions = null; // Since the re-initialization will revert the layers to their default LayerFormats, explicitly // re-apply the stored LayerFormats foreach (string layerID in layerFormatDictionary.Keys) mapResourceItem.LayerDefinitions[layerID].LayerFormat = layerFormatDictionary[layerID]; #endregion mapTips.LayerFormat = layerFormat; // Refresh the MapTips and the resource on which MapTips are to be shown to apply the changes mapTips.RefreshMapTips(); adfMap.RefreshResource(mapTips.ResourceName); } #endregion }