Bug
Bug ID Number | NIM035583 |
---|---|
Submitted | May 27, 2008 |
Last Modified | June 5, 2024 |
Applies to | No Product Found |
Version found | 9.3 |
Version Fixed | N/A |
Status | Fixed |
To set the current tool when the application first initializes, add the following code to the PreRender event for the page in which the Map and Toolbar controls reside:
Code:
if (!IsPostBack)
{
// Set variables to Map and Toolbar controls in page.
// These references are merely provided for convenience.
ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap = Map1;
ESRI.ArcGIS.ADF.Web.UI.WebControls.Toolbar adfToolbar = Toolbar1;
// Use the Toolbar current tool to set the Map current tool
ESRI.ArcGIS.ADF.Web.UI.WebControls.MapToolItem mapToolItem =
adfMap.ToolItems.Find(adfToolbar.CurrentTool) as ESRI.ArcGIS.ADF.Web.UI.WebControls.MapToolItem;
adfMap.CurrentToolItem = mapToolItem;
string scriptKeyCustom = "customOnLoad";
if (!this.Page.ClientScript.IsStartupScriptRegistered(GetType(), scriptKeyCustom))
{
// Use ADF JavaScript to set the current tool for the map control on the client.
ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolbarItem toolbarItem =
adfToolbar.ToolbarItems.Find(adfToolbar.CurrentTool);
ESRI.ArcGIS.ADF.Web.UI.WebControls.Tool currentTool =
toolbarItem as ESRI.ArcGIS.ADF.Web.UI.WebControls.Tool;
string startupScript = string.Format(@"
function onLoadFunction(){{
var clientAction = Toolbars['{0}'].items['{1}'].clientAction;
var clientFunction = clientAction + ""('{2}', '{1}', {3}, '{4}')"";
eval(clientFunction);
}}
Sys.Application.add_load(onLoadFunction);",
adfToolbar.ClientID,
currentTool.Name,
adfMap.ClientID,
currentTool.ShowLoading.ToString().ToLower(),
currentTool.Cursor);
this.Page.ClientScript.RegisterStartupScript(GetType(), scriptKeyCustom, startupScript, true);
}
}
To set the current tool during an operation at runtime (e.g., return results from a task), use the following code as a guide:
Code:
// Current tool name
string newCurrentTool = "MapPan";
ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap = Map1;
ESRI.ArcGIS.ADF.Web.UI.WebControls.Toolbar adfToolbar = Toolbar1;
// Set Toolbar current tool - server
adfToolbar.CurrentTool = newCurrentTool;
ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolbarItem toolbarItem =
adfToolbar.ToolbarItems.Find(adfToolbar.CurrentTool);
ESRI.ArcGIS.ADF.Web.UI.WebControls.Tool currentTool =
toolbarItem as ESRI.ArcGIS.ADF.Web.UI.WebControls.Tool;
// Set Map Current tool - server
ESRI.ArcGIS.ADF.Web.UI.WebControls.MapToolItem mapToolItem =
adfMap.ToolItems.Find(adfToolbar.CurrentTool) as ESRI.ArcGIS.ADF.Web.UI.WebControls.MapToolItem;
adfMap.CurrentToolItem = mapToolItem;
// Set current tool on the client (sync toolbar and map controls in browser)
string setActiveToolScript = string.Format(@"
// Set toolbar current tool - client
var toolbar = Toolbars['{0}'];
var currentToolField = $get(toolbar.currentToolField);
currentToolField.value = '{1}';
toolbar.selectTool();
toolbar.refreshGroup();
// Set map current tool - server
var clientAction = toolbar.items['{1}'].clientAction;
var clientFunction = clientAction + ""('{2}', '{1}', {3}, '{4}')"";
eval(clientFunction);
",
adfToolbar.ClientID,
currentTool.Name,
adfMap.ClientID,
currentTool.ShowLoading.ToString().ToLower(),
currentTool.Cursor);
ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult cr =
ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript(setActiveToolScript);
Bug ID: NIM035583
Software:
Get help from ArcGIS experts
Download the Esri Support App