ArcGIS_SelectBufferTool_CSharp\Default.aspx.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 partial class _Default : System.Web.UI.Page { private ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection _callbackResultCollection = new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection(); private string _targetResourceName = "MapResourceItem0"; #region ASP.NET Web Page Events protected void Page_Load(object sender, System.EventArgs e) { ScriptManager1.RegisterAsyncPostBackControl(ClearAllButton); ClearAllButton.Click += new System.EventHandler(ClearAllButton_Click); } protected void Page_PreRender(object sender, System.EventArgs e) { try { // Initialize the target resource name session variable only if the page request is at the beginning // of a session if (Session.IsNewSession) Session["targetResourceName"] = _targetResourceName; // Make sure the page is not being rendered during a postback (i.e. is rendering during initial page // load or on page refresh) if (!IsPostBack) { // Create a query functionality object to use for retrieving the target resource's queryable layers ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality commonMapFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)Map1.GetFunctionality(_targetResourceName); ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisResource = commonMapFunctionality.Resource; ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality queryFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisResource.CreateFunctionality( typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null); // Retrieve the queryable layers string[] layerIDs = null; string[] layerNames = null; queryFunctionality.GetQueryableLayers(null, out layerIDs, out layerNames); // Add the queryable layers to the active layer drop-down list for (int i = 0; i < layerNames.Length; i++) activeLayerDropDownList.Items.Add(layerNames[i]); // Add all the ArcGIS Server unit types to the units drop-down list except for unknown, points, // and decimal degress System.Array agsUnitTypes = System.Enum.GetValues(typeof(ESRI.ArcGIS.ADF.Web.DataSources.Units)); foreach (int agsUnitType in agsUnitTypes) { string unit = agsUnitTypes.GetValue(agsUnitType).ToString(); if ((unit != "Unknown") && (unit != "DecimalDegrees") && (unit != "Points")) unitsDropDownList.Items.Add(unit); } } } catch (System.Exception exception) { string jsErrorAlertString = string.Format("<script>{0}</script>", Utility.GetJavaScriptErrorString(exception)); Response.Write(jsErrorAlertString); } } #endregion #region ASP.Net Web Controls events void ClearAllButton_Click(object sender, System.EventArgs e) { ClearGraphicsAndSelection(); } #endregion #region Instance Methods // Clears all selected features and removes all graphics from the target resource private void ClearGraphicsAndSelection() { // Get the map functionality of the target resource ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality agsMapFunctionality = Map1.GetFunctionality(_targetResourceName) as ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality; // Get the map description of the target resource and clear all graphics from it ESRI.ArcGIS.ADF.ArcGISServer.MapDescription agsSoapMapDescription = agsMapFunctionality.MapDescription; agsSoapMapDescription.CustomGraphics = null; // Iterate through each layer's layer description and clear all selected features // from each ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription[] agsSoapLayerDescriptionArray = agsSoapMapDescription.LayerDescriptions; foreach (ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription agsSoapLayerDescription in agsSoapLayerDescriptionArray) agsSoapLayerDescription.SelectionFeatures = null; // Refresh the target resource so the changes are displayed Map1.RefreshResource(_targetResourceName); _callbackResultCollection.CopyFrom(Map1.CallbackResults); ScriptManager1.RegisterDataItem(Page, _callbackResultCollection.ToString(), false); } #endregion }